// Copyright Epic Games, Inc. All Rights Reserved. using System.Collections.Generic; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; 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 { get; set; } /// /// The engine compatible changelist to set in the version files. /// [TaskParameter(Optional = true)] public int CompatibleChange { get; set; } /// /// The branch string. /// [TaskParameter] public string Branch { get; set; } /// /// The build version string. /// [TaskParameter(Optional = true)] public string Build { get; set; } /// /// The URL for a running continuous integration job. /// [TaskParameter(Optional = true)] public string BuildURL { get; set; } /// /// Whether to set the IS_LICENSEE_VERSION flag to true. /// [TaskParameter(Optional = true)] public bool Licensee { get; set; } /// /// Whether to set the ENGINE_IS_PROMOTED_BUILD flag to true. /// [TaskParameter(Optional = true)] public bool Promoted { get; set; } = 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 { get; set; } /// /// Tag to be applied to build products of this task. /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)] public string Tag { get; set; } } /// /// 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 { readonly SetVersionTaskParameters _parameters; /// /// Construct a version task /// /// Parameters for this task public SetVersionTask(SetVersionTaskParameters 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) { // 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 { /// /// ExecuteAsync a task instance /// /// /// public static async Task ExecuteAsync(BgTaskImpl task) { HashSet buildProducts = new HashSet(); await task.ExecuteAsync(new JobContext(null!, 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)); } } }