C#: Parallelize restore logic of missing packages

This commit is contained in:
Tamas Vajk
2023-09-18 12:32:44 +02:00
parent fc3bc95147
commit dfd7f1e78b
5 changed files with 59 additions and 36 deletions

View File

@@ -37,6 +37,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
}
}
private bool RunCommand(string args, out string stdout)
{
var success = dotnetCliInvoker.RunCommand(args, out var output);
stdout = string.Join("\n", output);
return success;
}
private static string GetRestoreArgs(string projectOrSolutionFile, string packageDirectory) =>
$"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true";
@@ -47,9 +54,8 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
{
args += $" --configfile \"{pathToNugetConfig}\"";
}
var success = dotnetCliInvoker.RunCommand(args, out var output);
stdout = string.Join("\n", output);
return success;
return RunCommand(args, out stdout);
}
public bool RestoreSolutionToDirectory(string solutionFile, string packageDirectory, out IEnumerable<string> projects)
@@ -70,16 +76,16 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
return false;
}
public bool New(string folder)
public bool New(string folder, out string stdout)
{
var args = $"new console --no-restore --output \"{folder}\"";
return dotnetCliInvoker.RunCommand(args);
return RunCommand(args, out stdout);
}
public bool AddPackage(string folder, string package)
public bool AddPackage(string folder, string package, out string stdout)
{
var args = $"add \"{folder}\" package \"{package}\" --no-restore";
return dotnetCliInvoker.RunCommand(args);
return RunCommand(args, out stdout);
}
public IList<string> GetListedRuntimes() => GetListed("--list-runtimes", "runtime");
@@ -88,7 +94,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
private IList<string> GetListed(string args, string artifact)
{
if (dotnetCliInvoker.RunCommand(args, out var artifacts))
if (dotnetCliInvoker.RunCommand(args, out IList<string> artifacts))
{
progressMonitor.LogInfo($"Found {artifact}s: {string.Join("\n", artifacts)}");
return artifacts;