mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Run dotnet exec command silently.
This commit is contained in:
committed by
Tamas Vajk
parent
d391246f27
commit
d48ab36273
@@ -133,10 +133,9 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
}
|
||||
|
||||
var views = GetFiles("*.cshtml")
|
||||
.Concat(GetFiles("*.razor"))
|
||||
.ToArray();
|
||||
.Concat(GetFiles("*.razor"));
|
||||
|
||||
if (views.Length > 0)
|
||||
if (views.Any())
|
||||
{
|
||||
// TODO: use SDK specified in global.json
|
||||
// TODO: add feature flag to control razor generation
|
||||
|
||||
@@ -34,20 +34,35 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
}
|
||||
}
|
||||
|
||||
private bool RunCommand(string args)
|
||||
private static ProcessStartInfo MakeDotnetStartInfo(string args) =>
|
||||
new ProcessStartInfo(dotnet, args)
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true
|
||||
};
|
||||
|
||||
private bool RunCommandAux(string args, bool silent)
|
||||
{
|
||||
progressMonitor.RunningProcess($"{dotnet} {args}");
|
||||
using var proc = Process.Start(dotnet, args);
|
||||
proc.WaitForExit();
|
||||
if (proc.ExitCode != 0)
|
||||
using var proc = silent
|
||||
? Process.Start(MakeDotnetStartInfo(args))
|
||||
: Process.Start(dotnet, args);
|
||||
proc?.WaitForExit();
|
||||
var exitCode = proc?.ExitCode ?? -1;
|
||||
if (exitCode != 0)
|
||||
{
|
||||
progressMonitor.CommandFailed(dotnet, args, proc.ExitCode);
|
||||
progressMonitor.CommandFailed(dotnet, args, exitCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RunCommand(string args) =>
|
||||
RunCommandAux(args, false);
|
||||
|
||||
private bool RunCommandSilently(string args) =>
|
||||
RunCommandAux(args, true);
|
||||
|
||||
public bool RestoreToDirectory(string projectOrSolutionFile, string packageDirectory, string? pathToNugetConfig = null)
|
||||
{
|
||||
var args = $"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true";
|
||||
@@ -75,11 +90,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
private IList<string> GetListed(string args, string artifact)
|
||||
{
|
||||
progressMonitor.RunningProcess($"{dotnet} {args}");
|
||||
var pi = new ProcessStartInfo(dotnet, args)
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
var pi = MakeDotnetStartInfo(args);
|
||||
var exitCode = pi.ReadOutput(out var artifacts);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
@@ -92,9 +103,8 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
|
||||
public bool Exec(string execArgs)
|
||||
{
|
||||
// TODO: we might need to swallow the stdout of the started process to not pollute the logs of the extraction.
|
||||
var args = $"exec {execArgs}";
|
||||
return RunCommand(args);
|
||||
return RunCommandSilently(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user