using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using UnrealBuildTool;
namespace AutomationTool.Tasks
{
///
/// Parameters for the version task
///
public class SetVersionTaskParameters
{
///
/// The changelist to set in the version files
///
[TaskParameter]
public int Change;
///
/// The branch string
///
[TaskParameter]
public string Branch;
///
/// The build version string
///
[TaskParameter(Optional = true)]
public string Build;
///
/// Whether to set the IS_LICENSEE_VERSION flag to true
///
[TaskParameter(Optional = true)]
public bool Licensee;
///
/// If set, don't actually write to the files - just return the version files that would be updated. Useful for local builds.
///
[TaskParameter(Optional = true)]
public bool SkipWrite;
///
/// Tag to be applied to build products of this task
///
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
public string Tag;
}
///
/// Task which updates the version files in the current branch
///
[TaskElement("SetVersion", typeof(SetVersionTaskParameters))]
public class SetVersionTask : CustomTask
{
///
/// Parameters for the task
///
SetVersionTaskParameters Parameters;
///
/// Construct a version task
///
/// Parameters for this task
public SetVersionTask(SetVersionTaskParameters 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)
{
// Update the version files
List FileNames = UE4Build.StaticUpdateVersionFiles(Parameters.Change, Parameters.Branch, Parameters.Build, Parameters.Licensee, !Parameters.SkipWrite);
List VersionFiles = FileNames.Select(x => new FileReference(x)).ToList();
// Apply the optional tag to them
foreach(string TagName in FindTagNamesFromList(Parameters.Tag))
{
FindOrAddTagSet(TagNameToFileSet, TagName).UnionWith(VersionFiles);
}
// Add them to the list of build products
BuildProducts.UnionWith(VersionFiles);
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()
{
yield break;
}
///
/// 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);
}
}
}