Skip to content

Commit

Permalink
[wasm] Fix analyzer support in templates (#77704)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
radical authored Nov 1, 2022
1 parent 7ba371c commit 6631b47
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 17 deletions.
18 changes: 5 additions & 13 deletions src/libraries/sendtohelix-wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
</PrepareForBuildHelixWorkItems_WasmDependsOn>

<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);StageEmSdkForHelix;PrepareForBuildHelixWorkItems_Wasm</BuildHelixWorkItemsDependsOn>
<BuildHelixWorkItemsDependsOn Condition="'$(WindowsShell)' != 'true'">$(BuildHelixWorkItemsDependsOn);DownloadFirefoxToSendToHelix</BuildHelixWorkItemsDependsOn>
<IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload>
<EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems>

<!-- on unix CI has emscripten provisioned in $(EMSDK_PATH) as `/usr/local/emscripten`. -->
<EMSDK_PATH Condition="$([MSBuild]::IsOSPlatform('WINDOWS')) and '$(EMSDK_PATH)' == ''">$(RepoRoot)src\mono\wasm\emsdk\</EMSDK_PATH>
<EmSdkDirForHelixPayload>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'emsdk'))</EmSdkDirForHelixPayload>
<FirefoxForHelixPayload>$(TestArchiveRoot)firefox.zip</FirefoxForHelixPayload>
<DebuggerHost Condition="'$(DebuggerHost)' == ''">chrome</DebuggerHost>

<NeedsWorkload Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsWorkload>
Expand Down Expand Up @@ -159,17 +157,18 @@
<Target Name="PrepareHelixCorrelationPayload_Wasm">
<Message Condition="'$(NeedsEMSDK)' == 'true' or '$(NeedsEMSDKNode)' == 'true'" Importance="High" Text="Using emsdk: $(EmSdkDirForHelixPayload)" />

<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and !Exists($(ChromeDir))"
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'chrome' and !Exists($(ChromeDir))"
Text="Could not find chrome at $(ChromeDir)" />
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and !Exists($(ChromeDriverDir))"
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'chrome' and !Exists($(ChromeDriverDir))"
Text="Could not find chromedriver at $(ChromeDriverDir)" />
<Error Condition="'$(NeedsToRunOnBrowser)' == 'true' and '$(DebuggerHost)' == 'firefox' and !Exists($(FirefoxDir))"
Text="Could not find firefox at $(FirefoxDir)" />

<ItemGroup Condition="'$(NeedsToRunOnBrowser)' == 'true'">
<HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDir)" />
<HelixCorrelationPayload Condition="'$(DebuggerHost)' == 'chrome'" Include="$(ChromeDriverDir)" />

<!--<HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="firefox" Uri="$(FirefoxUrl)" />-->
<HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="$(FirefoxForHelixPayload)" />
<HelixCorrelationPayload Condition="'$(WindowsShell)' != 'true' and '$(DebuggerHost)' == 'firefox'" Include="$(FirefoxDir)" />
</ItemGroup>

<ItemGroup Condition="'$(NeedsEMSDK)' == 'true'">
Expand Down Expand Up @@ -291,11 +290,4 @@
DestinationFiles="@(_EmSdkFiles -> '$(EmSdkDirForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>

<Target Name="DownloadFirefoxToSendToHelix" Condition="!Exists($(FirefoxForHelixPayload)) and '$(DebuggerHost)' == 'firefox'">
<DownloadFile SourceUrl="$(FirefoxUrl)" DestinationFolder="$(TestArchiveRoot)" SkipUnchangedFiles="true">
<Output TaskParameter="DownloadedFile" PropertyName="_DownloadedFile" />
</DownloadFile>
<Exec Command="tar -xf $(_DownloadedFile) -C $(TestArchiveRoot) &amp;&amp; rm $(_DownloadedFile) &amp;&amp; cd $(TestArchiveRoot) &amp;&amp; zip -q -r firefox.zip firefox"/>
</Target>
</Project>
1 change: 1 addition & 0 deletions src/libraries/sendtohelix.proj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
HelixTargetQueues=$(HelixTargetQueues);
BuildTargetFramework=$(BuildTargetFramework)
</_PropertiesToPass>
<_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">$(DebuggerHost)</_DebuggerHosts>
<_DebuggerHosts Condition="'$(_DebuggerHosts)' == ''">chrome</_DebuggerHosts>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/mono/sample/wasm/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
2 changes: 2 additions & 0 deletions src/mono/sample/wasm/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)CommonAssemblyInfo.cs" />

<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Expand Down
7 changes: 5 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s
return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{localNuGetsPath}"" />");
}

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);
Expand All @@ -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("<RunAnalyzers>true</RunAnalyzers>");
return projectfile;
}

public string CreateBlazorWasmTemplateProject(string id)
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<ItemGroup>
<!-- Allow running/debugging from VS -->
<ProjectCapability Include="DotNetCoreWeb"/>

<SupportedPlatform Condition="'$(IsWasmProject)' == 'true'" Remove="@(SupportedPlatform)" />
<SupportedPlatform Condition="'$(IsWasmProject)' == 'true'" Include="browser" />
</ItemGroup>

<PropertyGroup Label="Identify app bundle directory to run from">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<DebuggerHost Condition="'$(DebuggerHost)' == '' or ('$(DebuggerHost)' != 'chrome' and '$(DebuggerHost)' != 'firefox')">chrome</DebuggerHost>
<DefineConstants Condition="'$(DebuggerHost)' == 'chrome'">$(DefineConstants);RUN_IN_CHROME</DefineConstants>
<BrowserHost Condition="$([MSBuild]::IsOSPlatform('windows'))">windows</BrowserHost>
<InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and '$(DebuggerHost)' == 'chrome' and ('$(ContinuousIntegrationBuild)' == 'true' or Exists('/.dockerenv'))">true</InstallChromeForTests>
<InstallFirefoxForTests Condition="'$(DebuggerHost)' == 'firefox' and '$(InstallFirefoxForTests)' == '' and '$(ContinuousIntegrationBuild)' != 'true' and Exists('/.dockerenv')">true</InstallFirefoxForTests>
<_ProvisionBrowser Condition="'$(ContinuousIntegrationBuild)' == 'true' or Exists('/.dockerenv')">true</_ProvisionBrowser>
<InstallChromeForTests Condition="'$(InstallChromeForTests)' == '' and '$(DebuggerHost)' == 'chrome' and '$(_ProvisionBrowser)' == 'true'">true</InstallChromeForTests>
<InstallFirefoxForTests Condition="'$(InstallFirefoxForTests)' == '' and '$(DebuggerHost)' == 'firefox' and '$(_ProvisionBrowser)' == 'true'">true</InstallFirefoxForTests>

<!-- Set RunSettingsFilePath property which is read by VSTest. -->
<RunSettingsFilePath Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(OutputPath).runsettings</RunSettingsFilePath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
ArchiveDirForHelix=$(TargetDir);
TestArchiveTestsDir=$(TestArchiveTestsDir);
ExtractTestClassNamesForHelix=$(ExtractTestClassNamesForHelix);
DebuggerHost=$(DebuggerHost);
DotNetForTests=$([MSBuild]::NormalizePath($(DotNetRoot), $(DotNetTool)))" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
@@ -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")]

0 comments on commit 6631b47

Please sign in to comment.