// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. using AutomationTool; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Tools.DotNETCommon; using UnrealBuildTool; namespace BuildGraph.Tasks { /// /// Parameters for a spawn task /// public class SpawnTaskParameters { /// /// Executable to spawn /// [TaskParameter] public string Exe; /// /// Arguments for the newly created process /// [TaskParameter(Optional = true)] public string Arguments; /// /// The minimum exit code which is treated as an error. /// [TaskParameter(Optional = true)] public int ErrorLevel = 1; } /// /// Spawns an external executable and waits for it to complete. /// [TaskElement("Spawn", typeof(SpawnTaskParameters))] public class SpawnTask : CustomTask { /// /// Parameters for this task /// SpawnTaskParameters Parameters; /// /// Construct a spawn task /// /// Parameters for the task public SpawnTask(SpawnTaskParameters InParameters) { Parameters = InParameters; } /// /// 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 public override void Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { IProcessResult Result = CommandUtils.Run(Parameters.Exe, Parameters.Arguments); if(Result.ExitCode < 0 || Result.ExitCode >= Parameters.ErrorLevel) { throw new AutomationException("{0} terminated with an exit code indicating an error ({1})", Path.GetFileName(Parameters.Exe), Result.ExitCode); } } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter Writer) { Write(Writer, Parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { yield break; } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { yield break; } } }