Skip to content

Commit 0aa1b5a

Browse files
committed
[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
1 parent 0678940 commit 0aa1b5a

11 files changed

+61
-45
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,5 @@ public string GetRuntimeNativeDir(string tfm = BuildTestBase.DefaultTargetFramew
160160

161161
protected static string s_directoryBuildPropsForLocal = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.props"));
162162
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"));
166163
}
167164
}

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

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Wasm.Build.Tests
2828
public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixture>, IDisposable
2929
{
3030
public const string DefaultTargetFramework = "net7.0";
31-
public static readonly string NuGetConfigFileNameForDefaultFramework = $"nuget7.config";
31+
public const string DefaultTargetFrameworkForBlazor = "net7.0";
3232
protected static readonly bool s_skipProjectCleanup;
3333
protected static readonly string s_xharnessRunnerCommand;
3434
protected string? _projectDir;
@@ -49,6 +49,9 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
4949

5050
public static bool IsUsingWorkloads => s_buildEnv.IsWorkload;
5151
public static bool IsNotUsingWorkloads => !s_buildEnv.IsWorkload;
52+
public static string GetNuGetConfigPathFor(string targetFramework) =>
53+
Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with
54+
// targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
5255

5356
static BuildTestBase()
5457
{
@@ -289,7 +292,7 @@ protected void InitPaths(string id)
289292
Directory.CreateDirectory(_logPath);
290293
}
291294

292-
protected static void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = false)
295+
protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = false, string targetFramework = DefaultTargetFramework)
293296
{
294297
Directory.CreateDirectory(dir);
295298
File.WriteAllText(Path.Combine(dir, "Directory.Build.props"), s_buildEnv.DirectoryBuildPropsContents);
@@ -300,15 +303,13 @@ protected static void InitProjectDir(string dir, bool addNuGetSourceForLocalPack
300303
{
301304
File.WriteAllText(targetNuGetConfigPath,
302305
GetNuGetConfigWithLocalPackagesPath(
303-
Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework),
306+
GetNuGetConfigPathFor(targetFramework),
304307
s_buildEnv.BuiltNuGetsPath));
305308
}
306309
else
307310
{
308-
File.Copy(Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework),
309-
targetNuGetConfigPath);
311+
File.Copy(GetNuGetConfigPathFor(targetFramework), targetNuGetConfigPath);
310312
}
311-
Directory.CreateDirectory(Path.Combine(dir, ".nuget"));
312313
}
313314

314315
protected const string SimpleProjectTemplate =
@@ -414,7 +415,14 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
414415
AssertRuntimePackPath(result.buildOutput, options.TargetFramework ?? DefaultTargetFramework);
415416

416417
string bundleDir = Path.Combine(GetBinDir(config: buildArgs.Config, targetFramework: options.TargetFramework ?? DefaultTargetFramework), "AppBundle");
417-
AssertBasicAppBundle(bundleDir, buildArgs.ProjectName, buildArgs.Config, options.MainJS ?? "test-main.js", options.HasV8Script, options.HasIcudt, options.DotnetWasmFromRuntimePack ?? !buildArgs.AOT, options.TargetFramework ?? DefaultTargetFramework);
418+
AssertBasicAppBundle(bundleDir,
419+
buildArgs.ProjectName,
420+
buildArgs.Config,
421+
options.MainJS ?? "test-main.js",
422+
options.HasV8Script,
423+
options.TargetFramework ?? DefaultTargetFramework,
424+
options.HasIcudt,
425+
options.DotnetWasmFromRuntimePack ?? !buildArgs.AOT);
418426
}
419427

420428
if (options.UseCache)
@@ -430,17 +438,16 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
430438
}
431439
}
432440

433-
public void InitBlazorWasmProjectDir(string id)
441+
public void InitBlazorWasmProjectDir(string id, string targetFramework = DefaultTargetFrameworkForBlazor)
434442
{
435443
InitPaths(id);
436444
if (Directory.Exists(_projectDir))
437445
Directory.Delete(_projectDir, recursive: true);
438446
Directory.CreateDirectory(_projectDir);
439-
Directory.CreateDirectory(Path.Combine(_projectDir, ".nuget"));
440447

441448
File.WriteAllText(Path.Combine(_projectDir, "nuget.config"),
442449
GetNuGetConfigWithLocalPackagesPath(
443-
Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework),
450+
GetNuGetConfigPathFor(targetFramework),
444451
s_buildEnv.BuiltNuGetsPath));
445452

