mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Improve code quality based on PR review
This commit is contained in:
@@ -46,11 +46,6 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
|
||||
public IList<string> RunProcessIn { get; } = new List<string>();
|
||||
public IDictionary<string, int> RunProcess { get; } = new Dictionary<string, int>();
|
||||
|
||||
/// <summary>
|
||||
/// (process-exit code) pairs for commands that are executed during the assembly of the autobuild script.
|
||||
/// </summary>
|
||||
public IDictionary<string, int> RunProcessExecuteDuring { get; } = new Dictionary<string, int>();
|
||||
public IDictionary<string, string> RunProcessOut { get; } = new Dictionary<string, string>();
|
||||
public IDictionary<string, string> RunProcessWorkingDirectory { get; } = new Dictionary<string, string>();
|
||||
public HashSet<string> CreateDirectories { get; } = new HashSet<string>();
|
||||
@@ -71,7 +66,7 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
if (wd != workingDirectory)
|
||||
throw new ArgumentException($"Unexpected RunProcessWorkingDirectory, got {wd ?? "null"} expected {workingDirectory ?? "null"} in {pattern}");
|
||||
|
||||
if (!RunProcess.TryGetValue(pattern, out var ret) && !RunProcessExecuteDuring.TryGetValue(pattern, out ret))
|
||||
if (!RunProcess.TryGetValue(pattern, out var ret))
|
||||
throw new ArgumentException("Missing RunProcess " + pattern);
|
||||
|
||||
return ret;
|
||||
@@ -86,7 +81,7 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
if (wd != workingDirectory)
|
||||
throw new ArgumentException($"Unexpected RunProcessWorkingDirectory, got {wd ?? "null"} expected {workingDirectory ?? "null"} in {pattern}");
|
||||
|
||||
if (!RunProcess.TryGetValue(pattern, out var ret) && !RunProcessExecuteDuring.TryGetValue(pattern, out ret))
|
||||
if (!RunProcess.TryGetValue(pattern, out var ret))
|
||||
throw new ArgumentException("Missing RunProcess " + pattern);
|
||||
|
||||
return ret;
|
||||
@@ -167,6 +162,10 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
|
||||
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;
|
||||
|
||||
public bool IsMonoInstalled { get; set; }
|
||||
|
||||
bool IBuildActions.IsMonoInstalled() => IsMonoInstalled;
|
||||
|
||||
public string PathCombine(params string[] parts)
|
||||
{
|
||||
return string.Join(IsWindows ? '\\' : '/', parts.Where(p => !string.IsNullOrWhiteSpace(p)));
|
||||
@@ -804,7 +803,7 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestDirsProjLinux_WithMono()
|
||||
{
|
||||
actions.RunProcessExecuteDuring[@"mono --version"] = 0;
|
||||
actions.IsMonoInstalled = true;
|
||||
|
||||
actions.RunProcess[@"nuget restore C:\Project/dirs.proj -DisableParallelProcessing"] = 1;
|
||||
actions.RunProcess[@"mono scratch/.nuget/nuget.exe restore C:\Project/dirs.proj -DisableParallelProcessing"] = 0;
|
||||
@@ -817,7 +816,7 @@ namespace Semmle.Autobuild.CSharp.Tests
|
||||
[Fact]
|
||||
public void TestDirsProjLinux_WithoutMono()
|
||||
{
|
||||
actions.RunProcessExecuteDuring[@"mono --version"] = 1;
|
||||
actions.IsMonoInstalled = false;
|
||||
|
||||
actions.RunProcess[@"dotnet msbuild /t:restore C:\Project/dirs.proj"] = 0;
|
||||
actions.RunProcess[@"dotnet msbuild C:\Project/dirs.proj /t:rebuild"] = 0;
|
||||
|
||||
@@ -150,6 +150,10 @@ namespace Semmle.Autobuild.Cpp.Tests
|
||||
|
||||
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;
|
||||
|
||||
public bool IsMonoInstalled { get; set; }
|
||||
|
||||
bool IBuildActions.IsMonoInstalled() => IsMonoInstalled;
|
||||
|
||||
string IBuildActions.PathCombine(params string[] parts)
|
||||
{
|
||||
return string.Join(IsWindows ? '\\' : '/', parts.Where(p => !string.IsNullOrWhiteSpace(p)));
|
||||
|
||||
@@ -74,12 +74,7 @@ namespace Semmle.Autobuild.Shared
|
||||
Argument("-DisableParallelProcessing").
|
||||
Script;
|
||||
|
||||
BuildScript GetMonoVersionScript() => new CommandBuilder(builder.Actions).
|
||||
RunCommand("mono").
|
||||
Argument("--version").
|
||||
Script;
|
||||
|
||||
var preferDotnet = !builder.Actions.IsWindows() && GetMonoVersionScript().Run(builder.Actions, (_, _) => { }, (_, _, _) => { }) != 0;
|
||||
var preferDotnet = !builder.Actions.IsWindows() && !builder.Actions.IsMonoInstalled();
|
||||
|
||||
var nugetRestore = GetNugetRestoreScript();
|
||||
var msbuildRestoreCommand = new CommandBuilder(builder.Actions).
|
||||
|
||||
@@ -125,6 +125,11 @@ namespace Semmle.Util
|
||||
/// <returns>True if we are running on Apple Silicon.</returns>
|
||||
bool IsRunningOnAppleSilicon();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if Mono is installed.
|
||||
/// </summary>
|
||||
bool IsMonoInstalled();
|
||||
|
||||
/// <summary>
|
||||
/// Combine path segments, Path.Combine().
|
||||
/// </summary>
|
||||
@@ -261,6 +266,25 @@ namespace Semmle.Util
|
||||
}
|
||||
}
|
||||
|
||||
bool IBuildActions.IsMonoInstalled()
|
||||
{
|
||||
var thisBuildActions = (IBuildActions)this;
|
||||
|
||||
if (thisBuildActions.IsWindows())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return 0 == thisBuildActions.RunProcess("mono", "--version", workingDirectory: null, env: null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts);
|
||||
|
||||
void IBuildActions.WriteAllText(string filename, string contents) => File.WriteAllText(filename, contents);
|
||||
|
||||
Reference in New Issue
Block a user