From 6631b47896d1111fa984c8ceef3ae7e7bb47caea Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 1 Nov 2022 13:48:32 -0400 Subject: [PATCH] [wasm] Fix analyzer support in templates (#77704) - Add `[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")]` to the browser, and console templates. This would allow the analyzers, if enabled, to treat the assembly as one that will run only on browser. - Populate `@(SupportedPlatform)` with only `browser`, for *wasm* projects, similar to https://github.com/dotnet/sdk/blob/fef8cedfb6b4ac85a7e135f3e4f155e29cdcbdf1/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.5_0.targets#L75-L79 - This also fixes the firefox CI build which regressed recently --- src/libraries/sendtohelix-wasm.targets | 18 +++++------------- src/libraries/sendtohelix.proj | 1 + src/mono/sample/wasm/CommonAssemblyInfo.cs | 4 ++++ src/mono/sample/wasm/Directory.Build.props | 2 ++ .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 7 +++++-- src/mono/wasm/build/WasmApp.targets | 3 +++ .../DebuggerTestSuite/DebuggerTestSuite.csproj | 5 +++-- .../Wasm.Debugger.Tests.csproj | 1 + .../browser/Properties/AssemblyInfo.cs | 4 ++++ .../console/Properties/AssemblyInfo.cs | 4 ++++ 10 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 src/mono/sample/wasm/CommonAssemblyInfo.cs create mode 100644 src/mono/wasm/templates/templates/browser/Properties/AssemblyInfo.cs create mode 100644 src/mono/wasm/templates/templates/console/Properties/AssemblyInfo.cs diff --git a/src/libraries/sendtohelix-wasm.targets b/src/libraries/sendtohelix-wasm.targets index fcdcdad18e3..12edd38bd05 100644 --- a/src/libraries/sendtohelix-wasm.targets +++ b/src/libraries/sendtohelix-wasm.targets @@ -38,14 +38,12 @@ $(BuildHelixWorkItemsDependsOn);StageEmSdkForHelix;PrepareForBuildHelixWorkItems_Wasm - $(BuildHelixWorkItemsDependsOn);DownloadFirefoxToSendToHelix false false $(RepoRoot)src\mono\wasm\emsdk\ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'emsdk')) - $(TestArchiveRoot)firefox.zip chrome true @@ -159,17 +157,18 @@ - - + - - + @@ -291,11 +290,4 @@ DestinationFiles="@(_EmSdkFiles -> '$(EmSdkDirForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')" SkipUnchangedFiles="true" /> - - - - - - - diff --git a/src/libraries/sendtohelix.proj b/src/libraries/sendtohelix.proj index 60de339e340..6aca13e92bc 100644 --- a/src/libraries/sendtohelix.proj +++ b/src/libraries/sendtohelix.proj @@ -48,6 +48,7 @@ HelixTargetQueues=$(HelixTargetQueues); BuildTargetFramework=$(BuildTargetFramework) + <_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">$(DebuggerHost) <_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">chrome diff --git a/src/mono/sample/wasm/CommonAssemblyInfo.cs b/src/mono/sample/wasm/CommonAssemblyInfo.cs new file mode 100644 index 00000000000..9ad9b578f20 --- /dev/null +++ b/src/mono/sample/wasm/CommonAssemblyInfo.cs @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] diff --git a/src/mono/sample/wasm/Directory.Build.props b/src/mono/sample/wasm/Directory.Build.props index 7382a6e5ce8..d03dbcf0213 100644 --- a/src/mono/sample/wasm/Directory.Build.props +++ b/src/mono/sample/wasm/Directory.Build.props @@ -32,6 +32,8 @@ + + diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 5e87669e4cf..e1c52076598 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -463,7 +463,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s return contents.Replace(s_nugetInsertionTag, $@""); } - public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "") + public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "", bool runAnalyzers = true) { InitPaths(id); InitProjectDir(_projectDir, addNuGetSourceForLocalPackages: true); @@ -483,7 +483,10 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse .ExecuteWithCapturedOutput($"new {template} {extraArgs}") .EnsureSuccessful(); - return Path.Combine(_projectDir!, $"{id}.csproj"); + string projectfile = Path.Combine(_projectDir!, $"{id}.csproj"); + if (runAnalyzers) + AddItemsPropertiesToProject("true"); + return projectfile; } public string CreateBlazorWasmTemplateProject(string id) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 5cb9d26781b..a2031cab545 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -120,6 +120,9 @@ + + + diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestSuite.csproj b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestSuite.csproj index 68dd92779b0..d74faaeb66e 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestSuite.csproj +++ b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestSuite.csproj @@ -7,8 +7,9 @@ chrome $(DefineConstants);RUN_IN_CHROME windows - true - true + <_ProvisionBrowser Condition="'$(ContinuousIntegrationBuild)' == 'true' or Exists('/.dockerenv')">true + true + true $(OutputPath).runsettings diff --git a/src/mono/wasm/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj b/src/mono/wasm/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj index 2dd8ac14f2b..66490809749 100644 --- a/src/mono/wasm/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj +++ b/src/mono/wasm/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj @@ -37,6 +37,7 @@ ArchiveDirForHelix=$(TargetDir); TestArchiveTestsDir=$(TestArchiveTestsDir); ExtractTestClassNamesForHelix=$(ExtractTestClassNamesForHelix); + DebuggerHost=$(DebuggerHost); DotNetForTests=$([MSBuild]::NormalizePath($(DotNetRoot), $(DotNetTool)))" /> diff --git a/src/mono/wasm/templates/templates/browser/Properties/AssemblyInfo.cs b/src/mono/wasm/templates/templates/browser/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..9ad9b578f20 --- /dev/null +++ b/src/mono/wasm/templates/templates/browser/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] diff --git a/src/mono/wasm/templates/templates/console/Properties/AssemblyInfo.cs b/src/mono/wasm/templates/templates/console/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..9ad9b578f20 --- /dev/null +++ b/src/mono/wasm/templates/templates/console/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] -- GitLab