// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. 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 AutomationTool.Tasks { /// /// Parameters for the version task /// public class SetVersionTaskParameters { /// /// The changelist to set in the version files /// [TaskParameter] public int Change; /// /// The engine compatible changelist to set in the version files /// [TaskParameter(Optional = true)] public int CompatibleChange; /// /// 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; /// /// Whether to set the ENGINE_IS_PROMOTED_BUILD flag to true /// [TaskParameter(Optional = true)] public bool Promoted = true; /// /// 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; } /// /// Updates the local version files (Engine/Source/Runtime/Launch/Resources/Version.h, Engine/Build/Build.version, and Engine/Source/Programs/DotNETCommon/Metadata.cs) with the given version information. /// [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 public override void Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { // Update the version files List VersionFiles = UE4Build.StaticUpdateVersionFiles(Parameters.Change, Parameters.CompatibleChange, Parameters.Branch, Parameters.Build, Parameters.Licensee, Parameters.Promoted, !Parameters.SkipWrite); // 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); } /// /// 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); } } }