// 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 task that strips symbols from a set of files /// public class StripTaskParameters { /// /// The platform toolchain to strip binaries /// [TaskParameter] public UnrealTargetPlatform Platform; /// /// The directory to find files in /// [TaskParameter(Optional = true)] public DirectoryReference BaseDir; /// /// List of file specifications separated by semicolons (eg. Engine/.../*.pdb), or the name of a tag set /// [TaskParameter(ValidationType = TaskParameterValidationType.FileSpec)] public string Files; /// /// Output directory for the stripped files. Defaults to the input path (overwriting the input files). /// [TaskParameter(Optional = true)] public DirectoryReference OutputDir; /// /// Tag to be applied to build products of this task /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)] public string Tag; } /// /// Strips debugging information from a set of files. /// [TaskElement("Strip", typeof(StripTaskParameters))] public class StripTask : CustomTask { /// /// Parameters for this task /// StripTaskParameters Parameters; /// /// Construct a spawn task /// /// Parameters for the task public StripTask(StripTaskParameters 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) { // Get the base directory DirectoryReference BaseDir = Parameters.BaseDir; // Get the output directory DirectoryReference OutputDir = Parameters.OutputDir; // Find the matching files FileReference[] SourceFiles = ResolveFilespec(BaseDir, Parameters.Files, TagNameToFileSet).OrderBy(x => x.FullName).ToArray(); // Create the matching target files FileReference[] TargetFiles = SourceFiles.Select(x => FileReference.Combine(OutputDir, x.MakeRelativeTo(BaseDir))).ToArray(); // Run the stripping command Platform TargetPlatform = Platform.GetPlatform(Parameters.Platform); for (int Idx = 0; Idx < SourceFiles.Length; Idx++) { DirectoryReference.CreateDirectory(TargetFiles[Idx].Directory); if (SourceFiles[Idx] == TargetFiles[Idx]) { CommandUtils.LogInformation("Stripping symbols: {0}", SourceFiles[Idx].FullName); } else { CommandUtils.LogInformation("Stripping symbols: {0} -> {1}", SourceFiles[Idx].FullName, TargetFiles[Idx].FullName); } TargetPlatform.StripSymbols(SourceFiles[Idx], TargetFiles[Idx]); } // Apply the optional tag to the build products foreach(string TagName in FindTagNamesFromList(Parameters.Tag)) { FindOrAddTagSet(TagNameToFileSet, TagName).UnionWith(TargetFiles); } // Add the target files to the set of build products BuildProducts.UnionWith(TargetFiles); } /// /// 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); } } }