Skip to content

[release/7.0][wasm] Use the correct runtime pack version when the workload is not installed #75028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion eng/testing/workloads-testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<PropertyGroup Condition="'$(TestUsingWorkloads)' == 'true'">
<!-- for non-ci builds, we install the sdk when tests are run -->
<InstallWorkloadForTesting Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(ArchiveTests)' == 'true'">true</InstallWorkloadForTesting>
</PropertyGroup>

<PropertyGroup Condition="'$(InstallWorkloadForTesting)' == 'true'">
<_SdkForWorkloadTestingBasePath>$(ArtifactsBinDir)</_SdkForWorkloadTestingBasePath>
<_SdkWithNoWorkloadPath>$([MSBuild]::NormalizeDirectory($(_SdkForWorkloadTestingBasePath), 'dotnet-none'))</_SdkWithNoWorkloadPath>
<_SdkWithNoWorkloadStampPath>$([MSBuild]::NormalizePath($(_SdkWithNoWorkloadPath), '.version-$(SdkVersionForWorkloadTesting).stamp'))</_SdkWithNoWorkloadStampPath>
Expand Down Expand Up @@ -190,7 +192,7 @@

<Target Name="_InstallWorkloads"
Inputs="@(AvailableNuGetsInArtifacts)"
Outputs="@(_SdkWithWorkloadToInstall->'%(StampPath)')">
Outputs="@(_SdkWithWorkloadToInstall->'%(StampPath)');$(_SdkWithNoWorkloadStampPath)">
<ItemGroup>
<_BuiltNuGets Include="$(LibrariesShippingPackagesDir)\*.nupkg" />
</ItemGroup>
Expand All @@ -205,5 +207,7 @@
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
SdkWithNoWorkloadInstalledPath="$(_SdkWithNoWorkloadPath)"
/>

<WriteLinesToFile Lines="" File="$(_SdkWithNoWorkloadStampPath)" />
</Target>
</Project>
9 changes: 9 additions & 0 deletions src/libraries/sendtohelix-wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<WasmBuildTargetsDir>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'build'))</WasmBuildTargetsDir>
<TestEchoMiddleware>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'bin', 'NetCoreServer', '$(Configuration)', '$(AspNetCoreAppCurrent)'))</TestEchoMiddleware>
<RemoteLoopMiddleware>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'bin', 'RemoteLoopServer', '$(Configuration)', '$(AspNetCoreAppCurrent)'))</RemoteLoopMiddleware>
<_ShippingPackagesPath>$([MSBuild]::NormalizeDirectory($(ArtifactsDir), 'packages', $(Configuration), 'Shipping'))</_ShippingPackagesPath>
<WorkItemPrefix Condition="'$(IsWasmDebuggerTests)' == 'true'">$(DebuggerHost)-</WorkItemPrefix>
<WorkItemPrefix Condition="'$(WorkItemPrefix)' == '' and '$(Scenario)' != ''">$(Scenario)-</WorkItemPrefix>

Expand Down Expand Up @@ -56,6 +57,7 @@
<NeedsEMSDKNode Condition="'$(Scenario)' == 'WasmTestOnNodeJs' or '$(Scenario)' == 'BuildWasmApps'">true</NeedsEMSDKNode>
<NeedsToRunOnBrowser Condition="'$(Scenario)' == 'WasmTestOnBrowser' or '$(Scenario)' == 'BuildWasmApps'">true</NeedsToRunOnBrowser>
<NeedsToRunOnBrowser Condition="'$(NeedsToRunOnBrowser)' == '' and '$(IsWasmDebuggerTests)' == 'true'">true</NeedsToRunOnBrowser>
<NeedsBuiltNugets Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsBuiltNugets>

<IncludeXHarnessCli>true</IncludeXHarnessCli>
<EnableXHarnessTelemetry>false</EnableXHarnessTelemetry>
Expand Down Expand Up @@ -121,6 +123,9 @@
<ItemGroup Condition="'$(Scenario)' == 'BuildWasmApps'">
<HelixPreCommand Condition="'$(WindowsShell)' == 'true'" Include="set &quot;XUnitTraitArg=$(_XUnitTraitArg)&quot;" />
<HelixPreCommand Condition="'$(WindowsShell)' != 'true'" Include="export &quot;XUnitTraitArg=$(_XUnitTraitArg)&quot;" />

