Skip to content

Commit

Permalink
[wasm] WBT: Use a clean NUGET_PACKAGES dir separate from the project …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
radical committed Sep 29, 2022
1 parent 55120ac commit 0678940
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/BlazorWasmBuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void BugRegression_60479_WithRazorClassLib()
Directory.CreateDirectory(wasmProjectDir);
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
.WithWorkingDirectory(wasmProjectDir)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("new blazorwasm")
.EnsureSuccessful();

Expand All @@ -249,6 +250,7 @@ public void BugRegression_60479_WithRazorClassLib()
Directory.CreateDirectory(razorProjectDir);
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
.WithWorkingDirectory(razorProjectDir)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("new razorclasslib")
.EnsureSuccessful();

Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/BlazorWasmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private CommandResult PublishForRequiresWorkloadTest(string config, string extra
string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog");
return new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("publish",
$"-bl:{publishLogPath}",
$"-p:Configuration={config}");
Expand Down Expand Up @@ -109,6 +110,7 @@ private void BuildNet50Project(string config, bool aot, bool expectError, string
string publishLogPath = Path.Combine(logPath, $"{id}.binlog");
CommandResult result = new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("publish",
$"-bl:{publishLogPath}",
(aot ? "-p:RunAOTCompilation=true" : ""),
Expand Down
15 changes: 8 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
protected string _logPath;
protected bool _enablePerTestCleanup = false;
protected SharedBuildPerTestClassFixture _buildContext;
protected string _nugetPackagesDir = string.Empty;

// FIXME: use an envvar to override this
protected static int s_defaultPerTestTimeoutMs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 30*60*1000 : 15*60*1000;
Expand Down Expand Up @@ -63,13 +64,6 @@ static BuildTestBase()
else
s_xharnessRunnerCommand = EnvironmentVariables.XHarnessCliPath;

string? nugetPackagesPath = Environment.GetEnvironmentVariable("NUGET_PACKAGES");
if (!string.IsNullOrEmpty(nugetPackagesPath))
{
if (!Directory.Exists(nugetPackagesPath))
Directory.CreateDirectory(nugetPackagesPath);
}

Console.WriteLine ("");
Console.WriteLine ($"==============================================================================================");
Console.WriteLine ($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ===============");
Expand Down Expand Up @@ -286,7 +280,12 @@ protected void InitPaths(string id)
if (_projectDir == null)
_projectDir = Path.Combine(AppContext.BaseDirectory, id);
_logPath = Path.Combine(s_buildEnv.LogRootPath, id);
_nugetPackagesDir = Path.Combine(BuildEnvironment.TmpPath, "nuget", id);

if (Directory.Exists(_nugetPackagesDir))
Directory.Delete(_nugetPackagesDir, recursive: true);

Directory.CreateDirectory(_nugetPackagesDir!);
Directory.CreateDirectory(_logPath);
}

Expand Down Expand Up @@ -405,6 +404,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
foreach (var kvp in options.ExtraBuildEnvironmentVariables!)
envVars[kvp.Key] = kvp.Value;
}
envVars["NUGET_PACKAGES"] = _nugetPackagesDir;
result = AssertBuild(sb.ToString(), id, expectSuccess: options.ExpectSuccess, envVars: envVars);

// check that we are using the correct runtime pack!
Expand Down Expand Up @@ -487,6 +487,7 @@ public string CreateBlazorWasmTemplateProject(string id)
InitBlazorWasmProjectDir(id);
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("new blazorwasm")
.EnsureSuccessful();

Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/CleanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void Blazor_BuildThenClean_NativeRelinking(string config)
string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog");
new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}")
.EnsureSuccessful();

Expand Down Expand Up @@ -89,6 +90,7 @@ private void Blazor_BuildNativeNonNative_ThenCleanTest(string config, bool first
string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog");
new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _projectDir!)
.ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}")
.EnsureSuccessful();

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void BlazorWasm_CanRunMonoAOTCross_WithNoTrimming(string config)
string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog");
CommandResult res = new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.ExecuteWithCapturedOutput("publish",
$"-bl:{publishLogPath}",
"-p:RunAOTCompilation=true",
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/Wasm.Build.Tests/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class RunCommand : DotNetCommand
{
public RunCommand(BuildEnvironment buildEnv, ITestOutputHelper _testOutput, string label="") : base(buildEnv, _testOutput, false, label)
{
WithEnvironmentVariables(buildEnv.EnvVars);
WithEnvironmentVariable("DOTNET_ROOT", buildEnv.DotNet);
WithEnvironmentVariable("DOTNET_INSTALL_DIR", Path.GetDirectoryName(buildEnv.DotNet)!);
WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0");
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async virtual Task<CommandResult> ExecuteAsync(params string[] args)
{
var resolvedCommand = _command;
string fullArgs = GetFullArgs(args);
_testOutput.WriteLine($"[{_label}] Executing - {resolvedCommand} {fullArgs} - {WorkingDirectoryInfo()}");
_testOutput.WriteLine($"[{_label}] Executing - {resolvedCommand} {fullArgs} {WorkingDirectoryInfo()}");
return await ExecuteAsyncInternal(resolvedCommand, fullArgs);
}

Expand Down

0 comments on commit 0678940

Please sign in to comment.