using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnrealBuildTool; using AutomationTool; namespace AutomationTool { /// /// Parameters for a compile task /// public class CompileTaskParameters { /// /// The target to compile /// [TaskParameter] public string Target; /// /// The configuration to compile /// [TaskParameter] public UnrealTargetConfiguration Configuration; /// /// The platform to compile for /// [TaskParameter] public UnrealTargetPlatform Platform; /// /// Additional arguments for UnrealBuildTool /// [TaskParameter(Optional = true)] public string Arguments; } /// /// Task which compiles a target with UnrealBuildTool /// [TaskElement("Compile", typeof(CompileTaskParameters))] public class CompileTask : CustomTask { /// /// List of targets to compile. As well as the target specifically added for this task, additional compile tasks may be merged with it. /// List Targets = new List(); /// /// Construct a compile task /// /// Parameters for this task public CompileTask(CompileTaskParameters Parameters) { Targets.Add(new UE4Build.BuildTarget { TargetName = Parameters.Target, Platform = Parameters.Platform, Config = Parameters.Configuration, UBTArgs = "-nobuilduht " + (Parameters.Arguments ?? "") }); } /// /// Allow this task to merge with other tasks within the same node. This can be useful to allow tasks to execute in parallel and reduce overheads. /// /// Other tasks that this task can merge with. If a merge takes place, the other tasks should be removed from the list. public override void Merge(List OtherTasks) { for (int Idx = 0; Idx < OtherTasks.Count; Idx++) { CompileTask OtherCompileTask = OtherTasks[Idx] as CompileTask; if (OtherCompileTask != null) { Targets.AddRange(OtherCompileTask.Targets); OtherTasks.RemoveAt(Idx); } } } /// /// Execute the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include /// True if the task succeeded public override bool Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { UE4Build Builder = new UE4Build(Job.OwnerCommand); UE4Build.BuildAgenda Agenda = new UE4Build.BuildAgenda(); Agenda.Targets.AddRange(Targets); Builder.Build(Agenda, InDeleteBuildProducts: false, InUpdateVersionFiles: false, InForceNoXGE: CommandUtils.IsBuildMachine, InUseParallelExecutor: true); UE4Build.CheckBuildProducts(Builder.BuildProductFiles); BuildProducts.UnionWith(Builder.BuildProductFiles.Select(x => new FileReference(x))); return true; } } }