<HelixPreCommand Condition="'$(WindowsShell)' == 'true'" Include="set &quot;BUILT_NUGETS_PATH=%HELIX_CORRELATION_PAYLOAD%/built-nugets&quot;" />
<HelixPreCommand Condition="'$(WindowsShell)' != 'true'" Include="export &quot;BUILT_NUGETS_PATH=$HELIX_CORRELATION_PAYLOAD/built-nugets&quot;" />
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -187,6 +192,10 @@
<HelixCorrelationPayload Include="$(TestEchoMiddleware)" Destination="xharness/TestEchoMiddleware" Condition="Exists('$(TestEchoMiddleware)')" />
<HelixCorrelationPayload Include="$(RemoteLoopMiddleware)" Destination="xharness/RemoteLoopMiddleware" Condition="Exists('$(RemoteLoopMiddleware)')" />
</ItemGroup>

<ItemGroup Condition="'$(NeedsBuiltNugets)' == 'true'">
<HelixCorrelationPayload Include="$(_ShippingPackagesPath)" Destination="built-nugets" />
</ItemGroup>
</Target>

<Target Name="PrepareForBuildHelixWorkItems_Wasm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk.net6" />
</ImportGroup>

<PropertyGroup Condition="'$(TargetsNet6)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(TargetPlatformIdentifier)' == 'macOS' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst' or '$(TargetPlatformIdentifier)' == 'tvos' or ('$(RuntimeIdentifier)' == 'browser-wasm' and '$(UsingBrowserRuntimeWorkload)' == 'true'))">
<PropertyGroup Condition="'$(TargetsNet6)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(TargetPlatformIdentifier)' == 'macOS' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst' or '$(TargetPlatformIdentifier)' == 'tvos' or '$(RuntimeIdentifier)' == 'browser-wasm')">
<_MonoWorkloadTargetsMobile>true</_MonoWorkloadTargetsMobile>
<_MonoWorkloadRuntimePackPackageVersion>$(_RuntimePackInWorkloadVersion6)</_MonoWorkloadRuntimePackPackageVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk.net7" />
</ImportGroup>

<PropertyGroup Condition="'$(TargetsNet7)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(TargetPlatformIdentifier)' == 'macOS' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst' or '$(TargetPlatformIdentifier)' == 'tvos' or ('$(RuntimeIdentifier)' == 'browser-wasm' and '$(UsingBrowserRuntimeWorkload)' == 'true'))">
<PropertyGroup Condition="'$(TargetsNet7)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(TargetPlatformIdentifier)' == 'macOS' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst' or '$(TargetPlatformIdentifier)' == 'tvos' or '$(RuntimeIdentifier)' == 'browser-wasm')">
<_MonoWorkloadTargetsMobile>true</_MonoWorkloadTargetsMobile>
<_MonoWorkloadRuntimePackPackageVersion>$(_RuntimePackInWorkloadVersion7)</_MonoWorkloadRuntimePackPackageVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public override bool Execute()

if (!ExecuteInternal(req) && !req.IgnoreErrors)
return false;

File.WriteAllText(req.StampPath, string.Empty);
}

