From 8f9401008e5f55010b5af37959ea2dc2173671c8 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Tue, 28 Nov 2023 08:34:46 -0800 Subject: [PATCH 1/4] Emit ".exe" for functions from NetFX entry point assemblies --- sdk/Sdk.Generators/Constants.cs | 1 + ...unctionMetadataProviderGenerator.Parser.cs | 8 +++---- .../FunctionMetadataProviderGenerator.cs | 21 ++++++++++++++++--- .../FunctionsMetadataParsingContext.cs | 10 +++++++++ ...Microsoft.Azure.Functions.Worker.Sdk.props | 1 + 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionsMetadataParsingContext.cs diff --git a/sdk/Sdk.Generators/Constants.cs b/sdk/Sdk.Generators/Constants.cs index c64b01633..68a25a127 100644 --- a/sdk/Sdk.Generators/Constants.cs +++ b/sdk/Sdk.Generators/Constants.cs @@ -12,6 +12,7 @@ internal static class Languages internal static class BuildProperties { + internal const string MSBuildTargetFrameworkIdentifier = "build_property.TargetFrameworkIdentifier"; internal const string MSBuildRootNamespace = "build_property.RootNamespace"; internal const string GeneratedCodeNamespace = "build_property.FunctionsGeneratedCodeNamespace"; internal const string EnableSourceGen = "build_property.FunctionsEnableMetadataSourceGen"; diff --git a/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs index 3a49c95a1..f52016db1 100644 --- a/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs +++ b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionMetadataProviderGenerator.Parser.cs @@ -40,7 +40,8 @@ public Parser(GeneratorExecutionContext context) /// Takes in candidate methods from the user compilation and parses them to return function metadata info as GeneratorFunctionMetadata. /// /// List of candidate methods from the syntax receiver. - public IReadOnlyList GetFunctionMetadataInfo(List methods) + /// An instance of . Optional. + public IReadOnlyList GetFunctionMetadataInfo(List methods, FunctionsMetadataParsingContext? genContext = null) { var result = ImmutableArray.CreateBuilder(); @@ -49,14 +50,13 @@ public IReadOnlyList GetFunctionMetadataInfo(List functionMetadataInfo = p.GetFunctionMetadataInfo(entryAssemblyFuncs.Concat(dependentFuncs).ToList()); + var entryAssemblyParsingContext = new FunctionsMetadataParsingContext + { + ScriptFileExtension = GetScriptFileExtensionForEntryPointAssemblyFunctions(context) + }; + var entryAssemblyFunctions = p.GetFunctionMetadataInfo(entryAssemblyFunctionSymbols.ToList(), entryAssemblyParsingContext); + var dependentAssemblyFunctions = p.GetFunctionMetadataInfo(dependentAssemblyFunctionSymbols.ToList()); + + var functionMetadataInfo = entryAssemblyFunctions.Concat(dependentAssemblyFunctions).ToList(); // Proceed to generate the file if function metadata info was successfully returned if (functionMetadataInfo.Count > 0) @@ -63,6 +71,13 @@ public void Initialize(GeneratorInitializationContext context) context.RegisterForSyntaxNotifications(() => new FunctionMethodSyntaxReceiver()); } + private static string GetScriptFileExtensionForEntryPointAssemblyFunctions(GeneratorExecutionContext context) + { + context.AnalyzerConfigOptions.GlobalOptions.TryGetValue(Constants.BuildProperties.MSBuildTargetFrameworkIdentifier, out var value); + + return string.Equals(value, ".NETFramework", StringComparison.OrdinalIgnoreCase) ? ".exe" : ".dll"; + } + private static bool ShouldIncludeAutoGeneratedAttributes(GeneratorExecutionContext context) { if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue( diff --git a/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionsMetadataParsingContext.cs b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionsMetadataParsingContext.cs new file mode 100644 index 000000000..475ac737e --- /dev/null +++ b/sdk/Sdk.Generators/FunctionMetadataProviderGenerator/FunctionsMetadataParsingContext.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information.; + +namespace Microsoft.Azure.Functions.Worker.Sdk.Generators +{ + internal sealed class FunctionsMetadataParsingContext + { + public string? ScriptFileExtension { get; set; } + } +} diff --git a/sdk/Sdk/Targets/Microsoft.Azure.Functions.Worker.Sdk.props b/sdk/Sdk/Targets/Microsoft.Azure.Functions.Worker.Sdk.props index d24ff04fb..d7e98339a 100644 --- a/sdk/Sdk/Targets/Microsoft.Azure.Functions.Worker.Sdk.props +++ b/sdk/Sdk/Targets/Microsoft.Azure.Functions.Worker.Sdk.props @@ -26,6 +26,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and +