using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutomationTool; using UnrealBuildTool; using System.Xml; using System.IO; namespace BuildGraph.Tasks { /// /// Parameters for a task which calls another UAT command /// public class CommandTaskParameters { /// /// The command name to execute /// [TaskParameter] public string Name; /// /// Arguments to be passed to the command /// [TaskParameter(Optional = true)] public string Arguments; /// /// If non-null, instructs telemetry from the command to be merged into the telemetry for this UAT instance with the given prefix. May be an empty (non-null) string. /// [TaskParameter(Optional = true)] public string MergeTelemetryWithPrefix; } /// /// Implements a task which calls another UAT command /// [TaskElement("Command", typeof(CommandTaskParameters))] public class CommandTask : CustomTask { /// /// Parameters for this task /// CommandTaskParameters Parameters; /// /// Construct a new CommandTask. /// /// Parameters for this task public CommandTask(CommandTaskParameters 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 /// True if the task succeeded public override bool Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { // If we're merging telemetry from the child process, get a temp filename for it FileReference TelemetryFile = null; if (Parameters.MergeTelemetryWithPrefix != null) { TelemetryFile = FileReference.Combine(CommandUtils.RootDirectory, "Engine", "Intermediate", "UAT", "Telemetry.json"); TelemetryFile.Directory.CreateDirectory(); } // Run the command string CommandLine = Parameters.Name; if (!String.IsNullOrEmpty(Parameters.Arguments)) { CommandLine += String.Format(" {0}", Parameters.Arguments); } if(TelemetryFile != null) { CommandLine += String.Format(" -Telemetry={0}", CommandUtils.MakePathSafeToUseWithCommandLine(TelemetryFile.FullName)); } try { CommandUtils.RunUAT(CommandUtils.CmdEnv, CommandLine); } catch(CommandUtils.CommandFailedException) { return false; } // Merge in any new telemetry data that was produced if (Parameters.MergeTelemetryWithPrefix != null) { TelemetryData NewTelemetry; if (TelemetryData.TryRead(TelemetryFile.FullName, out NewTelemetry)) { CommandUtils.Telemetry.Merge(Parameters.MergeTelemetryWithPrefix, NewTelemetry); } } return true; } /// /// 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; } } }