4using System.Collections.Generic;
6using System.Runtime.InteropServices;
7using Nuke.Common.Tooling;
12using Nuke.Cola.Tooling;
14using Nuke.Common.Utilities;
15using Newtonsoft.Json.Converters;
38 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
45 if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
49 (AbsolutePath)
@"/Users/Shared/Epic Games",
53 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
58 (AbsolutePath)
@"/Users/Shared/Epic Games",
63 throw new Exception(
"Attempting to build on an unsupported platform");
71 MissingMemberHandling = MissingMemberHandling.Ignore,
72 DefaultValueHandling = DefaultValueHandling.Populate,
73 NullValueHandling = NullValueHandling.Include,
75 new StringEnumConverter(
false)
82 public static void WriteJson(
object input, AbsolutePath path)
84 var sb =
new StringBuilder();
85 var sw =
new StringWriter(sb);
87 using var jtw =
new JsonTextWriter(sw)
89 Formatting = Formatting.Indented,
94 var serializer =
new JsonSerializer()
96 NullValueHandling = NullValueHandling.Ignore,
97 Formatting = Formatting.Indented,
99 new StringEnumConverter(
false)
102 serializer.Serialize(jtw, input);
103 File.WriteAllText(path, sb.ToString());
116 public static AbsolutePath
GetEnginePath(
string engineAssociation,
bool ignoreCache =
false)
120 IUnrealLocator locator = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
124 Log.Debug(
"Looking for Unreal Engine installation {0}", engineAssociation);
127 Assert.NotNull(
EnginePathCache,
"Couldn't find Unreal Engine with that association");
143 => ~(compatibility - 1);
159 => (enginePath /
"Engine" /
"Build" /
"InstalledBuild.txt").FileExists();
176 public static bool IsSource(AbsolutePath enginePath)
199 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
202 if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
205 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
208 throw new Exception(
"Attempting to build on an unsupported platform");
220 ofVersion.EnginePath /
"Engine" /
"Build" /
"BatchFiles" /
"Mac" /
"RunMono.sh";
227 => p => p.AssertZeroExitCodeNoLog(repeatErrorsOnFailure);
233 var ubtPath = ofVersion.SemanticalVersion.Major >= 5
234 ? ofVersion.EnginePath /
"Engine" /
"Binaries" /
"DotNET" /
"UnrealBuildTool" /
"UnrealBuildTool.exe"
235 : ofVersion.EnginePath /
"Engine" /
"Binaries" /
"DotNET" /
"UnrealBuildTool.exe";
237 return ToolExResolver.GetTool(ubtPath)
238 .WithSemanticLogging()
257 config.Invoke(toolConfig);
259 arguments: toolConfig.Gather(ofVersion),
260 workingDirectory: ofVersion.
EnginePath /
"Engine" /
"Source",
283 var scriptExt = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"bat" :
"sh";
284 return ToolExResolver.GetTool(ofVersion.
EnginePath /
"Engine" /
"Build" /
"BatchFiles" / $
"RunUAT.{scriptExt}")
285 .WithSemanticLogging(filter: l =>
286 !(l.Contains(
"Reading chunk manifest") && l.Contains(
"which contains 0 entries"))
303 config?.Invoke(toolConfig);
305 arguments: $
"{toolConfig.Gather(ofVersion):nq}",
306 workingDirectory: ofVersion.
EnginePath /
"Engine" /
"Source",
330 (folder /
"Intermediate").ExistingDirectory()?.DeleteDirectory();
331 (folder /
"Binaries").ExistingDirectory()?.DeleteDirectory();
332 (folder /
"DerivedDataCache").ExistingDirectory()?.DeleteDirectory();
340 var configPath = projectFolder /
"Config" /
"DefaultGame.ini";
341 if (!File.Exists(configPath))
return "Fill in Copyright info...";
343 var crLine = File.ReadAllLines(configPath)
344 .FirstOrDefault(l => l.StartsWith(
"CopyrightNotice="));
346 if (
string.IsNullOrWhiteSpace(crLine))
return "Fill in Copyright info...";
348 var crEntry = crLine.Split(
'=', 2, StringSplitOptions.TrimEntries);
349 if (crEntry.Length < 2)
return "Fill in Copyright info...";
365 var ext = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
".exe" :
"";
366 var path = binaries / (name + ext);
368 if (!path.FileExists())
369 path = binaries / (
"Unreal" + name + ext);
371 Assert.FileExists(path, $
"Requested tool {name} doesn't exist.");
372 return ToolExResolver.GetTool(path)
High level representation of an Unreal Engine version.
Version SemanticalVersion
Semantical version representation of the given Unreal Engine.
AbsolutePath EnginePath
Cached engine path.
An empty Unreal Locator implementation which doesn't know about installed instances,...
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
static bool IsSource(EngineVersion ofVersion)
Are we working with an engine built from source?
static Action< IProcess > UnrealToolExitHandler(bool repeatErrorsOnFailure=false)
Exit handler which throws an exception on error which doesn't include the entire process output,...
static void WriteJson(object input, AbsolutePath path)
Write data in JSON with Unreal conventions of JSON format.
static EngineVersion Version(IUnrealBuild build)
Get high-level version of currently used Engine.
static ToolEx AutomationTool(EngineVersion ofVersion)
Prepare invocation for UAT.
static ToolEx AutomationTool(IUnrealBuild build, Action< UatConfig > config)
Prepare invocation for UAT with extra fluent-API configuration.
static bool IsSource(IUnrealBuild build)
Are we working with an engine built from source?
static UnrealPlatform GetHostPlatform()
Get the current development platform Nuke.Unreal is ran on.
static ToolEx AutomationTool(IUnrealBuild build)
Prepare invocation for UAT.
static bool IsInstalled(IUnrealBuild build)
Are we working with a vanilla engine most probably installed via the Marketplace?
static ToolEx GetTool(IUnrealBuild build, string name)
Get a native binary tool from Engine/Binaries folder. Unreal tools written in C# or stored in other f...
static AbsolutePath MacRunMono(EngineVersion ofVersion)
On Mac many Unreal tools need the Mono bootstrap.
static ToolEx AutomationTool(EngineVersion ofVersion, Action< UatConfig > config)
Prepare invocation for UAT with extra fluent-API configuration.
static UnrealPlatformFlag GetHostPlatformFlag()
Get the current development platform flag Nuke.Unreal is ran on.
static ToolEx BuildTool(EngineVersion ofVersion)
Prepare invocation for UBT.
static void InvalidateEnginePathCache()
In the rare and unlikely case that the Engine location may have changed during one session.
static bool IsSource(AbsolutePath enginePath)
Is given path an engine built from source?
static string ReadCopyrightFromProject(AbsolutePath projectFolder)
Read copyright info from the project's DefaultGame.ini
static ToolEx BuildTool(IUnrealBuild build)
Prepare invocation for UBT.
static UnrealCompatibility AndLater(this UnrealCompatibility compatibility)
Create a compatibility flag mask which indicates that a feature is available un-broken in given and t...
static bool Is5(IUnrealBuild build)
Are we working with UE5.
static readonly JsonSerializerSettings JsonReadSettings
Common JsonSerializerSettings for Unreal conventions of JSON format.
static bool Is4(IUnrealBuild build)
Are we working with UE4.
static bool IsInstalled(AbsolutePath enginePath)
Is given path a vanilla engine most probably installed via the Marketplace?
static ? AbsolutePath EnginePathCache
Once the Engine location is found for the current session, it ain't gonna move around,...
static bool IsInstalled(EngineVersion ofVersion)
Are we working with a vanilla engine most probably installed via the Marketplace?
static ToolEx BuildTool(EngineVersion ofVersion, Action< UbtConfig > config)
Prepare invocation for UBT with extra fluent-API configuration.
static void ClearFolder(AbsolutePath folder)
Clear intermediate folders of Unreal from a given folder.
static readonly? HashSet< AbsolutePath > EngineSearchPaths
Frankly this is not really relevant anymore.
static AbsolutePath GetEnginePath(string engineAssociation, bool ignoreCache=false)
Get the Unreal Engine path based on an input association text. (version, GUID or absolute path)
static ToolEx BuildTool(IUnrealBuild build, Action< UbtConfig > config)
Prepare invocation for UBT with extra fluent-API configuration.
Base interface for build components which require an UnrealBuild main class.
Common interface for locating Unreal Engine instances in different environments.
AbsolutePath? GetEngine(string name)
Get the path to an installed engine by its name or its absolute path.
UnrealPlatformFlag
Bit-field representation of Unreal platforms and platform-families.
UnrealCompatibility
A flag enum representation for checking the Unreal version compatibility of various features....