using AutomationTool; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using UnrealBuildTool; namespace BuildGraph.Tasks { /// /// Parameters for a copy task /// public class CopyTaskParameters { /// /// List of file specifications separated by semicolons (eg. *.cpp;Engine/.../*.bat), or the name of a tag set. Relative paths are based at FromDir. /// [TaskParameter] public string Files; /// /// The base directory to copy from. /// [TaskParameter] public string FromDir; /// /// The directory to copy to /// [TaskParameter] public string ToDir; /// /// Tag to be applied to build products of this task /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)] public string Tag; } /// /// Task which copies files from one directory to another /// [TaskElement("Copy", typeof(CopyTaskParameters))] public class CopyTask : CustomTask { /// /// Parameters for this task /// CopyTaskParameters Parameters; /// /// Constructor /// /// Parameters for this task public CopyTask(CopyTaskParameters 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) { // Get the source and target directories DirectoryReference FromDir = ResolveDirectory(Parameters.FromDir); DirectoryReference ToDir = ResolveDirectory(Parameters.ToDir); // Copy all the files IEnumerable SourceFiles = ResolveFilespec(FromDir, Parameters.Files, TagNameToFileSet); IEnumerable TargetFiles = SourceFiles.Select(x => FileReference.Combine(ToDir, x.MakeRelativeTo(FromDir))); if(!FromDir.Exists() && !SourceFiles.Any()) { CommandUtils.Log("Skipping copy of files from '{0}' - directory does not exist.", FromDir.FullName); } else if(FromDir == ToDir) { CommandUtils.Log("Skipping copy of files in '{0}' - source directory is same as target directory", FromDir.FullName); } else { CommandUtils.ThreadedCopyFiles(SourceFiles.Select(x => x.FullName).ToList(), TargetFiles.Select(x => x.FullName).ToList()); } BuildProducts.UnionWith(TargetFiles); // Apply the optional output tag to them foreach(string TagName in FindTagNamesFromList(Parameters.Tag)) { FindOrAddTagSet(TagNameToFileSet, TagName).UnionWith(TargetFiles); } 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() { return FindTagNamesFromFilespec(Parameters.Files); } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { return FindTagNamesFromList(Parameters.Tag); } } }