mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C# standalone: accept path to .dotnet folder
This commit is contained in:
@@ -48,7 +48,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.dotnet = new DotNet(progressMonitor);
|
this.dotnet = new DotNet(options, progressMonitor);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
/// The number of threads to use.
|
/// The number of threads to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int Threads { get; }
|
int Threads { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path to the local ".dotnet" directory, if any.
|
||||||
|
/// </summary>
|
||||||
|
string? DotNetPath { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DependencyOptions : IDependencyOptions
|
public class DependencyOptions : IDependencyOptions
|
||||||
@@ -80,5 +85,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
Excludes.Any(path.Contains);
|
Excludes.Any(path.Contains);
|
||||||
|
|
||||||
public int Threads { get; set; } = EnvironmentVariables.GetDefaultNumberOfThreads();
|
public int Threads { get; set; } = EnvironmentVariables.GetDefaultNumberOfThreads();
|
||||||
|
|
||||||
|
public string? DotNetPath { get; set; } = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using Semmle.Util;
|
using Semmle.Util;
|
||||||
|
|
||||||
namespace Semmle.Extraction.CSharp.DependencyFetching
|
namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||||
@@ -10,12 +11,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DotNet : IDotNet
|
internal class DotNet : IDotNet
|
||||||
{
|
{
|
||||||
private const string dotnet = "dotnet";
|
|
||||||
private readonly ProgressMonitor progressMonitor;
|
private readonly ProgressMonitor progressMonitor;
|
||||||
|
private readonly string dotnet;
|
||||||
|
|
||||||
public DotNet(ProgressMonitor progressMonitor)
|
public DotNet(IDependencyOptions options, ProgressMonitor progressMonitor)
|
||||||
{
|
{
|
||||||
this.progressMonitor = progressMonitor;
|
this.progressMonitor = progressMonitor;
|
||||||
|
this.dotnet = Path.Combine(options.DotNetPath ?? string.Empty, "dotnet");
|
||||||
Info();
|
Info();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) =>
|
private ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) =>
|
||||||
new ProcessStartInfo(dotnet, args)
|
new ProcessStartInfo(dotnet, args)
|
||||||
{
|
{
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
@@ -39,7 +41,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
private bool RunCommand(string args)
|
private bool RunCommand(string args)
|
||||||
{
|
{
|
||||||
progressMonitor.RunningProcess($"{dotnet} {args}");
|
progressMonitor.RunningProcess($"{dotnet} {args}");
|
||||||
using var proc = Process.Start(MakeDotnetStartInfo(args, redirectStandardOutput: false));
|
using var proc = Process.Start(this.MakeDotnetStartInfo(args, redirectStandardOutput: false));
|
||||||
proc?.WaitForExit();
|
proc?.WaitForExit();
|
||||||
var exitCode = proc?.ExitCode ?? -1;
|
var exitCode = proc?.ExitCode ?? -1;
|
||||||
if (exitCode != 0)
|
if (exitCode != 0)
|
||||||
@@ -77,7 +79,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
private IList<string> GetListed(string args, string artifact)
|
private IList<string> GetListed(string args, string artifact)
|
||||||
{
|
{
|
||||||
progressMonitor.RunningProcess($"{dotnet} {args}");
|
progressMonitor.RunningProcess($"{dotnet} {args}");
|
||||||
var pi = MakeDotnetStartInfo(args, redirectStandardOutput: true);
|
var pi = this.MakeDotnetStartInfo(args, redirectStandardOutput: true);
|
||||||
var exitCode = pi.ReadOutput(out var artifacts);
|
var exitCode = pi.ReadOutput(out var artifacts);
|
||||||
if (exitCode != 0)
|
if (exitCode != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ namespace Semmle.Extraction.CSharp.Standalone
|
|||||||
case "references":
|
case "references":
|
||||||
dependencies.DllDirs.Add(value);
|
dependencies.DllDirs.Add(value);
|
||||||
return true;
|
return true;
|
||||||
|
case "dotnet":
|
||||||
|
dependencies.DotNetPath = value;
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return base.HandleOption(key, value);
|
return base.HandleOption(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user