mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +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("dotnet");
|
||||
var dotnetPath = FileUtils.FindExecutableOnPath(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("mono");
|
||||
var monoPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
|
||||
var monoDirs = monoPath != null
|
||||
? new[] { monoPath }
|
||||
: new[] { "/usr/lib/mono", @"C:\Program Files\Mono\lib\mono" };
|
||||
|
||||
@@ -62,11 +62,17 @@ namespace Semmle.Util
|
||||
/// </summary>
|
||||
public static string FindExecutableOnPath(string exe)
|
||||
{
|
||||
var isWindows = Win32.IsWindows();
|
||||
var paths = Environment.GetEnvironmentVariable("PATH").Split(isWindows ? ';' : ':');
|
||||
var exes = isWindows
|
||||
? Environment.GetEnvironmentVariable("PATHEXT").Split(';').Select(ext => exe + ext)
|
||||
: new[] { exe };
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
exes = new[] { exe };
|
||||
}
|
||||
var candidates = paths.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
|
||||
return candidates.FirstOrDefault();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user