mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
C#: Address review comments
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
{
|
||||
get
|
||||
{
|
||||
var dotnetPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
|
||||
var dotnetPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
|
||||
var dotnetDirs = dotnetPath != null
|
||||
? new[] { dotnetPath }
|
||||
: new[] { "/usr/share/dotnet", @"C:\Program Files\dotnet" };
|
||||
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
{
|
||||
get
|
||||
{
|
||||
var monoPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
|
||||
var monoPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
|
||||
var monoDirs = monoPath != null
|
||||
? new[] { monoPath }
|
||||
: new[] { "/usr/lib/mono", @"C:\Program Files\Mono\lib\mono" };
|
||||
|
||||
@@ -54,27 +54,29 @@ namespace Semmle.Util
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the path for the executable <paramref name="exe"/> based on the
|
||||
/// Finds the path for the program <paramref name="prog"/> based on the
|
||||
/// <code>PATH</code> environment variable, and in the case of Windows the
|
||||
/// <code>PATHEXT</code> environment variable.
|
||||
///
|
||||
/// Returns <code>null</code> of no path can be found.
|
||||
/// </summary>
|
||||
public static string FindExecutableOnPath(string exe)
|
||||
public static string FindProgramOnPath(string prog)
|
||||
{
|
||||
var paths = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
|
||||
var paths = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator);
|
||||
string[] exes;
|
||||
if (Win32.IsWindows())
|
||||
{
|
||||
var extensions = Environment.GetEnvironmentVariable("PATHEXT").Split(';').ToArray();
|
||||
exes = extensions.Any(exe.EndsWith) ? new[] { exe } : extensions.Select(ext => exe + ext).ToArray();
|
||||
var extensions = Environment.GetEnvironmentVariable("PATHEXT")?.Split(';')?.ToArray();
|
||||
exes = extensions == null || extensions.Any(prog.EndsWith)
|
||||
? new[] { prog }
|
||||
: extensions.Select(ext => prog + ext).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
exes = new[] { exe };
|
||||
exes = new[] { prog };
|
||||
}
|
||||
var candidates = paths.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
|
||||
return candidates.FirstOrDefault();
|
||||
var candidates = paths?.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
|
||||
return candidates?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user