Skip to content

Commit 870e466

Browse files
maraflewingjeffschwMSFT
authored
[release/9.0] [browser] Make boot json file name configurable (#108708)
* [browser] Make boot json file name configurable * Fix test based on state in 9 * Avoid need for change in SDK repo --------- Co-authored-by: Larry Ewing <[email protected]> Co-authored-by: Jeff Schwartz <[email protected]>
1 parent 3fcc122 commit 870e466

File tree

8 files changed

+67
-10
lines changed

8 files changed

+67
-10
lines changed

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ Copyright (c) .NET Foundation. All rights reserved.
199199
<_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">false</_WasmFingerprintAssets>
200200
<_WasmFingerprintDotnetJs>$(WasmFingerprintDotnetJs)</_WasmFingerprintDotnetJs>
201201
<_WasmFingerprintDotnetJs Condition="'$(_WasmFingerprintDotnetJs)' == ''">false</_WasmFingerprintDotnetJs>
202+
<_WasmBootConfigFileName>$(WasmBootConfigFileName)</_WasmBootConfigFileName>
203+
<_WasmBootConfigFileName Condition="'$(_WasmBootConfigFileName)' == ''">blazor.boot.json</_WasmBootConfigFileName>
204+
<_WasmPublishBootConfigFileName Condition="'$(_WasmBootConfigFileName)' == 'blazor.boot.json'">blazor.publish.boot.json</_WasmPublishBootConfigFileName>
205+
<_WasmPublishBootConfigFileName Condition="'$(_WasmPublishBootConfigFileName)' == ''">publish.$(_WasmBootConfigFileName)</_WasmPublishBootConfigFileName>
202206

203207
<!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
204208
<PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
@@ -327,7 +331,7 @@ Copyright (c) .NET Foundation. All rights reserved.
327331

328332
<Target Name="_GenerateBuildWasmBootJson" DependsOnTargets="$(GenerateBuildWasmBootJsonDependsOn)">
329333
<PropertyGroup>
330-
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
334+
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)$(_WasmBootConfigFileName)</_WasmBuildBootJsonPath>
331335
</PropertyGroup>
332336

333337
<ItemGroup>
@@ -392,13 +396,13 @@ Copyright (c) .NET Foundation. All rights reserved.
392396
</ItemGroup>
393397

394398
<PropertyGroup>
395-
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
399+
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)$(_WasmBootConfigFileName)</_WasmBuildBootJsonPath>
396400
</PropertyGroup>
397401

398402
<ItemGroup>
399403
<_BuildWasmBootJson
400404
Include="$(_WasmBuildBootJsonPath)"
401-
RelativePath="_framework/blazor.boot.json" />
405+
RelativePath="_framework/$(_WasmBootConfigFileName)" />
402406
</ItemGroup>
403407

404408
<DefineStaticWebAssets
@@ -589,8 +593,8 @@ Copyright (c) .NET Foundation. All rights reserved.
589593
<Target Name="_AddPublishWasmBootJsonToStaticWebAssets" DependsOnTargets="GeneratePublishWasmBootJson">
590594
<ItemGroup>
591595
<_PublishWasmBootJson
592-
Include="$(IntermediateOutputPath)blazor.publish.boot.json"
593-
RelativePath="_framework/blazor.boot.json" />
596+
Include="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"
597+
RelativePath="_framework/$(_WasmBootConfigFileName)" />
594598
</ItemGroup>
595599

596600
<DefineStaticWebAssets
@@ -659,7 +663,7 @@ Copyright (c) .NET Foundation. All rights reserved.
659663
DebugLevel="$(WasmDebugLevel)"
660664
LinkerEnabled="$(PublishTrimmed)"
661665
CacheBootResources="$(BlazorCacheBootResources)"
662-
OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json"
666+
OutputPath="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"
663667
ConfigurationFiles="@(_WasmPublishConfigFile)"
664668
LazyLoadedAssemblies="@(BlazorWebAssemblyLazyLoad)"
665669
InvariantGlobalization="$(InvariantGlobalization)"
@@ -679,7 +683,7 @@ Copyright (c) .NET Foundation. All rights reserved.
679683
FingerprintAssets="$(_WasmFingerprintAssets)" />
680684

681685
<ItemGroup>
682-
<FileWrites Include="$(IntermediateOutputPath)blazor.publish.boot.json" />
686+
<FileWrites Include="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)" />
683687
</ItemGroup>
684688

