// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
using System.Linq;
using AutomationTool;
using UnrealBuildTool;
using System.Xml;
using EpicGames.Core;
using UnrealBuildBase;
using EpicGames.BuildGraph;
using System.Runtime.Versioning;
namespace Win.Automation
{
///
/// Parameters for a task that adds source indexing information to symbol files (PDB).
///
public class SrcSrvTaskParameters
{
///
/// List of output files. PDBs will be extracted from this list.
///
[TaskParameter]
public string BinaryFiles;
///
/// List of source files to index and embed into the PDBs.
///
[TaskParameter]
public string SourceFiles;
///
/// Branch to base all the depot source files from
///
[TaskParameter]
public string Branch;
///
/// Changelist to sync files from
///
[TaskParameter]
public int Change;
///
/// List of file path mappings to be applied during source indexing. It is needed only when using VFS (Virtual File System)
/// feature when compiling the binary. VFS replaces the real local paths used with standardized paths like Z:\UEVFS\...
/// Since these virtualized paths don't match paths used by the local workspace, we need to map them manually so that
/// paths in object files/symbols matched the data we have in source indexing.
/// It's a semicolon-separated list of path assignments e.g.
/// "[Root]\Samples\Games\SampleGame=Z:\UEVFS\SampleGame;[Root]=Z:\UEVFS\Root"
///
/// [Root] will be replaced with Unreal.RootDirectory.
/// You need to ensure that the mapping used here matches the conventions used by Unreal Build Tool.
/// We may improve it in the future but current the VFS mapping used during compilation is not available outside of UBT.
///
[TaskParameter(Optional = true)]
public string VFSMapping { get; set; }
}
///
/// Task which strips symbols from a set of files
/// Note that this task only supports source indexing for Windows-like platforms.
/// SymStore can be considered a generalization of this task because in addition to uploading symbols
/// it can also index sources and supports consoles as well (any missing platform that supports
/// source indexing in general may add support for it by extending PublishSymbols).
/// Check SymStoreTaskParameters.IndexSources/SourceFiles/Branch/Change
///
[TaskElement("SrcSrv", typeof(SrcSrvTaskParameters))]
public class SrcSrvTask : CustomTask
{
///
/// Parameters for this task
///
SrcSrvTaskParameters Parameters;
///
/// Construct a spawn task
///
/// Parameters for the task
public SrcSrvTask(SrcSrvTaskParameters 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
[SupportedOSPlatform("windows")]
public override void Execute(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet)
{
FileReference[] BinaryFiles = ResolveFilespec(Unreal.RootDirectory, Parameters.BinaryFiles, TagNameToFileSet).ToArray();
FileReference[] SourceFiles = ResolveFilespec(Unreal.RootDirectory, Parameters.SourceFiles, TagNameToFileSet).ToArray();
Execute(BinaryFiles, SourceFiles, Parameters.Branch, Parameters.Change, Parameters.VFSMapping);
}
[SupportedOSPlatform("windows")]
internal static void Execute(FileReference[] BinaryFiles, FileReference[] SourceFiles, string Branch, int Change, string VFSMapping)
{
IEnumerable PdbFiles = BinaryFiles.Where(x => x.HasExtension(".pdb"));
Win64Platform WindowsPlatform = Platform.GetPlatform(UnrealTargetPlatform.Win64) as Win64Platform;
WindowsPlatform.AddSourceIndexToSymbols(PdbFiles, SourceFiles, Branch, Change, VFSMapping);
}
///
/// 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()
{
foreach(string TagName in FindTagNamesFromFilespec(Parameters.BinaryFiles))
{
yield return TagName;
}
foreach(string TagName in FindTagNamesFromFilespec(Parameters.SourceFiles))
{
yield return TagName;
}
}
///
/// 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;
}
}
public static partial class BgStateExtensions
{
///
/// Add source indexing information to symbol files (PDB).
///
///
/// List of output files. PDBs will be extracted from this list.
/// List of source files to index and embed into the PDBs.
/// Branch to base all the depot source files from.
/// Changelist to sync files from.
/// List of Virtual File System transformations to apply to paths during source code indexing. Pass an empty string if no transformations are needed
/// e.g. when VFS was not used when compiling binaries. Check description of SrcSrvTaskParameters.VFSMapping for details about the expected syntax.
///
[SupportedOSPlatform("windows")]
public static void SrcSrv(this BgContext State, HashSet BinaryFiles, HashSet SourceFiles, string Branch, int Change, string VFSMapping)
{
SrcSrvTask.Execute(BinaryFiles.ToArray(), SourceFiles.ToArray(), Branch, Change, VFSMapping);
}
}
}