using AutomationTool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using UnrealBuildTool;
namespace BuildGraph.Tasks
{
///
/// Parameters for a task that runs the cooker
///
public class CookTaskParameters
{
///
/// Project file to be cooked
///
[TaskParameter]
public string Project;
///
/// The cook platform to target (eg. WindowsNoEditor)
///
[TaskParameter]
public string Platform;
///
/// List of maps to be cooked, separated by '+' characters
///
[TaskParameter(Optional = true)]
public string Maps;
///
/// Additional arguments to be passed to the cooker
///
[TaskParameter(Optional = true)]
public bool Versioned = false;
///
/// Additional arguments to be passed to the cooker
///
[TaskParameter(Optional = true)]
public string Arguments = "";
///
/// Tag to be applied to build products of this task
///
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
public string Tag;
}
///
/// Cook a selection of maps for a certain platform
///
[TaskElement("Cook", typeof(CookTaskParameters))]
public class CookTask : CustomTask
{
///
/// Parameters for the task
///
CookTaskParameters Parameters;
///
/// Constructor.
///
/// Parameters for this task
public CookTask(CookTaskParameters 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)
{
// Figure out the project that this target belongs to
FileReference ProjectFile = null;
if(Parameters.Project != null)
{
ProjectFile = new FileReference(Parameters.Project);
if(!ProjectFile.Exists())
{
CommandUtils.LogError("Missing project file - {0}", ProjectFile.FullName);
return false;
}
}
// Execute the cooker
using(TelemetryStopwatch CookStopwatch = new TelemetryStopwatch("Cook.{0}.{1}", (ProjectFile == null)? "UE4" : ProjectFile.GetFileNameWithoutExtension(), Parameters.Platform))
{
string[] Maps = (Parameters.Maps == null)? null : Parameters.Maps.Split(new char[]{ '+' });
string Arguments = (Parameters.Versioned ? "" : "-Unversioned ") + "-LogCmds=\"LogSavePackage Warning\" " + Parameters.Arguments;
CommandUtils.CookCommandlet(ProjectFile, "UE4Editor-Cmd.exe", Maps, null, null, null, Parameters.Platform, Arguments);
}
// Find all the cooked files
DirectoryReference CookedDirectory = DirectoryReference.Combine(ProjectFile.Directory, "Saved", "Cooked", Parameters.Platform);
if(!CookedDirectory.Exists())
{
CommandUtils.LogError("Cook output directory not found ({0})", CookedDirectory.FullName);
return false;
}
List CookedFiles = CookedDirectory.EnumerateFileReferences("*", System.IO.SearchOption.AllDirectories).ToList();
if(CookedFiles.Count == 0)
{
CommandUtils.LogError("Cooking did not produce any files in {0}", CookedDirectory.FullName);
return false;
}
// Apply the optional tag to the build products
foreach(string TagName in FindTagNamesFromList(Parameters.Tag))
{
FindOrAddTagSet(TagNameToFileSet, TagName).UnionWith(CookedFiles);
}
// Add them to the set of build products
BuildProducts.UnionWith(CookedFiles);
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);
}
}
}