-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasi] Add
WasiAppBuilder
task (#82126)
* Address review feedback from @pavelsavara
- Loading branch information
Showing
9 changed files
with
258 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.WebAssembly.AppHost; | ||
|
||
public static class FileUtils | ||
{ | ||
private static readonly string[] s_extensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
? new[] { ".exe", ".cmd", ".bat" } | ||
: new[] { "" }; | ||
|
||
public static bool TryFindExecutableInPATH(string filename, [NotNullWhen(true)] out string? fullPath, [NotNullWhen(false)] out string? errorMessage) | ||
{ | ||
errorMessage = null; | ||
fullPath = null; | ||
if (File.Exists(filename)) | ||
{ | ||
fullPath = Path.GetFullPath(filename); | ||
return true; | ||
} | ||
|
||
if (Path.IsPathRooted(filename)) | ||
{ | ||
fullPath = filename; | ||
return true; | ||
} | ||
|
||
var path = Environment.GetEnvironmentVariable("PATH"); | ||
if (string.IsNullOrEmpty(path)) | ||
{ | ||
errorMessage = "Could not find environment variable PATH"; | ||
return false; | ||
} | ||
|
||
string[] searchPaths = path.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries); | ||
if (searchPaths.Length == 0) | ||
{ | ||
errorMessage = $"No paths set in environment variable PATH"; | ||
return false; | ||
} | ||
|
||
List<string> filenamesTried = new(s_extensions.Length); | ||
foreach (string extn in s_extensions) | ||
{ | ||
string filenameWithExtn = filename + extn; | ||
filenamesTried.Add(filenameWithExtn); | ||
foreach (string searchPath in searchPaths) | ||
{ | ||
var pathToCheck = Path.Combine(searchPath, filenameWithExtn); | ||
if (File.Exists(pathToCheck)) | ||
{ | ||
fullPath = pathToCheck; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
// Could not find the path | ||
errorMessage = $"Tried to look for {string.Join(", ", filenamesTried)} in PATH: {string.Join(", ", searchPaths)} ."; | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.