mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Simplify dotnet SDK check in autobuilder
This commit is contained in:
@@ -558,8 +558,8 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestLinuxBuildlessExtractionSuccess()
|
||||
{
|
||||
actions.RunProcess["dotnet --info"] = 0;
|
||||
actions.RunProcessOut["dotnet --info"] = "";
|
||||
actions.RunProcess["dotnet --list-sdks"] = 0;
|
||||
actions.RunProcessOut["dotnet --list-sdks"] = "any version";
|
||||
actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0;
|
||||
actions.FileExists["csharp.log"] = true;
|
||||
actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = "";
|
||||
@@ -575,8 +575,8 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestLinuxBuildlessExtractionFailed()
|
||||
{
|
||||
actions.RunProcess["dotnet --info"] = 0;
|
||||
actions.RunProcessOut["dotnet --info"] = "";
|
||||
actions.RunProcess["dotnet --list-sdks"] = 0;
|
||||
actions.RunProcessOut["dotnet --list-sdks"] = "any version";
|
||||
actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 10;
|
||||
actions.FileExists["csharp.log"] = true;
|
||||
actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = "";
|
||||
@@ -592,8 +592,8 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestLinuxBuildlessExtractionSolution()
|
||||
{
|
||||
actions.RunProcess["dotnet --info"] = 0;
|
||||
actions.RunProcessOut["dotnet --info"] = "";
|
||||
actions.RunProcess["dotnet --list-sdks"] = 0;
|
||||
actions.RunProcessOut["dotnet --list-sdks"] = "any version";
|
||||
actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0;
|
||||
actions.FileExists["csharp.log"] = true;
|
||||
actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = "";
|
||||
@@ -609,8 +609,8 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestLinuxBuildlessExtractionNoDotnet()
|
||||
{
|
||||
actions.RunProcess["dotnet --info"] = 1;
|
||||
actions.RunProcessOut["dotnet --info"] = "";
|
||||
actions.RunProcess["dotnet --list-sdks"] = 1;
|
||||
actions.RunProcessOut["dotnet --list-sdks"] = "";
|
||||
actions.RunProcess[@"chmod u+x scratch/.dotnet/dotnet-install.sh"] = 0;
|
||||
actions.RunProcess[@"scratch/.dotnet/dotnet-install.sh --channel release --version 8.0.101 --install-dir scratch/.dotnet"] = 0;
|
||||
actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone --dotnet scratch/.dotnet"] = 0;
|
||||
@@ -915,8 +915,8 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestSkipNugetBuildless()
|
||||
{
|
||||
actions.RunProcess["dotnet --info"] = 0;
|
||||
actions.RunProcessOut["dotnet --info"] = "";
|
||||
actions.RunProcess["dotnet --list-sdks"] = 0;
|
||||
actions.RunProcessOut["dotnet --list-sdks"] = "any version";
|
||||
actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0;
|
||||
actions.FileExists["csharp.log"] = true;
|
||||
actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = "";
|
||||
|
||||
@@ -163,18 +163,8 @@ namespace Semmle.Autobuild.CSharp
|
||||
|
||||
if (ensureDotNetAvailable)
|
||||
{
|
||||
return BuildScript.Bind(GetInfoScript(builder.Actions), (infoLines, infoRet) =>
|
||||
{
|
||||
if (infoRet == 0)
|
||||
{
|
||||
return BuildScript.Failure;
|
||||
}
|
||||
|
||||
const string latestDotNetSdkVersion = "8.0.101";
|
||||
builder.Log(Severity.Info, $"No .NET Core SDK found. Attempting to install version {latestDotNetSdkVersion}.");
|
||||
return DownloadDotNetVersion(builder, installDir, latestDotNetSdkVersion, checkInstalledSdkVersion: false);
|
||||
});
|
||||
|
||||
const string latestDotNetSdkVersion = "8.0.101";
|
||||
return DownloadDotNetVersion(builder, installDir, latestDotNetSdkVersion, needExactVersion: false);
|
||||
}
|
||||
|
||||
return BuildScript.Failure;
|
||||
@@ -186,20 +176,25 @@ namespace Semmle.Autobuild.CSharp
|
||||
///
|
||||
/// See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script.
|
||||
/// </summary>
|
||||
private static BuildScript DownloadDotNetVersion(IAutobuilder<AutobuildOptionsShared> builder, string path, string version, bool checkInstalledSdkVersion = true)
|
||||
private static BuildScript DownloadDotNetVersion(IAutobuilder<AutobuildOptionsShared> builder, string path, string version, bool needExactVersion = true)
|
||||
{
|
||||
var firstScript = checkInstalledSdkVersion
|
||||
? GetInstalledSdksScript(builder.Actions)
|
||||
: BuildScript.Success;
|
||||
|
||||
return BuildScript.Bind(firstScript, (sdks, sdksRet) =>
|
||||
return BuildScript.Bind(GetInstalledSdksScript(builder.Actions), (sdks, sdksRet) =>
|
||||
{
|
||||
if (checkInstalledSdkVersion && sdksRet == 0 && sdks.Count == 1 && sdks[0].StartsWith(version + " ", StringComparison.Ordinal))
|
||||
if (needExactVersion && sdksRet == 0 && sdks.Count == 1 && sdks[0].StartsWith(version + " ", StringComparison.Ordinal))
|
||||
{
|
||||
// The requested SDK is already installed (and no other SDKs are installed), so
|
||||
// no need to reinstall
|
||||
return BuildScript.Failure;
|
||||
}
|
||||
else if (!needExactVersion && sdksRet == 0 && sdks.Count > 0)
|
||||
{
|
||||
// there's at least one SDK installed, so no need to reinstall
|
||||
return BuildScript.Failure;
|
||||
}
|
||||
else if (!needExactVersion && sdksRet != 0)
|
||||
{
|
||||
builder.Log(Severity.Info, "No .NET Core SDK found.");
|
||||
}
|
||||
|
||||
builder.Log(Severity.Info, "Attempting to download .NET Core {0}", version);
|
||||
|
||||
@@ -269,14 +264,6 @@ namespace Semmle.Autobuild.CSharp
|
||||
return listSdks.Script;
|
||||
}
|
||||
|
||||
private static BuildScript GetInfoScript(IBuildActions actions)
|
||||
{
|
||||
var info = new CommandBuilder(actions, silent: true).
|
||||
RunCommand("dotnet").
|
||||
Argument("--info");
|
||||
return info.Script;
|
||||
}
|
||||
|
||||
private static string DotNetCommand(IBuildActions actions, string? dotNetPath) =>
|
||||
dotNetPath is not null ? actions.PathCombine(dotNetPath, "dotnet") : "dotnet";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user