Skip to content

Commit

Permalink
[wasm] fix weird build failures
Browse files Browse the repository at this point in the history
`MSBuildSDKsPath` is set by runtime repo, and that interferes with the
test projects. To avoid this the `MSBuildSDKsPath` was set to `""` in
the test environment. But even that can negatively affect the build
because msbuild treats environment variables as "global properties" that
cannot be changed. This manifests when running:

`$ dotnet run --no-build`

.. it would fail with `/foo/bar.csproj is not a valid project file`.

Instead, explicitly *remove* `MSBuildSDKsPath` from the environment when
invoking the process.
  • Loading branch information
radical committed Sep 29, 2022
1 parent 57ff0dd commit 1a731fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public BuildEnvironment()
EnvVars["DOTNET_INSTALL_DIR"] = sdkForWorkloadPath;
EnvVars["DOTNET_MULTILEVEL_LOOKUP"] = "0";
EnvVars["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1";
EnvVars["MSBuildSDKsPath"] = string.Empty;
EnvVars["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}";
EnvVars["EM_WORKAROUND_PYTHON_BUG_34780"] = "1";

Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ public static (int exitCode, string buildOutput) RunProcess(string path,
processStartInfo.EnvironmentVariables[envVar.Key] = envVar.Value;
_testOutput.WriteLine($"\t{envVar.Key} = {envVar.Value}");
}

// runtime repo sets this, which interferes with the tests
processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath");
}

Process process = new ();
Expand Down
13 changes: 13 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,18 @@ public static void UpdateTo(this IDictionary<string, (string fullPath, bool unch
dict[filename] = (oldValue.fullPath, unchanged);
}
}

public static ProcessStartInfo RemoveEnvironmentVariables(this ProcessStartInfo psi, params string[] names)
{
var env = psi.Environment;
foreach (string name in names)
{
string? key = env.Keys.FirstOrDefault(k => string.Compare(k, name, StringComparison.OrdinalIgnoreCase) == 0);
if (key is not null)
env.Remove("MSBuildSDKsPath");
}

return psi;
}
}
}
3 changes: 3 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ private Process CreateProcess(string executable, string args)
psi.Environment["DOTNET_MULTILEVEL_LOOKUP"] = "0";
psi.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1";

// runtime repo sets this, which interferes with the tests
psi.RemoveEnvironmentVariables("MSBuildSDKsPath");
AddEnvironmentVariablesTo(psi);
AddWorkingDirectoryTo(psi);
var process = new Process
Expand Down Expand Up @@ -201,6 +203,7 @@ private void AddEnvironmentVariablesTo(ProcessStartInfo psi)
{
foreach (var item in Environment)
{
_testOutput.WriteLine($"\t[{item.Key}] = {item.Value}");
psi.Environment[item.Key] = item.Value;
}
}
Expand Down

0 comments on commit 1a731fb

Please sign in to comment.