using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using UnrealBuildTool;
namespace AutomationTool.Tasks
{
///
/// Parameters for a task which runs a UE4 commandlet
///
public class CommandletTaskParameters
{
///
/// The commandlet name to execute
///
[TaskParameter]
public string Name;
///
/// The project to run the editor with
///
[TaskParameter(Optional = true)]
public string Project;
///
/// Arguments to be passed to the commandlet
///
[TaskParameter(Optional = true)]
public string Arguments;
///
/// The editor executable to use. Defaults to the development UE4Editor executable for the current platform.
///
[TaskParameter(Optional = true)]
public string EditorExe;
}
///
/// Implements a task which calls another UAT command
///
[TaskElement("Commandlet", typeof(CommandletTaskParameters))]
public class CommandletTask : CustomTask
{
///
/// Parameters for this task
///
CommandletTaskParameters Parameters;
///
/// Construct a new CommandletTask.
///
/// Parameters for this task
public CommandletTask(CommandletTaskParameters 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)
{
// Get the full path to the project file
FileReference ProjectFile = null;
if(!String.IsNullOrEmpty(Parameters.Project))
{
ProjectFile = ResolveFile(Parameters.Project);
}
// Get the path to the editor, and check it exists
FileReference EditorExe;
if(String.IsNullOrEmpty(Parameters.EditorExe))
{
EditorExe = new FileReference(HostPlatform.Current.GetUE4ExePath("UE4Editor-Cmd.exe"));
}
else
{
EditorExe = ResolveFile(Parameters.EditorExe);
}
// Make sure the editor exists
if(!EditorExe.Exists())
{
CommandUtils.LogError("{0} does not exist", EditorExe.FullName);
return false;
}
// Run the commandlet
CommandUtils.RunCommandlet(ProjectFile, EditorExe.FullName, Parameters.Name, Parameters.Arguments);
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()
{
yield break;
}
}
}