Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/BuildGraph/Task.cs
Andrew Grant 0b4257e23a Copying //UE4/Orion-Staging to //UE4/Main (Source //Orion/Dev-General @ 2927258)
#lockdown Nick.Penwarden

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

Change 2927181 on 2016/03/29 by Dmitry.Rekman

	(Optionally) exclude idle time from server FPS charts.

	- Time spent waiting for the next frame in order to hit capped FPS can be optionally excluded by using t.FPSChart.ExcludeIdleTime (set to 1 for servers).
	- Server FPS charts analytics events and log output will include the information if idle time was excluded.

	- Also: added a log line each time we detect a server hitch for easier pin-pointing them in the log.

	#rb Paul.Moore
	#codereview Paul.Moore, Michael.Noland
	#tests Ran Linux server and Windows client on compatible content.

Change 2927084 on 2016/03/29 by Ben.Marsh

	BuildGraph: Don't allow triggers to run until all their order dependencies are complete. Just because a downstream node doesn't have a dependency on an upstream node via temp storage doesn't mean it can run immediately.

	#rb none
	#tests none

Change 2927060 on 2016/03/29 by Michael.Noland

	Renamed GPU analytics event from GPU to DesktopGPU to reflect that it is the default desktop adapter and not the one we initialized (which is GPUAdapter)
	Updated text/log based FPS chart events to print out GPUAdapter instead (with DesktopGPU in parens if they differ, e.g., in an optimus setup)
	#rb marcus.wassmer
	#tests Ran and did some fps charts

Change 2927048 on 2016/03/29 by Michael.Noland

	HLOD: Removed an unused cvar r.HLODEnabled (everything is done thru r.HLOD)
	#tests Compiled and ran Paragon
	#rb marcus.wassmer

Change 2926920 on 2016/03/29 by Ben.Marsh

	BuildGraph: Update schema with Rename task.

Change 2926911 on 2016/03/29 by Ben.Marsh

	BuildGraph: Add a task which can rename files matching a given wildcard. Syntax is: <Rename Files="*.txt" To="*.md"> or <Rename Files="Engine/Build/..." From="*.txt" To="*.md"/>

	#rb none
	#tests none

Change 2926908 on 2016/03/29 by Andrew.Grant

	Fix for CDO properties of renamed blueprints not being applied
	#rb none
	#tests loaded Origin map (renamed from Playgo3) and verified properties are applied.

Change 2926799 on 2016/03/29 by Jason.Bestimt

	#ORION_DG - Merge MAIN (23) @ CL# 2926780

	#RB:none
	#Tests:none

Change 2926663 on 2016/03/29 by david.nikdel

	#ROBOMERGE-OBO: jason.bestimt
	#ROBOMERGE-SOURCE: CL 2926660 in //Orion/Release-0.23/... via CL 2926662
	#ROBOMERGE-BOT: ORION (Main -> Dev-General)

	#ORION_23 - Potential fix for Cook failures

	"Fix shelved in 2926635, tested in Dev-Blueprints. Could not run any GEditor related logic safely in ShutdownModule because of the same destruction issue orders that caused the bug in the first place. I will chat with Editor team about nulling out GEditor the same way we null out GUnrealEd."

	#RB:none
	#Tests: none

	[CodeReviewed]: andrew.grant, dan.oconnor

Change 2926510 on 2016/03/29 by Andrew.Grant

	Potential fix for OR-18207 - editor becomes unresponsive (audio deadlock)
	#rb none
	#tests compiled

Change 2926495 on 2016/03/29 by Rob.Cannaday

	Change storing HTTP requests as raw pointers to weak pointers with validity being checked via Pinning it
	#jira FORT-18947
	#jira OR-17695
	#tests golden path
	#rb eric.newman

Change 2926427 on 2016/03/29 by Josh.Markiewicz

	#UE4 - fixed typo
	#rb none
	#tests none

Change 2926250 on 2016/03/29 by Martin.Mittring

	fixed OR-18489 HERO: IGGY: RMB on E ability causes blinding hair effect
	#rb:Chris.Bunner
	#codereview:Brian.Karis

Change 2926224 on 2016/03/29 by Daniel.Lamb

	Fix for potenital threading issue with Console manager removing vars which could cause double free.
	#rb Robert.Manuszewski
	#test Orion cook

Change 2926174 on 2016/03/29 by Gareth.Martin

	Cloned fix for bUseMaterialPositionOffsetInStaticLighting crashing across from //UE4/Dev-Landscape/ to unblock people
	#rb
	#tests editor

Change 2925968 on 2016/03/29 by David.Nikdel

	#MCP #OSS
	- Read RedirectUrl from ini

	#RB: Eric.Newman
	#TESTS: compiled in another branch (merge over)
	#ROBOMERGE: Main

