Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/BuildGraph/Task.cs
Ben Marsh 3e80336791 Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3092544)
#lockdown Nick.Penwarden
#rb none

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

Change 3079316 on 2016/08/05 by Ben.Marsh

	Better PCH selection in ShaderFormatOpenGL and MetalShaderFormat - make sure Core is the first included header.

Change 3080579 on 2016/08/08 by Ben.Marsh

	Slate: Move DEBUG_TAB_MANAGEMENT into SDockingTabStack.h to remove circular include dependency with DockingPrivate.h.

Change 3080587 on 2016/08/08 by Ben.Marsh

	StandaloneRenderer: Move platform includes into a separate header so we can make individual headers self-contained, without having a circular dependency on StandaloneRendererPrivate.h.

Change 3080789 on 2016/08/08 by Ben.Marsh

	Move BuildGraph tasks for chunking, posting builds, labeling builds, and merging manifests into the MCP project. While we do provide public interfaces for this functionality, we don't currently expect anyone outside Epic to be using them.

Change 3080815 on 2016/08/08 by Ben.Marsh

	BuildGraph: Add a -GenerateDocs option, which writes out an HTML file constructed from C# XML documentation containing all the task information.

Change 3081374 on 2016/08/08 by Ben.Marsh

	UBT: Invalidate the makefile if any UHT headers are deleted. Should fix issue where files are moved from one module to another, and the original module no longer contains any generated headers. Its include path needs to be removed from the compile environment.

Change 3083152 on 2016/08/09 by Ben.Marsh

	PR #2667: Add Intel C++ Compiler support to Windows build (Contributed by JeffRous)

Change 3084039 on 2016/08/10 by Ben.Marsh

	BuildGraph: Add additional markup for parameter attributes. Also improve some documation.

Change 3084240 on 2016/08/10 by Ben.Marsh

	Plugins: Allow plugins in the project folder to replace plugins in the engine folder with the same name. Prohibit multiple plugins with the same name at other times.

Change 3084337 on 2016/08/10 by Ben.Marsh

	UBT: Specify the -precompile option when generating project files for a target, so we include all valid modules for intellisense.

Change 3085594 on 2016/08/11 by Ben.Marsh

	Change modules which reference a public header for their PCH to use a private PCH instead, even if it just includes the public header for now.

Change 3085999 on 2016/08/11 by Ben.Marsh

	Add some missing #pragma once directives.

Change 3086146 on 2016/08/11 by Ben.Marsh

	Core: Move prototype and linkage specifier for ConsoleCommandLibrary_* functions into header matching cpp file.

Change 3086172 on 2016/08/11 by Ben.Marsh

	Fixup some C-style header guards to use #pragma once instead.

