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.Tag)] 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) { DirectoryReference FromDir = ResolveDirectory(Parameters.FromDir); DirectoryReference ToDir = ResolveDirectory(Parameters.ToDir); if(FromDir != ToDir) { // Copy all the files IEnumerable SourceFiles = ResolveFilespec(FromDir, Parameters.Files, TagNameToFileSet); IEnumerable TargetFiles = SourceFiles.Select(x => FileReference.Combine(ToDir, x.MakeRelativeTo(FromDir))); CommandUtils.ThreadedCopyFiles(SourceFiles.Select(x => x.FullName).ToList(), TargetFiles.Select(x => x.FullName).ToList()); BuildProducts.UnionWith(TargetFiles); // Apply the optional output tag to them if(!String.IsNullOrEmpty(Parameters.Tag)) { FindOrAddTagSet(TagNameToFileSet, Parameters.Tag).UnionWith(TargetFiles); } } return true; } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter Writer) { Write(Writer, Parameters); } } }