From 83002aba254836ddfd851602769a2a2c58f84102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 13:14:35 +0200 Subject: [PATCH 1/8] More relaxed regex to check fingerprint --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 52c6c3c3d5ed2..42e38fe1b24e9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -856,12 +856,12 @@ void AssertFileExists(string fileName) Assert.True(File.Exists(absolutePath), $"Expected to find '{absolutePath}'"); } - string versionHashRegex = @"\d.0.\d?(-[a-z]+(\.\d\.\d+\.\d)?)?\.([a-zA-Z0-9])+"; + string versionHashRegex = @"\.(?.+)\.(?[a-zA-Z0-9]+)\."; Assert.Collection( dotnetJsEntries.OrderBy(f => f), - item => { Assert.Equal(expectFingerprinting ? $"dotnet\\.{versionHashRegex}\\.js" : "dotnet.js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.native\\.{versionHashRegex}\\.js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.runtime\\.{versionHashRegex}\\.js", item); AssertFileExists(item); } + item => { Assert.Equal(expectFingerprinting ? $"dotnet{versionHashRegex}js" : "dotnet.js", item); AssertFileExists(item); }, + item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); }, + item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); } ); } } From 29a542f36b8aeee517ac9987385f763e2d97256c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 13:14:59 +0200 Subject: [PATCH 2/8] Test .NET 7.0 fingerprinting --- .../Blazor/BuildPublishTests.cs | 32 +++++++++-------- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 34 ++++++++++++++----- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 8a021a68f1c37..ec1c21d9756b8 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -65,15 +65,17 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config) } [Theory] - [InlineData("Debug")] - [InlineData("Release")] - public void DefaultTemplate_BuildNative_WithWorkload(string config) + [InlineData("Debug", "net8.0")] + [InlineData("Release", "net8.0")] + [InlineData("Debug", "net7.0")] + [InlineData("Release", "net7.0")] + public void DefaultTemplate_BuildNative_WithWorkload(string config, string targetFramework) { string id = $"blz_buildandbuildnative_{config}_{Path.GetRandomFileName()}"; - CreateBlazorWasmTemplateProject(id); + CreateBlazorWasmTemplateProject(id, targetFramework); - BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked), "/p:WasmBuildNative=true"); + BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked) { TargetFramework = targetFramework }, "/p:WasmBuildNative=true"); } // Disabling for now - publish folder can have more than one dotnet*hash*js, and not sure @@ -83,18 +85,18 @@ public void DefaultTemplate_BuildNative_WithWorkload(string config) //[InlineData("Release")] //public void DefaultTemplate_AOT_OnlyWithPublishCommandLine_Then_PublishNoAOT(string config) //{ - //string id = $"blz_aot_pub_{config}"; - //CreateBlazorWasmTemplateProject(id); + //string id = $"blz_aot_pub_{config}"; + //CreateBlazorWasmTemplateProject(id); - //// No relinking, no AOT - //BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack); + //// No relinking, no AOT + //BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack); - //// AOT=true only for the publish command line, similar to what - //// would happen when setting it in Publish dialog for VS - //BlazorPublish(new BlazorBuildOptions(id, config, expectedFileType: NativeFilesType.AOT, "-p:RunAOTCompilation=true"); + //// AOT=true only for the publish command line, similar to what + //// would happen when setting it in Publish dialog for VS + //BlazorPublish(new BlazorBuildOptions(id, config, expectedFileType: NativeFilesType.AOT, "-p:RunAOTCompilation=true"); - //// publish again, no AOT - //BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked); + //// publish again, no AOT + //BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked); //} [Theory] @@ -212,7 +214,7 @@ public void BugRegression_60479_WithRazorClassLib() string razorClassLibraryFileName = UseWebcil ? $"RazorClassLibrary{WebcilInWasmExtension}" : "RazorClassLibrary.dll"; AddItemsPropertiesToProject(wasmProjectFile, extraItems: @$" - + "); _projectDir = wasmProjectDir; diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 42e38fe1b24e9..f6ddfe5478789 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -527,13 +527,17 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse return projectfile; } - public string CreateBlazorWasmTemplateProject(string id) + public string CreateBlazorWasmTemplateProject(string id, string? targetFramework = null) { + string extraArgs = string.Empty; + if (targetFramework != null) + extraArgs += " -f " + targetFramework; + InitBlazorWasmProjectDir(id); new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("new blazorwasm") + .ExecuteWithCapturedOutput($"new blazorwasm{extraArgs}") .EnsureSuccessful(); string projectFile = Path.Combine(_projectDir!, $"{id}.csproj"); @@ -824,7 +828,7 @@ protected static void AssertFile(string file0, string file1, string? label = nul return result; } - protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null, bool expectFingerprinting = false) + protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null) { binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework); @@ -857,12 +861,24 @@ void AssertFileExists(string fileName) } string versionHashRegex = @"\.(?.+)\.(?[a-zA-Z0-9]+)\."; - Assert.Collection( - dotnetJsEntries.OrderBy(f => f), - item => { Assert.Equal(expectFingerprinting ? $"dotnet{versionHashRegex}js" : "dotnet.js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); } - ); + + // .NET 6/7 has a single dotnet.js with fingerprint, .NET 8 and later has more files with loader without fingerprint + if (targetFramework == "net6.0" || targetFramework == "net7.0") + { + Assert.Collection( + dotnetJsEntries.OrderBy(f => f), + item => { Assert.Matches($"dotnet{versionHashRegex}js", item); AssertFileExists(item); } + ); + } + else + { + Assert.Collection( + dotnetJsEntries.OrderBy(f => f), + item => { Assert.Equal("dotnet.js", item); AssertFileExists(item); }, + item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); }, + item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); } + ); + } } } From cfd05bea2f4b4ff563b5a48b020379374dee790c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 13:26:26 +0200 Subject: [PATCH 3/8] Use ResolvedRuntimePack to get runtime pack version --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 7b9af4e65a539..e85d5860f62b5 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -190,14 +190,13 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmConfigFileCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" /> - <_DotNetJsItem Include="@(ReferenceCopyLocalPaths)" Condition="('%(FileName)' == 'dotnet' or '%(FileName)' == 'dotnet.native') and '%(Extension)' == '.js'" /> - <_DotNetJsBuildVersion>%(_DotNetJsItem.NuGetPackageVersion) + <_DotNetJsBuildVersion>%(ResolvedRuntimePack.NuGetPackageVersion) - - <_DotNetJsItem Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.DestinationSubPath)' == 'dotnet.js' AND '%(ResolvedFileToPublish.AssetType)' == 'native'" /> - - - <_DotNetJsVersion>%(_DotNetJsItem.NuGetPackageVersion) + <_DotNetJsVersion>%(ResolvedRuntimePack.NuGetPackageVersion) Date: Mon, 5 Jun 2023 14:02:16 +0200 Subject: [PATCH 4/8] Fix WBT for finterprinting --- .../Blazor/BuildPublishTests.cs | 18 ++++--- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 50 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index ec1c21d9756b8..2b90761d797df 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -65,17 +65,21 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config) } [Theory] - [InlineData("Debug", "net8.0")] - [InlineData("Release", "net8.0")] - [InlineData("Debug", "net7.0")] - [InlineData("Release", "net7.0")] - public void DefaultTemplate_BuildNative_WithWorkload(string config, string targetFramework) + [InlineData("Debug", false)] + [InlineData("Release", false)] + [InlineData("Debug", true)] + [InlineData("Release", true)] + public void DefaultTemplate_BuildNative_WithWorkload(string config, bool expectFingerprintOnDotnetJs) { string id = $"blz_buildandbuildnative_{config}_{Path.GetRandomFileName()}"; - CreateBlazorWasmTemplateProject(id, targetFramework); + CreateBlazorWasmTemplateProject(id); - BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked) { TargetFramework = targetFramework }, "/p:WasmBuildNative=true"); + BlazorBuild( + new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs), + "/p:WasmBuildNative=true", + (expectFingerprintOnDotnetJs ? " /p:WasmFingerprintDotnetJs=true" : string.Empty) + ); } // Disabling for now - publish folder can have more than one dotnet*hash*js, and not sure diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index f6ddfe5478789..17e7cb4df217e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -527,17 +527,13 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse return projectfile; } - public string CreateBlazorWasmTemplateProject(string id, string? targetFramework = null) + public string CreateBlazorWasmTemplateProject(string id) { - string extraArgs = string.Empty; - if (targetFramework != null) - extraArgs += " -f " + targetFramework; - InitBlazorWasmProjectDir(id); new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput($"new blazorwasm{extraArgs}") + .ExecuteWithCapturedOutput($"new blazorwasm") .EnsureSuccessful(); string projectFile = Path.Combine(_projectDir!, $"{id}.csproj"); @@ -557,7 +553,8 @@ public string CreateBlazorWasmTemplateProject(string id, string? targetFramework AssertBlazorBundle(options.Config, isPublish: false, dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack, - targetFramework: options.TargetFramework); + targetFramework: options.TargetFramework, + expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs); return res; } @@ -569,7 +566,8 @@ public string CreateBlazorWasmTemplateProject(string id, string? targetFramework AssertBlazorBundle(options.Config, isPublish: true, dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack, - targetFramework: options.TargetFramework); + targetFramework: options.TargetFramework, + expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs); if (options.ExpectedFileType == NativeFilesType.AOT) { @@ -828,7 +826,7 @@ protected static void AssertFile(string file0, string file1, string? label = nul return result; } - protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null) + protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null, bool expectFingerprintOnDotnetJs = false) { binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework); @@ -862,23 +860,20 @@ void AssertFileExists(string fileName) string versionHashRegex = @"\.(?.+)\.(?[a-zA-Z0-9]+)\."; - // .NET 6/7 has a single dotnet.js with fingerprint, .NET 8 and later has more files with loader without fingerprint - if (targetFramework == "net6.0" || targetFramework == "net7.0") - { - Assert.Collection( - dotnetJsEntries.OrderBy(f => f), - item => { Assert.Matches($"dotnet{versionHashRegex}js", item); AssertFileExists(item); } - ); - } - else - { - Assert.Collection( - dotnetJsEntries.OrderBy(f => f), - item => { Assert.Equal("dotnet.js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); }, - item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); } - ); - } + Assert.Collection( + dotnetJsEntries.OrderBy(f => f), + item => + { + if (expectFingerprintOnDotnetJs) + Assert.Matches($"dotnet{versionHashRegex}js", item); + else + Assert.Equal("dotnet.js", item); + + AssertFileExists(item); + }, + item => { Assert.Matches($"dotnet\\.native{versionHashRegex}js", item); AssertFileExists(item); }, + item => { Assert.Matches($"dotnet\\.runtime{versionHashRegex}js", item); AssertFileExists(item); } + ); } } @@ -1306,7 +1301,8 @@ public record BlazorBuildOptions NativeFilesType ExpectedFileType, string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor, bool WarnAsError = true, - bool ExpectRelinkDirWhenPublishing = false + bool ExpectRelinkDirWhenPublishing = false, + bool ExpectFingerprintOnDotnetJs = false ); public enum GlobalizationMode From cdda1c3f723a786ec54fb63e202df795a4d2e41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 5 Jun 2023 14:03:09 +0200 Subject: [PATCH 5/8] Remove extra interpolation --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 17e7cb4df217e..1411a8d04e84a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -533,7 +533,7 @@ public string CreateBlazorWasmTemplateProject(string id) new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput($"new blazorwasm") + .ExecuteWithCapturedOutput("new blazorwasm") .EnsureSuccessful(); string projectFile = Path.Combine(_projectDir!, $"{id}.csproj"); From b37df91a1345f9d7bb2375141aef7da028c37b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 6 Jun 2023 14:12:57 +0200 Subject: [PATCH 6/8] Feedback --- ...rosoft.NET.Sdk.WebAssembly.Browser.targets | 21 +++++++++---------- .../Blazor/BuildPublishTests.cs | 14 +++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index e85d5860f62b5..42fb5fa679ab2 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -187,7 +187,13 @@ Copyright (c) .NET Foundation. All rights reserved. - + + + <_WasmRuntimePackVersion>%(ResolvedRuntimePack.NuGetPackageVersion) + + + + <_WasmConfigFileCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" /> @@ -195,9 +201,6 @@ Copyright (c) .NET Foundation. All rights reserved. - - <_DotNetJsBuildVersion>%(ResolvedRuntimePack.NuGetPackageVersion) - - +