Skip to content

Commit

Permalink
Merge branch 'added-an-option-to-add-additional-environment-var' into…
Browse files Browse the repository at this point in the history
… 'main'

Added an option to add additional environment variables to the global settings in fastbuild

See merge request Sharpmake/sharpmake!426
  • Loading branch information
baudronp committed Jul 10, 2023
2 parents 71c16c8 + a88b4de commit d19711d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sharpmake.Generators/FastBuild/Bff.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static class ConfigurationFile
""USERPROFILE=$USERPROFILE$"",
""SystemRoot=[fastBuildSystemRoot]""
""PATH=[fastBuildPATH]""
[envAdditionalVariables]
}
#endif[envRemoveGuards]
";
Expand All @@ -80,6 +81,7 @@ public static class ConfigurationFile
{
""TMPDIR=$TMPDIR$"",
""PATH=[fastBuildPATH]""
[envAdditionalVariables]
}
#endif[envRemoveGuards]
";
Expand Down
7 changes: 7 additions & 0 deletions Sharpmake.Generators/FastBuild/MasterBff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ private static void WriteMasterSettingsSection(FileGenerator masterBffGenerator,
fastBuildEnvironments += Bff.Template.ConfigurationFile.WinEnvironment;
}

string envAdditionalVariables = FileGeneratorUtilities.RemoveLineTag;
if (FastBuildSettings.AdditionalGlobalEnvironmentVariables.Any())
{
envAdditionalVariables = string.Join(Environment.NewLine, FastBuildSettings.AdditionalGlobalEnvironmentVariables.Select(keyValue => $" \"{keyValue.Key}={keyValue.Value}\""));
}

using (masterBffGenerator.Declare("fastBuildProjectName", "Master"))
using (masterBffGenerator.Declare("CachePath", cachePath))
using (masterBffGenerator.Declare("CachePluginDLL", cachePluginDLL))
Expand All @@ -666,6 +672,7 @@ private static void WriteMasterSettingsSection(FileGenerator masterBffGenerator,
using (masterBffGenerator.Declare("AdditionalGlobalSettings", additionalGlobalSettings))
using (masterBffGenerator.Declare("fastBuildEnvironments", fastBuildEnvironments))
using (masterBffGenerator.Declare("envRemoveGuards", envRemoveGuards))
using (masterBffGenerator.Declare("envAdditionalVariables", envAdditionalVariables))
{
masterBffGenerator.Write(Bff.Template.ConfigurationFile.HeaderFile);
masterBffGenerator.Write(Bff.Template.ConfigurationFile.GlobalSettings);
Expand Down
5 changes: 5 additions & 0 deletions Sharpmake/FastBuildSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static class FastBuildSettings
/// </summary>
public static readonly IList<string> AdditionalGlobalSettings = new List<string>();

/// <summary>
/// Additional environment variables to add to the global environment settings node (key, value)
/// </summary>
public static readonly IDictionary<string, string> AdditionalGlobalEnvironmentVariables = new Dictionary<string, string>();

/// <summary>
/// Path to the fastbuild plugin dll if any. This typically will be the path to the Ubisoft asset store plugin DLL but could be any other compatible implementation.
/// CachePath must also be set to an appropriate url.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public static void SharpmakeMain(Sharpmake.Arguments arguments)
// This is necessary since there is no rc.exe in the same directory than link.exe
FastBuildSettings.SetPathToResourceCompilerInEnvironment = true;

// Add an additional environment variable for fastbuild for testing
FastBuildSettings.AdditionalGlobalEnvironmentVariables.Add("KEY", "VALUE");

KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2019, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);
KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2022, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Settings
"USERPROFILE=$USERPROFILE$",
"SystemRoot=C:\WINDOWS"
"PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64"
"KEY=VALUE"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Settings
"USERPROFILE=$USERPROFILE$",
"SystemRoot=C:\WINDOWS"
"PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64"
"KEY=VALUE"
}

}
Expand Down

0 comments on commit d19711d

Please sign in to comment.