Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/BuildGraph/Node.cs
Ben Marsh 1ae32843fa Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3058348)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2982033 on 2016/05/18 by Chad.Garyet

	Checking in progress on the ue4 BuildGraph conversion.
	Builds and Compiles editor and game on all platforms
	Builds DDC on win64 and mac
	Builds Tools on win64

Change 3047983 on 2016/07/13 by Ben.Marsh

	PR #2597: Fix P4 environment used for running BuildUGS commandlet (Contributed by paulevans)

Change 3048267 on 2016/07/13 by Ben.Marsh

	BuildGraph: Allow more permissive list of characters for node names; just restrict against characters which are illegal in filenames. Allows creating aggregate names which match job names (eg. "Editor, Tools & Monolithics").

Change 3048293 on 2016/07/13 by Ben.Marsh

	BuildGraph: Allow passing -listonly without a specific -target=... parameter in BuildGraph, to see the contents of the entire script.

Change 3048454 on 2016/07/13 by Ben.Marsh

	BuildGraph: Disable output of error messages when just printing the contents of the graph.

Change 3048507 on 2016/07/13 by Ben.Marsh

	BuildGraph: Rename "Ticket" to "Token" for files used to ensure exclusive access to run part of a build.

Change 3049459 on 2016/07/14 by Matthew.Griffin

	Updated location of HTML5 SDKs for Installed Builds
	#jira UE-32171

Change 3049675 on 2016/07/14 by Matthew.Griffin

	Ensured that all platforms are registered when running -validateplatform command
	#jira UE-31082

Change 3049922 on 2016/07/14 by Ben.Marsh

	UBT: Fix path to XML config file in boilerplate message.

Change 3051483 on 2016/07/15 by Ben.Marsh

	EC: Remove code to prettify node names, now that we can have pretty node names explicitly.

Change 3051522 on 2016/07/15 by Ben.Marsh

	BuildGraph: Change spawn task to fail if a non-zero exit code is returned by an external program. The minimum exit code to be treated as an error can be set using the "ErrorLevel" attribute, similar to ERRORLEVEL in DOS.

Change 3051770 on 2016/07/15 by Ben.Marsh

	UGS: Add support for narrowing virtual streams; fetch event and precompiled binaries for parent stream instead.

Change 3052990 on 2016/07/17 by Ben.Marsh

	Show the names of people with notifications disabled in the heading of failure emails, so it's clear that they're not on CC.