return !Log.HasLoggedErrors;
Expand Down Expand Up @@ -399,6 +401,7 @@ internal sealed record InstallWorkloadRequest(
public string ManifestName => Workload.GetMetadata("ManifestName");
public string Version => Workload.GetMetadata("Version");
public string TargetPath => Target.GetMetadata("InstallPath");
public string StampPath => Target.GetMetadata("StampPath");
public bool IgnoreErrors => Workload.GetMetadata("IgnoreErrors").ToLowerInvariant() == "true";
public string WorkloadId => Workload.ItemSpec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public BlazorWasmBuildPublishTests(ITestOutputHelper output, SharedBuildPerTestC
_enablePerTestCleanup = true;
}

[Theory]
[Theory, TestCategory("no-workload")]
[InlineData("Debug")]
[InlineData("Release")]
public void DefaultTemplate_WithoutWorkload(string config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

#nullable enable
Expand All @@ -25,6 +24,7 @@ public class BuildEnvironment
public string LogRootPath { get; init; }

public string WorkloadPacksDir { get; init; }
public string BuiltNuGetsPath { get; init; }

public static readonly string RelativeTestAssetsPath = @"..\testassets\";
public static readonly string TestAssetsPath = Path.Combine(AppContext.BaseDirectory, "testassets");
Expand Down Expand Up @@ -99,6 +99,11 @@ public BuildEnvironment()
DirectoryBuildTargetsContents = s_directoryBuildTargetsForLocal;
}

if (EnvironmentVariables.BuiltNuGetsPath is null || !Directory.Exists(EnvironmentVariables.BuiltNuGetsPath))
throw new Exception($"Cannot find 'BUILT_NUGETS_PATH={EnvironmentVariables.BuiltNuGetsPath}'");

BuiltNuGetsPath = EnvironmentVariables.BuiltNuGetsPath;

// `runtime` repo's build environment sets these, and they
// mess up the build for the test project, which is using a different
// dotnet
Expand Down
38 changes: 31 additions & 7 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
protected static int s_defaultPerTestTimeoutMs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 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 -->";
private static Regex s_runtimePackPathRegex;
private static int s_testCounter;
private readonly int _testIdx;
Expand Down Expand Up @@ -213,6 +214,16 @@ protected static string RunWithXHarness(string testCommand, string testLogPath,
args.Append($" --expected-exit-code={expectedAppExitCode}");
args.Append($" {extraXHarnessArgs ?? string.Empty}");

if (File.Exists("/.dockerenv"))
args.Append(" --browser-arg=--no-sandbox");

if (!string.IsNullOrEmpty(EnvironmentVariables.BrowserPathForTests))
{
if (!File.Exists(EnvironmentVariables.BrowserPathForTests))
throw new Exception($"Cannot find BROWSER_PATH_FOR_TESTS={EnvironmentVariables.BrowserPathForTests}");
args.Append($" --browser-path=\"{EnvironmentVariables.BrowserPathForTests}\"");
}

args.Append(" -- ");
if (extraXHarnessMonoArgs != null)
{
Expand Down Expand Up @@ -325,7 +336,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
{
_testOutput.WriteLine ($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}");

Assert.True(product.Result, $"Found existing build at {product.ProjectDir}, but it had failed. Check 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}");
_projectDir = product.ProjectDir;

// use this test's id for the run logs
Expand Down Expand Up @@ -359,7 +371,6 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
string logFilePath = Path.Combine(_logPath, $"{buildArgs.ProjectName}{logFileSuffix}.binlog");
_testOutput.WriteLine($"-------- Building ---------");
_testOutput.WriteLine($"Binlog path: {logFilePath}");
_testOutput.WriteLine($"Binlog path: {logFilePath}");
sb.Append($" /bl:\"{logFilePath}\" /nologo");
sb.Append($" /v:{options.Verbosity ?? "minimal"}");
if (buildArgs.ExtraBuildArgs != null)
Expand Down Expand Up @@ -410,11 +421,24 @@ public void InitBlazorWasmProjectDir(string id)
Directory.CreateDirectory(_projectDir);
Directory.CreateDirectory(Path.Combine(_projectDir, ".nuget"));

File.Copy(Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework), Path.Combine(_projectDir, "nuget.config"));
File.WriteAllText(Path.Combine(_projectDir, "nuget.config"),
GetNuGetConfigWithLocalPackagesPath(
Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework),
s_buildEnv.BuiltNuGetsPath));

File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.targets"), Path.Combine(_projectDir, "Directory.Build.targets"));
}

private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, string localNuGetsPath)
{
string contents = File.ReadAllText(templatePath);
if (contents.IndexOf(s_nugetInsertionTag, StringComparison.InvariantCultureIgnoreCase) < 0)
throw new Exception($"Could not find {s_nugetInsertionTag} in {templatePath}");

return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{localNuGetsPath}"" />");
}

