Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
27 changes: 27 additions & 0 deletions FrostingContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace BuildScripts;

public static class FrostingContextExtensions
{
private static readonly ProcessSettings _processSettings;

static FrostingContextExtensions() => _processSettings = new ProcessSettings();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do:

private static readonly ProcessSettings _processSettings = new();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 99399d0


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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to use the => thingy here if you want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 99399d0

}

public static int ShellExecute(this FrostingContext context, string command, string environmentVariables = "")

@harry-cpp harry-cpp Apr 29, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass env variables in a separate function SetShellEnvVariables(parms string[] env)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 23d2fc1

From our previous discussion, the export keyword is in fact required. Without it, the environment variables do not stay set if the command executes something that in turn executes something else. So the export is required for the entire run of the process.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, I was not able to find any decent way of doing space character escapes in the command. The problem comes in situations where you want to set an environment variable such as

context.SetShellEnvironmentVariables("CFLAGS", $"-w -arch arm64 -I{dependencyDir}/include");

The space escapes would need to be set for the path in the -I flag, however you would need to differentiate between what is a path and what isn't, such as the -w -arch arm64 part. Otherwise, you end up with a sanitized environment variable such as CFLAGS="-w\ -arch\ arm64\ -i/path/to\ some/directory/include;" which fails to run.

Open to suggestions on this if still needed

@harry-cpp harry-cpp Apr 30, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are supposed to set it to either:

CFLAGS=-w\ -arch\ arm64\ -i/path/to\ some/directory/include;

or

CFLAGS="-w -arch arm64 -i/path/to some/directory/include";

{
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}\"";
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