Skip to content
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: 1 addition & 5 deletions csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ public static BuildScript WithDotNet(IAutobuilder<AutobuildOptionsShared> builde
var temp = FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var shouldCleanUp);
return DotNet.WithDotNet(builder.Actions, builder.Logger, builder.Paths.Select(x => x.Item1), temp, shouldCleanUp, ensureDotNetAvailable, builder.Options.DotNetVersion, installDir =>
{
var env = new Dictionary<string, string>
{
{ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true" },
{ "MSBUILDDISABLENODEREUSE", "1" }
};
var env = DotNet.MinimalEnvironment.ToDictionary();
if (installDir is not null)
{
// The installation succeeded, so use the newly installed .NET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -140,6 +141,8 @@ public IList<string> GetNugetFeedsFromFolder(string folderPath)
// The version number should be kept in sync with the version .NET version used for building the application.
public const string LatestDotNetSdkVersion = "9.0.300";

public static ReadOnlyDictionary<string, string> MinimalEnvironment => IDotNetCliInvoker.MinimalEnvironment;

/// <summary>
/// Returns a script for downloading relevant versions of the
/// .NET SDK. The SDK(s) will be installed at <code>installDir</code>
Expand Down Expand Up @@ -254,7 +257,6 @@ BuildScript GetInstall(string pwsh) =>
else
{
var dotnetInstallPath = actions.PathCombine(tempWorkingDirectory, ".dotnet", "dotnet-install.sh");

var downloadDotNetInstallSh = BuildScript.DownloadFile(
"https://dot.net/v1/dotnet-install.sh",
dotnetInstallPath,
Expand All @@ -269,17 +271,28 @@ BuildScript GetInstall(string pwsh) =>
prelude = downloadDotNetInstallSh & chmod.Script;
postlude = shouldCleanUp ? BuildScript.DeleteFile(dotnetInstallPath) : BuildScript.Success;

getInstall = version => new CommandBuilder(actions).
RunCommand(dotnetInstallPath).
Argument("--channel").
Argument("release").
Argument("--version").
Argument(version).
Argument("--install-dir").
Argument(path).Script;
getInstall = version =>
{
var cb = new CommandBuilder(actions).
RunCommand(dotnetInstallPath).
Argument("--channel").
Argument("release").
Argument("--version").
Argument(version);

// Request ARM64 architecture on Apple Silicon machines
if (actions.IsRunningOnAppleSilicon())
{
cb.Argument("--architecture").
Argument("arm64");
}
Comment on lines +283 to +288
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by comment: does this not cause problems for the tracer? I assume some test would have caught it if it was a problem, but I am curious about why this is OK. Would it maybe make sense to document that in a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the ARM machines (when inspecting the output from the other tests) it looks like the RiD is osx-arm64 for the installed .NET versions (at least those being used). Without setting this explicitly, the install script downloads the osx-x64 version. According to CoPilot it can cause problems when different versions of .NET are installed on the same machine. Changing this appears to have a positive effect when running the (traced .NET 10) tests on the MacOS 15 and MacOS26 runners.


return cb.Argument("--install-dir").
Argument(path).Script;
};
}

var dotnetInfo = new CommandBuilder(actions).
var dotnetInfo = new CommandBuilder(actions, environment: MinimalEnvironment).
RunCommand(actions.PathCombine(path, "dotnet")).
Argument("--info").Script;

Expand Down Expand Up @@ -311,7 +324,7 @@ BuildScript GetInstall(string pwsh) =>

private static BuildScript GetInstalledSdksScript(IBuildActions actions)
{
var listSdks = new CommandBuilder(actions, silent: true).
var listSdks = new CommandBuilder(actions, silent: true, environment: MinimalEnvironment).
RunCommand("dotnet").
Argument("--list-sdks");
return listSdks.Script;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using Semmle.Util;
using Semmle.Util.Logging;
Expand Down Expand Up @@ -36,10 +37,12 @@ private ProcessStartInfo MakeDotnetStartInfo(string args, string? workingDirecto
{
startInfo.WorkingDirectory = workingDirectory;
}
// Set the .NET CLI language to English to avoid localized output.
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"] = "en";
startInfo.EnvironmentVariables["MSBUILDDISABLENODEREUSE"] = "1";
startInfo.EnvironmentVariables["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "true";

// Set minimal environment variables.
foreach (var kvp in IDotNetCliInvoker.MinimalEnvironment)
{
startInfo.EnvironmentVariables[kvp.Key] = kvp.Value;
}

// Configure the proxy settings, if applicable.
if (this.proxy != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Semmle.Extraction.CSharp.DependencyFetching
{
Expand All @@ -9,6 +10,20 @@ internal interface IDotNetCliInvoker
/// </summary>
string Exec { get; }

/// <summary>
/// A minimal environment for running the .NET CLI.
///
/// DOTNET_CLI_UI_LANGUAGE: The .NET CLI language is set to English to avoid localized output.
/// MSBUILDDISABLENODEREUSE: To ensure clean environment for each build.
/// DOTNET_SKIP_FIRST_TIME_EXPERIENCE: To skip first time experience messages.
/// </summary>
static ReadOnlyDictionary<string, string> MinimalEnvironment { get; } = new(new Dictionary<string, string>
{
{"DOTNET_CLI_UI_LANGUAGE", "en"},
{"MSBUILDDISABLENODEREUSE", "1"},
{"DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true"}
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: The doc comment above explains DOTNET_CLI_UI_LANGUAGE but not the other two environment variables. Would it make sense to document why we are setting them as well? DOTNET_SKIP_FIRST_TIME_EXPERIENCE is kind of obvious, but MSBUILDDISABLENODEREUSE maybe less so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no comment explaining this before and I just moved the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add some comments - then the tests will also be run a again 😄

});

/// <summary>
/// Execute `dotnet <paramref name="args"/>` and return true if the command succeeded, otherwise false.
/// If `silent` is true the output of the command is logged as `debug` otherwise as `info`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "10.0.100"
}
}
5 changes: 5 additions & 0 deletions csharp/ql/integration-tests/all-platforms/dotnet_10/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test1(codeql, csharp):
codeql.database.create()

def test2(codeql, csharp):
codeql.database.create(build_mode="none")
Loading