// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using EpicGames.Core;
using UnrealBuildBase;
namespace AutomationTool.Tasks
{
///
/// Parameters for a task that signs a set of files.
///
public class SignTaskParameters
{
///
/// List of file specifications separated by semicolons (for example, *.cpp;Engine/.../*.bat), or the name of a tag set.
///
[TaskParameter(ValidationType = TaskParameterValidationType.FileSpec)]
public string Files { get; set; }
///
/// Optional description for the signed content
///
[TaskParameter(Optional = true)]
public string Description { get; set; }
///
/// Tag to be applied to build products of this task.
///
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
public string Tag { get; set; }
///
/// If true, the calls to the signing tool will be performed in parallel.
///
[TaskParameter(Optional = true)]
public bool Parallel { get; set; }
}
///
/// Signs a set of executable files with an installed certificate.
///
[TaskElement("Sign", typeof(SignTaskParameters))]
public class SignTask : BgTaskImpl
{
///
/// Parameters for this task
///
readonly SignTaskParameters _parameters;
///
/// Construct a spawn task
///
/// Parameters for the task
public SignTask(SignTaskParameters parameters)
{
_parameters = parameters;
}
///
/// ExecuteAsync 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 Task ExecuteAsync(JobContext job, HashSet buildProducts, Dictionary> tagNameToFileSet)
{
// Find the matching files
FileReference[] files = ResolveFilespec(Unreal.RootDirectory, _parameters.Files, tagNameToFileSet).OrderBy(x => x.FullName).ToArray();
// Sign all the files
CodeSign.SignMultipleIfEXEOrDLL(job.OwnerCommand, (files.Select(x => x.FullName).ToList()), Description: _parameters.Description, _parameters.Parallel);
// Apply the optional tag to the build products
foreach (string tagName in FindTagNamesFromList(_parameters.Tag))
{
FindOrAddTagSet(tagNameToFileSet, tagName).UnionWith(files);
}
// Add them to the list of build products
buildProducts.UnionWith(files);
return Task.CompletedTask;
}
///
/// 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);
}
}
}