Skip to content

Commit aaedf79

Browse files
authored
Support running Setup.csx on non-Windows (#1059)
* Support running Setup.csx on non-Windows * Addressing PR issues with default shell and script
1 parent 7dd27d1 commit aaedf79

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

tools/Setup.csx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Setup {
4040

4141
private void PrintHelp()
4242
{
43-
Console.WriteLine("USAGE: dotnet script Setup.csx -- <Target-Path> [-vs|-vscode] [-debug|-release]");
43+
Console.WriteLine("USAGE: Setup.[sh|cmd] -- <Target-Path> [-vs|-vscode] [-debug|-release]");
4444
Console.WriteLine("");
4545
Console.WriteLine("\t<Target-Path> is the path to the VS Code C/C++ Extension or root path of Visual Studio.");
4646
Console.WriteLine("\tFor Example:");
@@ -58,7 +58,7 @@ class Setup {
5858

5959
foreach (string arg in args)
6060
{
61-
if (arg.StartsWith("-") || arg.StartsWith("/"))
61+
if (arg.StartsWith("-"))
6262
{
6363
switch(arg.Substring(1).ToLower())
6464
{
@@ -69,6 +69,10 @@ class Setup {
6969
break;
7070
case "vs":
7171
Client = Client.VS;
72+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
73+
{
74+
throw new InvalidOperationException("Patching MIEngine with VS bits is not applicable for non-Windows Platforms.");
75+
}
7276
break;
7377
case "vscode":
7478
Client = Client.VSCode;
@@ -182,7 +186,15 @@ class Setup {
182186
{
183187
if (Client == Client.VSCode)
184188
{
185-
string vscodeExtensionPath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\.vscode\\extensions");
189+
string vscodeExtensionPath = string.Empty;
190+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
191+
{
192+
vscodeExtensionPath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\.vscode\\extensions");
193+
}
194+
else
195+
{
196+
vscodeExtensionPath = Path.Join(Environment.GetEnvironmentVariable("HOME"), ".vscode/extensions");
197+
}
186198
IEnumerable<string> extensions = Directory.EnumerateDirectories(vscodeExtensionPath);
187199

188200
foreach (string extension in extensions)
@@ -237,18 +249,25 @@ class Setup {
237249
}
238250
string destPath = Path.Join(TargetPath, lff.InstallDir, lff.FileName);
239251

252+
// Normalize Paths for OS
253+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
254+
{
255+
srcPath = srcPath.Replace('/', '\\');
256+
destPath = destPath.Replace('/', '\\');
257+
}
258+
else
259+
{
260+
srcPath = srcPath.Replace('\\', '/');
261+
destPath = destPath.Replace('\\', '/');
262+
}
263+
240264
Console.WriteLine(string.Format("Copying {0} to {1}.", srcPath, destPath));
241265

242266
// TODO: Support symlinking
243267
File.Copy(srcPath, destPath, overwrite: true);
244268
}
245269
}
246270

247-
}
248-
249-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
250-
{
251-
throw new InvalidOperationException("This script is only supported for Windows.");
252271
}
253272

254273
Setup setup = new Setup();

tools/Setup.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if ! hash dotnet 2>/dev/null; then
4+
echo "ERROR: The dotnet is not installed. see: https://dotnet.microsoft.com/download/dotnet-core"
5+
exit 1
6+
fi
7+
8+
if ! dotnet script -v &> /dev/null; then
9+
echo "dotnet script needs to be installed. Run 'dotnet tool install -g dotnet-script'".
10+
echo "More Information: https://github.com/filipw/dotnet-script#net-core-global-tool"
11+
exit 1
12+
fi
13+
14+
ScriptDir=$(dirname "$0")
15+
16+
"$ScriptDir/Setup.csx" "${@:1}"
17+
18+
exit 0

0 commit comments

Comments
 (0)