685689
</Target>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public record AssertWasmSdkBundleOptions(
1313
string BinFrameworkDir,
1414
string? PredefinedIcudt,
1515
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
16-
string BootJsonFileName = "blazor.boot.json",
16+
string BootConfigFileName = "blazor.boot.json",
1717
NativeFilesType ExpectedFileType = NativeFilesType.FromRuntimePack,
1818
RuntimeVariant RuntimeType = RuntimeVariant.SingleThreaded,
1919
bool ExpectFingerprintOnDotnetJs = false,
@@ -29,7 +29,7 @@ public record AssertWasmSdkBundleOptions(
2929
GlobalizationMode: GlobalizationMode,
3030
ExpectedFileType: ExpectedFileType,
3131
RuntimeType: RuntimeType,
32-
BootJsonFileName: BootJsonFileName,
32+
BootJsonFileName: BootConfigFileName,
3333
ExpectFingerprintOnDotnetJs: ExpectFingerprintOnDotnetJs,
3434
ExpectSymbolsFile: ExpectSymbolsFile,
3535
AssertIcuAssets: AssertIcuAssets,

src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorBuildOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public record BlazorBuildOptions
1111
string Config,
1212
NativeFilesType ExpectedFileType = NativeFilesType.FromRuntimePack,
1313
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor,
14+
string BootConfigFileName = "blazor.boot.json",
1415
bool IsPublish = false,
1516
bool WarnAsError = true,
1617
bool ExpectSuccess = true,

src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmProjectProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public BlazorWasmProjectProvider(ITestOutputHelper _testOutput, string? _project
1616
public void AssertBundle(BlazorBuildOptions options)
1717
=> AssertBundle(new AssertWasmSdkBundleOptions(
1818
Config: options.Config,
19+
BootConfigFileName: options.BootConfigFileName,
1920
IsPublish: options.IsPublish,
2021
TargetFramework: options.TargetFramework,
2122
BinFrameworkDir: options.BinFrameworkDir ?? FindBinFrameworkDir(options.Config, options.IsPublish, options.TargetFramework),

src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected void BuildProject(
6060
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
6161
bool assertAppBundle = true,
6262
bool expectSuccess = true,
63+
string bootConfigFileName = "blazor.boot.json",
6364
params string[] extraArgs)
6465
{
6566
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(
@@ -68,6 +69,7 @@ protected void BuildProject(
6869
BinFrameworkDir: binFrameworkDir,
6970
RuntimeType: runtimeType,
7071
AssertAppBundle: assertAppBundle,
72+
BootConfigFileName: bootConfigFileName,
7173
ExpectSuccess: expectSuccess), extraArgs);
7274
if (expectSuccess)
7375
{
@@ -83,12 +85,14 @@ protected void PublishProject(
8385
string configuration,
8486
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
8587
bool assertAppBundle = true,
88+
string bootConfigFileName = "blazor.boot.json",
8689
params string[] extraArgs)
8790
{
8891
(CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(
8992
Id: Id,
9093
Config: configuration,
9194
RuntimeType: runtimeType,
95+
BootConfigFileName: bootConfigFileName,
9296
AssertAppBundle: assertAppBundle), extraArgs);
9397
result.EnsureSuccessful();
9498
}

src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/ModuleConfigTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,33 @@ public async Task OutErrOverrideWorks()
7474
"Emscripten err override doesn't work"
7575
);
7676
}
77+
78+
[Theory]
79+
[InlineData("Release", true)]
80+
[InlineData("Release", false)]
81+
public async Task OverrideBootConfigName(string config, bool isPublish)
82+
{
83+
CopyTestAsset("WasmBasicTestApp", $"OverrideBootConfigName", "App");
84+
85+
string[] extraArgs = ["-p:WasmBootConfigFileName=boot.json"];
86+
if (isPublish)
87+
PublishProject(config, bootConfigFileName: "boot.json", extraArgs: extraArgs);
88+
else
89+
BuildProject(config, bootConfigFileName: "boot.json", extraArgs: extraArgs);
90+
91+
var runOptions = new RunOptions(
92+
Configuration: config,
93+
TestScenario: "OverrideBootConfigName"
94+
);
95+
var result = await (isPublish
96+
? RunSdkStyleAppForPublish(runOptions)
97+
: RunSdkStyleAppForBuild(runOptions)
98+
);
99+
100+
Assert.Collection(
101+
result.TestOutput,
102+
m => Assert.Equal("ConfigSrc: boot.json", m),
103+
m => Assert.Equal("Managed code has run", m)
104+
);
105+
}
77106
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Runtime.InteropServices.JavaScript;
2+
3+
public partial class OverrideBootConfigNameTest
4+
{
5+
[JSExport]
6+
public static void Run()
7+
{
8+
TestOutput.WriteLine("Managed code has run");
9+
}
10+
}

src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ switch (testCase) {
126126
};
127127
dotnet.withConfig({ maxParallelDownloads: maxParallelDownloads });
128128
break;
129+
case "OverrideBootConfigName":
130+
dotnet.withConfigSrc("boot.json");
131+
break;
129132
}
130133

131-
const { setModuleImports, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create();
134+
const { setModuleImports, Module, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create();
132135
const config = getConfig();
133136
const exports = await getAssemblyExports(config.mainAssemblyName);
134137
const assemblyExtension = Object.keys(config.resources.coreAssembly)[0].endsWith('.wasm') ? ".wasm" : ".dll";
@@ -206,6 +209,11 @@ try {
206209
exports.MemoryTest.Run();
207210
exit(0);
208211
break;
212+
break;
213+
case "OverrideBootConfigName":
214+
testOutput("ConfigSrc: " + Module.configSrc);
215+
exports.OverrideBootConfigNameTest.Run();
216+
exit(0);
209217
default:
210218
console.error(`Unknown test case: ${testCase}`);
211219
exit(3);

0 commit comments

Comments
 (0)