Skip to content

Commit eef3aab

Browse files
authored
Restore functions.metadata generation (#3246)
Reversed suppression of `functions.metadata` file generation in the SDK targets file, restoring default behavior.
1 parent 85b603f commit eef3aab

File tree

12 files changed

+216
-286
lines changed

12 files changed

+216
-286
lines changed

sdk/Sdk/Targets/Microsoft.Azure.Functions.Worker.Sdk.targets

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
4848
<FunctionsEnablePlaceholder Condition="'$(FunctionsEnablePlaceholder)' == ''">false</FunctionsEnablePlaceholder>
4949
<FunctionsEnableWorkerIndexing Condition="'$(FunctionsEnableWorkerIndexing)' == ''">true</FunctionsEnableWorkerIndexing>
5050
<FunctionsEnableMetadataSourceGen>$(FunctionsEnableWorkerIndexing)</FunctionsEnableMetadataSourceGen>
51-
<FunctionsAutoRegisterGeneratedMetadataProvider>$(FunctionsEnableWorkerIndexing)</FunctionsAutoRegisterGeneratedMetadataProvider>
52-
<FunctionsWriteMetadataJson Condition="'$(FunctionsWriteMetadataJson)' == '' AND '$(FunctionsEnableMetadataSourceGen)' == 'true'">false</FunctionsWriteMetadataJson>
53-
<FunctionsWriteMetadataJson Condition="'$(FunctionsWriteMetadataJson)' == ''">true</FunctionsWriteMetadataJson>
51+
<FunctionsAutoRegisterGeneratedMetadataProvider>$(FunctionsEnableWorkerIndexing)</FunctionsAutoRegisterGeneratedMetadataProvider>
5452

5553
<FunctionsEnableExecutorSourceGen Condition="'$(FunctionsEnableExecutorSourceGen)' == ''">true</FunctionsEnableExecutorSourceGen>
5654
<FunctionsAutoRegisterGeneratedFunctionsExecutor Condition="'$(FunctionsAutoRegisterGeneratedFunctionsExecutor)' == ''">true</FunctionsAutoRegisterGeneratedFunctionsExecutor>
@@ -193,10 +191,9 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
193191
ReferencePaths="@(ReferencePath)"
194192
ExtensionsCsProjFilePath="$(ExtensionsCsProj)"
195193
AzureFunctionsVersion="$(AzureFunctionsVersion)"
196-
WriteMetadataFile="$(FunctionsWriteMetadataJson)"
197194
TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)"
198195
TargetFrameworkVersion="$(TargetFrameworkVersion)"
199-
OutputPath="$(IntermediateOutputPath)" />
196+
OutputPath="$(IntermediateOutputPath)"/>
200197
</Target>
201198

202199
<!-- Generate worker.config.json. -->
@@ -250,8 +247,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
250247

251248
<!-- Hook all these files into CopyToOutputDirectory by appending to _NoneWithTargetPath. -->
252249
<ItemGroup>
253-
<_FunctionsAdditionalFile Include="$(_FunctionsMetadataPath)" Condition="'$(FunctionsWriteMetadataJson)' == 'true'" />
254-
<_FunctionsAdditionalFile Include="$(_FunctionsWorkerConfigPath);$(_FunctionsIntermediateExtensionUpdatedJsonPath)" />
250+
<_FunctionsAdditionalFile Include="$(_FunctionsMetadataPath);$(_FunctionsWorkerConfigPath);$(_FunctionsIntermediateExtensionUpdatedJsonPath)" />
255251
<_FunctionsAdditionalFile Include="$(_FunctionsMetadataLoaderExtensionFile)" SubPath="$(_FunctionsExtensionsDirectory)/" />
256252
<_NoneWithTargetPath Include="@(_FunctionsAdditionalFile)"
257253
TargetPath="%(_FunctionsAdditionalFile.SubPath)%(Filename)%(Extension)"

sdk/Sdk/Tasks/GenerateFunctionMetadata.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public class GenerateFunctionMetadata : Task
2626

2727
public string? ExtensionsCsProjFilePath { get; set; }
2828

