Skip to content

Commit b1c0fe9

Browse files
authored
[wasm] Wasm.Build.Tests improvements (#76381)
* InstallWorkloadFromArtifacts: Remove hack because we have an updated sdk now * [wasm] WBT: Make project names unique * [wasm] WBT: Use a clean NUGET_PACKAGES dir separate from the project directory * [wasm] WBT: Fixes to work with latest sdk - Use only one source of which tfm to use - Allow a different tfm for blazor - Add `dotnet8` nuget feed for tests - Support more than one choice for nuget.config, like for net7, or net8 * WBT: Revert to test projects created in bindir, instead of a temp one This was necessary because on windows the tmp path is very long, causing the test project paths to become too long causing build failures. * [wasm] fix weird build failures `MSBuildSDKsPath` is set by runtime repo, and that interferes with the test projects. To avoid this the `MSBuildSDKsPath` was set to `""` in the test environment. But even that can negatively affect the build because msbuild treats environment variables as "global properties" that cannot be changed. This manifests when running: `$ dotnet run --no-build` .. it would fail with `/foo/bar.csproj is not a valid project file`. Instead, explicitly *remove* `MSBuildSDKsPath` from the environment when invoking the process. * WBT: PInvokeTableGenerator: Find path to WasmAppBuilder.dll at test time .. instead of depending on *one* runtime pack version. This is needed when we have more than one workload installed. * WBT: Don't use the nuget packages directory as fallback. .. because we explicitly set `NUGET_PACKAGES` envvar now. * [wasm] Use the latest sdk for Wasm.Build.Tests * WBT: Add missing nuget8.config * WBT: workaround for #76201 * WasmAppHost: add rollforward=latestMajor
1 parent b3fdac7 commit b1c0fe9

17 files changed

+139
-118
lines changed

src/mono/wasm/Wasm.Build.Tests/BlazorWasmBuildPublishTests.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BlazorWasmBuildPublishTests(ITestOutputHelper output, SharedBuildPerTestC
2626
[InlineData("Release")]
2727
public void DefaultTemplate_WithoutWorkload(string config)
2828
{
29-
string id = $"blz_no_workload_{config}";
29+
string id = $"blz_no_workload_{config}_{Path.GetRandomFileName()}";
3030
CreateBlazorWasmTemplateProject(id);
3131

3232
// Build
@@ -43,7 +43,7 @@ public void DefaultTemplate_WithoutWorkload(string config)
4343
[InlineData("Release")]
4444
public void DefaultTemplate_NoAOT_WithWorkload(string config)
4545
{
46-
string id = $"blz_no_aot_{config}";
46+
string id = $"blz_no_aot_{config}_{Path.GetRandomFileName()}";
4747
CreateBlazorWasmTemplateProject(id);
4848

4949
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack));
@@ -63,7 +63,7 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config)
6363
[InlineData("Release")]
6464
public void DefaultTemplate_AOT_InProjectFile(string config)
6565
{
66-
string id = $"blz_aot_prj_file_{config}";
66+
string id = $"blz_aot_prj_file_{config}_{Path.GetRandomFileName()}";
6767
string projectFile = CreateBlazorWasmTemplateProject(id);
6868
AddItemsPropertiesToProject(projectFile, extraProperties: "<RunAOTCompilation>true</RunAOTCompilation>");
6969

@@ -82,10 +82,10 @@ public void DefaultTemplate_AOT_InProjectFile(string config)
8282
[InlineData("Debug", false)]
8383
[InlineData("Release", true)]
8484
[InlineData("Release", false)]
85-
[ActiveIssue("https://github.com/dotnet/runtime/issues/70985", TestPlatforms.Linux)]
85+
//[ActiveIssue("https://github.com/dotnet/runtime/issues/70985", TestPlatforms.Linux)]
8686
public void NativeBuild_WithDeployOnBuild_UsedByVS(string config, bool nativeRelink)
8787
{
88-
string id = $"blz_deploy_on_build_{config}_{nativeRelink}";
88+
string id = $"blz_deploy_on_build_{config}_{nativeRelink}_{Path.GetRandomFileName()}";
8989
string projectFile = CreateProjectWithNativeReference(id);
9090
AddItemsPropertiesToProject(projectFile, extraProperties: nativeRelink ? string.Empty : "<RunAOTCompilation>true</RunAOTCompilation>");
9191

@@ -94,7 +94,7 @@ public void NativeBuild_WithDeployOnBuild_UsedByVS(string config, bool nativeRel
9494

9595
var expectedFileType = nativeRelink ? NativeFilesType.Relinked : NativeFilesType.AOT;
9696

97-
AssertDotNetNativeFiles(expectedFileType, config, forPublish: true);
97+
AssertDotNetNativeFiles(expectedFileType, config, forPublish: true, targetFramework: DefaultTargetFrameworkForBlazor);
9898
AssertBlazorBundle(config, isPublish: true, dotnetWasmFromRuntimePack: false);
9999

100100
if (expectedFileType == NativeFilesType.AOT)
@@ -147,7 +147,7 @@ public void NativeBuild_WithDeployOnBuild_UsedByVS(string config, bool nativeRel
147147
[ActiveIssue("https://github.com/dotnet/runtime/issues/70985", TestPlatforms.Linux)]
148148
public void WithNativeReference_AOTInProjectFile(string config)
149149
{
150-
string id = $"blz_nativeref_aot_{config}";
150+
string id = $"blz_nativeref_aot_{config}_{Path.GetRandomFileName()}";
151151
string projectFile = CreateProjectWithNativeReference(id);
152152
AddItemsPropertiesToProject(projectFile, extraProperties: "<RunAOTCompilation>true</RunAOTCompilation>");
153153

@@ -165,7 +165,7 @@ public void WithNativeReference_AOTInProjectFile(string config)
165165
[ActiveIssue("https://github.com/dotnet/runtime/issues/70985", TestPlatforms.Linux)]
166166
public void WithNativeReference_AOTOnCommandLine(string config)
167167
{
168-
string id = $"blz_nativeref_aot_{config}";
168+
string id = $"blz_nativeref_aot_{config}_{Path.GetRandomFileName()}";
169169
CreateProjectWithNativeReference(id);
170170

171171
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked));
@@ -182,7 +182,7 @@ public void WithNativeReference_AOTOnCommandLine(string config)
182182
public void WithDllImportInMainAssembly(string config)
183183
{
184184
// Based on https://github.com/dotnet/runtime/issues/59255
185-
string id = $"blz_dllimp_{config}";
185+
string id = $"blz_dllimp_{config}_{Path.GetRandomFileName()}";
186186
string projectFile = CreateProjectWithNativeReference(id);
187187
string nativeSource = @"
188188
#include <stdio.h>
@@ -233,14 +233,15 @@ void CheckNativeFileLinked(bool forPublish)
233233
[Fact]
234234
public void BugRegression_60479_WithRazorClassLib()
235235
{
236-
string id = "blz_razor_lib_top";
236+
string id = $"blz_razor_lib_top_{Path.GetRandomFileName()}";
237237
InitBlazorWasmProjectDir(id);
238238

239239
string wasmProjectDir = Path.Combine(_projectDir!, "wasm");
240240
string wasmProjectFile = Path.Combine(wasmProjectDir, "wasm.csproj");
241241
Directory.CreateDirectory(wasmProjectDir);
242242
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
243243
.WithWorkingDirectory(wasmProjectDir)
244+
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
244245
.ExecuteWithCapturedOutput("new blazorwasm")
245246
.EnsureSuccessful();
246247

@@ -249,6 +250,7 @@ public void BugRegression_60479_WithRazorClassLib()
249250
Directory.CreateDirectory(razorProjectDir);
250251
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
251252
.WithWorkingDirectory(razorProjectDir)
253+
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
252254
.ExecuteWithCapturedOutput("new razorclasslib")
253255
.EnsureSuccessful();
254256

src/mono/wasm/Wasm.Build.Tests/BlazorWasmTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private CommandResult PublishForRequiresWorkloadTest(string config, string extra
6161
string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog");
6262
return new DotNetCommand(s_buildEnv, _testOutput)
6363
.WithWorkingDirectory(_projectDir!)
64+
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
6465
.ExecuteWithCapturedOutput("publish",
6566
$"-bl:{publishLogPath}",
6667
$"-p:Configuration={config}");
@@ -109,6 +110,7 @@ private void BuildNet50Project(string config, bool aot, bool expectError, string
109110
string publishLogPath = Path.Combine(logPath, $"{id}.binlog");
110111
CommandResult result = new DotNetCommand(s_buildEnv, _testOutput)
111112
.WithWorkingDirectory(_projectDir!)
113+
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
112114
.ExecuteWithCapturedOutput("publish",
113115
$"-bl:{publishLogPath}",
114116
(aot ? "-p:RunAOTCompilation=true" : ""),

src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BuildEnvironment
2727
public static readonly string RelativeTestAssetsPath = @"..\testassets\";
2828
public static readonly string TestAssetsPath = Path.Combine(AppContext.BaseDirectory, "testassets");
2929
public static readonly string TestDataPath = Path.Combine(AppContext.BaseDirectory, "data");
30-
public static readonly string TmpPath = Path.Combine(Path.GetTempPath(), "wasmbuildtests");
30+
public static readonly string TmpPath = Path.Combine(AppContext.BaseDirectory, "wbt");
3131

3232
private static readonly Dictionary<string, string> s_runtimePackVersions = new();
3333

@@ -107,7 +107,6 @@ public BuildEnvironment()
107107
EnvVars["DOTNET_INSTALL_DIR"] = sdkForWorkloadPath;
108108
EnvVars["DOTNET_MULTILEVEL_LOOKUP"] = "0";
109109
EnvVars["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1";
110-
EnvVars["MSBuildSDKsPath"] = string.Empty;
111110
EnvVars["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}";
112111
EnvVars["EM_WORKAROUND_PYTHON_BUG_34780"] = "1";
113112

@@ -160,8 +159,5 @@ public string GetRuntimeNativeDir(string tfm = BuildTestBase.DefaultTargetFramew
160159

161160
protected static string s_directoryBuildPropsForLocal = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.props"));
162161
protected static string s_directoryBuildTargetsForLocal = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.targets"));
163-
164-
protected static string s_directoryBuildPropsForBlazorLocal = File.ReadAllText(Path.Combine(TestDataPath, "Blazor.Local.Directory.Build.props"));
165-
protected static string s_directoryBuildTargetsForBlazorLocal = File.ReadAllText(Path.Combine(TestDataPath, "Blazor.Local.Directory.Build.targets"));
166162
}
167163
}

0 commit comments

Comments
 (0)