Change 3087289 on 2016/08/12 by Ben.Marsh

	Split out UPackage and UMetaData into their own headers (they're already implemented in separate CPP files)

Change 3087310 on 2016/08/12 by Ben.Marsh

	Move method stubs for FNullSlateSoundDevice into a CPP file, since they're exported from the SlateCore module.

Change 3087341 on 2016/08/12 by Ben.Marsh

	UdpMessaging: Move PCH before #if PLATFORM_DESKTOP; it will only be defined if the definition is included.

Change 3087457 on 2016/08/12 by Ben.Marsh

	Core: Reorganize the FTransform and FMatrix headers: Transform.h now includes TransformNonVectorized.h or TransformVectorized.h as appropriate, and UnrealMatrix.h is now Matrix.inl (and included from Matrix.h).

Change 3088407 on 2016/08/13 by Ben.Marsh

	Replace use of Windows SIZE_T define with the regular C++ size_t.

Change 3088416 on 2016/08/13 by Ben.Marsh

	Include a header from all .generated.cpp files (GeneratedCppIncludes.h) which includes all the basic types required to compile them, rather than assuming that the module PCH will include everything.

	Also include the real declarations of noexport classes in Object.h (now renamed to NoExportTypes.h for clarity) when the CPP macro is defined, so the .generated.deps.h file will automatically have the correct definitions for them at compile time rather than relying on them being in the private PCH.

	Finally, rename UObject.h to Object.h for consistency with the naming convention for all other UObject classes. UObject.h still exists for now, but outputs a deprecated message if included.

Change 3088544 on 2016/08/14 by Ben.Marsh

	Core: Move the definition of the TEXT() macro into Platform.h, to avoid having to include OS headers to get it.

Change 3088552 on 2016/08/14 by Ben.Marsh

	Fix compile errors for some modules that don't already include CoreUObject.h.

Change 3088925 on 2016/08/15 by Ben.Marsh

	Remove circular include dependencies from VulkanRHI.

Change 3088926 on 2016/08/15 by Ben.Marsh

	Remove duplicate definition for WITH_FIXED_AREA_ENTERING_COST from EngineDefines.h - always uses the definition from DetourNavMeshQuery.h instead.

Change 3088930 on 2016/08/15 by Ben.Marsh

	Remove circular include dependency from PhysX.

Change 3088935 on 2016/08/15 by Ben.Marsh

	OnlineSubsystemUtils: Move CPP files out of public header directory.

Change 3088965 on 2016/08/15 by Ben.Marsh

	Add private PCH to Landscape, MoviePlayer, TaskGraph, XAudio2 and RealtimeProfiler modules.

Change 3088966 on 2016/08/15 by Ben.Marsh

	Engine: Move CPP files out of public header directories.

Change 3089520 on 2016/08/15 by Ben.Marsh

	BuildGraph: Change documentation command to output markdown.

Change 3090299 on 2016/08/16 by Ben.Marsh

	D3D12RHI: Move around some implementations to fix circular header dependencies which are masked by delayed template instantiation.

Change 3090303 on 2016/08/16 by Ben.Marsh

	Engine: Add a template specialization for TPointerIsConvertibleFromTo<AActor, const volatile UObject> to fix dependency on complete AActor definition for static assert in TWeakPointer<AActor>, which only appears if including Level.h without Actor.h. Delayed template instantiation usually masks this issue.

Change 3091861 on 2016/08/17 by Ben.Marsh

	Remove circular header dependencies, and fix ambiguous include paths in OSVR.

Change 3092068 on 2016/08/17 by Ben.Marsh

	Moving VulkanDynamicRHI into its own header.

Change 3093133 on 2016/08/18 by Ben.Marsh

	EC: Include additional context lines for Clang errors.

Change 3093147 on 2016/08/18 by Ben.Marsh

	UBT: Add an error message when attempting to do a single-file compile with the wrong target selected.

Change 3093228 on 2016/08/18 by Ben.Marsh

	Remove redundant setting for remote server name from XML config, and set it to a valid machine in the engine config.

[CL 3093264 by Ben Marsh in Main branch]
2016-08-18 10:28:43 -04:00

406 lines
15 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 node/aggregate/agent name or tag name
/// </summary>
Target,
/// <summary>
/// A list of standard name or tag names separated by semicolons
/// </summary>
TargetList,
/// <summary>
/// A file specification, which may contain tags and wildcards.
/// </summary>
FileSpec,
/// <summary>
/// A single file name
/// </summary>
FileName,
/// <summary>
/// A single directory name
/// </summary>
DirectoryName,
}
/// <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>
/// Output this task out to an XML writer.
/// </summary>
public abstract void Write(XmlWriter Writer);
/// <summary>
/// Writes this task to an XML writer, using the given parameters object.
/// </summary>
/// <param name="Writer">Writer for the XML schema</param>
/// <param name="Parameters">Parameters object that this task is constructed with</param>
protected void Write(XmlWriter Writer, object Parameters)
{
TaskElementAttribute Element = GetType().GetCustomAttribute<TaskElementAttribute>();
Writer.WriteStartElement(Element.Name);
foreach (FieldInfo Field in Parameters.GetType().GetFields())
{
if (Field.MemberType == MemberTypes.Field)
{
TaskParameterAttribute ParameterAttribute = Field.GetCustomAttribute<TaskParameterAttribute>();
if (ParameterAttribute != null)
{
object Value = Field.GetValue(Parameters);
if (Value != null && Field.FieldType == typeof(bool) && (bool)Value == false)
{
Value = null;
}
if (Value != null)
{
Writer.WriteAttributeString(Field.Name, Value.ToString());
}
}
}
}
Writer.WriteEndElement();
}
/// <summary>
/// Find all the tags which are used as inputs to this task
/// </summary>
/// <returns>The tag names which are read by this task</returns>
public abstract IEnumerable<string> FindConsumedTagNames();
/// <summary>
/// Find all the tags which are modified by this task
/// </summary>
/// <returns>The tag names which are modified by this task</returns>
public abstract IEnumerable<string> FindProducedTagNames();
/// <summary>
/// Adds tag names from a filespec
/// </summary>
/// <param name="Filespec">A filespec, as can be passed to ResolveFilespec</param>
/// <returns>Tag names from this filespec</returns>
protected IEnumerable<string> FindTagNamesFromFilespec(string Filespec)
{
if(!String.IsNullOrEmpty(Filespec))
{
foreach(string Pattern in SplitDelimitedList(Filespec))
{
if(Pattern.StartsWith("#"))
{
yield return Pattern;
}
}
}
}
/// <summary>
/// Enumerates tag names from a list
/// </summary>
/// <param name="TagList">List of tags separated by semicolons</param>
/// <returns>Tag names from this filespec</returns>
protected IEnumerable<string> FindTagNamesFromList(string TagList)
{
if(!String.IsNullOrEmpty(TagList))
{
foreach(string TagName in SplitDelimitedList(TagList))
{
yield return TagName;
}
}
}
/// <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="TagNameToFileSet">Map of tag names to the set of files they contain</param>
/// <param name="TagName">The tag name to return a set for. A leading '#' character is required.</param>
/// <returns>Set of files</returns>
public static HashSet<FileReference> FindOrAddTagSet(Dictionary<string, HashSet<FileReference>> TagNameToFileSet, string TagName)
{
// Make sure the tag name contains a single leading hash
if (TagName.LastIndexOf('#') != 0)
{
throw new AutomationException("Tag name '{0}' is not valid - should contain a single leading '#' character", TagName);
}
// Any spaces should be later than the second char - most likely to be a typo if directly after the # character
if (TagName.IndexOf(' ') == 1)
{
throw new AutomationException("Tag name '{0}' is not valid - spaces should only be used to separate words", TagName);
}
// 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.", TagName);
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
List<string> Patterns = SplitDelimitedList(DelimitedPatterns);
return ResolveFilespecWithExcludePatterns(DefaultDirectory, Patterns, ExcludePatterns, TagNameToFileSet);
}
/// <summary>
/// Resolve a list of files, tag names or file specifications 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="FilePatterns">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, List<string> FilePatterns, List<string> ExcludePatterns, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
{
// Parse each of the patterns, and add the results into the given sets
HashSet<FileReference> Files = new HashSet<FileReference>();
foreach(string Pattern in FilePatterns)
{
// Check if it's a tag name
if(Pattern.StartsWith("#"))
{
Files.UnionWith(FindOrAddTagSet(TagNameToFileSet, Pattern));
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 List<string> SplitDelimitedList(string Text)
{
return Text.Split(';').Select(x => x.Trim()).Where(x => x.Length > 0).ToList();
}
}
}