29-
public bool WriteMetadataFile { get; set; } = true;
30-
3129
[Required]
3230
public ITaskItem[]? ReferencePaths { get; set; }
3331

@@ -69,18 +67,11 @@ public override bool Execute()
6967

7068
private void WriteMetadataWithRetry(IEnumerable<SdkFunctionMetadata> functions)
7169
{
72-
if (!WriteMetadataFile)
73-
{
74-
Log.LogMessage("Skipping writing function metadata file.");
75-
return;
76-
}
77-
7870
int attempt = 0;
7971
while (attempt < 10)
8072
{
8173
try
8274
{
83-
Log.LogMessage($"Writing function metadata to {OutputPath} directory.");
8475
FunctionMetadataJsonWriter.WriteMetadata(functions, OutputPath!);
8576
break;
8677
}

sdk/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
- My change description (#PR/#issue)
55
-->
66

7-
### Microsoft.Azure.Functions.Worker.Sdk <version>
7+
### Microsoft.Azure.Functions.Worker.Sdk 2.0.7
88

9-
- <entry>
9+
- Reversal of change to suppress generation of functions.metadata file
1010

1111
### Microsoft.Azure.Functions.Worker.Sdk.Generators <version>
1212

test/E2ETests/E2ETests/AspNetCore/CancellationEndToEndTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public async Task HttpTriggerFunctions_WithCancellationToken_BehaveAsExpected(st
3737
await TestUtility.RetryAsync(() =>
3838
{
3939
invocationStartLog = _fixture.TestLogs.CoreToolsLogs.Where(p => p.Contains($"Executing 'Functions.{functionName}'"));
40-
return Task.FromResult(invocationStartLog.Any());
40+
return Task.FromResult(invocationStartLog.Count() >= 1);
4141
});
4242

43-
// The task should be cancelled before it completes, mimicking a client closing the connection.
43+
// The task should be cancelled before it completes, mimicing a client closing the connection.
4444
// This should lead to the worker getting an InvocationCancel request from the functions host
4545
cts.Cancel();
4646
await Assert.ThrowsAsync<TaskCanceledException>(async () => await task);
@@ -49,13 +49,13 @@ await TestUtility.RetryAsync(() =>
4949
await TestUtility.RetryAsync(() =>
5050
{
5151
invocationEndLog = _fixture.TestLogs.CoreToolsLogs.Where(p => p.Contains($"Executed 'Functions.{functionName}'"));
52-
return Task.FromResult(invocationEndLog.Any());
52+
return Task.FromResult(invocationEndLog.Count() >= 1);
5353
});
5454

5555
Assert.Contains(_fixture.TestLogs.CoreToolsLogs, log => log.Contains(expectedMessage, StringComparison.OrdinalIgnoreCase));
5656

5757
// TODO: 2/3 of the test invocations will fail until the host with the ForwarderProxy fix is released - uncomment this line when the fix is released
58-
Assert.NotNull(invocationResult); // just here to 'use' invocationResult to avoid a warning.
58+
Assert.NotEqual(null, invocationResult); // just here to 'use' invocationResult to avoid a warning.
5959
// Assert.Contains(_fixture.TestLogs.CoreToolsLogs, log => log.Contains($"'Functions.{functionName}' ({invocationResult}", StringComparison.OrdinalIgnoreCase));
6060
}
6161

test/E2ETests/E2ETests/Fixtures/FunctionAppFixture.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ namespace Microsoft.Azure.Functions.Tests.E2ETests
1717
{
1818
public class FunctionAppFixture : IAsyncLifetime
1919
{
20-
private readonly string _testApp = Constants.TestAppNames.E2EApp;
2120
private readonly ILogger _logger;
2221
private bool _disposed;
2322
private Process _funcProcess;
2423
private JobObjectRegistry _jobObjectRegistry;
24+
private string _testApp = Constants.TestAppNames.E2EApp;
2525

2626
public FunctionAppFixture(IMessageSink messageSink)
2727
{
@@ -32,8 +32,7 @@ public FunctionAppFixture(IMessageSink messageSink)
3232
_logger = loggerFactory.CreateLogger<FunctionAppFixture>();
3333
}
3434

35-
internal FunctionAppFixture(IMessageSink messageSink, string testApp)
36-
: this(messageSink)
35+
internal FunctionAppFixture(IMessageSink messageSink, string testApp) : this(messageSink)
3736
{
3837
_testApp = testApp;
3938
}

test/Sdk.E2ETests/InnerBuildTests.cs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
54
using System.IO;
65
using System.Threading.Tasks;
76
using Newtonsoft.Json.Linq;
@@ -10,27 +9,25 @@
109

1110
namespace Microsoft.Azure.Functions.Sdk.E2ETests
1211
{
13-
public sealed class InnerBuildTests(ITestOutputHelper testOutputHelper) : IDisposable
12+
public class InnerBuildTests
1413
{
15-
private readonly ProjectBuilder _builder = new(
16-
testOutputHelper,
17-
Path.Combine(TestUtility.TestResourcesProjectsRoot, "FunctionApp01", "FunctionApp01.csproj"));
14+
private readonly ITestOutputHelper _testOutputHelper;
1815

19-
[Theory]
20-
[InlineData("", false)]
21-
[InlineData("-p:FunctionsEnableWorkerIndexing=true", false)]
22-
[InlineData("-p:FunctionsEnableWorkerIndexing=true -p:FunctionsWriteMetadataJson=false", false)]
23-
[InlineData("-p:FunctionsEnableWorkerIndexing=true -p:FunctionsWriteMetadataJson=true", true)]
24-
[InlineData("-p:FunctionsEnableWorkerIndexing=false", true)]
25-
[InlineData("-p:FunctionsEnableWorkerIndexing=false -p:FunctionsWriteMetadataJson=false", false)]
26-
[InlineData("-p:FunctionsEnableWorkerIndexing=false -p:FunctionsWriteMetadataJson=true", true)]
27-
public async Task Build_ScansReferences(string parameters, bool metadataGenerated)
16+
public InnerBuildTests(ITestOutputHelper testOutputHelper)
2817
{
29-
await _builder.RestoreAsync();
30-
await _builder.BuildAsync(parameters, restore: false);
18+
_testOutputHelper = testOutputHelper;
19+
}
20+
21+
[Fact]
22+
public async Task Build_ScansReferences()
23+
{
24+
string outputDir = await TestUtility.InitializeTestAsync(_testOutputHelper, nameof(Build_ScansReferences));
25+
string projectFileDirectory = Path.Combine(TestUtility.TestResourcesProjectsRoot, "FunctionApp01", "FunctionApp01.csproj");
26+
27+
await TestUtility.RestoreAndBuildProjectAsync(projectFileDirectory, outputDir, null, _testOutputHelper);
3128

3229
// Verify extensions.json contents
33-
string extensionsJsonPath = Path.Combine(_builder.OutputPath, "extensions.json");
30+
string extensionsJsonPath = Path.Combine(outputDir, "extensions.json");
3431
Assert.True(File.Exists(extensionsJsonPath));
3532

3633
JToken extensionsJsonContents = JObject.Parse(File.ReadAllText(extensionsJsonPath));
@@ -57,13 +54,8 @@ public async Task Build_ScansReferences(string parameters, bool metadataGenerate
5754
Assert.True(JToken.DeepEquals(expectedExtensionsJson, extensionsJsonContents));
5855

5956
// Verify functions.metadata contents
60-
string functionsMetadataPath = Path.Combine(_builder.OutputPath, "functions.metadata");
61-
Assert.Equal(metadataGenerated, File.Exists(functionsMetadataPath));
62-
63-
if (!metadataGenerated)
64-
{
65-
return;
66-
}
57+
string functionsMetadataPath = Path.Combine(outputDir, "functions.metadata");
58+
Assert.True(File.Exists(functionsMetadataPath));
6759

6860
JToken functionsMetadataContents = JArray.Parse(File.ReadAllText(functionsMetadataPath));
6961
JToken expectedFunctionsMetadata = JArray.Parse(@"[
@@ -123,7 +115,5 @@ public async Task Build_ScansReferences(string parameters, bool metadataGenerate
123115

124116
Assert.True(JToken.DeepEquals(expectedFunctionsMetadata, functionsMetadataContents));
125117
}
126-
127-
public void Dispose() => _builder.Dispose();
128118
}
129119
}

test/Sdk.E2ETests/ProcessWrapper.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66
using System.Text;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using Xunit.Abstractions;
910

1011
namespace Microsoft.Azure.Functions.Sdk.E2ETests
1112
{
12-
public static class ProcessWrapper
13+
public class ProcessWrapper
1314
{
14-
public static async Task<int?> RunProcessAsync(
15-
string fileName, string arguments, string workingDirectory = null, Action<string> log = null)
15+
16+
public async Task<int?> RunProcess(string fileName, string arguments, string workingDirectory, ITestOutputHelper testOutputHelper = null)
1617
{
17-
return await RunProcessInternalAsync(fileName, arguments, workingDirectory, log);
18+
return await RunProcessInternal(fileName, arguments, workingDirectory, testOutputHelper);
1819
}
1920

20-
public static async Task<Tuple<int?, string>> RunProcessForOutputAsync(
21-
string fileName, string arguments, string workingDirectory = null, Action<string> log = null)
21+
public async Task<Tuple<int?, string>> RunProcessForOutput(string fileName, string arguments, string workingDirectory, ITestOutputHelper testOutputHelper = null)
2222
{
2323
StringBuilder processOutputStringBuilder = new StringBuilder();
24-
var exitCode = await RunProcessInternalAsync(fileName, arguments, workingDirectory, log, processOutputStringBuilder);
24+
var exitCode = await RunProcessInternal(fileName, arguments, workingDirectory, testOutputHelper, processOutputStringBuilder);
2525
return new Tuple<int?,string>(exitCode, processOutputStringBuilder.ToString());
2626
}
2727

28-
private static async Task<int?> RunProcessInternalAsync(
29-
string fileName, string arguments, string workingDirectory = null, Action<string> log = null, StringBuilder processOutputBuilder = null)
28+
private async Task<int?> RunProcessInternal(string fileName, string arguments, string workingDirectory, ITestOutputHelper testOutputHelper = null, StringBuilder processOutputBuilder = null)
3029
{
3130

3231
SemaphoreSlim processExitSemaphore = new SemaphoreSlim(0, 1);
@@ -54,17 +53,23 @@ public static class ProcessWrapper
5453
{
5554
if (o.Data != null)
5655
{
57-
log?.Invoke($"[{DateTime.UtcNow:O}] Error: {o.Data}");
58-
processOutputBuilder?.AppendLine(o.Data);
56+
testOutputHelper.WriteLine($"[{DateTime.UtcNow:O}] Error: {o.Data}");
57+
if (processOutputBuilder != null)
58+
{
59+
processOutputBuilder.AppendLine(o.Data);
60+
}
5961
}
6062
};
6163

6264
testProcess.OutputDataReceived += (s, o) =>
6365
{
6466
if (o.Data != null)
6567
{
66-
log?.Invoke($"[{DateTime.UtcNow:O}] {o.Data}");
67-
processOutputBuilder?.AppendLine(o.Data);
68+
testOutputHelper.WriteLine($"[{DateTime.UtcNow:O}] {o.Data}");
69+
if (processOutputBuilder != null)
70+
{
71+
processOutputBuilder.AppendLine(o.Data);
72+
}
6873
}
6974
};
7075

@@ -76,7 +81,7 @@ public static class ProcessWrapper
7681
int wait = 3 * 60 * 1000;
7782
if (!await processExitSemaphore.WaitAsync(wait))
7883
{
79-
log?.Invoke($"Process '{testProcess.Id}' did not exit in {wait}ms.");
84+
testOutputHelper?.WriteLine($"Process '{testProcess.Id}' did not exit in {wait}ms.");
8085
testProcess.Kill();
8186
}
8287

test/Sdk.E2ETests/ProjectBuilder.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)