public string CreateWasmTemplateProject(string id, string template = "wasmbrowser")
{
InitPaths(id);
Expand Down Expand Up @@ -636,10 +660,10 @@ protected static void AssertFile(string file0, string file1, string? label=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)
Assert.True(0 == result.exitCode, $"Build process exited with non-zero exit code: {result.exitCode}");
else
Assert.True(0 != result.exitCode, $"Build should have failed, but it didn't. Process exited with exitCode : {result.exitCode}");
if (expectSuccess && result.exitCode != 0)
throw new XunitException($"Build process exited with non-zero exit code: {result.exitCode}");
if (!expectSuccess && result.exitCode == 0)
throw new XunitException($"Build should have failed, but it didn't. Process exited with exitCode : {result.exitCode}");

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ internal static class EnvironmentVariables
internal static readonly string? TestLogPath = Environment.GetEnvironmentVariable("TEST_LOG_PATH");
internal static readonly string? SkipProjectCleanup = Environment.GetEnvironmentVariable("SKIP_PROJECT_CLEANUP");
internal static readonly string? XHarnessCliPath = Environment.GetEnvironmentVariable("XHARNESS_CLI_PATH");
internal static readonly string? BuiltNuGetsPath = Environment.GetEnvironmentVariable("BUILT_NUGETS_PATH");
internal static readonly string? BrowserPathForTests = Environment.GetEnvironmentVariable("BROWSER_PATH_FOR_TESTS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="chmod +x $HELIX_WORKITEM_ROOT/.playwright/node/linux/node" />
</ItemGroup>

<PropertyGroup Condition="'$(Scenario)' == 'BuildWasmApps'">
<PropertyGroup>
<_XUnitTraitArg Condition="'$(TestUsingWorkloads)' == 'true'">-notrait category=no-workload</_XUnitTraitArg>
<_XUnitTraitArg Condition="'$(TestUsingWorkloads)' != 'true'">-trait category=no-workload</_XUnitTraitArg>
</PropertyGroup>
Expand All @@ -69,6 +69,9 @@

<RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export BASE_DIR=$(ArtifactsBinDir)" />
<RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set BASE_DIR=$(ArtifactsBinDir)" />

<RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export BUILT_NUGETS_PATH=$(LibrariesShippingPackagesDir)/" />
<RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set BUILT_NUGETS_PATH=$(LibrariesShippingPackagesDir)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
<EmscriptenEnvVars Include="FROZEN_CACHE=" Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup>

<Target Name="PrintRuntimePackPath" BeforeTargets="Publish">
<Target Name="PrintRuntimePackPath" AfterTargets="ResolveFrameworkReferences" Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
<Error Text="Expected to find a ResolvedRuntimePack item, but found none."
Condition="@(ResolvedRuntimePack -> Count()) == 0" />

<Error Text="Missing PackageDirectory metadata on ResolvedRuntimePack: @(ResolvedRuntimePack -> '%(Identity), %(NugetPackageId), %(NuGetPackageVersion), %(NuGetPackageDirectory)')"
Condition="'%(ResolvedRuntimePack.PackageDirectory)' == ''" />
<Message Text="** MicrosoftNetCoreAppRuntimePackDir : %(ResolvedRuntimePack.PackageDirectory)" Importance="High" />

<Error Text="Missing NuGetPackageVersion metadata on ResolvedRuntimePack: @(ResolvedRuntimePack -> '%(Identity), %(NugetPackageId), %(NuGetPackageVersion), %(NuGetPackageDirectory)')"
Condition="'%(ResolvedRuntimePack.NuGetPackageVersion)' == ''" />
<Message Text="** ResolvedRuntimePack Version : %(ResolvedRuntimePack.NuGetPackageVersion)" Importance="High" />

<!-- Using internal properties for the version here. This will be fixed when net6-on-7 workload testing
changes land -->
<Error Condition="$([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '7.0')) and
'%(ResolvedRuntimePack.NuGetPackageVersion)' != $(_RuntimePackInWorkloadVersion7)"
Text="Expected Runtime pack version = '$(_RuntimePackInWorkloadVersion7)', but got '%(ResolvedRuntimePack.NuGetPackageVersion)'" />

<Error Condition="$([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '6.0')) and
'%(ResolvedRuntimePack.NuGetPackageVersion)' != $(_RuntimePackInWorkloadVersion6)"
Text="Expected Runtime pack version = '$(_RuntimePackInWorkloadVersion6)', but got '%(ResolvedRuntimePack.NuGetPackageVersion)'" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</fallbackPackageFolders>
<packageSources>
<clear />
<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
Expand Down