// on Linux sharding does not work because we rely on LANG env var to check locale and emcc is overwriting it
protected static RunHost s_hostsForOSLocaleSensitiveTests = RunHost.Chrome;
// FIXME: use an envvar to override this
- protected static int s_defaultPerTestTimeoutMs = s_isWindows ? 30*60*1000 : 15*60*1000;
+ protected static int s_defaultPerTestTimeoutMs = s_isWindows ? 30 * 60 * 1000 : 15 * 60 * 1000;
protected static BuildEnvironment s_buildEnv;
private const string s_runtimePackPathPattern = "\\*\\* MicrosoftNetCoreAppRuntimePackDir : '([^ ']*)'";
private const string s_nugetInsertionTag = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->";
public static bool UseWebcil => s_buildEnv.UseWebcil;
public static string GetNuGetConfigPathFor(string targetFramework) =>
Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with
- // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
+ // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
static BuildTestBase()
{
else
s_xharnessRunnerCommand = EnvironmentVariables.XHarnessCliPath;
- Console.WriteLine ("");
- Console.WriteLine ($"==============================================================================================");
- Console.WriteLine ($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ===============");
+ Console.WriteLine("");
+ Console.WriteLine($"==============================================================================================");
+ Console.WriteLine($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ===============");
if (UseWebcil)
Console.WriteLine($"=============== Using .webcil ===============");
- Console.WriteLine ($"==============================================================================================");
- Console.WriteLine ("");
+ Console.WriteLine($"==============================================================================================");
+ Console.WriteLine("");
}
catch (Exception ex)
{
- Console.WriteLine ($"Exception: {ex}");
+ Console.WriteLine($"Exception: {ex}");
throw;
}
}
- aot but no wrapper - check that AppBundle wasn't generated
*/
- public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config=null, string? extraArgs=null)
+ public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config = null, string? extraArgs = null)
{
if (extraArgs == null)
extraArgs = string.Empty;
protected string RunAndTestWasmApp(BuildArgs buildArgs,
RunHost host,
string id,
- Action<string>? test=null,
+ Action<string>? test = null,
string? buildDir = null,
string? bundleDir = null,
int expectedExitCode = 0,
}
protected static string RunWithXHarness(string testCommand, string testLogPath, string projectName, string bundleDir,
- ITestOutputHelper _testOutput, IDictionary<string, string>? envVars=null,
- int expectedAppExitCode=0, int xharnessExitCode=0, string? extraXHarnessArgs=null,
- string? appArgs=null, string? extraXHarnessMonoArgs = null, bool useWasmConsoleOutput = false)
+ ITestOutputHelper _testOutput, IDictionary<string, string>? envVars = null,
+ int expectedAppExitCode = 0, int xharnessExitCode = 0, string? extraXHarnessArgs = null,
+ string? appArgs = null, string? extraXHarnessMonoArgs = null, bool useWasmConsoleOutput = false)
{
_testOutput.WriteLine($"============== {testCommand} =============");
Directory.CreateDirectory(testLogPath);
##INSERT_AT_END##
</Project>";
- protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties="", string extraItems="", string insertAtEnd="", string projectTemplate=SimpleProjectTemplate)
+ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties = "", string extraItems = "", string insertAtEnd = "", string projectTemplate = SimpleProjectTemplate)
{
if (buildArgs.AOT)
{
extraProperties += $"\n<EmccVerbose>{s_isWindows}</EmccVerbose>\n";
}
- if (UseWebcil) {
+ if (UseWebcil)
+ {
extraProperties += "<WasmEnableWebcil>true</WasmEnableWebcil>\n";
}
string msgPrefix = options.Label != null ? $"[{options.Label}] " : string.Empty;
if (options.UseCache && _buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product))
{
- _testOutput.WriteLine ($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}");
+ _testOutput.WriteLine($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}");
if (!product.Result)
throw new XunitException($"Found existing build at {product.ProjectDir}, but it had failed. Check build log at {product.LogFile}");
return res;
}
- protected (CommandResult, string) BlazorBuildInternal(string id, string config, bool publish=false, bool setWasmDevel=true, params string[] extraArgs)
+ protected (CommandResult, string) BlazorBuildInternal(string id, string config, bool publish = false, bool setWasmDevel = true, params string[] extraArgs)
{
string label = publish ? "publish" : "build";
_testOutput.WriteLine($"{Environment.NewLine}** {label} **{Environment.NewLine}");
{
mainJS,
"dotnet.native.wasm",
- "mono-config.json",
+ "_framework/blazor.boot.json",
"dotnet.js",
"dotnet.native.js",
"dotnet.runtime.js"
//FIXME: um.. what about these? embedded? why is linker omitting them?
//foreach (string file in Directory.EnumerateFiles(managedDir, "*.dll"))
//{
- //string pdb = Path.ChangeExtension(file, ".pdb");
- //Assert.True(File.Exists(pdb), $"Could not find {pdb} for {file}");
+ //string pdb = Path.ChangeExtension(file, ".pdb");
+ //Assert.True(File.Exists(pdb), $"Could not find {pdb} for {file}");
//}
}
protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null)
=> AssertFilesExist(dir, filenames, label, expectToExist: false);
- protected static void AssertFilesExist(string dir, IEnumerable<string> filenames, string? label = null, bool expectToExist=true)
+ protected static void AssertFilesExist(string dir, IEnumerable<string> filenames, string? label = null, bool expectToExist = true)
{
string prefix = label != null ? $"{label}: " : string.Empty;
if (!Directory.Exists(dir))
}
}
- protected static void AssertSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: true);
- protected static void AssertNotSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: false);
+ protected static void AssertSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: true);
+ protected static void AssertNotSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: false);
- protected static void AssertFile(string file0, string file1, string? label=null, bool same=true)
+ protected static void AssertFile(string file0, string file1, string? label = null, bool same = true)
{
Assert.True(File.Exists(file0), $"{label}: Expected to find {file0}");
Assert.True(File.Exists(file1), $"{label}: Expected to find {file1}");
throw new XunitException($"{label}:{Environment.NewLine} File sizes should not match for {file0} ({finfo0.Length}), and {file1} ({finfo1.Length})");
}
- protected (int exitCode, string buildOutput) AssertBuild(string args, string label="build", bool expectSuccess=true, IDictionary<string, string>? envVars=null, int? timeoutMs=null)
+ protected (int exitCode, string buildOutput) AssertBuild(string args, string label = "build", bool expectSuccess = true, IDictionary<string, string>? envVars = null, int? timeoutMs = null)
{
var result = RunProcess(s_buildEnv.DotNet, _testOutput, args, workingDir: _projectDir, label: label, envVars: envVars, timeoutMs: timeoutMs ?? s_defaultPerTestTimeoutMs);
if (expectSuccess && result.exitCode != 0)
return result;
}
- protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir=null)
+ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasmFromRuntimePack, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null)
{
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework);
var runtimeObj = bootJsonNode?["resources"]?["runtime"]?.AsObject();
Assert.NotNull(runtimeObj);
- string msgPrefix=$"[{( isPublish ? "publish" : "build" )}]";
+ string msgPrefix = $"[{(isPublish ? "publish" : "build")}]";
Assert.True(runtimeObj!.Where(kvp => kvp.Key == (isNet7AndBelow ? "dotnet.wasm" : "dotnet.native.wasm")).Any(), $"{msgPrefix} Could not find dotnet.native.wasm entry in blazor.boot.json");
Assert.True(runtimeObj!.Where(kvp => kvp.Key.StartsWith("dotnet.", StringComparison.OrdinalIgnoreCase) &&
kvp.Key.EndsWith(".js", StringComparison.OrdinalIgnoreCase)).Any(),
return first ?? Path.Combine(parentDir, dirName);
}
- protected string GetBinDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null)
+ protected string GetBinDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null)
{
var dir = baseDir ?? _projectDir;
Assert.NotNull(dir);
return Path.Combine(dir!, "bin", config, targetFramework, "browser-wasm");
}
- protected string GetObjDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null)
+ protected string GetObjDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null)
{
var dir = baseDir ?? _projectDir;
Assert.NotNull(dir);
return projectFile;
}
- public void BlazorAddRazorButton(string buttonText, string customCode, string methodName="test", string razorPage="Pages/Counter.razor")
+ public void BlazorAddRazorButton(string buttonText, string customCode, string methodName = "test", string razorPage = "Pages/Counter.razor")
{
string additionalCode = $$"""
<p role="{{methodName}}">Output: @outputText</p>
// Keeping these methods with explicit Build/Publish in the name
// so in the test code it is evident which is being run!
- public Task BlazorRunForBuildWithDotnetRun(string config, Func<IPage, Task>? test=null, string extraArgs="--no-build")
+ public Task BlazorRunForBuildWithDotnetRun(string config, Func<IPage, Task>? test = null, string extraArgs = "--no-build")
=> BlazorRunTest($"run -c {config} {extraArgs}", _projectDir!, test);
- public Task BlazorRunForPublishWithWebServer(string config, Func<IPage, Task>? test=null, string extraArgs="")
+ public Task BlazorRunForPublishWithWebServer(string config, Func<IPage, Task>? test = null, string extraArgs = "")
=> BlazorRunTest($"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files {extraArgs}",
Path.GetFullPath(Path.Combine(FindBlazorBinFrameworkDir(config, forPublish: true), "..")),
test);
{
_testOutput.WriteLine($"Running {path} {args}");
_testOutput.WriteLine($"WorkingDirectory: {workingDir}");
- StringBuilder outputBuilder = new ();
+ StringBuilder outputBuilder = new();
object syncObj = new();
var processStartInfo = new ProcessStartInfo
processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath");
}
- Process process = new ();
+ Process process = new();
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;
}
}
- public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties=null, string? extraItems=null, string? atTheEnd=null)
+ public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties = null, string? extraItems = null, string? atTheEnd = null)
{
if (!File.Exists(projectFile))
- throw new Exception ($"{projectFile} does not exist");
+ throw new Exception($"{projectFile} does not exist");
if (extraProperties == null && extraItems == null && atTheEnd == null)
return projectFile;
return string.IsNullOrEmpty(value) ? defaultValue : value;
}
- internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish=true)
+ internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish = true)
{
string objDir = GetObjDir(buildArgs.Config);
string bundleDir = Path.Combine(GetBinDir(baseDir: _projectDir, config: buildArgs.Config), "AppBundle");
string ProjectFileContents,
string? ExtraBuildArgs);
public record BuildProduct(string ProjectDir, string LogFile, bool Result, string BuildOutput);
- internal record FileStat (bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath);
+ internal record FileStat(bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath);
internal record BuildPaths(string ObjWasmDir, string ObjDir, string BinDir, string BundleDir);
public record BuildProjectOptions
(
- Action? InitProject = null,
- bool? DotnetWasmFromRuntimePack = null,
- GlobalizationMode? GlobalizationMode = null,
- string? PredefinedIcudt = null,
- bool UseCache = true,
- bool ExpectSuccess = true,
- bool AssertAppBundle = true,
- bool CreateProject = true,
- bool Publish = true,
- bool BuildOnlyAfterPublish = true,
- bool HasV8Script = true,
- string? Verbosity = null,
- string? Label = null,
- string? TargetFramework = null,
- string? MainJS = null,
- bool IsBrowserProject = true,
+ Action? InitProject = null,
+ bool? DotnetWasmFromRuntimePack = null,
+ GlobalizationMode? GlobalizationMode = null,
+ string? PredefinedIcudt = null,
+ bool UseCache = true,
+ bool ExpectSuccess = true,
+ bool AssertAppBundle = true,
+ bool CreateProject = true,
+ bool Publish = true,
+ bool BuildOnlyAfterPublish = true,
+ bool HasV8Script = true,
+ string? Verbosity = null,
+ string? Label = null,
+ string? TargetFramework = null,
+ string? MainJS = null,
+ bool IsBrowserProject = true,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
);
NativeFilesType ExpectedFileType,
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor,
bool WarnAsError = true,
- bool ExpectRelinkDirWhenPublishing=false
+ bool ExpectRelinkDirWhenPublishing = false
);
public enum GlobalizationMode
public class WasmAppBuilder : WasmAppBuilderBaseTask
{
public ITaskItem[]? RemoteSources { get; set; }
- public bool IncludeThreadsWorker {get; set; }
- public int PThreadPoolSize {get; set; }
+ public bool IncludeThreadsWorker { get; set; }
+ public int PThreadPoolSize { get; set; }
public bool UseWebcil { get; set; }
// <summary>
- // Extra json elements to add to mono-config.json
+ // Extra json elements to add to _framework/blazor.boot.json
//
// Metadata:
// - Value: can be a number, bool, quoted string, or json string
private class AssetEntry
{
- protected AssetEntry (string name, string hash, string behavior)
+ protected AssetEntry(string name, string hash, string behavior)
{
Name = name;
Behavior = behavior;
private sealed class AssemblyEntry : AssetEntry
{
- public AssemblyEntry(string name, string hash) : base(name, hash, "assembly") {}
+ public AssemblyEntry(string name, string hash) : base(name, hash, "assembly") { }
}
private sealed class PdbEntry : AssetEntry
{
- public PdbEntry(string name, string hash) : base(name, hash, "pdb") {}
+ public PdbEntry(string name, string hash) : base(name, hash, "pdb") { }
}
private sealed class SatelliteAssemblyEntry : AssetEntry
private sealed class VfsEntry : AssetEntry
{
- public VfsEntry(string name, string hash) : base(name, hash, "vfs") {}
+ public VfsEntry(string name, string hash) : base(name, hash, "vfs") { }
[JsonPropertyName("virtualPath")]
public string? VirtualPath { get; set; }
}
private sealed class IcuData : AssetEntry
{
- public IcuData(string name, string hash) : base(name, hash, "icu") {}
+ public IcuData(string name, string hash) : base(name, hash, "icu") { }
[JsonPropertyName("loadRemote")]
public bool LoadRemote { get; set; }
}
private sealed class SymbolsData : AssetEntry
{
- public SymbolsData(string name, string hash) : base(name, hash, "symbols") {}
+ public SymbolsData(string name, string hash) : base(name, hash, "symbols") { }
}
protected override bool ValidateArguments()
}
MainAssemblyName = Path.GetFileName(MainAssemblyName);
- var config = new WasmAppConfig ()
+ var config = new WasmAppConfig()
{
MainAssemblyName = MainAssemblyName,
GlobalizationMode = InvariantGlobalization ? "invariant" : HybridGlobalization ? "hybrid" : "icu"
Directory.CreateDirectory(AppDir!);
Directory.CreateDirectory(asmRootPath);
if (UseWebcil)
- Log.LogMessage (MessageImportance.Normal, "Converting assemblies to Webcil");
+ Log.LogMessage(MessageImportance.Normal, "Converting assemblies to Webcil");
foreach (var assembly in _assemblies)
{
if (UseWebcil)
}
else if (name == "dotnet.native.wasm")
{
- config.Assets.Add(new WasmEntry (name, Utils.ComputeIntegrity(item.ItemSpec)) );
+ config.Assets.Add(new WasmEntry(name, Utils.ComputeIntegrity(item.ItemSpec)));
}
else if (name == "dotnet.native.js")
{
}
else if (IncludeThreadsWorker && name == "dotnet.native.worker.js")
{
- config.Assets.Add(new ThreadsWorkerEntry (name, Utils.ComputeIntegrity(item.ItemSpec)));
+ config.Assets.Add(new ThreadsWorkerEntry(name, Utils.ComputeIntegrity(item.ItemSpec)));
}
- else if(name == "dotnet.native.js.symbols")
+ else if (name == "dotnet.native.js.symbols")
{
config.Assets.Add(new SymbolsData(name, Utils.ComputeIntegrity(item.ItemSpec)));
}
var vfsPath = Path.Combine(supportFilesDir, generatedFileName);
FileCopyChecked(item.ItemSpec, vfsPath, "FilesToIncludeInFileSystem");
- var asset = new VfsEntry ($"supportFiles/{generatedFileName}", Utils.ComputeIntegrity(vfsPath)) {
+ var asset = new VfsEntry($"supportFiles/{generatedFileName}", Utils.ComputeIntegrity(vfsPath))
+ {
VirtualPath = targetPath
};
config.Assets.Add(asset);
using (var sw = File.CreateText(tmpMonoConfigPath))
{
var sb = new StringBuilder();
- foreach(AssetEntry asset in config.Assets)
+ foreach (AssetEntry asset in config.Assets)
{
sb.Append(asset.Hash);
}
config.AssetsHash = Utils.ComputeTextIntegrity(sb.ToString());
- var json = JsonSerializer.Serialize (config, new JsonSerializerOptions { WriteIndented = true });
+ var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
sw.Write(json);
}
- string monoConfigPath = Path.Combine(AppDir, "mono-config.json");
+
+ string monoConfigDir = Path.Combine(AppDir, "_framework");
+ if (!Directory.Exists(monoConfigDir))
+ Directory.CreateDirectory(monoConfigDir);
+
+ string monoConfigPath = Path.Combine(monoConfigDir, "blazor.boot.json"); // TODO: Unify with Wasm SDK
Utils.CopyIfDifferent(tmpMonoConfigPath, monoConfigPath, useHash: false);
_fileWrites.Add(monoConfigPath);