Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/BuildGraph/Graph.cs
Andrew Grant 04588ce474 Copying //UE4/Orion-Staging to //UE4/Main (Source: //Orion/Dev-General @ 3037465)
#lockdown Nick.Penwarden

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

Change 3037044 on 2016/07/04 by Ben.Woodhouse

	(Content only change)
	Roll back WorldAlignedNormal material function to the previous version (which worked properly). The broken version was actually checked in back in 2014 (//depot/UE4-Fortnite/...@2342687), but it only hit //UE4/main very recently.
	#jira OR-24849
	#rb me

Change 3036463 on 2016/07/01 by Andrew.Grant

	Clarified BP compiler message
	#rb na
	#tests compiled AnimBP_Grux_Base

Change 3036424 on 2016/07/01 by Andrew.Grant

	Integrated fix from //UE4/Main for state not being cleared when rebuidling HMSM.
	#rb na
	#tests verified warnings gone after resaving Agora_Terrain

Change 3036317 on 2016/07/01 by Ben.Salem

	Allow FTests to be run in succession, and allow them to also be run in game instead of just editor.
	These are engine changes that have been tested extensively in fortnite, and have gone through a minor test pass here as well.
	#rb william.ewen, bob.tellez
	#tests Ran through all of Howitzer's new FTests in one run!

Change 3036168 on 2016/07/01 by Frank.Fella

	MovieSceneRendering - Fix a crash when deserializing burn in options. Change from Andrew Rodham.

	#rb Me for Andrew.
	#tests Movie scene renders in a separate process no longer crash when the burn in options are missing.

Change 3035632 on 2016/07/01 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Merge 28.2 @ CL 3035536

	#RB:none
	#Tests:none

	#ROBOMERGE-SOURCE: CL 3035630 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3035237 on 2016/07/01 by Dmitry.Rekman

	Updated WebRTC libs to avoid SIGPIPE (OR-24857).

	- Should also remove debug output.
	- These fixes has been previously done for OR-13279 but apparently libs have been recompiled from earlier sources since that.
	- Current libs have been compiled by Lee Clark (CL 3034752).

	#rb Lee Clark
	#codereview Lee.Clark, Andrew.Grant, Sam.Zamani
	#tests Run PS4 client, made sure XMPP connection was established and got some traffic.

Change 3035210 on 2016/07/01 by Andrew.Grant

	Fix for broken AI / abilities
	#rb none
	#tests Golden path with gadget, all abilities working, AI are happy and combatitive again

Change 3034936 on 2016/06/30 by Josh.Markiewicz

	#UE4 - separated out basic features from update/patch/hotfix manager into generic engine class
	- left Orion specific overloads around
	#rb none
	#tests PS4/PC/Server hotfix and update checks (with and without update required)
	#codereview ian.fox, ben.zeigler, bob.tellez

Change 3034935 on 2016/06/30 by Josh.Markiewicz

	#UE4 - make sure that mcp client keys, names, and ids can't have extraneous spaces in them from the ini file
	#codereview sam.zamani, shon.love, david.nikdel, eric.newman
	#tests paragon launch
	#rb none

Change 3034933 on 2016/06/30 by Josh.Markiewicz

	#UE4 - moved OnlineHotfixManager out of deprecated classes directory
	#rb none
	#tests compiles

Change 3034524 on 2016/06/30 by Andrew.Grant

	Fix for team assignment being broken in blueprints
	#rb Dan.OConnor
	#tests Golden Path with sparrow, verified arrow AOE color is correct and harvesters deliver XP

Change 3034521 on 2016/06/30 by Andrew.Grant

	Setting replay version to 0 for v29
	#rb none
	#tests none

Change 3034483 on 2016/06/30 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Repair main build integration

	#RB:none
	#Tests:none

	[CodeReviewed]: david.ratti

	#ROBOMERGE-SOURCE: CL 3034395 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3034481 on 2016/06/30 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Merge 28.2 @ CL 3034181

	#RB:none
	#Tests:none

	#ROBOMERGE-SOURCE: CL 3034319 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3034464 on 2016/06/30 by Martin.Wilson

	Fix for trying to load preview mesh for skeleton when the preview meshes skeleton doesn't match

	#rb Jurre.DeBaare
	#tests Asset loading in the editor

Change 3034194 on 2016/06/30 by Martin.Wilson

	Fix for rendering crash

	#codereview Rolando.Caloca
	#rb Rolando.Caloca

	#test editor startup

Change 3034192 on 2016/06/30 by Andrew.Grant

	Removing Fortnight madness

	#codereview Ben.Marsh
	#rb none
	#tests compiled

Change 3034106 on 2016/06/30 by Martin.Wilson

	Fix retargetting of anim blueprints so that all animations referred to are collected and duplicated, not just direct bp variables

	#rb Thomas.Sarkanen
	#tests In editor retargeting of various blueprint setups

Change 3034041 on 2016/06/30 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: antony.carter
	Exposing some of the slate interfaces for upcoming Social Plugin usage

	#RB Jamie.Dale
	#TESTS NA

	#ROBOMERGE-SOURCE: CL 3034040 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3033591 on 2016/06/29 by Andrew.Grant

	Merging //UE4/Main @ 3033257 through Orion-Staging
	#rb none
	#tests engine QA, golden path in PIE and out, BuildCookRun PS4

Change 3033545 on 2016/06/29 by Josh.Markiewicz

	#UE4 - fixed shadowed variable
	#rb none
	#tests compiles

Change 3033462 on 2016/06/29 by Josh.Markiewicz

	#UE4 - notify game about net guid mismatch or net checksum failures
	#rb john.pollard
	#codereview john.pollard, dave.ratti, andrew.grant, matt.oelfke
	#tests triggered fake mismatches while networked

Change 3033453 on 2016/06/29 by Josh.Markiewicz

	#UE4 - turned off extra logging feature now that the auth expiration issues have been solved
	- removes some bad log spam showing up in live (starting when already started, stopped when not started)
	#rb none
	#tests none
	#codereview ben.zeigler, sam.zamani

Change 3033020 on 2016/06/29 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: david.nikdel
	#OGF
	Merging //GamePlugins/Main/PluginTestGame/Plugins/OnlineGameplayFramework/...
	to //Orion/Main/OrionGame/Plugins/OnlineGameplayFramework/...
	---------
	- Support for exclusive profile locking (by dedicated servers)
	- PostAdd event for IMcpItemAware
	- New McpItemDefinitionBase class
	- Support for converting to new colon-based template ids
	- Improvements to FJsonObjectWrapper (technically an engine change)
	- Ability to specify an explicit fulfillment class to instantiate
	- Ability to split catalog localization out from the main data.
	- Couple of Orion fix ups for the new code
	- Re-exported catalog (loc data now separated out)
	---------
	#RB: none
	#TESTS: login, mcp, etc
	[CodeReviewed]: Jason.Bestimt

	#ROBOMERGE-SOURCE: CL 3033018 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3032623 on 2016/06/29 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Merge 28.2 @ CL 3032459

	#RB:none
	#Tests:none

	#ROBOMERGE-SOURCE: CL 3032516 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3032451 on 2016/06/29 by bruce.nesbit

	Added code in AutoPopulateInstanceProperties to populate vector and scalar parameter data.

	#rb SimonT

	#tests PIE

Change 3031620 on 2016/06/28 by Aaron.McLeran

	Implementing CL 3029659 to Dev-General.

	Adding new minor feature to add new concurrency mode to allow not stopping old sounds if new sound is not lower priority (or is same priority) than any existing sounds in concurrency group

	#rb marc.audy
	#TESTS existing concurrency doesn't break. New concurrency rule results in not stopping sounds if new sound is not lower pri than existing sounds

Change 3031616 on 2016/06/28 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: bob.ferreira
	Fixed an additional cast issue (hopefully the last!) in SetupSkyIrradianceEnvironmentMapConstants where Scene objects were not being cast and/or null checked

	#rb Marcus.Wassmer
	#tests Compiled and verified clients connected to server
	#jira OR-24678

	#ROBOMERGE-SOURCE: CL 3031610 in //Orion/Release-28/... via CL 3031611 via CL 3031613 via CL 3031614
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3031607 on 2016/06/28 by Josh.Markiewicz

	#UE4 - pass the UniqueNetId along with client beacons so the server can tell who is making requests
	#rb sam.zamani
	#codereview paul.moore
	#tests draft lobby golden path

Change 3031606 on 2016/06/28 by Josh.Markiewicz

	#UE4 - added code to stop logging out players from reservation beacon on timeouts if game doesn't request it
	#rb sam.zamani
	#codereview paul.moore
	#tests draft lobby golden path

Change 3031598 on 2016/06/28 by Josh.Markiewicz

	#UE4 - FUniqueNetIdRepl is stored on the UNetConnection and passed into engine login functions rather than TSharedPtr<FUniqueNetId>
	- wrapped class is safer and simplifies some other code
	#rb sam.zamani
	#tests draft lobby golden path
	#codereview paul.moore

Change 3031523 on 2016/06/28 by Josh.Markiewicz

	#UE4 - added ToDebugString to FUniqueNetIdRepl
	#rb none
	#tests draft lobby golden path

Change 3031366 on 2016/06/28 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: bob.ferreira
	Adding proper checks for Scene objects if it returns null

	#rb Marcus.Wassmer
	#tests Compiled and verified clients connected to server
	#jira OR-24678

	#ROBOMERGE-SOURCE: CL 3031361 in //Orion/Release-28/... via CL 3031362 via CL 3031363 via CL 3031365
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3030919 on 2016/06/28 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: bob.ferreira
	Fixed issue that was causing client bots to crash when running with -nullrhi. Now use interface provided by the Scene object.

	#rb Marcus.Wassmer
	#tests Compiled and verified clients connected to server
	#jira OR-24678

	#ROBOMERGE-SOURCE: CL 3030914 in //Orion/Release-28/... via CL 3030915 via CL 3030916 via CL 3030917
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3030715 on 2016/06/28 by David.Ratti

	removing warning. It is valid to use the ability system with actors without an animinstance.

	#rb none
	#test compile

Change 3030663 on 2016/06/28 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Merge 28.2 @ CL 3030407

	#RB:none
	#Tests:none

	#ROBOMERGE-SOURCE: CL 3030660 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3030533 on 2016/06/28 by Marcus.Wassmer

	Fix incorrect warning
	#rb none
	#test none
	#codereview Daniel.Lamb

Change 3030526 on 2016/06/28 by bruce.nesbit

	Re-added MaxRoughness changes in scalability config and added ECVF_Scalability to the CVar for same

	#rb none

	#codereview Marcus.Wassmer

	#tests PIE

Change 3029022 on 2016/06/27 by Jason.Bestimt

	#ROBOMERGE-AUTHOR: jason.bestimt
	#ORION_MAIN - Merge 28.2 @ CL 3028879

	#RB:none
	#tests:none

	#ROBOMERGE-SOURCE: CL 3029020 in //Orion/Main/...
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

Change 3028712 on 2016/06/27 by David.Ratti

	AbilitySystem debug hud
	-Made this more accessible from the base engine system. No longer required to forward calls from the owning actor class'es DisplayDebug function

	PlayerController::DisplayDebug
	-Set DisplayDebugManager's Y pos to the out Y pos, so that subsequent debug huds don't overlap with this one

	#rb none
	#tests gameplay ability sample project

[CL 3043787 by Andrew Grant in Main branch]
2016-07-08 22:29:24 -04:00

597 lines
20 KiB
C#

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using AutomationTool;
using UnrealBuildTool;
using System.Reflection;
using System.Xml;
using System.Linq;
using System.Diagnostics;
namespace AutomationTool
{
/// <summary>
/// Options for how the graph should be printed
/// </summary>
enum GraphPrintOptions
{
/// <summary>
/// Includes the list of dependencies for each node
/// </summary>
ShowDependencies = 0x1,
/// <summary>
/// Includes the list of notifiers for each node
/// </summary>
ShowNotifications = 0x2,
}
/// <summary>
/// Diagnostic message from the graph script. These messages are parsed at startup, then culled along with the rest of the graph nodes before output. Doing so
/// allows errors and warnings which are only output if a node is part of the graph being executed.
/// </summary>
class GraphDiagnostic
{
/// <summary>
/// The diagnostic event type
/// </summary>
public LogEventType EventType;
/// <summary>
/// The message to display
/// </summary>
public string Message;
/// <summary>
/// The node which this diagnostic is declared in. If the node is culled from the graph, the message will not be displayed.
/// </summary>
public Node EnclosingNode;
/// <summary>
/// The agent that this diagnostic is declared in. If the entire agent is culled from the graph, the message will not be displayed.
/// </summary>
public Agent EnclosingAgent;
/// <summary>
/// The trigger that this diagnostic is declared in. If this trigger is not being run, the message will not be displayed.
/// </summary>
public ManualTrigger EnclosingTrigger;
}
/// <summary>
/// Definition of a graph.
/// </summary>
class Graph
{
/// <summary>
/// List of agents containing nodes to execute
/// </summary>
public List<Agent> Agents = new List<Agent>();
/// <summary>
/// All manual triggers that are part of this graph
/// </summary>
public Dictionary<string, ManualTrigger> NameToTrigger = new Dictionary<string, ManualTrigger>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping from name to agent
/// </summary>
public Dictionary<string, Agent> NameToAgent = new Dictionary<string, Agent>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping of names to the corresponding node.
/// </summary>
public Dictionary<string, Node> NameToNode = new Dictionary<string,Node>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping of names to the corresponding report.
/// </summary>
public Dictionary<string, Report> NameToReport = new Dictionary<string, Report>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping of names to their corresponding node output.
/// </summary>
public HashSet<string> LocalTagNames = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping of names to their corresponding node output.
/// </summary>
public Dictionary<string, NodeOutput> TagNameToNodeOutput = new Dictionary<string,NodeOutput>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Mapping of aggregate names to their respective nodes
/// </summary>
public Dictionary<string, Node[]> AggregateNameToNodes = new Dictionary<string,Node[]>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// List of badges that can be displayed for this build
/// </summary>
public List<Badge> Badges = new List<Badge>();
/// <summary>
/// Diagnostic messages for this graph
/// </summary>
public List<GraphDiagnostic> Diagnostics = new List<GraphDiagnostic>();
/// <summary>
/// Default constructor
/// </summary>
public Graph()
{
}
/// <summary>
/// Checks whether a given name already exists
/// </summary>
/// <param name="Name">The name to check.</param>
/// <returns>True if the name exists, false otherwise.</returns>
public bool ContainsName(string Name)
{
return NameToNode.ContainsKey(Name) || NameToReport.ContainsKey(Name) || AggregateNameToNodes.ContainsKey(Name);
}
/// <summary>
/// Tries to resolve the given name to one or more nodes. Checks for aggregates, and actual nodes.
/// </summary>
/// <param name="Name">The name to search for</param>
/// <param name="OutNodes">If the name is a match, receives an array of nodes and their output names</param>
/// <returns>True if the name was found, false otherwise.</returns>
public bool TryResolveReference(string Name, out Node[] OutNodes)
{
// Check if it's a tag reference or node reference
if(Name.StartsWith("#"))
{
// Check if it's a regular node or output name
NodeOutput Output;
if(TagNameToNodeOutput.TryGetValue(Name, out Output))
{
OutNodes = new Node[]{ Output.ProducingNode };
return true;
}
}
else
{
// Check if it's a regular node or output name
Node Node;
if(NameToNode.TryGetValue(Name, out Node))
{
OutNodes = new Node[]{ Node };
return true;
}
// Check if it's an aggregate name
Node[] Nodes;
if(AggregateNameToNodes.TryGetValue(Name, out Nodes))
{
OutNodes = Nodes;
return true;
}
// Check if it's a group name
Agent Agent;
if(NameToAgent.TryGetValue(Name, out Agent))
{
OutNodes = Agent.Nodes.ToArray();
return true;
}
}
// Otherwise fail
OutNodes = null;
return false;
}
/// <summary>
/// Tries to resolve the given name to one or more node outputs. Checks for aggregates, and actual nodes.
/// </summary>
/// <param name="Name">The name to search for</param>
/// <param name="OutOutputs">If the name is a match, receives an array of nodes and their output names</param>
/// <returns>True if the name was found, false otherwise.</returns>
public bool TryResolveInputReference(string Name, out NodeOutput[] OutOutputs)
{
// Check if it's a tag reference or node reference
if(Name.StartsWith("#"))
{
// Check if it's a regular node or output name
NodeOutput Output;
if(TagNameToNodeOutput.TryGetValue(Name, out Output))
{
OutOutputs = new NodeOutput[]{ Output };
return true;
}
}
else
{
// Check if it's a regular node or output name
Node Node;
if(NameToNode.TryGetValue(Name, out Node))
{
OutOutputs = Node.Outputs.Union(Node.Inputs).ToArray();
return true;
}
// Check if it's an aggregate name
Node[] Nodes;
if(AggregateNameToNodes.TryGetValue(Name, out Nodes))
{
OutOutputs = Nodes.SelectMany(x => x.Outputs.Union(x.Inputs)).Distinct().ToArray();
return true;
}
}
// Otherwise fail
OutOutputs = null;
return false;
}
/// <summary>
/// Cull the graph to only include the given nodes and their dependencies
/// </summary>
/// <param name="TargetNodes">A set of target nodes to build</param>
public void Select(IEnumerable<Node> TargetNodes)
{
// Find this node and all its dependencies
HashSet<Node> RetainNodes = new HashSet<Node>(TargetNodes);
foreach(Node TargetNode in TargetNodes)
{
RetainNodes.UnionWith(TargetNode.InputDependencies);
}
// Remove all the nodes which are not marked to be kept
foreach(Agent Agent in Agents)
{
Agent.Nodes = Agent.Nodes.Where(x => RetainNodes.Contains(x)).ToList();
}
// Remove all the empty agents
Agents.RemoveAll(x => x.Nodes.Count == 0);
// Trim down the list of nodes for each report to the ones that are being built
foreach (Report Report in NameToReport.Values)
{
Report.Nodes.RemoveWhere(x => !RetainNodes.Contains(x));
}
// Remove all the empty reports
NameToReport = NameToReport.Where(x => x.Value.Nodes.Count > 0).ToDictionary(Pair => Pair.Key, Pair => Pair.Value, StringComparer.InvariantCultureIgnoreCase);
// Remove all the order dependencies which are no longer part of the graph. Since we don't need to build them, we don't need to wait for them
foreach(Node Node in RetainNodes)
{
Node.OrderDependencies = Node.OrderDependencies.Where(x => RetainNodes.Contains(x)).ToArray();
}
// Create a new list of triggers from all the nodes which are left
NameToTrigger = RetainNodes.Where(x => x.ControllingTrigger != null).Select(x => x.ControllingTrigger).Distinct().ToDictionary(x => x.Name, x => x, StringComparer.InvariantCultureIgnoreCase);
// Create a new list of aggregates for everything that's left
AggregateNameToNodes = AggregateNameToNodes.Where(x => x.Value.All(y => RetainNodes.Contains(y))).ToDictionary(Pair => Pair.Key, Pair => Pair.Value, StringComparer.InvariantCultureIgnoreCase);
// Remove any badges which do not have all their dependencies
Badges.RemoveAll(x => x.Nodes.Any(y => !RetainNodes.Contains(y)));
// Remove any diagnostics which are no longer part of the graph
Diagnostics.RemoveAll(x => (x.EnclosingNode != null && !RetainNodes.Contains(x.EnclosingNode)) || (x.EnclosingAgent != null && !Agents.Contains(x.EnclosingAgent)));
}
/// <summary>
/// Writes a preprocessed build graph to a script file
/// </summary>
/// <param name="File">The file to load</param>
public void Write(FileReference File, FileReference SchemaFile)
{
XmlWriterSettings Settings = new XmlWriterSettings();
Settings.Indent = true;
Settings.IndentChars = "\t";
using (XmlWriter Writer = XmlWriter.Create(File.FullName, Settings))
{
Writer.WriteStartElement("BuildGraph", "http://www.epicgames.com/BuildGraph");
if (SchemaFile != null)
{
Writer.WriteAttributeString("schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.epicgames.com/BuildGraph " + SchemaFile.MakeRelativeTo(File.Directory));
}
foreach (Agent Agent in Agents)
{
Agent.Write(Writer, null);
}
foreach (ManualTrigger ControllingTrigger in Agents.SelectMany(x => x.Nodes).Where(x => x.ControllingTrigger != null).Select(x => x.ControllingTrigger).Distinct())
{
Writer.WriteStartElement("Trigger");
Writer.WriteAttributeString("Name", ControllingTrigger.QualifiedName);
foreach (Agent Agent in Agents)
{
Agent.Write(Writer, ControllingTrigger);
}
Writer.WriteEndElement();
}
foreach (KeyValuePair<string, Node[]> Aggregate in AggregateNameToNodes)
{
Writer.WriteStartElement("Aggregate");
Writer.WriteAttributeString("Name", Aggregate.Key);
Writer.WriteAttributeString("Requires", String.Join(";", Aggregate.Value.Select(x => x.Name)));
Writer.WriteEndElement();
}
foreach (Report Report in NameToReport.Values)
{
Writer.WriteStartElement("Report");
Writer.WriteAttributeString("Name", Report.Name);
Writer.WriteAttributeString("Requires", String.Join(";", Report.Nodes.Select(x => x.Name)));
Writer.WriteEndElement();
}
foreach (Badge Badge in Badges)
{
Writer.WriteStartElement("Badge");
Writer.WriteAttributeString("Name", Badge.Name);
if (Badge.Project != null)
{
Writer.WriteAttributeString("Project", Badge.Project);
}
Writer.WriteAttributeString("Requires", String.Join(";", Badge.Nodes.Select(x => x.Name)));
Writer.WriteEndElement();
}
Writer.WriteEndElement();
}
}
/// <summary>
/// Export the build graph to a Json file, for parallel execution by the build system
/// </summary>
/// <param name="File">Output file to write</param>
/// <param name="ActivatedTriggers">Set of triggers which have been activated</param>
/// <param name="CompletedNodes">Set of nodes which have been completed</param>
public void Export(FileReference File, HashSet<ManualTrigger> ActivatedTriggers, HashSet<Node> CompletedNodes)
{
// Find all the nodes which we're actually going to execute. We'll use this to filter the graph.
HashSet<Node> NodesToExecute = new HashSet<Node>();
foreach(Node Node in Agents.SelectMany(x => x.Nodes))
{
if(!CompletedNodes.Contains(Node))
{
if(Node.ControllingTrigger == null || ActivatedTriggers.Contains(Node.ControllingTrigger))
{
NodesToExecute.Add(Node);
}
}
}
// Open the output file
using(JsonWriter JsonWriter = new JsonWriter(File.FullName))
{
JsonWriter.WriteObjectStart();
// Write all the agents
JsonWriter.WriteArrayStart("Groups");
foreach(Agent Agent in Agents)
{
Node[] Nodes = Agent.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
if(Nodes.Length > 0)
{
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Agent.Name);
JsonWriter.WriteArrayStart("Agent Types");
foreach(string AgentType in Agent.PossibleTypes)
{
JsonWriter.WriteValue(AgentType);
}
JsonWriter.WriteArrayEnd();
JsonWriter.WriteArrayStart("Nodes");
foreach(Node Node in Nodes)
{
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Node.Name);
JsonWriter.WriteValue("DependsOn", String.Join(";", Node.GetDirectOrderDependencies().Where(x => NodesToExecute.Contains(x))));
JsonWriter.WriteObjectStart("Notify");
JsonWriter.WriteValue("Default", String.Join(";", Node.NotifyUsers));
JsonWriter.WriteValue("Submitters", String.Join(";", Node.NotifySubmitters));
JsonWriter.WriteValue("Warnings", Node.bNotifyOnWarnings);
JsonWriter.WriteObjectEnd();
JsonWriter.WriteObjectEnd();
}
JsonWriter.WriteArrayEnd();
JsonWriter.WriteObjectEnd();
}
}
JsonWriter.WriteArrayEnd();
// Write all the badges
JsonWriter.WriteArrayStart("Badges");
foreach (Badge Badge in Badges)
{
Node[] Dependencies = Badge.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
if (Dependencies.Length > 0)
{
// Reduce that list to the smallest subset of direct dependencies
HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
foreach (Node Dependency in Dependencies)
{
DirectDependencies.ExceptWith(Dependency.OrderDependencies);
}
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Badge.Name);
if (!String.IsNullOrEmpty(Badge.Project))
{
JsonWriter.WriteValue("Project", Badge.Project);
}
JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
JsonWriter.WriteObjectEnd();
}
}
JsonWriter.WriteArrayEnd();
// Write all the triggers and reports.
JsonWriter.WriteArrayStart("Reports");
foreach (Report Report in NameToReport.Values)
{
Node[] Dependencies = Report.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
if (Dependencies.Length > 0)
{
// Reduce that list to the smallest subset of direct dependencies
HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
foreach (Node Dependency in Dependencies)
{
DirectDependencies.ExceptWith(Dependency.OrderDependencies);
}
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Report.Name);
JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
JsonWriter.WriteValue("Notify", String.Join(";", Report.NotifyUsers));
JsonWriter.WriteValue("IsTrigger", false);
JsonWriter.WriteObjectEnd();
}
}
foreach (ManualTrigger Trigger in NameToTrigger.Values)
{
if(!ActivatedTriggers.Contains(Trigger) && NodesToExecute.Any(x => x.ControllingTrigger == Trigger.Parent))
{
// Find all the nodes that this trigger is dependent on
HashSet<Node> Dependencies = new HashSet<Node>();
foreach(Node Node in Agents.SelectMany(x => x.Nodes))
{
for(ManualTrigger ControllingTrigger = Node.ControllingTrigger; ControllingTrigger != null; ControllingTrigger = ControllingTrigger.Parent)
{
if(ControllingTrigger == Trigger)
{
Dependencies.UnionWith(Node.OrderDependencies.Where(x => x.ControllingTrigger != Trigger && NodesToExecute.Contains(x)));
break;
}
}
}
// Reduce that list to the smallest subset of direct dependencies
HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
foreach(Node Dependency in Dependencies)
{
DirectDependencies.ExceptWith(Dependency.OrderDependencies);
}
// Write out the object
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Trigger.Name);
JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
JsonWriter.WriteValue("DirectDependencies", String.Join(";", Dependencies.Where(x => DirectDependencies.Contains(x)).Select(x => x.Name)));
JsonWriter.WriteValue("Notify", String.Join(";", Trigger.NotifyUsers));
JsonWriter.WriteValue("IsTrigger", true);
JsonWriter.WriteObjectEnd();
}
}
JsonWriter.WriteArrayEnd();
JsonWriter.WriteObjectEnd();
}
}
/// <summary>
/// Print the contents of the graph
/// </summary>
/// <param name="NodeToState">Mapping of node to its current state</param>
/// <param name="Options">Options for how to print the graph</param>
public void Print(HashSet<Node> CompletedNodes, GraphPrintOptions Options)
{
// Get a list of all the triggers, including the null global one
List<ManualTrigger> AllTriggers = new List<ManualTrigger>();
AllTriggers.Add(null);
AllTriggers.AddRange(NameToTrigger.Values.OrderBy(x => x.QualifiedName));
// Output all the triggers in order
CommandUtils.Log("");
CommandUtils.Log("Graph:");
foreach(ManualTrigger Trigger in AllTriggers)
{
// Filter everything by this trigger
Dictionary<Agent, Node[]> FilteredAgentToNodes = new Dictionary<Agent,Node[]>();
foreach(Agent Agent in Agents)
{
Node[] Nodes = Agent.Nodes.Where(x => x.ControllingTrigger == Trigger).ToArray();
if(Nodes.Length > 0)
{
FilteredAgentToNodes[Agent] = Nodes;
}
}
// Skip this trigger if there's nothing to display
if(FilteredAgentToNodes.Count == 0)
{
continue;
}
// Print the trigger name
CommandUtils.Log(" Trigger: {0}", (Trigger == null)? "None" : Trigger.QualifiedName);
if(Trigger != null && Options.HasFlag(GraphPrintOptions.ShowNotifications))
{
foreach(string User in Trigger.NotifyUsers)
{
CommandUtils.Log(" notify> {0}", User);
}
}
// Output all the agents for this trigger
foreach(Agent Agent in Agents)
{
Node[] Nodes;
if(FilteredAgentToNodes.TryGetValue(Agent, out Nodes))
{
CommandUtils.Log(" Agent: {0} ({1})", Agent.Name, String.Join(";", Agent.PossibleTypes));
foreach(Node Node in Nodes)
{
CommandUtils.Log(" Node: {0}{1}", Node.Name, CompletedNodes.Contains(Node)? " (completed)" : "");
if(Options.HasFlag(GraphPrintOptions.ShowDependencies))
{
HashSet<Node> InputDependencies = new HashSet<Node>(Node.GetDirectInputDependencies());
foreach(Node InputDependency in InputDependencies)
{
CommandUtils.Log(" input> {0}", InputDependency.Name);
}
HashSet<Node> OrderDependencies = new HashSet<Node>(Node.GetDirectOrderDependencies());
foreach(Node OrderDependency in OrderDependencies.Except(InputDependencies))
{
CommandUtils.Log(" after> {0}", OrderDependency.Name);
}
}
if(Options.HasFlag(GraphPrintOptions.ShowNotifications))
{
string Label = Node.bNotifyOnWarnings? "warnings" : "errors";
foreach(string User in Node.NotifyUsers)
{
CommandUtils.Log(" {0}> {1}", Label, User);
}
foreach(string Submitter in Node.NotifySubmitters)
{
CommandUtils.Log(" {0}> submitters to {1}", Label, Submitter);
}
}
}
}
}
}
CommandUtils.Log("");
// Print out all the aggregates
string[] AggregateNames = AggregateNameToNodes.Keys.OrderBy(x => x).ToArray();
if(AggregateNames.Length > 0)
{
CommandUtils.Log("Aggregates:");
foreach(string AggregateName in AggregateNames)
{
CommandUtils.Log(" {0}", AggregateName);
}
CommandUtils.Log("");
}
}
}
}