446453
File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
@@ -497,8 +504,12 @@ public string CreateBlazorWasmTemplateProject(string id)
497504
protected (CommandResult, string) BlazorBuild(BlazorBuildOptions options, params string[] extraArgs)
498505
{
499506
var res = BuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, extraArgs);
507+
_testOutput.WriteLine($"BlazorBuild, options.tfm: {options.TargetFramework}");
500508
AssertDotNetNativeFiles(options.ExpectedFileType, options.Config, forPublish: false, targetFramework: options.TargetFramework);
501-
AssertBlazorBundle(options.Config, isPublish: false, dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack);
509+
AssertBlazorBundle(options.Config,
510+
isPublish: false,
511+
dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack,
512+
targetFramework: options.TargetFramework);
502513

503514
return res;
504515
}
@@ -507,7 +518,10 @@ public string CreateBlazorWasmTemplateProject(string id)
507518
{
508519
var res = BuildInternal(options.Id, options.Config, publish: true, setWasmDevel: false, extraArgs);
509520
AssertDotNetNativeFiles(options.ExpectedFileType, options.Config, forPublish: true, targetFramework: options.TargetFramework);
510-
AssertBlazorBundle(options.Config, isPublish: true, dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack);
521+
AssertBlazorBundle(options.Config,
522+
isPublish: true,
523+
dotnetWasmFromRuntimePack: options.ExpectedFileType == NativeFilesType.FromRuntimePack,
524+
targetFramework: options.TargetFramework);
511525

512526
if (options.ExpectedFileType == NativeFilesType.AOT)
513527
{
@@ -539,17 +553,18 @@ public string CreateBlazorWasmTemplateProject(string id)
539553

540554
CommandResult res = new DotNetCommand(s_buildEnv, _testOutput)
541555
.WithWorkingDirectory(_projectDir!)
556+
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
542557
.ExecuteWithCapturedOutput(combinedArgs)
543558
.EnsureSuccessful();
544559

545560
return (res, logPath);
546561
}
547562

548-
protected void AssertDotNetNativeFiles(NativeFilesType type, string config, bool forPublish, string targetFramework = DefaultTargetFramework)
563+
protected void AssertDotNetNativeFiles(NativeFilesType type, string config, bool forPublish, string targetFramework)
549564
{
550565
string label = forPublish ? "publish" : "build";
551566
string objBuildDir = Path.Combine(_projectDir!, "obj", config, targetFramework, "wasm", forPublish ? "for-publish" : "for-build");
552-
string binFrameworkDir = FindBlazorBinFrameworkDir(config, forPublish);
567+
string binFrameworkDir = FindBlazorBinFrameworkDir(config, forPublish, framework: targetFramework);
553568

554569
string srcDir = type switch
555570
{
@@ -590,7 +605,14 @@ static void AssertRuntimePackPath(string buildOutput, string targetFramework)
590605
throw new XunitException($"Runtime pack path doesn't match.{Environment.NewLine}Expected: '{expectedRuntimePackDir}'{Environment.NewLine}Actual: '{actualPath}'");
591606
}
592607

593-
protected static void AssertBasicAppBundle(string bundleDir, string projectName, string config, string mainJS, bool hasV8Script, bool hasIcudt=true, bool dotnetWasmFromRuntimePack=true, string targetFramework=DefaultTargetFramework)
608+
protected static void AssertBasicAppBundle(string bundleDir,
609+
string projectName,
610+
string config,
611+
string mainJS,
612+
bool hasV8Script,
613+
string targetFramework,
614+
bool hasIcudt = true,
615+
bool dotnetWasmFromRuntimePack = true)
594616
{
595617
AssertFilesExist(bundleDir, new []
596618
{
@@ -638,7 +660,7 @@ protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack,
638660
same: fromRuntimePack);
639661
}
640662

641-
protected static void AssertDotNetJsSymbols(string bundleDir, bool fromRuntimePack, string targetFramework=DefaultTargetFramework)
663+
protected static void AssertDotNetJsSymbols(string bundleDir, bool fromRuntimePack, string targetFramework)
642664
=> AssertFile(Path.Combine(s_buildEnv.GetRuntimeNativeDir(targetFramework), "dotnet.js.symbols"),
643665
Path.Combine(bundleDir, "dotnet.js.symbols"),
644666
same: fromRuntimePack);
@@ -690,11 +712,11 @@ protected static void AssertFile(string file0, string file1, string? label=null,
690712
return result;
691713
}
692714

693-
protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string? binFrameworkDir=null, string targetFramework=DefaultTargetFramework)
715+
protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir=null)
694716
{
695-
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish);
717+
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework);
696718

