Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
UnrealBuild.Project.cs
1using System.IO;
2using Newtonsoft.Json.Linq;
3using Nuke.Common;
4using Nuke.Common.IO;
5using Nuke.Common.Utilities;
6using Serilog;
7
8// Maximum line length of long parameter description:
9// ------------------------------------------------------------
10
11namespace Nuke.Unreal;
12
13public abstract partial class UnrealBuild : NukeBuild, IUnrealBuild
14{
15 private AbsolutePath? _projectCache = null;
16
17 /// <summary>
18 /// <para>
19 /// Optionally specify a path to a `.uproject` file.
20 /// </para>
21 /// <para>
22 /// If not overridden Nuke.Unreal will traverse upwards on the directory tree,
23 /// then sift through all subdirectories recursively (ignoring some known folders)
24 /// </para>
25 /// </summary>
26 public virtual AbsolutePath ProjectPath
27 {
28 get
29 {
30 if (_projectCache != null) return _projectCache;
31
32 var projectCachePath = TemporaryDirectory / "UProjectFile.txt";
33 if (projectCachePath.FileExists())
34 {
35 _projectCache = AbsolutePath.Create(projectCachePath.ReadAllText().Trim());
36 }
37 if (!projectCachePath.FileExists() || !_projectCache.FileExists())
38 {
39 Log.Information("Detecting Unreal project");
40 if (BuildCommon.LookAroundFor(f => f.EndsWith(".uproject"), out var candidate))
41 {
42 projectCachePath.WriteAllText(candidate);
43 _projectCache = candidate;
44 }
45 }
46 Assert.NotNull(_projectCache, "This build doesn't seem to be an Unreal project.");
47 Log.Information($"Unreal project: {_projectCache}");
48 return _projectCache!;
49 }
50 }
51
52 /// <summary>
53 /// Path to folder containing the `.project` file
54 /// </summary>
55 public AbsolutePath ProjectFolder => ProjectPath.Parent;
56 public AbsolutePath PluginsFolder => ProjectFolder / "Plugins";
57
58 /// <summary>
59 /// Short name of the project
60 /// </summary>
61 public string ProjectName => Path.GetFileNameWithoutExtension(ProjectPath);
62
63 private ProjectDescriptor? _projectDescriptor;
64
65 /// <summary>
66 /// "Immutable" C# representation of the `.uproject` contents
67 /// </summary>
69 {
70 get => _projectDescriptor
72 protected set => _projectDescriptor = value;
73 }
74}
Extra build related utilities not necessarily associated with Unreal tasks.
static bool LookAroundFor(Func< string, bool > predicate, out AbsolutePath? result)
Look for something in subtree of a folder or in parent folders based on a predicate.
AbsolutePath ProjectFolder
Path to folder containing the .project file.
virtual AbsolutePath ProjectPath
string ProjectName
Short name of the project.
ProjectDescriptor ProjectDescriptor
"Immutable" C# representation of the .uproject contents
AbsolutePath PluginsFolder
Path to the Unreal plugins folder of this project.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static readonly JsonSerializerSettings JsonReadSettings
Common JsonSerializerSettings for Unreal conventions of JSON format.
Definition Unreal.cs:69