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{
13 public abstract partial class UnrealBuild : NukeBuild
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
75 private bool? _isPerforceCache = null;
76
77 /// <summary>
78 /// Does this project reside in a Perforce workspace?
79 /// </summary>
80 public virtual bool IsPerforce {
81 get
82 {
83 if (_isPerforceCache != null) return _isPerforceCache ?? false;
84
85 var isP4CachePath = TemporaryDirectory / "IsP4.txt";
86 if (isP4CachePath.FileExists())
87 _isPerforceCache = bool.Parse(isP4CachePath.ReadAllText().Trim());
88 else
89 {
90 Log.Information("Detecting Perforce workspace");
91 var isP4 = BuildCommon.LookAroundFor(
92 f => Path.GetFileName(f).EqualsOrdinalIgnoreCase("p4config.txt"),
93 out _
94 );
95 isP4CachePath.WriteAllText(isP4.ToString());
96 _isPerforceCache = isP4;
97 }
98 Log.Information(_isPerforceCache ?? false
99 ? "Project is managed by Perforce"
100 : "Project is not in a Perforce Workspace"
101 );
102 return _isPerforceCache ?? false;
103 }
104 }
105 }
106}
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
virtual bool IsPerforce
Does this project reside in a Perforce workspace?
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