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)
122 Log.Debug(
"Looking for Unreal Engine installation {0}", engineAssociation);
125 Assert.NotNull(
EnginePathCache,
"Couldn't find Unreal Engine with that association");
141 => ~(compatibility - 1);
157 => (enginePath /
"Engine" /
"Build" /
"InstalledBuild.txt").FileExists();
164 var buildVersionPath = enginePath /
"Engine" /
"Build" /
"Build.version";
165 Assert.FileExists(buildVersionPath, $
"Specified path was not an Unreal Engine instance ({buildVersionPath})");
184 public static bool IsSource(AbsolutePath enginePath)
207 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
210 if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
213 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
216 throw new Exception(
"Attempting to build on an unsupported platform");
228 ofVersion.EnginePath /
"Engine" /
"Build" /
"BatchFiles" /
"Mac" /
"RunMono.sh";
235 => p => p.AssertZeroExitCodeNoLog(repeatErrorsOnFailure);
241 var ubtPath = ofVersion.SemanticalVersion.Major >= 5
242 ? ofVersion.EnginePath /
"Engine" /
"Binaries" /
"DotNET" /
"UnrealBuildTool" /
"UnrealBuildTool.exe"
243 : ofVersion.EnginePath /
"Engine" /
"Binaries" /
"DotNET" /
"UnrealBuildTool.exe";
245 return ToolExResolver.GetTool(ubtPath)
246 .WithSemanticLogging()
265 config.Invoke(toolConfig);
267 arguments: toolConfig.Gather(ofVersion),
268 workingDirectory: ofVersion.
EnginePath /
"Engine" /
"Source",
291 var scriptExt = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"bat" :
"sh";
292 return ToolExResolver.GetTool(ofVersion.
EnginePath /
"Engine" /
"Build" /
"BatchFiles" / $
"RunUAT.{scriptExt}")
293 .WithSemanticLogging(filter: l =>
294 !(l.Contains(
"Reading chunk manifest") && l.Contains(
"which contains 0 entries"))
311 config?.Invoke(toolConfig);
313 arguments: $
"{toolConfig.Gather(ofVersion):nq}",
314 workingDirectory: ofVersion.
EnginePath /
"Engine" /
"Source",
338 (folder /
"Intermediate").ExistingDirectory()?.DeleteDirectory();
339 (folder /
"Binaries").ExistingDirectory()?.DeleteDirectory();
340 (folder /
"DerivedDataCache").ExistingDirectory()?.DeleteDirectory();
348 var configPath = projectFolder /
"Config" /
"DefaultGame.ini";
349 if (!File.Exists(configPath))
return "Fill in Copyright info...";
351 var crLine = File.ReadAllLines(configPath)
352 .FirstOrDefault(l => l.StartsWith(
"CopyrightNotice="));
354 if (
string.IsNullOrWhiteSpace(crLine))
return "Fill in Copyright info...";
356 var crEntry = crLine.Split(
'=', 2, StringSplitOptions.TrimEntries);
357 if (crEntry.Length < 2)
return "Fill in Copyright info...";
373 var ext = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
".exe" :
"";
374 var path = binaries / (name + ext);
376 if (!path.FileExists())
377 path = binaries / (
"Unreal" + name + ext);
379 Assert.FileExists(path, $
"Requested tool {name} doesn't exist.");
380 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.
Static functions and common utilities for locating Unreal Engine.
static IUnrealLocator Make()
Get the current platform implementation of an Unreal Locator.
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 UnrealBuildVersion GetBuildVersion(AbsolutePath enginePath)
Gets the parsed content of Build.version file of an engine instance.
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....
record class UnrealBuildVersion(int MajorVersion, int MinorVersion, int PatchVersion, ulong? Changelist, ulong? CompatibleChangelist, int? IsLicenseeVersion, int? IsPromotedBuild, string? BranchName)
Represents a Build.version file in an engine instance.