[wasm] Don't use `_WasmDevel=true` when publishing (#87544)
authorAnkit Jain <radical@gmail.com>
Thu, 15 Jun 2023 01:24:46 +0000 (21:24 -0400)
committerGitHub <noreply@github.com>
Thu, 15 Jun 2023 01:24:46 +0000 (21:24 -0400)
* [wasm] Add missing Wasm.Build.Tests.Blazor.AppsettingsTests to list of tests to run

* [wasm] CI: Trigger only wasm jobs on workload-testing.targets changes, since only wasm is using this currently

* [wasm] host: Add `--no-silent` command line parameter

- this is the equivalent to `--verbose`
- The default is "silent" behavior

Cannot use `--verbose` because that conflicts with `dotnet run`.

* [wasm] WBT: Update template tests to use `--no-silent` with `dotnet run`

.. which would be useful in debugging tests.

* [wasm] Don't use _WasmDevel=true whenever publishing

`_WasmDevel=true` causes the optimization flags to be `-O0`.

- This *was* automatically set whenever `Configuration=Debug`, and
`WasmBuildNative=true`, which is useful when relinking in inner loop.
- But when publishing, and relinking/AOT, `-O0` results in larger output.

* Update src/mono/wasm/host/JSEngineHost.cs

* Address feedback from @ilonatommy

eng/pipelines/common/evaluate-default-paths.yml
eng/testing/scenarios/BuildWasmAppsJobsList.txt
src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs
src/mono/wasm/build/WasmApp.Native.targets
src/mono/wasm/host/CommonConfiguration.cs
src/mono/wasm/host/JSEngineHost.cs
src/mono/wasm/host/Utils.cs

index 8527d6a..adf4dc8 100644 (file)
@@ -13,6 +13,7 @@ parameters:
         eng/testing/tests.browser.targets
         eng/testing/tests.was*.targets
         eng/testing/was*provisioning.targets
+        eng/testing/workloads-testing.targets
         src/libraries/sendtohelix-wasm.targets
         src/libraries/sendtohelix-wasi.targets
         src/mono/mono/**/*wasm*
index 914e6a2..e84e70c 100644 (file)
@@ -7,6 +7,7 @@ Wasm.Build.Tests.Blazor.BuildPublishTests
 Wasm.Build.Tests.Blazor.MiscTests
 Wasm.Build.Tests.Blazor.MiscTests2
 Wasm.Build.Tests.Blazor.NativeRefTests
+Wasm.Build.Tests.Blazor.AppsettingsTests
 Wasm.Build.Tests.BuildPublishTests
 Wasm.Build.Tests.CleanTests
 Wasm.Build.Tests.ConfigSrcTests
index ea57866..8b58299 100644 (file)
@@ -154,9 +154,11 @@ namespace Wasm.Build.Tests
 
             AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true, targetFramework: DefaultTargetFramework);
 
-            (int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config}", workingDir: _projectDir);
-            Assert.Equal(0, exitCode);
-            Assert.Contains("Hello, Console!", output);
+            CommandResult res = new RunCommand(s_buildEnv, _testOutput)
+                                        .WithWorkingDirectory(_projectDir!)
+                                        .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config}")
+                                        .EnsureSuccessful();
+            Assert.Contains("Hello, Console!", res.Output);
 
             if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product))
                 throw new XunitException($"Test bug: could not get the build product in the cache");
@@ -224,12 +226,14 @@ namespace Wasm.Build.Tests
 
             AssertDotNetJsSymbols(Path.Combine(GetBinDir(config, expectedTFM), "AppBundle"), fromRuntimePack: !relinking, targetFramework: expectedTFM);
 
-            (int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config} x y z", workingDir: _projectDir);
-            Assert.Equal(42, exitCode);
+            CommandResult res = new RunCommand(s_buildEnv, _testOutput)
+                                        .WithWorkingDirectory(_projectDir!)
+                                        .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config} x y z")
+                                        .EnsureExitCode(42);
 
-            Assert.Contains("args[0] = x", output);
-            Assert.Contains("args[1] = y", output);
-            Assert.Contains("args[2] = z", output);
+            Assert.Contains("args[0] = x", res.Output);
+            Assert.Contains("args[1] = y", res.Output);
+            Assert.Contains("args[2] = z", res.Output);
         }
 
         public static TheoryData<bool, bool, string> TestDataForAppBundleDir()
@@ -279,7 +283,7 @@ namespace Wasm.Build.Tests
                                             .WithWorkingDirectory(workingDir);
 
                 await using var runner = new BrowserRunner(_testOutput);
-                var page = await runner.RunAsync(runCommand, $"run -c {config} --project {projectFile} --forward-console");
+                var page = await runner.RunAsync(runCommand, $"run --no-silent -c {config} --project {projectFile} --forward-console");
                 await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2));
                 Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines));
             }
@@ -289,7 +293,7 @@ namespace Wasm.Build.Tests
                                             .WithWorkingDirectory(workingDir);
 
                 await using var runner = new BrowserRunner(_testOutput);
-                var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build --project {projectFile} --forward-console");
+                var page = await runner.RunAsync(runCommand, $"run --no-silent -c {config} --no-build --project {projectFile} --forward-console");
                 await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2));
                 Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines));
             }
@@ -309,7 +313,7 @@ namespace Wasm.Build.Tests
             string workingDir = runOutsideProjectDirectory ? BuildEnvironment.TmpPath : _projectDir!;
 
             {
-                string runArgs = $"run -c {config} --project {projectFile}";
+                string runArgs = $"run --no-silent -c {config} --project {projectFile}";
                 runArgs += " x y z";
                 using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id)
                                     .WithWorkingDirectory(workingDir)
