// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. using AutomationTool; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Tools.DotNETCommon; using UnrealBuildTool; namespace BuildGraph.Tasks { /// /// Parameters for a zip task /// public class ZipTaskParameters { /// /// The directory to read compressed files from /// [TaskParameter] public DirectoryReference FromDir; /// /// List of file specifications separated by semicolons (eg. *.cpp;Engine/.../*.bat), or the name of a tag set. Relative paths are taken from FromDir. /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.FileSpec)] public string Files; /// /// The zip file to create /// [TaskParameter] public FileReference ZipFile; /// /// Tag to be applied to the created zip file /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)] public string Tag; } /// /// Compresses files into a zip archive. /// [TaskElement("Zip", typeof(ZipTaskParameters))] public class ZipTask : CustomTask { /// /// Parameters for this task /// ZipTaskParameters Parameters; /// /// Constructor /// /// Parameters for this task public ZipTask(ZipTaskParameters 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) { // Find all the input files IEnumerable Files; if(Parameters.Files == null) { Files = DirectoryReference.EnumerateFiles(Parameters.FromDir, "*", System.IO.SearchOption.AllDirectories); } else { Files = ResolveFilespec(Parameters.FromDir, Parameters.Files, TagNameToFileSet); } // Create the zip file CommandUtils.ZipFiles(Parameters.ZipFile, Parameters.FromDir, Files); // Apply the optional tag to the produced archive foreach(string TagName in FindTagNamesFromList(Parameters.Tag)) { FindOrAddTagSet(TagNameToFileSet, TagName).Add(Parameters.ZipFile); } // Add the archive to the set of build products BuildProducts.Add(Parameters.ZipFile); } /// /// 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); } } }