[CL 2929424 by Andrew Grant in Main branch]
2016-03-31 15:18:30 -04:00

284 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using UnrealBuildTool;
namespace AutomationTool
{
/// <summary>
/// Specifies validation that should be performed on a task parameter.
/// </summary>
public enum TaskParameterValidationType
{
/// <summary>
/// Allow any valid values for the field type.
/// </summary>
Default,
/// <summary>
/// A standard name; alphanumeric characters, plus underscore and space. Spaces at the start or end, or more than one in a row are prohibited.
/// </summary>
Name,
/// <summary>
/// A list of names separated by semicolons
/// </summary>
NameList,
/// <summary>
/// A tag name (a regular name with '#' prefix)
/// </summary>
Tag,
/// <summary>
/// A list of tag names separated by semicolons
/// </summary>
TagList,
/// <summary>
/// A standard name or tag name
/// </summary>
NameOrTag,
/// <summary>
/// A list of standard name or tag names separated by semicolons
/// </summary>
NameOrTagList,
}
/// <summary>
/// Attribute to mark parameters to a task, which should be read as XML attributes from the script file.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class TaskParameterAttribute : Attribute
{
/// <summary>
/// Whether the parameter can be omitted
/// </summary>
public bool Optional
{
get;
set;
}
/// <summary>
/// Sets additional restrictions on how this field is validated in the schema. Default is to allow any valid field type.
/// </summary>
public TaskParameterValidationType ValidationType
{
get;
set;
}
}
/// <summary>
/// Attribute used to associate an XML element name with a parameter block that can be used to construct tasks
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class TaskElementAttribute : Attribute
{
/// <summary>
/// Name of the XML element that can be used to denote this class
/// </summary>
public string Name;
/// <summary>
/// Type to be constructed from the deserialized element
/// </summary>
public Type ParametersType;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InName">Name of the XML element used to denote this object</param>
/// <param name="InParametersType">Type to be constructed from this object</param>
public TaskElementAttribute(string InName, Type InParametersType)
{
Name = InName;
ParametersType = InParametersType;
}
}
/// <summary>
/// Base class for all custom build tasks
/// </summary>
public abstract class CustomTask
{
/// <summary>
/// Allow this task to merge with other tasks within the same node if it can. This can be useful to allow tasks to execute in parallel.
/// </summary>
/// <param name="OtherTasks">Other tasks that this task can merge with. If a merge takes place, the other tasks should be removed from the list.</param>
public virtual void Merge(List<CustomTask> OtherTasks)
{
}
/// <summary>
/// Execute 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</param>
/// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns>
public abstract bool Execute(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet);
/// <summary>
/// Resolves a single name to a file reference, resolving relative paths to the root of the current path.
/// </summary>
/// <param name="Name">Name of the file</param>
/// <returns>Fully qualified file reference</returns>
public static FileReference ResolveFile(string Name)
{
if(Path.IsPathRooted(Name))
{
return new FileReference(Name);
}
else
{
return new FileReference(Path.Combine(CommandUtils.CmdEnv.LocalRoot, Name));
}
}
/// <summary>
/// Resolves a directory reference from the given string. Assumes the root directory is the root of the current branch.
/// </summary>
/// <param name="Name">Name of the directory. May be null or empty.</param>
/// <returns>The resolved directory</returns>
public static DirectoryReference ResolveDirectory(string Name)
{
if(String.IsNullOrEmpty(Name))
{
return CommandUtils.RootDirectory;
}
else if(Path.IsPathRooted(Name))
{
return new DirectoryReference(Name);
}
else
{
return DirectoryReference.Combine(CommandUtils.RootDirectory, Name);
}
}
/// <summary>
/// Finds or adds a set containing files with the given tag
/// </summary>
/// <param name="Name">The tag name to return a set for. An leading '#' character is optional.</param>
/// <returns>Set of files</returns>
public static HashSet<FileReference> FindOrAddTagSet(Dictionary<string, HashSet<FileReference>> TagNameToFileSet, string Name)
{
// Get the clean tag name, without the leading '#' character
string TagName = Name.StartsWith("#")? Name.Substring(1) : Name;
// Find the files which match this tag
HashSet<FileReference> Files;
if(!TagNameToFileSet.TryGetValue(TagName, out Files))
{
Files = new HashSet<FileReference>();
TagNameToFileSet.Add(TagName, Files);
}
// If we got a null reference, it's because the tag is not listed as an input for this node (see RunGraph.BuildSingleNode). Fill it in, but only with an error.
if(Files == null)
{
CommandUtils.LogError("Attempt to reference tag '{0}', which is not listed as a dependency of this node.", Name);
Files = new HashSet<FileReference>();
TagNameToFileSet.Add(TagName, Files);
}
return Files;
}
/// <summary>
/// Resolve a list of files, tag names or file specifications separated by semicolons. Supported entries may be:
/// a) The name of a tag set (eg. #CompiledBinaries)
/// b) Relative or absolute filenames
/// c) A simple file pattern (eg. Foo/*.cpp)
/// d) A full directory wildcard (eg. Engine/...)
/// Note that wildcards may only match the last fragment in a pattern, so matches like "/*/Foo.txt" and "/.../Bar.txt" are illegal.
/// </summary>
/// <param name="DefaultDirectory">The default directory to resolve relative paths to</param>
/// <param name="DelimitedPatterns">List of files, tag names, or file specifications to include separated by semicolons.</param>
/// <param name="TagNameToFileSet">Mapping of tag name to fileset, as passed to the Execute() method</param>
/// <returns>Set of matching files.</returns>
public static HashSet<FileReference> ResolveFilespec(DirectoryReference DefaultDirectory, string DelimitedPatterns, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
List<string> ExcludePatterns = new List<string>();
return ResolveFilespecWithExcludePatterns(DefaultDirectory, DelimitedPatterns, ExcludePatterns, TagNameToFileSet);
}
/// <summary>
/// Resolve a list of files, tag names or file specifications separated by semicolons as above, but preserves any directory references for further processing.
/// </summary>
/// <param name="DefaultDirectory">The default directory to resolve relative paths to</param>
/// <param name="DelimitedPatterns">List of files, tag names, or file specifications to include separated by semicolons.</param>
/// <param name="ExcludePatterns">Set of patterns to apply to directory searches. This can greatly speed up enumeration by earlying out of recursive directory searches if large directories are excluded (eg. .../Intermediate/...).</param>
/// <param name="TagNameToFileSet">Mapping of tag name to fileset, as passed to the Execute() method</param>
/// <returns>Set of matching files.</returns>
public static HashSet<FileReference> ResolveFilespecWithExcludePatterns(DirectoryReference DefaultDirectory, string DelimitedPatterns, List<string> ExcludePatterns, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
// Split the argument into a list of patterns
string[] Patterns = SplitDelimitedList(DelimitedPatterns);
// Parse each of the patterns, and add the results into the given sets
HashSet<FileReference> Files = new HashSet<FileReference>();
foreach(string Pattern in Patterns)
{
// Check if it's a tag name
if(Pattern.StartsWith("#"))
{
Files.UnionWith(FindOrAddTagSet(TagNameToFileSet, Pattern.Substring(1)));
continue;
}
// If it doesn't contain any wildcards, just add the pattern directly
int WildcardIdx = FileFilter.FindWildcardIndex(Pattern);
if(WildcardIdx == -1)
{
Files.Add(FileReference.Combine(DefaultDirectory, Pattern));
continue;
}
// Find the base directory for the search. We construct this in a very deliberate way including the directory separator itself, so matches
// against the OS root directory will resolve correctly both on Mac (where / is the filesystem root) and Windows (where / refers to the current drive).
int LastDirectoryIdx = Pattern.LastIndexOfAny(new char[]{ Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, WildcardIdx);
DirectoryReference BaseDir = DirectoryReference.Combine(DefaultDirectory, Pattern.Substring(0, LastDirectoryIdx + 1));
// Construct the absolute include pattern to match against, re-inserting the resolved base directory to construct a canonical path.
string IncludePattern = BaseDir.FullName.TrimEnd(new char[]{ Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }) + "/" + Pattern.Substring(LastDirectoryIdx + 1);
// Construct a filter and apply it to the directory
if(BaseDir.Exists())
{
FileFilter Filter = new FileFilter();
Filter.AddRule(IncludePattern, FileFilterType.Include);
Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
Files.UnionWith(Filter.ApplyToDirectory(BaseDir, BaseDir.FullName, true));
}
}
// If we have exclude rules, create and run a filter against all the output files to catch things that weren't added from an include
if(ExcludePatterns.Count > 0)
{
FileFilter Filter = new FileFilter(FileFilterType.Include);
Filter.AddRules(ExcludePatterns, FileFilterType.Exclude);
Files.RemoveWhere(x => !Filter.Matches(x.FullName));
}
return Files;
}
/// <summary>
/// Splits a string separated by semicolons into a list, removing empty entries
/// </summary>
/// <param name="Text">The input string</param>
/// <returns>Array of the parsed items</returns>
public static string[] SplitDelimitedList(string Text)
{
return Text.Split(';').Select(x => x.Trim()).Where(x => x.Length > 0).ToArray();
}
}
}