@@ -325,7 +329,7 @@ namespace Wasm.Build.Tests
 
             {
                 // Run with --no-build
-                string runArgs = $"run -c {config} --project {projectFile} --no-build";
+                string runArgs = $"run --no-silent -c {config} --project {projectFile} --no-build";
                 runArgs += " x y z";
                 using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id)
                                 .WithWorkingDirectory(workingDir);
@@ -404,7 +408,7 @@ namespace Wasm.Build.Tests
                 AssertFilesDontExist(Path.Combine(GetBinDir(config), "AppBundle"), new[] { "dotnet.native.js.symbols" });
             }
 
-            string runArgs = $"run --no-build -c {config}";
+            string runArgs = $"run --no-silent --no-build -c {config}";
             runArgs += " x y z";
             var res = new RunCommand(s_buildEnv, _testOutput, label: id)
                                 .WithWorkingDirectory(_projectDir!)
@@ -440,7 +444,7 @@ namespace Wasm.Build.Tests
                                         .WithWorkingDirectory(_projectDir!);
 
             await using var runner = new BrowserRunner(_testOutput);
-            var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build -r browser-wasm --forward-console");
+            var page = await runner.RunAsync(runCommand, $"run --no-silent -c {config} --no-build -r browser-wasm --forward-console");
             await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2));
             Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines));
         }
index 8093fb9..0c8a017 100644 (file)
 
       <_DriverGenCNeeded Condition="'$(_DriverGenCNeeded)' == '' and '$(_WasmShouldAOT)' == 'true'">true</_DriverGenCNeeded>
 
-      <_WasmDevel Condition="'$(_WasmDevel)' == '' and '$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug'">true</_WasmDevel>
+      <_WasmDevel Condition="'$(_WasmDevel)' == '' and '$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">true</_WasmDevel>
 
       <_EmccOptimizationFlagDefault Condition="'$(_WasmDevel)' == 'true'">-O0</_EmccOptimizationFlagDefault>
       <_EmccOptimizationFlagDefault Condition="'$(_EmccOptimizationFlagDefault)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">-O1</_EmccOptimizationFlagDefault>
index db7a595..fc7e9eb 100644 (file)
@@ -1,8 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-#nullable enable
-
 using Mono.Options;
 using System.Linq;
 using System;
@@ -23,6 +21,7 @@ internal sealed class CommonConfiguration
     public HostConfig HostConfig { get; init; }
     public WasmHostProperties HostProperties { get; init; }
     public IEnumerable<string> HostArguments { get; init; }
+    public bool Silent { get; private set; } = true;
 
     private string? hostArg;
     private string? _runtimeConfigPath;
@@ -38,6 +37,7 @@ internal sealed class CommonConfiguration
             { "host|h=", "Host config name", v => hostArg = v },
             { "runtime-config|r=", "runtimeconfig.json path for the app", v => _runtimeConfigPath = v },
             { "extra-host-arg=", "Extra argument to be passed to the host", hostArgsList.Add },
+            { "no-silent", "Verbose output from WasmAppHost", _ => Silent = false }
         };
 
         RemainingArgs = options.Parse(args);
index cfcdf35..c7e9e6d 100644 (file)
@@ -25,14 +25,14 @@ internal sealed class JSEngineHost
         _logger = logger;
     }
 
-    public static async Task<int> InvokeAsync(CommonConfiguration commonArgs,
+    public static Task<int> InvokeAsync(CommonConfiguration commonArgs,
                                               ILoggerFactory _,
                                               ILogger logger,
                                               CancellationToken _1)
     {
         var args = new JSEngineArguments(commonArgs);
         args.Validate();
-        return await new JSEngineHost(args, logger).RunAsync();
+        return new JSEngineHost(args, logger).RunAsync();
     }
 
     private async Task<int> RunAsync()
@@ -88,8 +88,11 @@ internal sealed class JSEngineHost
         int exitCode = await Utils.TryRunProcess(psi,
                                     _logger,
                                     msg => { if (msg != null) _logger.LogInformation(msg); },
-                                    msg => { if (msg != null) _logger.LogInformation(msg); });
+                                    msg => { if (msg != null) _logger.LogInformation(msg); },
+                                    silent: _args.CommonConfig.Silent);
 
+        if (!_args.CommonConfig.Silent)
+            Console.WriteLine($"{_args.Host} exited with {exitCode}");
         return exitCode;
     }
 }
index 5ed3bc4..80d5540 100644 (file)
@@ -17,10 +17,12 @@ public class Utils
         ILogger logger,
         Action<string?>? logStdOut = null,
         Action<string?>? logStdErr = null,
+        bool silent = false,
         string? label = null)
     {
         string msgPrefix = label == null ? string.Empty : $"[{label}] ";
-        logger.LogInformation($"{msgPrefix}Running: {psi.FileName} {string.Join(" ", psi.ArgumentList)}");
+        if (!silent)
+            logger.LogInformation($"{msgPrefix}Running: {psi.FileName} {string.Join(" ", psi.ArgumentList)}");
 
         psi.UseShellExecute = false;
         psi.CreateNoWindow = true;
@@ -29,7 +31,8 @@ public class Utils
         if (logStdErr != null)
             psi.RedirectStandardError = true;
 
-        logger.LogDebug($"{msgPrefix}Using working directory: {psi.WorkingDirectory ?? Environment.CurrentDirectory}", msgPrefix);
+        if (!silent)
+            logger.LogDebug($"{msgPrefix}Using working directory: {psi.WorkingDirectory ?? Environment.CurrentDirectory}", msgPrefix);
 
         // if (psi.EnvironmentVariables.Count > 0)
             // logger.LogDebug($"{msgPrefix}Setting environment variables for execution:", msgPrefix);