// Copyright 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 EpicGames.Core; using UnrealBuildBase; namespace AutomationTool.Tasks { /// /// Parameters for a task that executes MSBuild /// public class MsBuildTaskParameters { /// /// The C# project file to compile. Using semicolons, more than one project file can be specified. /// [TaskParameter] public string Project; /// /// The configuration to compile. /// [TaskParameter(Optional = true)] public string Configuration; /// /// The platform to compile. /// [TaskParameter(Optional = true)] public string Platform; /// /// Additional options to pass to the compiler. /// [TaskParameter(Optional = true)] public string Arguments; /// /// The MSBuild output verbosity. /// [TaskParameter(Optional = true)] public string Verbosity = "minimal"; } /// /// Executes MsBuild /// [TaskElement("MsBuild", typeof(MsBuildTaskParameters))] public class MsBuildTask : BgTaskImpl { /// /// Parameters for the task /// MsBuildTaskParameters Parameters; /// /// Constructor. /// /// Parameters for this task public MsBuildTask(MsBuildTaskParameters 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) { // Get the project file HashSet ProjectFiles = ResolveFilespec(Unreal.RootDirectory, Parameters.Project, TagNameToFileSet); foreach(FileReference ProjectFile in ProjectFiles) { if(!FileReference.Exists(ProjectFile)) { throw new AutomationException("Couldn't find project file '{0}'", ProjectFile.FullName); } } // Build the argument list List Arguments = new List(); if(!String.IsNullOrEmpty(Parameters.Platform)) { Arguments.Add(String.Format("/p:Platform={0}", CommandUtils.MakePathSafeToUseWithCommandLine(Parameters.Platform))); } if(!String.IsNullOrEmpty(Parameters.Configuration)) { Arguments.Add(String.Format("/p:Configuration={0}", CommandUtils.MakePathSafeToUseWithCommandLine(Parameters.Configuration))); } if(!String.IsNullOrEmpty(Parameters.Arguments)) { Arguments.Add(Parameters.Arguments); } if(!String.IsNullOrEmpty(Parameters.Verbosity)) { Arguments.Add(String.Format("/verbosity:{0}", Parameters.Verbosity)); } Arguments.Add("/nologo"); // Build all the projects foreach(FileReference ProjectFile in ProjectFiles) { CommandUtils.MsBuild(CommandUtils.CmdEnv, ProjectFile.FullName, String.Join(" ", Arguments), null); } 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.Project); } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { return new string[0]; } } }