-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLyraGame.Target.cs
More file actions
286 lines (247 loc) · 11.4 KB
/
LyraGame.Target.cs
File metadata and controls
286 lines (247 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System;
using System.IO;
using EpicGames.Core;
using System.Collections.Generic;
using UnrealBuildBase;
using Microsoft.Extensions.Logging;
public class LyraGameTarget : TargetRules
{
public LyraGameTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
ExtraModuleNames.AddRange(new string[] { "LyraGame" });
LyraGameTarget.ApplySharedLyraTargetSettings(this);
}
private static bool bHasWarnedAboutShared = false;
internal static void ApplySharedLyraTargetSettings(TargetRules Target)
{
ILogger Logger = Target.Logger;
Target.DefaultBuildSettings = BuildSettingsVersion.V6;
Target.IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
bool bIsTest = Target.Configuration == UnrealTargetConfiguration.Test;
bool bIsShipping = Target.Configuration == UnrealTargetConfiguration.Shipping;
bool bIsDedicatedServer = Target.Type == TargetType.Server;
if (Target.BuildEnvironment == TargetBuildEnvironment.Unique)
{
Target.CppCompileWarningSettings.ShadowVariableWarningLevel = WarningLevel.Error;
Target.bUseLoggingInShipping = true;
Target.bTrackRHIResourceInfoForTest = true;
if (bIsShipping && !bIsDedicatedServer)
{
// Make sure that we validate certificates for HTTPS traffic
Target.bDisableUnverifiedCertificates = true;
// Uncomment these lines to lock down the command line processing
// This will only allow the specified command line arguments to be parsed
//Target.GlobalDefinitions.Add("UE_COMMAND_LINE_USES_ALLOW_LIST=1");
//Target.GlobalDefinitions.Add("UE_OVERRIDE_COMMAND_LINE_ALLOW_LIST=\"-space -separated -list -of -commands\"");
// Uncomment this line to filter out sensitive command line arguments that you
// don't want to go into the log file (e.g., if you were uploading logs)
//Target.GlobalDefinitions.Add("FILTER_COMMANDLINE_LOGGING=\"-some_connection_id -some_other_arg\"");
}
if (bIsShipping || bIsTest)
{
// Disable reading generated/non-ufs ini files
Target.bAllowGeneratedIniWhenCooked = false;
Target.bAllowNonUFSIniWhenCooked = false;
}
if (Target.Type != TargetType.Editor)
{
// We don't use the path tracer at runtime, only for beauty shots, and this DLL is quite large
Target.DisablePlugins.Add("OpenImageDenoise");
// Reduce memory use in AssetRegistry always-loaded data, but add more cputime expensive queries
Target.GlobalDefinitions.Add("UE_ASSETREGISTRY_INDIRECT_ASSETDATA_POINTERS=1");
}
LyraGameTarget.ConfigureGameFeaturePlugins(Target);
}
else
{
// !!!!!!!!!!!! WARNING !!!!!!!!!!!!!
// Any changes in here must not affect PCH generation, or the target
// needs to be set to TargetBuildEnvironment.Unique
// This only works in editor or Unique build environments
if (Target.Type == TargetType.Editor)
{
LyraGameTarget.ConfigureGameFeaturePlugins(Target);
}
else
{
// Shared monolithic builds cannot enable/disable plugins or change any options because it tries to re-use the installed engine binaries
if (!bHasWarnedAboutShared)
{
bHasWarnedAboutShared = true;
Logger.LogWarning("LyraGameEOS and dynamic target options are disabled when packaging from an installed version of the engine");
}
}
}
}
static public bool ShouldEnableAllGameFeaturePlugins(TargetRules Target)
{
if (Target.Type == TargetType.Editor)
{
// With return true, editor builds will build all game feature plugins, but it may or may not load them all.
// This is so you can enable plugins in the editor without needing to compile code.
// return true;
}
bool bIsBuildMachine = Target.AdditionalProperties.GetProperty("IsBuildMachine") == "1";
if (bIsBuildMachine)
{
// This could be used to enable all plugins for build machines
// return true;
}
// By default use the default plugin rules as set by the plugin browser in the editor
// This is important because this code may not be run at all for launcher-installed versions of the engine
return false;
}
private static Dictionary<string, JsonObject> AllPluginRootJsonObjectsByName = new Dictionary<string, JsonObject>();
// Configures which game feature plugins we want to have enabled
// This is a fairly simple implementation, but you might do things like build different
// plugins based on the target release version of the current branch, e.g., enabling
// work-in-progress features in main but disabling them in the current release branch.
static public void ConfigureGameFeaturePlugins(TargetRules Target)
{
ILogger Logger = Target.Logger;
Log.TraceInformationOnce("Compiling GameFeaturePlugins in branch {0}", Target.Version.BranchName);
bool bBuildAllGameFeaturePlugins = ShouldEnableAllGameFeaturePlugins(Target);
// Load all of the game feature .uplugin descriptors
List<FileReference> CombinedPluginList = new List<FileReference>();
List<DirectoryReference> GameFeaturePluginRoots = Unreal.GetExtensionDirs(Target.ProjectFile.Directory, Path.Combine("Plugins", "GameFeatures"));
foreach (DirectoryReference SearchDir in GameFeaturePluginRoots)
{
CombinedPluginList.AddRange(PluginsBase.EnumeratePlugins(SearchDir));
}
if (CombinedPluginList.Count > 0)
{
Dictionary<string, List<string>> AllPluginReferencesByName = new Dictionary<string, List<string>>();
foreach (FileReference PluginFile in CombinedPluginList)
{
if (PluginFile != null && FileReference.Exists(PluginFile))
{
bool bEnabled = false;
bool bForceDisabled = false;
try
{
JsonObject RawObject;
lock (AllPluginRootJsonObjectsByName)
{
if (!AllPluginRootJsonObjectsByName.TryGetValue(PluginFile.GetFileNameWithoutExtension(), out RawObject))
{
RawObject = JsonObject.Read(PluginFile);
AllPluginRootJsonObjectsByName.Add(PluginFile.GetFileNameWithoutExtension(), RawObject);
}
}
// Validate that all GameFeaturePlugins are disabled by default
// If EnabledByDefault is true and a plugin is disabled the name will be embedded in the executable
// If this is a problem, enable this warning and change the game feature editor plugin templates to disable EnabledByDefault for new plugins
bool bEnabledByDefault = false;
if (!RawObject.TryGetBoolField("EnabledByDefault", out bEnabledByDefault) || bEnabledByDefault == true)
{
//Log.TraceWarning("GameFeaturePlugin {0}, does not set EnabledByDefault to false. This is required for built-in GameFeaturePlugins.", PluginFile.GetFileNameWithoutExtension());
}
// Validate that all GameFeaturePlugins are set to explicitly loaded
// This is important because game feature plugins expect to be loaded after project startup
bool bExplicitlyLoaded = false;
if (!RawObject.TryGetBoolField("ExplicitlyLoaded", out bExplicitlyLoaded) || bExplicitlyLoaded == false)
{
Logger.LogWarning("GameFeaturePlugin {0}, does not set ExplicitlyLoaded to true. This is required for GameFeaturePlugins.", PluginFile.GetFileNameWithoutExtension());
}
// You could read an additional field here that is project specific, e.g.,
//string PluginReleaseVersion;
//if (RawObject.TryGetStringField("MyProjectReleaseVersion", out PluginReleaseVersion))
//{
// bEnabled = SomeFunctionOf(PluginReleaseVersion, CurrentReleaseVersion) || bBuildAllGameFeaturePlugins;
//}
if (bBuildAllGameFeaturePlugins)
{
// We are in a mode where we want all game feature plugins, except ones we can't load or compile
bEnabled = true;
}
// Prevent using editor-only feature plugins in non-editor builds
bool bEditorOnly = false;
if (RawObject.TryGetBoolField("EditorOnly", out bEditorOnly))
{
if (bEditorOnly && (Target.Type != TargetType.Editor) && !bBuildAllGameFeaturePlugins)
{
// The plugin is editor only and we are building a non-editor target, so it is disabled
bForceDisabled = true;
}
}
else
{
// EditorOnly is optional
}
// some plugins should only be available in certain branches
string RestrictToBranch;
if (RawObject.TryGetStringField("RestrictToBranch", out RestrictToBranch))
{
if (!Target.Version.BranchName.Equals(RestrictToBranch, StringComparison.OrdinalIgnoreCase))
{
// The plugin is for a specific branch, and this isn't it
bForceDisabled = true;
Logger.LogDebug("GameFeaturePlugin {Name} was marked as restricted to other branches. Disabling.", PluginFile.GetFileNameWithoutExtension());
}
else
{
Logger.LogDebug("GameFeaturePlugin {Name} was marked as restricted to this branch. Leaving enabled.", PluginFile.GetFileNameWithoutExtension());
}
}
// Plugins can be marked as NeverBuild which overrides the above
bool bNeverBuild = false;
if (RawObject.TryGetBoolField("NeverBuild", out bNeverBuild) && bNeverBuild)
{
// This plugin was marked to never compile, so don't
bForceDisabled = true;
Logger.LogDebug("GameFeaturePlugin {Name} was marked as NeverBuild, disabling.", PluginFile.GetFileNameWithoutExtension());
}
// Keep track of plugin references for validation later
JsonObject[] PluginReferencesArray;
if (RawObject.TryGetObjectArrayField("Plugins", out PluginReferencesArray))
{
foreach (JsonObject ReferenceObject in PluginReferencesArray)
{
bool bRefEnabled = false;
if (ReferenceObject.TryGetBoolField("Enabled", out bRefEnabled) && bRefEnabled == true)
{
string PluginReferenceName;
if (ReferenceObject.TryGetStringField("Name", out PluginReferenceName))
{
string ReferencerName = PluginFile.GetFileNameWithoutExtension();
if (!AllPluginReferencesByName.ContainsKey(ReferencerName))
{
AllPluginReferencesByName[ReferencerName] = new List<string>();
}
AllPluginReferencesByName[ReferencerName].Add(PluginReferenceName);
}
}
}
}
}
catch (Exception ParseException)
{
Logger.LogWarning("Failed to parse GameFeaturePlugin file {Name}, disabling. Exception: {1}", PluginFile.GetFileNameWithoutExtension(), ParseException.Message);
bForceDisabled = true;
}
// Disabled has priority over enabled
if (bForceDisabled)
{
bEnabled = false;
}
// Print out the final decision for this plugin
Logger.LogDebug("ConfigureGameFeaturePlugins() has decided to {Action} feature {Name}", bEnabled ? "enable" : (bForceDisabled ? "disable" : "ignore"), PluginFile.GetFileNameWithoutExtension());
// Enable or disable it
if (bEnabled)
{
Target.EnablePlugins.Add(PluginFile.GetFileNameWithoutExtension());
}
else if (bForceDisabled)
{
Target.DisablePlugins.Add(PluginFile.GetFileNameWithoutExtension());
}
}
}
// If you use something like a release version, consider doing a reference validation to make sure
// that plugins with sooner release versions don't depend on content with later release versions
}
}
}