Skip to content

Commit 3b010a2

Browse files
committed
C# standalone: accept path to .dotnet folder
1 parent 4c2a7aa commit 3b010a2

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
4848

4949
try
5050
{
51-
this.dotnet = new DotNet(progressMonitor);
51+
this.dotnet = new DotNet(options, progressMonitor);
5252
}
5353
catch
5454
{

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public interface IDependencyOptions
5656
/// The number of threads to use.
5757
/// </summary>
5858
int Threads { get; }
59+
60+
/// <summary>
61+
/// The path to the local ".dotnet" directory, if any.
62+
/// </summary>
63+
string? DotNetPath { get; }
5964
}
6065

6166
public class DependencyOptions : IDependencyOptions
@@ -80,5 +85,7 @@ public bool ExcludesFile(string path) =>
8085
Excludes.Any(path.Contains);
8186

8287
public int Threads { get; set; } = EnvironmentVariables.GetDefaultNumberOfThreads();
88+
89+
public string? DotNetPath { get; set; } = null;
8390
}
8491
}

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using Semmle.Util;
56

67
namespace Semmle.Extraction.CSharp.DependencyFetching
@@ -10,12 +11,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
1011
/// </summary>
1112
internal class DotNet : IDotNet
1213
{
13-
private const string dotnet = "dotnet";
1414
private readonly ProgressMonitor progressMonitor;
15+
private readonly string dotnet;
1516

16-
public DotNet(ProgressMonitor progressMonitor)
17+
public DotNet(IDependencyOptions options, ProgressMonitor progressMonitor)
1718
{
1819
this.progressMonitor = progressMonitor;
20+
this.dotnet = Path.Combine(options.DotNetPath ?? string.Empty, "dotnet");
1921
Info();
2022
}
2123

@@ -29,7 +31,7 @@ private void Info()
2931
}
3032
}
3133

32-
private static ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) =>
34+
private ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) =>
3335
new ProcessStartInfo(dotnet, args)
3436
{
3537
UseShellExecute = false,
@@ -39,7 +41,7 @@ private static ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectSt
3941
private bool RunCommand(string args)
4042
{
4143
progressMonitor.RunningProcess($"{dotnet} {args}");
42-
using var proc = Process.Start(MakeDotnetStartInfo(args, redirectStandardOutput: false));
44+
using var proc = Process.Start(this.MakeDotnetStartInfo(args, redirectStandardOutput: false));
4345
proc?.WaitForExit();
4446
var exitCode = proc?.ExitCode ?? -1;
4547
if (exitCode != 0)
@@ -77,7 +79,7 @@ public bool AddPackage(string folder, string package)
7779
private IList<string> GetListed(string args, string artifact)
7880
{
7981
progressMonitor.RunningProcess($"{dotnet} {args}");
80-
var pi = MakeDotnetStartInfo(args, redirectStandardOutput: true);
82+
var pi = this.MakeDotnetStartInfo(args, redirectStandardOutput: true);
8183
var exitCode = pi.ReadOutput(out var artifacts);
8284
if (exitCode != 0)
8385
{

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Options.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public override bool HandleOption(string key, string value)
5353
case "references":
5454
dependencies.DllDirs.Add(value);
5555
return true;
56+
case "dotnet":
57+
dependencies.DotNetPath = value;
58+
return true;
5659
default:
5760
return base.HandleOption(key, value);
5861
}

0 commit comments

Comments
 (0)