// Copyright Epic Games, Inc. All Rights Reserved. using EpicGames.BuildGraph; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; using UnrealBuildTool; using UnrealBuildBase; 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; /// /// The URL for a running continuous integration job. /// [TaskParameter(Optional = true)] public string BuildURL; /// /// 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, do not 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/Shared/Metadata.cs) with the given version information. /// [TaskElement("SetVersion", typeof(SetVersionTaskParameters))] public class SetVersionTask : BgTaskImpl { /// /// 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 Task ExecuteAsync(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { // Update the version files List VersionFiles = UnrealBuild.StaticUpdateVersionFiles(Parameters.Change, Parameters.CompatibleChange, Parameters.Branch, Parameters.Build, Parameters.BuildURL, 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); 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() { 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); } } /// /// Task wrapper methods /// public static partial class StandardTasks { /// /// Execute a task instance /// /// /// public static async Task ExecuteAsync(BgTaskImpl Task) { HashSet BuildProducts = new HashSet(); await Task.ExecuteAsync(new JobContext(null!), BuildProducts, new Dictionary>()); return FileSet.FromFiles(Unreal.RootDirectory, BuildProducts); } /// /// Updates the current engine version /// public static async Task SetVersionAsync(int Change, string Branch, int? CompatibleChange = null, string Build = null, string BuildURL = null, bool? Licensee = null, bool? Promoted = null, bool? SkipWrite = null) { SetVersionTaskParameters Parameters = new SetVersionTaskParameters(); Parameters.Change = Change; Parameters.CompatibleChange = CompatibleChange ?? Parameters.CompatibleChange; Parameters.Branch = Branch ?? Parameters.Branch; Parameters.Build = Build ?? Parameters.Build; Parameters.BuildURL = BuildURL ?? Parameters.BuildURL; Parameters.Licensee = Licensee ?? Parameters.Licensee; Parameters.Promoted = Promoted ?? Parameters.Promoted; Parameters.SkipWrite = SkipWrite ?? Parameters.SkipWrite; return await ExecuteAsync(new SetVersionTask(Parameters)); } } }