Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions FrostingContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace BuildScripts;

public static class FrostingContextExtensions
{
private static readonly ProcessSettings _processSettings = new();
private static string _environmentVariables = string.Empty;

public static void SetShellWorkingDir(this FrostingContext context, string path) => _processSettings.WorkingDirectory = path;

public static void SetShellEnvironmentVariables(this FrostingContext context, params string[] env)
{
_environmentVariables = string.Empty;
for(int i = 0; i < env.Length; i+= 2)
{
string key = env[i];
string value = $"'{env[i + 1]}'";
_environmentVariables += $"export {key}={value};";
}
}

public static void ClearShellEnvironmentVariables(this FrostingContext context) => _environmentVariables = string.Empty;

public static int ShellExecute(this FrostingContext context, string command)
{
string shellCommandPath = context switch
{
_ when context.IsRunningOnWindows() => @"C:\msys64\usr\bin\bash.exe",
_ when context.IsRunningOnLinux() => "sh",
_ when context.IsRunningOnMacOs() => "zsh",
_ => throw new PlatformNotSupportedException("Unsupported Platform")
};

_processSettings.Arguments = $"-c \"{_environmentVariables} {command}\"";
context.Information($"Executing: {shellCommandPath} {string.Join(' ', _processSettings.Arguments)}");
return context.StartProcess(shellCommandPath, _processSettings);
}
}
8 changes: 8 additions & 0 deletions MonoGame.Tool.BuildScripts.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Tool.BuildScripts", "MonoGame.Tool.BuildScripts.csproj", "{BADF2727-6775-4E00-93D2-6725D2E3F5BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -11,4 +13,10 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BADF2727-6775-4E00-93D2-6725D2E3F5BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BADF2727-6775-4E00-93D2-6725D2E3F5BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BADF2727-6775-4E00-93D2-6725D2E3F5BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BADF2727-6775-4E00-93D2-6725D2E3F5BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal