Skip to content

Commit

Permalink
[browser] Fix encoding problem when publishing (#82833)
Browse files Browse the repository at this point in the history
* Fixed #78953.

* New wbt publish test case: Unicode sign in project name.

* Removed duplicated, unused function + addressed @akoeplinger review.

* Fix.

* Revert AOT tests to fix them in a follow-up.

* Test Blazor as well.

* @radical's review: test reduction + relinking

* Block relinking tests with Unicode signs.

* Added active issue link.
  • Loading branch information
ilonatommy committed Mar 16, 2023
1 parent 571fbb8 commit 7f0c19a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BuildPublishTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
[InlineData("Release")]
public void DefaultTemplate_WithoutWorkload(string config)
{
string id = $"blz_no_workload_{config}_{Path.GetRandomFileName()}";
string id = $"blz_no_workload_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}";
CreateBlazorWasmTemplateProject(id);

// Build
Expand All @@ -45,7 +45,11 @@ public void DefaultTemplate_WithoutWorkload(string config)
[InlineData("Release")]
public void DefaultTemplate_NoAOT_WithWorkload(string config)
{
string id = $"blz_no_aot_{config}_{Path.GetRandomFileName()}";
// disable relinking tests for Unicode: github.com/emscripten-core/emscripten/issues/17817
// [ActiveIssue("https://github.com/dotnet/runtime/issues/83497")]
string id = config == "Release" ?
$"blz_no_aot_{config}_{Path.GetRandomFileName()}" :
$"blz_no_aot_{config}_{Path.GetRandomFileName()}_{s_unicodeChar}";
CreateBlazorWasmTemplateProject(id);

BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack));
Expand Down Expand Up @@ -92,7 +96,7 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config)
public async Task WithDllImportInMainAssembly(string config, bool build, bool publish)
{
// Based on https://github.com/dotnet/runtime/issues/59255
string id = $"blz_dllimp_{config}_";
string id = $"blz_dllimp_{config}_{s_unicodeChar}";
if (build && publish)
id += "build_then_publish";
else if (build)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public BuildPublishTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
[BuildAndRun(host: RunHost.Chrome, aot: false, config: "Debug")]
public void BuildThenPublishNoAOT(BuildArgs buildArgs, RunHost host, string id)
{
string projectName = $"build_publish_{buildArgs.Config}";
string projectName = $"build_publish_{buildArgs.Config}{s_unicodeChar}";

buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs);
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
public const string DefaultTargetFramework = "net8.0";
public const string DefaultTargetFrameworkForBlazor = "net8.0";
private const string DefaultEnvironmentLocale = "en-US";
protected static readonly char s_unicodeChar = '煉';
protected static readonly bool s_skipProjectCleanup;
protected static readonly string s_xharnessRunnerCommand;
protected string? _projectDir;
Expand Down
26 changes: 3 additions & 23 deletions src/tasks/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ static string CreateTemporaryBatchFile(string command)
using StreamWriter sw = new(file);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// set encoding to UTF-8 -> full Unicode support is needed for usernames -
// `command` contains tmp dir path with the username
sw.WriteLine(@"%SystemRoot%\System32\chcp.com 65001>nul");
sw.WriteLine("setlocal");
sw.WriteLine("set errorlevel=dummy");
sw.WriteLine("set errorlevel=");
Expand Down Expand Up @@ -193,29 +196,6 @@ public static (int, string) TryRunProcess(
return (process.ExitCode, outputBuilder.ToString().Trim('\r', '\n'));
}

internal static string CreateTemporaryBatchFile(string command)
{
string extn = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".cmd" : ".sh";
string file = Path.Combine(Path.GetTempPath(), $"tmp{Guid.NewGuid():N}{extn}");

using StreamWriter sw = new(file);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
sw.WriteLine("setlocal");
sw.WriteLine("set errorlevel=dummy");
sw.WriteLine("set errorlevel=");
}
else
{
// Use sh rather than bash, as not all 'nix systems necessarily have Bash installed
sw.WriteLine("#!/bin/sh");
}

sw.WriteLine(command);

return file;
}

public static bool CopyIfDifferent(string src, string dst, bool useHash)
{
if (!File.Exists(src))
Expand Down

0 comments on commit 7f0c19a

Please sign in to comment.