Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Scripts/BuildTarget.Automation.cs
andrew grant 72c05ae78b Fixed up Engine BenchmarkBuild and BuildTarget scripts for some UE5 / VK changes,
- Changes argument for building vanilla UE targets from "UE4" to "Unreal"
- Improved code that detects the project target to build to deal with projects that have multiple "Editor" targets
- Fixed issue where -noxge would cause -cook tasks not to be queued if there was no warm/hot/cold DDC argument
- Made -noxge the default if no -xge arg is specified

#rb pat.swanson

#ROBOMERGE-OWNER: andrew.grant
#ROBOMERGE-AUTHOR: andrew.grant
#ROBOMERGE-SOURCE: CL 18531909 via CL 18531922 via CL 18531923 via CL 18531933 via CL 18531940 via CL 18532363 via CL 18532390 via CL 18532802 via CL 18533930
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v899-18417669)

[CL 18534124 by andrew grant in ue5-release-engine-test branch]
2022-01-06 14:16:53 -05:00

350 lines
12 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using EpicGames.Core;
using UnrealBuildBase;
using UnrealBuildTool;
namespace AutomationTool
{
[Help("Builds the specified targets and configurations for the specified project.")]
[Help("Example BuildTarget -project=QAGame -target=Editor+Game -platform=Win64+Android -configuration=Development.")]
[Help("Note: Editor will only ever build for the current platform in a Development config and required tools will be included")]
[Help("project=<QAGame>", "Project to build. Will search current path and paths in ueprojectdirs. If omitted will build vanilla UnrealEditor")]
[Help("platform=Win64+Android", "Platforms to build, join multiple platforms using +")]
[Help("configuration=Development+Test", "Configurations to build, join multiple configurations using +")]
[Help("target=Editor+Game", "Targets to build, join multiple targets using +")]
[Help("notools", "Don't build any tools (UnrealPak, Lightmass, ShaderCompiler, CrashReporter")]
[Help("clean", "Do a clean build")]
[Help("NoXGE", "Toggle to disable the distributed build process")]
[Help("DisableUnity", "Toggle to disable the unity build system")]
public class BuildTarget : BuildCommand
{
// exposed as a property so projects can derive and set this directly
public string ProjectName { get; set; }
public string Targets { get; set; }
public string Platforms { get; set; }
public string Configurations { get; set; }
public bool Clean { get; set; }
public bool NoTools { get; set; }
public string UBTArgs { get; set; }
public bool Preview { get; set; }
// It would be nice to use SingleTargetProperties but we can't get rules
// For UE types..
public class SimpleTargetInfo
{
public string TargetName { get; private set; }
public TargetType Type { get; private set; }
public SimpleTargetInfo(string InName, TargetType InType)
{
TargetName = InName;
Type = InType;
}
}
public BuildTarget()
{
Platforms = HostPlatform.Current.HostEditorPlatform.ToString();
Configurations = "Development";
UBTArgs = "";
}
public override ExitCode Execute()
{
string[] Arguments = this.Params;
ProjectName = ParseParamValue("project", ProjectName);
Targets = ParseParamValue("target", Targets);
Platforms = ParseParamValue("platform", Platforms);
Configurations = ParseParamValue("configuration", Configurations);
Clean = ParseParam("clean") || Clean;
NoTools = ParseParam("NoTools") || NoTools;
UBTArgs = ParseParamValue("ubtargs", UBTArgs);
Preview = ParseParam("preview") || Preview;
if (string.IsNullOrEmpty(Targets))
{
throw new AutomationException("No target specified with -target. Use -help to see all options");
}
IEnumerable<string> TargetList = Targets.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
IEnumerable<UnrealTargetConfiguration> ConfigurationList = null;
IEnumerable<UnrealTargetPlatform> PlatformList = null;
try
{
ConfigurationList = Configurations.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
.Select(C => (UnrealTargetConfiguration)Enum.Parse(typeof(UnrealTargetConfiguration), C, true)).ToArray();
}
catch (Exception Ex)
{
LogError("Failed to parse configuration string. {0}", Ex.Message);
return ExitCode.Error_Arguments;
}
try
{
PlatformList = Platforms.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries)
.Select(C =>
{
UnrealTargetPlatform Platform;
if (!UnrealTargetPlatform.TryParse(C, out Platform))
{
throw new AutomationException("No such platform {0}", C);
}
return Platform;
}).ToArray();
}
catch (Exception Ex)
{
LogError("Failed to parse configuration string. {0}", Ex.Message);
return ExitCode.Error_Arguments;
}
FileReference ProjectFile = null;
if (!string.IsNullOrEmpty(ProjectName))
{
// find the project
ProjectFile = ProjectUtils.FindProjectFileFromName(ProjectName);
if (ProjectFile == null)
{
throw new AutomationException("Unable to find uproject file for {0}", ProjectName);
}
}
IEnumerable<SimpleTargetInfo> BuildTargets = TargetList.Select(T => ProjectTargetFromTargetName(T, ProjectFile, PlatformList, ConfigurationList)).ToArray();
bool ContainsEditor = BuildTargets.Where(T => T.Type == TargetType.Editor).Any();
bool SingleBuild = BuildTargets.Count() == 1 && PlatformList.Count() == 1 && ConfigurationList.Count() == 1;
if (!SingleBuild || (ContainsEditor && !NoTools))
{
UnrealBuild Build = new UnrealBuild(this);
Build.AlwaysBuildUHT = true;
UnrealBuild.BuildAgenda Agenda = new UnrealBuild.BuildAgenda();
SimpleTargetInfo EditorTarget = BuildTargets.Where(T => T.Type == TargetType.Editor).FirstOrDefault();
IEnumerable<SimpleTargetInfo> OtherTargets = BuildTargets.Where(T => T.Type != TargetType.Editor);
UnrealTargetPlatform CurrentPlatform = HostPlatform.Current.HostEditorPlatform;
if (EditorTarget != null)
{
Agenda.AddTarget(EditorTarget.TargetName, CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
if (!NoTools)
{
Agenda.AddTarget("UnrealPak", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
Agenda.AddTarget("ShaderCompileWorker", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
Agenda.AddTarget("UnrealLightmass", CurrentPlatform, UnrealTargetConfiguration.Development, ProjectFile, UBTArgs);
Agenda.AddTarget("CrashReportClient", CurrentPlatform, UnrealTargetConfiguration.Shipping, ProjectFile, UBTArgs);
Agenda.AddTarget("CrashReportClientEditor", CurrentPlatform, UnrealTargetConfiguration.Shipping, ProjectFile, UBTArgs);
}
}
foreach (SimpleTargetInfo Target in OtherTargets)
{
bool IsServer = Target.Type == TargetType.Server;
IEnumerable<UnrealTargetPlatform> PlatformsToBuild = IsServer ? new UnrealTargetPlatform[] { CurrentPlatform } : PlatformList;
foreach (UnrealTargetPlatform Platform in PlatformsToBuild)
{
foreach (UnrealTargetConfiguration Config in ConfigurationList)
{
Agenda.AddTarget(Target.TargetName, Platform, Config, ProjectFile, UBTArgs);
}
}
}
foreach (var Target in Agenda.Targets)
{
Log.TraceInformation("Will {0}build {1}", Clean ? "clean and " : "", Target);
if (Clean)
{
Target.Clean = Clean;
}
}
if (!Preview)
{
Build.Build(Agenda, InUpdateVersionFiles: false);
}
}
else
{
// Get the path to UBT
FileReference InstalledUBT = FileReference.Combine(Unreal.EngineDirectory, "Binaries", "DotNET", "UnrealBuildTool", "UnrealBuildTool.exe");
UnrealTargetPlatform PlatformToBuild = PlatformList.First();
UnrealTargetConfiguration ConfigToBuild = ConfigurationList.First();
string TargetToBuild = BuildTargets.First().TargetName;
if (!Preview)
{
// Compile the editor
string CommandLine = CommandUtils.UBTCommandline(ProjectFile, TargetToBuild, PlatformToBuild, ConfigToBuild, UBTArgs);
if (Clean)
{
CommandUtils.RunUBT(CommandUtils.CmdEnv, InstalledUBT.FullName, CommandLine + " -clean");
}
CommandUtils.RunUBT(CommandUtils.CmdEnv, InstalledUBT.FullName, CommandLine);
}
else
{
Log.TraceInformation("Will {0}build {1} {2} {3}", Clean ? "clean and " : "", TargetToBuild, PlatformToBuild, ConfigToBuild);
}
}
return ExitCode.Success;
}
/// <summary>
/// Takes a target type like "Editor" and returns the actual targetname used by the specified project. If no project is specified then
/// the name of the UE types (e.g. UnrealEditor) is returned.
/// </summary>
/// <param name="InTargetName"></param>
/// <param name="InProjectFile"></param>
/// <param name="InPlatformList"></param>
/// <param name="InConfigurationList"></param>
/// <returns></returns>
public SimpleTargetInfo ProjectTargetFromTargetName(string InTargetName, FileReference InProjectFile, IEnumerable<UnrealTargetPlatform> InPlatformList, IEnumerable<UnrealTargetConfiguration> InConfigurationList)
{
ProjectProperties Properties = InProjectFile != null ? ProjectUtils.GetProjectProperties(InProjectFile, InPlatformList.ToList(), InConfigurationList.ToList()) : null;
SimpleTargetInfo ProjectTarget = null;
IEnumerable<SimpleTargetInfo> AvailableTargets = null;
if (Properties != null && Properties.bIsCodeBasedProject)
{
AvailableTargets = Properties.Targets.Select(T => new SimpleTargetInfo(T.TargetName, T.Rules.Type));
}
else
{
// default UE targets
AvailableTargets = new[]
{
new SimpleTargetInfo("UnrealEditor", TargetType.Editor),
new SimpleTargetInfo("UnrealGame", TargetType.Game),
new SimpleTargetInfo("UnrealClient", TargetType.Client),
new SimpleTargetInfo("UnrealServer", TargetType.Server),
};
}
// If they asked for ShooterClient etc and that's there, just return that.
ProjectTarget = AvailableTargets.FirstOrDefault(T => T.TargetName.Equals(InTargetName, StringComparison.OrdinalIgnoreCase));
if (ProjectTarget == null)
{
// find targets that use rules of the desired type
IEnumerable<SimpleTargetInfo> MatchingTargetTypes = AvailableTargets
.Where(T => T.Type.ToString().Equals(InTargetName, StringComparison.OrdinalIgnoreCase));
if (MatchingTargetTypes.Any())
{
if (MatchingTargetTypes.Count() == 1)
{
ProjectTarget = MatchingTargetTypes.First();
}
else
{
// if multiple targets, pick the one that starts with project name and contains the target type
// (Some projects have multiple targets of a given type)
ProjectTarget = MatchingTargetTypes
.Where(T => string.CompareOrdinal(T.TargetName, 0, ProjectName, 0, 1) == 0)
.Where(T => T.TargetName.IndexOf(InTargetName, StringComparison.OrdinalIgnoreCase) > 0)
.FirstOrDefault();
}
}
}
if (ProjectTarget == null)
{
throw new AutomationException("{0} is not a valid target in {1}", InTargetName, InProjectFile);
}
return ProjectTarget;
}
}
[Help("Builds the editor for the specified project.")]
[Help("Example BuildEditor -project=QAGame")]
[Help("Note: Editor will only ever build for the current platform in a Development config and required tools will be included")]
[Help("project=<QAGame>", "Project to build. Will search current path and paths in ueprojectdirs. If omitted will build vanilla UnrealEditor")]
[Help("notools", "Don't build any tools (UHT, ShaderCompiler, CrashReporter")]
class BuildEditor : BuildTarget
{
public BuildEditor()
{
Targets = "Editor";
}
public override ExitCode Execute()
{
bool DoOpen = ParseParam("open");
ExitCode Status = base.Execute();
if (Status == ExitCode.Success && DoOpen)
{
OpenEditor OpenCmd = new OpenEditor();
OpenCmd.ProjectName = this.ProjectName;
Status = OpenCmd.Execute();
}
return Status;
}
}
[Help("Builds the game for the specified project.")]
[Help("Example BuildGame -project=QAGame -platform=Win64+Android -configuration=Development.")]
[Help("project=<QAGame>", "Project to build. Will search current path and paths in ueprojectdirs.")]
[Help("platform=Wind64+Android", "Platforms to build, join multiple platforms using +")]
[Help("configuration=Development+Test", "Configurations to build, join multiple configurations using +")]
[Help("notools", "Don't build any tools (UHT, ShaderCompiler, CrashReporter")]
class BuildGame : BuildTarget
{
public BuildGame()
{
Targets = "Game";
}
}
[Help("Builds the server for the specified project.")]
[Help("Example BuildServer -project=QAGame -platform=Win64 -configuration=Development.")]
[Help("project=<QAGame>", "Project to build. Will search current path and paths in ueprojectdirs.")]
[Help("platform=Win64", "Platforms to build, join multiple platforms using +")]
[Help("configuration=Development+Test", "Configurations to build, join multiple configurations using +")]
[Help("notools", "Don't build any tools (UHT, ShaderCompiler, CrashReporter")]
class BuildServer : BuildTarget
{
public BuildServer()
{
Targets = "Server";
}
}
}