From a96f6f119740e3fa363571c23ea2a3c67b50bf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 27 Jul 2023 23:48:50 +0200 Subject: [PATCH 1/9] Read AssetTraitValue when determining culture for resource during webcil transformation --- .../ConvertDllsToWebCil.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs index f5d0288ffe4e4f..2fde695f6b10a8 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs @@ -70,7 +70,10 @@ public override bool Execute() var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log); webcilWriter.ConvertToWebcil(); - string candicatePath = Path.Combine(OutputPath, candidate.GetMetadata("Culture")); + string candicatePath = candidate.GetMetadata("AssetTraitName") == "Culture" + ? Path.Combine(OutputPath, candidate.GetMetadata("AssetTraitValue")) + : OutputPath; + if (!Directory.Exists(candicatePath)) Directory.CreateDirectory(candicatePath); From bb96f2b51a56d99517631688c9dfd25fa617215c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 28 Jul 2023 12:04:46 +0200 Subject: [PATCH 2/9] Fix typo --- .../ConvertDllsToWebCil.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs index 2fde695f6b10a8..31a4c622ce3c1f 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs @@ -70,14 +70,14 @@ public override bool Execute() var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log); webcilWriter.ConvertToWebcil(); - string candicatePath = candidate.GetMetadata("AssetTraitName") == "Culture" + string candidatePath = candidate.GetMetadata("AssetTraitName") == "Culture" ? Path.Combine(OutputPath, candidate.GetMetadata("AssetTraitValue")) : OutputPath; - if (!Directory.Exists(candicatePath)) - Directory.CreateDirectory(candicatePath); + if (!Directory.Exists(candidatePath)) + Directory.CreateDirectory(candidatePath); - var finalWebcil = Path.Combine(candicatePath, webcilFileName); + var finalWebcil = Path.Combine(candidatePath, webcilFileName); if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true)) Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} ."); else From e1f9e994ecda9a29d8b47e04764d27aa0344e030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 28 Jul 2023 12:09:06 +0200 Subject: [PATCH 3/9] Add WBT with Blazor with resources in two cultures and build+publish --- .../Blazor/BuildPublishTests.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 520dc8d05c8b94..be626ed4959f1d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -276,4 +276,39 @@ private void BlazorAddRazorButton(string buttonText, string customCode, string m string oldContent = File.ReadAllText(counterRazorPath); File.WriteAllText(counterRazorPath, oldContent + additionalCode); } + + [Theory, TestCategory("no-workload")] + [InlineData("Debug")] + [InlineData("Release")] + public void DefaultTemplate_WithResources_Publish(string config) + { + string[] cultures = ["ja-JP", "es-ES"]; + string id = $"blz_no_workload_resources_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}"; + CreateBlazorWasmTemplateProject(id); + + // Ensure we have the source data we really on + string resxSourcePath = Path.Combine(BuildEnvironment.TestAssetsPath, "resx"); + foreach (string culture in cultures) + Assert.True(File.Exists(Path.Combine(resxSourcePath, $"words.{culture}.resx"))); + + Utils.DirectoryCopy(resxSourcePath, Path.Combine(_projectDir!, "resx")); + + // Build and assert resource dlls + BlazorBuild(new BlazorBuildOptions(id, config)); + AssertResourcesDlls(FindBlazorBinFrameworkDir(config, false)); + + // Publish and assert resource dlls + BlazorPublish(new BlazorBuildOptions(id, config)); + AssertResourcesDlls(FindBlazorBinFrameworkDir(config, true)); + + void AssertResourcesDlls(string basePath) + { + string dllExtension = UseWebcil ? ProjectProviderBase.WebcilInWasmExtension : ".dll"; + foreach (string culture in cultures) + { + string jaJPResources = Path.Combine(basePath, culture, $"{id}.resources{dllExtension}"); + Assert.True(File.Exists(jaJPResources), $"Expects to have a resource assembly at {jaJPResources}"); + } + } + } } From 6fcfb0b91614402f80d23c8c5d7a249fa4432511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 28 Jul 2023 21:10:20 +0200 Subject: [PATCH 4/9] Remove TestCategory --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index be626ed4959f1d..61dbb8173de8e9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -277,7 +277,7 @@ private void BlazorAddRazorButton(string buttonText, string customCode, string m File.WriteAllText(counterRazorPath, oldContent + additionalCode); } - [Theory, TestCategory("no-workload")] + [Theory] [InlineData("Debug")] [InlineData("Release")] public void DefaultTemplate_WithResources_Publish(string config) From 9301415682dbd3f625406f6041f68190bfa15400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Sat, 29 Jul 2023 00:53:17 +0200 Subject: [PATCH 5/9] Check for emcc-link.rsp instead of that for-build directory exists --- src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs | 2 +- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index 8918a74d404497..5b6dd0ca625bc1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -87,7 +87,7 @@ public string CreateBlazorWasmTemplateProject(string id) if (options.ExpectRelinkDirWhenPublishing) Assert.True(Directory.Exists(objBuildDir), $"Could not find expected {objBuildDir}, which gets created when relinking during Build. This is likely a test authoring error"); else - Assert.False(Directory.Exists(objBuildDir), $"Found unexpected {objBuildDir}, which gets created when relinking during Build"); + Assert.False(File.Exists(Path.Combine(objBuildDir, "emcc-link.rsp")), $"Found unexpected files in {objBuildDir}, which gets created when relinking during Build"); return (res, logPath); } diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 61dbb8173de8e9..3c49a4be31cdfc 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -283,7 +283,7 @@ private void BlazorAddRazorButton(string buttonText, string customCode, string m public void DefaultTemplate_WithResources_Publish(string config) { string[] cultures = ["ja-JP", "es-ES"]; - string id = $"blz_no_workload_resources_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}"; + string id = $"blz_resources_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}"; CreateBlazorWasmTemplateProject(id); // Ensure we have the source data we really on From 9a81a9d13f8b77ee37af7b7f548b04ddedb315af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Sat, 29 Jul 2023 08:32:24 +0200 Subject: [PATCH 6/9] Fix WBT? --- .../Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 3c49a4be31cdfc..caff363b1e00e2 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -294,11 +294,20 @@ public void DefaultTemplate_WithResources_Publish(string config) Utils.DirectoryCopy(resxSourcePath, Path.Combine(_projectDir!, "resx")); // Build and assert resource dlls - BlazorBuild(new BlazorBuildOptions(id, config)); + BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack)); AssertResourcesDlls(FindBlazorBinFrameworkDir(config, false)); // Publish and assert resource dlls - BlazorPublish(new BlazorBuildOptions(id, config)); + if (config == "Release") + { + // relinking in publish for Release config + BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true)); + } + else + { + BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack, ExpectRelinkDirWhenPublishing: true)); + } + AssertResourcesDlls(FindBlazorBinFrameworkDir(config, true)); void AssertResourcesDlls(string basePath) From 7915093db58733fabf098284d47f3068990bb4ea Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 7 Aug 2023 12:11:02 -0400 Subject: [PATCH 7/9] track api changes in main --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 12927e61b0abea..d5d73991a0b4a8 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -135,10 +135,9 @@ public void DefaultTemplate_WithResources_Publish(string config) void AssertResourcesDlls(string basePath) { - string dllExtension = UseWebcil ? ProjectProviderBase.WebcilInWasmExtension : ".dll"; foreach (string culture in cultures) { - string jaJPResources = Path.Combine(basePath, culture, $"{id}.resources{dllExtension}"); + string jaJPResources = Path.Combine(basePath, culture, $"{id}.resources{ProjectProviderBase.WasmAssemblyExtension}"); Assert.True(File.Exists(jaJPResources), $"Expects to have a resource assembly at {jaJPResources}"); } } From a830b48bf46b99dcc29e0e9696fe5b0bdc6bb134 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 8 Aug 2023 12:31:09 -0400 Subject: [PATCH 8/9] Avoid using unicode character in an unrelated test name. it breaks emcc build on windows --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index d5d73991a0b4a8..2b55cec2475975 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -106,7 +106,7 @@ public void DefaultTemplate_CheckFingerprinting(string config, bool expectFinger public void DefaultTemplate_WithResources_Publish(string config) { string[] cultures = ["ja-JP", "es-ES"]; - string id = $"blz_resources_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}"; + string id = $"blz_resources_{config}_{GetRandomId()}"; CreateBlazorWasmTemplateProject(id); // Ensure we have the source data we really on From 617842c368cb8e7294afcf416e7944c4edf47f2c Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 8 Aug 2023 12:31:19 -0400 Subject: [PATCH 9/9] cleanup --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 2b55cec2475975..ddca10f96aea89 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -109,7 +109,7 @@ public void DefaultTemplate_WithResources_Publish(string config) string id = $"blz_resources_{config}_{GetRandomId()}"; CreateBlazorWasmTemplateProject(id); - // Ensure we have the source data we really on + // Ensure we have the source data we rely on string resxSourcePath = Path.Combine(BuildEnvironment.TestAssetsPath, "resx"); foreach (string culture in cultures) Assert.True(File.Exists(Path.Combine(resxSourcePath, $"words.{culture}.resx"))); @@ -137,8 +137,8 @@ void AssertResourcesDlls(string basePath) { foreach (string culture in cultures) { - string jaJPResources = Path.Combine(basePath, culture, $"{id}.resources{ProjectProviderBase.WasmAssemblyExtension}"); - Assert.True(File.Exists(jaJPResources), $"Expects to have a resource assembly at {jaJPResources}"); + string resourceAssemblyPath = Path.Combine(basePath, culture, $"{id}.resources{ProjectProviderBase.WasmAssemblyExtension}"); + Assert.True(File.Exists(resourceAssemblyPath), $"Expects to have a resource assembly at {resourceAssemblyPath}"); } } }