697-
AssertBlazorBootJson(config, isPublish, binFrameworkDir: binFrameworkDir);
719+
AssertBlazorBootJson(config, isPublish, targetFramework, binFrameworkDir: binFrameworkDir);
698720
AssertFile(Path.Combine(s_buildEnv.GetRuntimeNativeDir(targetFramework), "dotnet.wasm"),
699721
Path.Combine(binFrameworkDir, "dotnet.wasm"),
700722
"Expected dotnet.wasm to be same as the runtime pack",
@@ -709,9 +731,9 @@ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasm
709731
same: dotnetWasmFromRuntimePack);
710732
}
711733

712-
protected void AssertBlazorBootJson(string config, bool isPublish, string? binFrameworkDir=null)
734+
protected void AssertBlazorBootJson(string config, bool isPublish, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir=null)
713735
{
714-
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish);
736+
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework);
715737

716738
string bootJsonPath = Path.Combine(binFrameworkDir, "blazor.boot.json");
717739
Assert.True(File.Exists(bootJsonPath), $"Expected to find {bootJsonPath}");
@@ -728,7 +750,7 @@ protected void AssertBlazorBootJson(string config, bool isPublish, string? binFr
728750
$"{msgPrefix} Could not find dotnet.*js in {bootJson}");
729751
}
730752

731-
protected string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFramework)
753+
protected string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor)
732754
{
733755
string basePath = Path.Combine(_projectDir!, "bin", config, framework);
734756
if (forPublish)
@@ -1005,6 +1027,6 @@ public record BlazorBuildOptions
10051027
string Id,
10061028
string Config,
10071029
NativeFilesType ExpectedFileType,
1008-
string TargetFramework = BuildTestBase.DefaultTargetFramework
1030+
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor
10091031
);
10101032
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Blazor_BuildThenClean_NativeRelinking(string config)
3636
AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties);
3737
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked));
3838

39-
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFramework, "wasm", "for-build");
39+
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm", "for-build");
4040
Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}");
4141

4242
string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog");
@@ -76,7 +76,7 @@ private void Blazor_BuildNativeNonNative_ThenCleanTest(string config, bool first
7676
BuildInternal(id, config, publish: false,
7777
extraArgs: relink ? "-p:WasmBuildNative=true" : string.Empty);
7878

79-
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFramework, "wasm", "for-build");
79+
string relinkDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm", "for-build");
8080
if (relink)
8181
Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}");
8282

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.IO;
8+
using System.Diagnostics;
89
using System.Text;
9-
using System.Collections;
10-
using Xunit.Abstractions;
1110

1211
#nullable enable
1312

src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/NoopNativeRebuildTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void BlazorNoopRebuild(string config)
4444
string projectFile = CreateBlazorWasmTemplateProject(id);
4545
AddItemsPropertiesToProject(projectFile, extraProperties: "<WasmBuildNative>true</WasmBuildNative>");
4646

47-
string objDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFramework, "wasm");
47+
string objDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm");
4848

4949
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked));
5050
File.Move(Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-build.binlog"),
@@ -71,7 +71,7 @@ public void BlazorOnlyLinkRebuild(string config)
7171
string projectFile = CreateBlazorWasmTemplateProject(id);
7272
AddItemsPropertiesToProject(projectFile, extraProperties: "<WasmBuildNative>true</WasmBuildNative>");
7373

74-
string objDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFramework, "wasm");
74+
string objDir = Path.Combine(_projectDir!, "obj", config, DefaultTargetFrameworkForBlazor, "wasm");
7575

7676
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.Relinked), "-p:EmccLinkOptimizationFlag=-O2");
7777
File.Move(Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-build.binlog"),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Linq;
67
using Xunit;
78
using Xunit.Abstractions;
89

0 commit comments

Comments
 (0)