6using Nuke.Common.Utilities.Collections;
8using Nuke.Common.Tools.Git;
11using Nuke.Common.Utilities;
12using Nuke.Common.ProjectModel;
14using System.Runtime.InteropServices;
15using Nuke.Cola.Tooling;
22 public abstract partial class UnrealBuild : NukeBuild
24 public virtual Target Info => _ => _
25 .Description(
"Prints curated information about project")
28 public virtual Target CleanDeployment => _ => _
29 .Description(
"Removes previous deployment folder")
30 .Executes(() =>
GetOutput().DeleteDirectory());
32 public virtual Target CleanProject => _ => _
33 .Description(
"Removes auto generated folders of Unreal Engine from the project")
36 public virtual Target CleanPlugins => _ => _
37 .Description(
"Removes auto generated folders of Unreal Engine from the plugins")
38 .OnlyWhenDynamic(() => PluginsFolder.DirectoryExists())
41 void recurseBody(AbsolutePath path)
43 if (Glob.Files(path,
"*.uplugin", GlobOptions.CaseInsensitive).Any())
45 Log.Debug(
"Cleaning plugin {0}", path);
50 foreach (var dir
in Directory.EnumerateDirectories(path))
52 recurseBody((AbsolutePath)dir);
57 foreach (var pluginDir
in Directory.EnumerateDirectories(PluginsFolder))
59 recurseBody((AbsolutePath)pluginDir);
63 public virtual Target Clean => _ => _
64 .Description(
"Removes auto generated folders of Unreal Engine")
65 .DependsOn(CleanProject)
66 .DependsOn(CleanPlugins);
68 public virtual Target Switch => _ => _
69 .Description(
"Switch to an explicit Engine version")
71 .Before(Prepare, Generate, BuildEditor, Build, Cook)
75 Log.Information($
"Targeting Unreal Engine {UnrealVersion} on platform {Platform}");
79 _projectDescriptor =
null;
80 _engineVersionCache =
null;
83 public virtual Target Prepare => _ => _
87 Run necessary preparations which needs to be done before Unreal tools can handle
88 the project. By default it is empty and the main build project may override it or
89 other Targets can depend on it / hook into it.
94 public virtual Target Generate => _ => _
98 Generate project files for the default IDE of the current platform
99 (Visual Studio or XCode)
118 public virtual Target BuildEditor => _ => _
122 Build the editor binaries so this project can be opened properly in the
139 "ShaderCompileWorker",
151 public virtual Target Build => _ => _
152 .Description(
"Build this project for execution")
162 .For(targets, (t, _) => _
163 .Target(t, Platform, Config)
186 var section =
ReadIniHierarchy(
"Game")[
"/Script/UnrealEd.ProjectPackagingSettings"];
187 return section !=
null && section
188 .GetFirst(
"ForDistribution",
new() { Value =
"" }).Value
189 .EqualsAnyOrdinalIgnoreCase(
"true",
"1");
192 public virtual Target Cook => _ => _
193 .Description(
"Cook Unreal assets for standalone game execution")
194 .DependsOn(BuildEditor)
199 var androidTextureMode = SelfAs<IAndroidTargets>()?.TextureMode
202 Config.ForEach(config =>
207 .Clientconfig(config)
215 .Targetplatform(Platform)
217 .If(InvokedTargets.Contains(BuildEditor), _ => _
220 .If(isAndroidPlatform, _ => _
221 .Cookflavor(androidTextureMode)
230 public virtual Target EnsureBuildPluginSupport => _ => _
234 Ensure support for plain C# build plugins without the need for CSX or dotnet
235 projects. This only needs to be done once, you can check the results into
242 var project = ProjectModelTasks.ParseProject(BuildProjectFile);
243 project.SkipEvaluation =
true;
244 var compileItems = project.GetItems(
"Compile");
245 var pattern =
"../**/*.nuke.cs";
247 if (BuildProjectFile.ReadAllText().Contains(pattern))
248 Log.Debug(
"Build project already supports standalone C# build plugins.");
251 Log.Information(
"Preparing build project to accept standalone C# files. {0}, in {1}", pattern, BuildProjectFile);
252 project.AddItem(
"Compile", pattern);
254 Log.Information(
"This only needs to be done once, you can check the results into source control.");
258 [Parameter(
"Do not use globally applicable UBT/UAT arguments with run-uat/run-ubt")]
259 public bool IgnoreGlobalArgs =
false;
261 public virtual Target RunUat => _ => _
262 .Description(
"Simply run UAT with arguments passed after `-->`")
267 .If(!IgnoreGlobalArgs, _ => _.Apply(
UatGlobal))
271 public virtual Target RunUbt => _ => _
272 .Description(
"Simply run UBT with arguments passed after `-->`")
277 .If(!IgnoreGlobalArgs, _ => _.Apply(
UbtGlobal))
281 public virtual Target RunShell => _ => _
285 Start a UShell session. This opens a new console window, and nuke will exit
286 immadiately. Working directory is the project folder, regardless of actual
294 var scriptExt = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"bat" :
"sh";
295 var ushellScript = ushellDir / (
"ushell." + scriptExt);
296 Common.Tooling.ProcessTasks.StartShell(
305 Name the Unreal tool to be run, You can omit the `Unreal` prefix and the extension.
307 nuke run --tool pak --> ./Path/To/MyProject.pak -Extract "D:/temp
"
308 nuke run --tool editor-cmd --> ~p -run=MyCommandlet
314 public virtual Target Run => _ => _
318 Run an Unreal tool from the engine binaries folder. You can omit the `Unreal`
319 prefix and the extension. For example:
321 nuke run --tool pak --> ./Path/To/MyProject.pak -Extract "D:/temp
"
322 nuke run --tool editor-cmd --> ~p -run=MyCommandlet
324 Working directory is the project folder, regardless of actual working
329 .Requires(() => Tool)
337 [Parameter(
"Name of the editor commandlet to run")]
340 public virtual Target RunEditorCmd => _ => _
341 .Description(
"Run an editor commandlet with arguments passed in after -->")
347 .Prepend($
"{ProjectPath} -run={Cmd}")
The main build class Unreal projects using Nuke.Unreal should inherit from. This class contains all b...
AbsolutePath ProjectFolder
Path to folder containing the .project file.
virtual IEnumerable< string > GetArgumentBlock(string name="")
Get optionally named argument block (section after -->) with contextual data substituted....
virtual AbsolutePath ProjectPath
string ProjectName
Short name of the project.
ProjectDescriptor ProjectDescriptor
"Immutable" C# representation of the .uproject contents
AbsolutePath UnrealEnginePath
Path to the root of the associated Unreal Engine installation/source.
virtual UbtConfig UbtGlobal(UbtConfig _)
UBT arguments to be applied globally for all UBT invocations. Override this function in your main bui...
virtual UatConfig UatCook(UatConfig _)
UAT arguments to be applied every time UAT is called for Cooking. Override this function in your main...
virtual AbsolutePath GetOutput()
Get an output folder where the targets should store their artifacts. Override this function in your m...
virtual ? string UnrealVersion
Most targets read the desired Unreal version from the project file.
virtual bool ForDistribution()
Enforce packaging for distribution when that is set from Game ini files. Override this function in yo...
ConfigIni ReadIniHierarchy(string shortName, IniHierarchyLevel lowestLevel=IniHierarchyLevel.Base, IniHierarchyLevel highestLevel=IniHierarchyLevel.Saved, bool considerPlugins=true, IEnumerable< string >? extraConfigSubfolder=null)
Read INI configuration emulating the same hierarchy of importance as Unreal Engine also does.
virtual void PrintInfo()
Print some rudimentary information onto console about this project and it's environment....
virtual UatConfig UatGlobal(UatConfig _)
UAT arguments to be applied globally for all UAT invocations. Override this function in your main bui...
Build configurations UBT supports.
The regular target types UBT supports.
static readonly UnrealTargetType Editor
Editor builds for the project.
static readonly UnrealTargetType Game
Can act as both client and server.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
static void WriteJson(object input, AbsolutePath path)
Write data in JSON with Unreal conventions of JSON format.
static Tool AutomationTool(EngineVersion ofVersion)
Prepare invocation for UAT.
static Tool GetTool(UnrealBuild build, string name)
Get a native binary tool from Engine/Binaries folder. Unreal tools written in C# or stored in other f...
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 Tool BuildTool(EngineVersion ofVersion)
Prepare invocation for UBT.
static UnrealPlatformFlag GetDefaultPlatform()
Get the current development platform Nuke.Unreal is ran on.
static void ClearFolder(AbsolutePath folder)
Clear intermediate folders of Unreal from a given folder.