Change 3053556 on 2016/07/18 by Ben.Marsh

	BuildGraph: Add a explicit <Option> tag instead of the <Property Default=""/> shenanigans, so that properties that are meant to be modified by the user are listed explicitly. Supported attributes are "DefaultValue" (which specifies a default if the user does not set it on the command line), "Description" (which explains the purpose of the option to users, which is displayed in a table when BuildGraph is invoked with the -listonly argument), and "Restrict" (which specifies a regex to validate an argument supplied by the user).

	Also add an <EnvVar Name="Blah"/> tag which imports the given environment variable as a property (or sets it to "" if it doesn't exist), and rename the <Choose>/<Option>/<Otherwise> triple to <Switch>/<Case>/<Default> to avoid confusion with the new <Option> tag.

Change 3053688 on 2016/07/18 by Ben.Marsh

	Update build scripts to link to p4-swarm rather than p4-web in dashboard pages and notification emails.

Change 3054039 on 2016/07/18 by Ben.Marsh

	Fix confusing message when compiler isn't installed if the target forces VS2013

Change 3054360 on 2016/07/18 by Ben.Marsh

	Remove GUBP support from EC scripts.

Change 3054399 on 2016/07/18 by Ben.Marsh

	Remove circular include from Json.h -> JsonSerializerMacros.h -> Json.h

Change 3055671 on 2016/07/19 by Ben.Marsh

	Remove incomplete UWP integration from UE4.

Change 3055943 on 2016/07/19 by Ben.Marsh

	Remove the WinRT target platform.

Change 3056270 on 2016/07/19 by Ben.Marsh

	Core: Move VectorRegister.h include to eliminate include dependency on UnrealMathUtility.h

Change 3056390 on 2016/07/19 by Ben.Marsh

	Core: Directly include headers required by default JsonWriter template instantiation.

Change 3057444 on 2016/07/20 by Ben.Marsh

	UBT: Fall back to checking for the VS140COMNTOOLS environment variable if we couldn't determine the Visual Studio installation directory from the registry. Allows using the standalone Visual Studio build tools to compile UE4.

Change 3058337 on 2016/07/20 by Ben.Marsh

	Remove EnvVarsToXML. All target platforms now determine their compile environment directly from the registry.

Change 3058348 on 2016/07/20 by Ben.Marsh

	Disable optimization for all automation projects. They don't generally do anything particularly CPU intensive, and VS2015 optimizations are inhibitive to debugging.

[CL 3058822 by Ben Marsh in Main branch]
2016-07-20 20:25:02 -04:00

273 lines
8.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnrealBuildTool;
using AutomationTool;
using System.Xml;
namespace AutomationTool
{
/// <summary>
/// Reference to an output tag from a particular node
/// </summary>
class NodeOutput
{
/// <summary>
/// The node which produces the given output
/// </summary>
public Node ProducingNode;
/// <summary>
/// Name of the tag
/// </summary>
public string TagName;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InProducingNode">Node which produces the given output</param>
/// <param name="InTagName">Name of the tag</param>
public NodeOutput(Node InProducingNode, string InTagName)
{
ProducingNode = InProducingNode;
TagName = InTagName;
}
/// <summary>
/// Returns a string representation of this output for debugging purposes
/// </summary>
/// <returns>The name of this output</returns>
public override string ToString()
{
return String.Format("{0}: {1}", ProducingNode.Name, TagName);
}
}
/// <summary>
/// Defines a node, a container for tasks and the smallest unit of execution that can be run as part of a build graph.
/// </summary>
class Node
{
/// <summary>
/// The node's name
/// </summary>
public string Name;
/// <summary>
/// Array of inputs which this node requires to run
/// </summary>
public NodeOutput[] Inputs;
/// <summary>
/// Array of outputs produced by this node
/// </summary>
public NodeOutput[] Outputs;
/// <summary>
/// Nodes which this node has input dependencies on
/// </summary>
public Node[] InputDependencies;
/// <summary>
/// Nodes which this node needs to run after
/// </summary>
public Node[] OrderDependencies;
/// <summary>
/// The trigger which controls whether this node will be executed
/// </summary>
public ManualTrigger ControllingTrigger;
/// <summary>
/// Tokens which must be acquired for this node to run
/// </summary>
public FileReference[] RequiredTokens;
/// <summary>
/// List of tasks to execute
/// </summary>
public List<CustomTask> Tasks = new List<CustomTask>();
/// <summary>
/// List of email addresses to notify if this node fails.
/// </summary>
public HashSet<string> NotifyUsers = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// If set, anyone that has submitted to one of the given paths will be notified on failure of this node
/// </summary>
public HashSet<string> NotifySubmitters = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Whether to ignore warnings produced by this node
/// </summary>
public bool bNotifyOnWarnings = true;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InName">The name of this node</param>
/// <param name="InInputs">Inputs that this node depends on</param>
/// <param name="InOutputNames">Names of the outputs that this node produces</param>
/// <param name="InInputDependencies">Nodes which this node is dependent on for its inputs</param>
/// <param name="InOrderDependencies">Nodes which this node needs to run after. Should include all input dependencies.</param>
/// <param name="InControllingTrigger">The trigger which this node is behind</param>
/// <param name="InRequiredTokens">Optional tokens which must be required for this node to run</param>
public Node(string InName, NodeOutput[] InInputs, string[] InOutputNames, Node[] InInputDependencies, Node[] InOrderDependencies, ManualTrigger InControllingTrigger, FileReference[] InRequiredTokens)
{
Name = InName;
Inputs = InInputs;
List<NodeOutput> AllOutputs = new List<NodeOutput>();
AllOutputs.Add(new NodeOutput(this, "#" + Name));
AllOutputs.AddRange(InOutputNames.Where(x => String.Compare(x, Name, StringComparison.InvariantCultureIgnoreCase) != 0).Select(x => new NodeOutput(this, x)));
Outputs = AllOutputs.ToArray();
InputDependencies = InInputDependencies;
OrderDependencies = InOrderDependencies;
ControllingTrigger = InControllingTrigger;
RequiredTokens = InRequiredTokens;
}
/// <summary>
/// Returns the default output for this node, which includes all build products
/// </summary>
public NodeOutput DefaultOutput
{
get { return Outputs[0]; }
}
/// <summary>
/// Build all the tasks for this node
/// </summary>
/// <param name="Job">Information about the current job</param>
/// <param name="BuildProducts">Set of build products produced by this node.</param>
/// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include. Should be set to contain the node inputs on entry.</param>
/// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns>
public bool Build(JobContext Job, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
// Allow tasks to merge together
MergeTasks();
// Build everything
HashSet<FileReference> BuildProducts = TagNameToFileSet[DefaultOutput.TagName];
foreach(CustomTask Task in Tasks)
{
if(!Task.Execute(Job, BuildProducts, TagNameToFileSet))
{
CommandUtils.Log("Failed to execute task.");
return false;
}
}
// Remove anything that doesn't exist, since these files weren't explicitly tagged
BuildProducts.RemoveWhere(x => !x.Exists());
return true;
}
/// <summary>
/// Merge tasks which can be combined together
/// </summary>
void MergeTasks()
{
List<CustomTask> MergedTasks = new List<CustomTask>();
while(Tasks.Count > 0)
{
CustomTask NextTask = Tasks[0];
Tasks.RemoveAt(0);
NextTask.Merge(Tasks);
MergedTasks.Add(NextTask);
}
Tasks = MergedTasks;
}
/// <summary>
/// Determines the minimal set of direct input dependencies for this node to run
/// </summary>
/// <returns>Sequence of nodes that are direct inputs to this node</returns>
public IEnumerable<Node> GetDirectInputDependencies()
{
HashSet<Node> DirectDependencies = new HashSet<Node>(InputDependencies);
foreach(Node InputDependency in InputDependencies)
{
DirectDependencies.ExceptWith(InputDependency.InputDependencies);
}
return DirectDependencies;
}
/// <summary>
/// Determines the minimal set of direct order dependencies for this node to run
/// </summary>
/// <returns>Sequence of nodes that are direct order dependencies of this node</returns>
public IEnumerable<Node> GetDirectOrderDependencies()
{
HashSet<Node> DirectDependencies = new HashSet<Node>(OrderDependencies);
foreach(Node OrderDependency in OrderDependencies)
{
DirectDependencies.ExceptWith(OrderDependency.OrderDependencies);
}
return DirectDependencies;
}
/// <summary>
/// Checks whether this node is downstream of the given trigger
/// </summary>
/// <param name="Trigger">The trigger to check</param>
/// <returns>True if the node is downstream of the trigger, false otherwise</returns>
public bool IsControlledBy(ManualTrigger Trigger)
{
return Trigger == null || ControllingTrigger == Trigger || (ControllingTrigger != null && ControllingTrigger.IsDownstreamFrom(Trigger));
}
/// <summary>
/// Write this node to an XML writer
/// </summary>
/// <param name="Writer">The writer to output the node to</param>
public void Write(XmlWriter Writer)
{
Writer.WriteStartElement("Node");
Writer.WriteAttributeString("Name", Name);
string[] RequireNames = Inputs.Select(x => x.TagName).ToArray();
if (RequireNames.Length > 0)
{
Writer.WriteAttributeString("Requires", String.Join(";", RequireNames));
}
string[] ProducesNames = Outputs.Where(x => x != DefaultOutput).Select(x => x.TagName).ToArray();
if (ProducesNames.Length > 0)
{
Writer.WriteAttributeString("Produces", String.Join(";", ProducesNames));
}
string[] AfterNames = GetDirectOrderDependencies().Except(InputDependencies).Select(x => x.Name).ToArray();
if (AfterNames.Length > 0)
{
Writer.WriteAttributeString("After", String.Join(";", AfterNames));
}
if (!bNotifyOnWarnings)
{
Writer.WriteAttributeString("NotifyOnWarnings", bNotifyOnWarnings.ToString());
}
foreach (CustomTask Task in Tasks)
{
Task.Write(Writer);
}
Writer.WriteEndElement();
}
/// <summary>
/// Returns the name of this node
/// </summary>
/// <returns>The name of this node</returns>
public override string ToString()
{
return Name;
}
}
}