2021-12-16 13:55:22 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2024-05-22 13:17:22 -04:00
using System ;
using System.Collections.Generic ;
using System.Threading.Tasks ;
using AutomationTool.Tasks ;
2021-12-16 13:55:22 -05:00
using EpicGames.BuildGraph ;
using EpicGames.BuildGraph.Expressions ;
2024-05-22 13:17:22 -04:00
using EpicGames.Core ;
2023-03-07 21:23:47 -05:00
using Microsoft.Extensions.Logging ;
2024-05-22 13:17:22 -04:00
using UnrealBuildBase ;
using UnrealBuildTool ;
using static AutomationTool . Tasks . StandardTasks ;
2021-12-16 13:55:22 -05:00
#nullable enable
namespace AutomationTool
{
class InstalledBuild : BgGraphBuilder
{
static FileSet Workspace { get ; } = FileSet . FromDirectory ( Unreal . RootDirectory ) ;
static DirectoryReference RootDir { get ; } = new DirectoryReference ( CommandUtils . CmdEnv . LocalRoot ) ;
static DirectoryReference IntermediateDir = > DirectoryReference . Combine ( RootDir , "Engine" , "Intermediate" , "Installed" ) ;
static DirectoryReference TempMiscDir = > DirectoryReference . Combine ( IntermediateDir , "General" ) ;
static DirectoryReference TempCsToolsDir = > DirectoryReference . Combine ( IntermediateDir , "CsTools" ) ;
2024-05-22 13:17:22 -04:00
static DirectoryReference TempDdcDir = > DirectoryReference . Combine ( IntermediateDir , "DDC" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
// static string[] PluginsExceptions =
// {
// "Engine/Plugins/Enterprise/DatasmithCADImporter/...",
// "Engine/Plugins/Enterprise/DatasmithC4DImporter/...",
// "Engine/Plugins/Enterprise/AxFImporter/...",
// "Engine/Plugins/Enterprise/MDLImporter/..."
// };
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
// static string[] WinSignFilter =
// {
// "*.exe",
// "*.dll"
// };
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
static readonly string [ ] s_winStripFilter =
2021-12-16 13:55:22 -05:00
{
"*.pdb" ,
"-/Engine/Binaries/Win64/UnrealEditor*.pdb" ,
"-/Engine/Plugins/.../Binaries/Win64/UnrealEditor*.pdb" ,
} ;
2024-05-22 13:17:22 -04:00
static List < string > GetDdcProjects ( UnrealTargetPlatform platform )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
List < string > projects = new List < string > ( ) ;
projects . Add ( "Templates/TP_AEC_ArchvisBP/TP_AEC_ArchvisBP.uproject" ) ;
projects . Add ( "Templates/TP_AEC_BlankBP/TP_AEC_BlankBP.uproject" ) ;
projects . Add ( "Templates/TP_AEC_CollabBP/TP_AEC_CollabBP.uproject" ) ;
projects . Add ( "Templates/TP_AEC_ProdConfigBP/TP_AEC_ProdConfigBP.uproject" ) ;
projects . Add ( "Templates/TP_FirstPersonBP/TP_FirstPersonBP.uproject" ) ;
projects . Add ( "Templates/TP_HandheldARBP/TP_HandheldARBP.uproject" ) ;
projects . Add ( "Templates/TP_AEC_HandheldARBP/TP_AEC_HandheldARBP.uproject" ) ;
projects . Add ( "Templates/TP_MFG_HandheldARBP/TP_MFG_HandheldARBP.uproject" ) ;
projects . Add ( "Templates/TP_MFG_CollabBP/TP_MFG_CollabBP.uproject" ) ;
projects . Add ( "Templates/TP_MFG_ProdConfigBP/TP_MFG_ProdConfigBP.uproject" ) ;
projects . Add ( "Templates/TP_PhotoStudioBP/TP_PhotoStudioBP.uproject" ) ;
projects . Add ( "Templates/TP_PuzzleBP/TP_PuzzleBP.uproject" ) ;
projects . Add ( "Templates/TP_ThirdPersonBP/TP_ThirdPersonBP.uproject" ) ;
projects . Add ( "Templates/TP_TopDownBP/TP_TopDownBP.uproject" ) ;
projects . Add ( "Templates/TP_VehicleAdvBP/TP_VehicleAdvBP.uproject" ) ;
projects . Add ( "Templates/TP_VirtualRealityBP/TP_VirtualRealityBP.uproject" ) ;
projects . Add ( "Templates/TP_DMXBP/TP_DMXBP.uproject" ) ;
2024-03-07 22:10:07 -05:00
// Projects.Add("Samples/StarterContent/StarterContent.uproject");
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
if ( platform = = UnrealTargetPlatform . Win64 )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
projects . Add ( "Templates/TP_InCamVFXBP/TP_InCamVFXBP.uproject" ) ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
return projects ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
public override BgGraph CreateGraph ( BgEnvironment context )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
string rootDir = CommandUtils . CmdEnv . LocalRoot ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgBoolOption hostPlatformOnly = new BgBoolOption ( "HostPlatformOnly" , "A helper option to make an installed build for your host platform only, so that you don't have to disable each platform individually" , false ) ;
BgBoolOption hostPlatformEditorOnly = new BgBoolOption ( "HostPlatformEditorOnly" , "A helper option to make an installed build for your host platform only, so that you don't have to disable each platform individually" , false ) ;
BgBoolOption allPlatforms = new BgBoolOption ( "AllPlatforms" , "Include all target platforms by default" , false ) ;
BgBoolOption compileDatasmithPlugins = new BgBoolOption ( "CompileDatasmithPlugins" , "If Datasmith plugins should be compiled on a separate node." , false ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
UnrealTargetPlatform currentHostPlatform = HostPlatform . Current . HostEditorPlatform ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgBool defaultWithWin64 = ! ( hostPlatformEditorOnly | ( hostPlatformOnly & ( currentHostPlatform ! = UnrealTargetPlatform . Win64 ) ) ) ;
BgBool defaultWithMac = ! ( hostPlatformEditorOnly | ( hostPlatformOnly & ( currentHostPlatform ! = UnrealTargetPlatform . Mac ) ) ) ;
BgBool defaultWithLinux = ! ( hostPlatformEditorOnly | ( hostPlatformOnly & ( currentHostPlatform ! = UnrealTargetPlatform . Linux ) ) ) ;
BgBool defaultWithLinuxArm64 = ! ( hostPlatformEditorOnly | ( hostPlatformOnly & ( currentHostPlatform ! = UnrealTargetPlatform . Linux ) ) ) ;
BgBool defaultWithPlatform = ! ( hostPlatformEditorOnly | hostPlatformOnly ) ;
BgBool defaultWithIos = ! ( ( currentHostPlatform ! = UnrealTargetPlatform . Mac ) & ! allPlatforms ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgBoolOption withWin64 = new BgBoolOption ( "WithWin64" , "Include the Win64 target platform" , defaultWithWin64 ) ;
BgBoolOption withMac = new BgBoolOption ( "WithMac" , "Include the Mac target platform" , defaultWithMac ) ;
BgBoolOption withAndroid = new BgBoolOption ( "WithAndroid" , "Include the Android target platform" , defaultWithPlatform ) ;
BgBoolOption withIos = new BgBoolOption ( "WithIOS" , "Include the iOS target platform" , defaultWithIos ) ;
BgBoolOption withTvos = new BgBoolOption ( "WithTVOS" , "Include the tvOS target platform" , defaultWithIos ) ;
BgBoolOption withLinux = new BgBoolOption ( "WithLinux" , "Include the Linux target platform" , defaultWithLinux ) ;
BgBoolOption withLinuxArm64 = new BgBoolOption ( "WithLinuxArm64" , "Include the Linux AArch64 target platform" , defaultWithLinuxArm64 ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgBoolOption withClient = new BgBoolOption ( "WithClient" , "Include precompiled client targets" , false ) ;
BgBoolOption withServer = new BgBoolOption ( "WithServer" , "Include precompiled server targets" , false ) ;
BgBoolOption withDdc = new BgBoolOption ( "WithDDC" , "Build a standalone derived-data cache for the engine content and templates" , true ) ;
BgBoolOption hostPlatformDdcOnly = new BgBoolOption ( "HostPlatformDDCOnly" , "Whether to include DDC for the host platform only" , true ) ;
BgBoolOption signExecutables = new BgBoolOption ( "SignExecutables" , "Sign the executables produced where signing is available" , false ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgStringOption analyticsTypeOverride = new BgStringOption ( "AnalyticsTypeOverride" , "Identifier for analytic events to send" , "" ) ;
BgBool embedSrcSrvInfo = new BgBoolOption ( "EmbedSrcSrvInfo" , "Whether to add Source indexing to Windows game apps so they can be added to a symbol server" , false ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgList < BgString > defaultGameConfigurations = BgList < BgString > . Create ( nameof ( UnrealTargetConfiguration . DebugGame ) , nameof ( UnrealTargetConfiguration . Development ) , nameof ( UnrealTargetConfiguration . Shipping ) ) ;
BgList < BgString > gameConfigurationStrings = new BgListOption ( "GameConfigurations" , description : "Which game configurations to include for packaged applications" , style : BgListOptionStyle . CheckList , values : defaultGameConfigurations ) ;
BgList < BgEnum < UnrealTargetConfiguration > > gameConfigurations = gameConfigurationStrings . Select ( x = > BgEnum < UnrealTargetConfiguration > . Parse ( x ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgBoolOption withFullDebugInfo = new BgBoolOption ( "WithFullDebugInfo" , "Generate full debug info for binary editor and packaged application builds" , false ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgStringOption builtDirectory = new BgStringOption ( "BuiltDirectory" , "Directory for outputting the built engine" , rootDir + "/LocalBuilds/Engine" ) ;
2022-06-24 15:18:50 -04:00
2024-05-22 13:17:22 -04:00
BgStringOption crashReporterApiurl = new BgStringOption ( "CrashReporterAPIURL" , "The URL to use to talk to the CrashReporterClient API." , "" ) ;
BgStringOption crashReporterApiKey = new BgStringOption ( "CrashReporterAPIKey" , "The API key to use to talk to the CrashReporterClient API." , "" ) ;
BgStringOption buildId = new BgStringOption ( "BuildId" , "The unique build identifier to associate with this installed build" , "" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgString crashReporterCompileArgs = "" ;
crashReporterCompileArgs = crashReporterCompileArgs . If ( crashReporterApiurl ! = "" & crashReporterApiKey ! = "" , BgString . Format ( "-define:CRC_TELEMETRY_URL=\"{0}\" -define:CRC_TELEMETRY_KEY_DEV=\"{1}\" -define:CRC_TELEMETRY_KEY_RELEASE=\"{1}\" -OverrideBuildEnvironment" , crashReporterApiurl , crashReporterApiKey ) ) ;
2022-06-24 15:18:50 -04:00
2024-05-22 13:17:22 -04:00
List < BgAggregate > aggregates = new List < BgAggregate > ( ) ;
2021-12-16 13:55:22 -05:00
/////// EDITORS ////////////////////////////////////////////////
//// Windows ////
2024-05-22 13:17:22 -04:00
BgAgent editorWin64 = new BgAgent ( "Editor Win64" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode versionFilesNode = editorWin64
2022-07-01 14:47:54 -04:00
. AddNode ( x = > UpdateVersionFilesAsync ( x ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode < BgFileSet > winEditorNode = editorWin64
. AddNode ( x = > CompileUnrealEditorWin64Async ( x , crashReporterCompileArgs , embedSrcSrvInfo , compileDatasmithPlugins , withFullDebugInfo , signExecutables ) )
. Requires ( versionFilesNode ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
aggregates . Add ( new BgAggregate ( "Win64 Editor" , winEditorNode , label : "Editors/Win64" ) ) ;
2021-12-16 13:55:22 -05:00
/////// TARGET PLATFORMS ////////////////////////////////////////////////
//// Win64 ////
2024-05-22 13:17:22 -04:00
BgAgent targetWin64 = new BgAgent ( "Target Win64" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode < BgFileSet > winGame = targetWin64
. AddNode ( x = > CompileUnrealGameWin64Async ( x , gameConfigurations , embedSrcSrvInfo , withFullDebugInfo , signExecutables ) )
. Requires ( versionFilesNode ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
aggregates . Add ( new BgAggregate ( "TargetPlatforms_Win64" , winGame ) ) ;
2021-12-16 13:55:22 -05:00
/////// TOOLS //////////////////////////////////////////////////////////
//// Build Rules ////
2024-05-22 13:17:22 -04:00
BgAgent buildRules = new BgAgent ( "BuildRules" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode rulesAssemblies = buildRules
. AddNode ( x = > CompileRulesAssembliesAsync ( x ) ) ;
2021-12-16 13:55:22 -05:00
//// Win Tools ////
2024-05-22 13:17:22 -04:00
BgAgent toolsGroupWin64 = new BgAgent ( "Tools Group Win64" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode < BgFileSet > winTools = toolsGroupWin64
. AddNode ( x = > BuildToolsWin64Async ( x , crashReporterCompileArgs ) )
. Requires ( versionFilesNode ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode < BgFileSet > csTools = toolsGroupWin64
. AddNode ( x = > BuildToolsCsAsync ( x , signExecutables ) )
. Requires ( versionFilesNode ) ;
2021-12-16 13:55:22 -05:00
/////// DDC //////////////////////////////////////////////////////////
2024-05-22 13:17:22 -04:00
BgAgent ddcGroupWin64 = new BgAgent ( "DDC Group Win64" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgList < BgString > ddcPlatformsWin64 = BgList < BgString > . Create ( "WindowsEditor" ) ;
ddcPlatformsWin64 = ddcPlatformsWin64 . If ( withWin64 , x = > x . Add ( "Windows" ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode ddcNode = ddcGroupWin64
. AddNode ( x = > BuildDdcWin64Async ( x , ddcPlatformsWin64 , BgList < BgFileSet > . Create ( winEditorNode . Output , winTools . Output ) ) )
. Requires ( winEditorNode , winTools ) ;
2021-12-16 13:55:22 -05:00
/////// STAGING ///////
// Windows
2024-05-22 13:17:22 -04:00
BgAgent winStageAgent = new BgAgent ( "Installed Build Group Win64" , "Win64_Licensee" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgList < BgFileSet > winInstalledFiles = BgList < BgFileSet > . Empty ;
winInstalledFiles = winInstalledFiles . Add ( winEditorNode . Output ) ;
winInstalledFiles = winInstalledFiles . Add ( winTools . Output ) ;
winInstalledFiles = winInstalledFiles . Add ( csTools . Output ) ;
winInstalledFiles = winInstalledFiles . If ( withWin64 , x = > x . Add ( winGame . Output ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgList < BgString > winPlatforms = BgList < BgString > . Empty ;
winPlatforms = winPlatforms . If ( withWin64 , x = > x . Add ( "Win64" ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgList < BgString > winContentOnlyPlatforms = BgList < BgString > . Empty ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgString winOutputDir = "LocalBuilds/Engine/Windows" ;
BgString winFinalizeArgs = BgString . Format ( "-OutputDir=\"{0}\" -Platforms={1} -ContentOnlyPlatforms={2}" , winOutputDir , BgString . Join ( ";" , winPlatforms ) , BgString . Join ( ";" , winContentOnlyPlatforms ) ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
BgNode winInstalledNode = winStageAgent
. AddNode ( x = > MakeInstalledBuildWin64Async ( x , winInstalledFiles , winFinalizeArgs , winOutputDir ) )
. Requires ( winInstalledFiles ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
aggregates . Add ( new BgAggregate ( "HostPlatforms_Win64" , winInstalledNode , label : "Builds/Win64" ) ) ;
2022-06-24 15:18:50 -04:00
2024-05-22 13:17:22 -04:00
return new BgGraph ( BgList < BgNode > . Empty , aggregates ) ;
2021-12-16 13:55:22 -05:00
}
/// <summary>
/// Update the build version
/// </summary>
2024-05-22 13:17:22 -04:00
static async Task UpdateVersionFilesAsync ( BgContext state )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
if ( state . IsBuildMachine )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
await SetVersionAsync ( state . Change , state . Stream . Replace ( '/' , '+' ) ) ;
2021-12-16 13:55:22 -05:00
}
}
/// <summary>
/// Builds the Windows editor
/// </summary>
[BgNodeName("Compile UnrealEditor Win64")]
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > CompileUnrealEditorWin64Async ( BgContext state , BgString crashReporterCompileArgs , BgBool embedSrcSrvInfo , BgBool compileDatasmithPlugins , BgBool withFullDebugInfo , BgBool signExecutables )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
_ = compileDatasmithPlugins ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
FileSet outputFiles = FileSet . Empty ;
outputFiles + = await CompileAsync ( "UnrealEditor" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . DebugGame , arguments : $"-precompile -allmodules {state.Get(crashReporterCompileArgs)}" ) ;
outputFiles + = await CompileAsync ( "UnrealEditor" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development , arguments : $"-precompile -allmodules {state.Get(crashReporterCompileArgs)}" ) ;
if ( state . Get ( embedSrcSrvInfo ) )
2021-12-16 13:55:22 -05:00
{
// Embed source info into the PDB files. Should be done from this machine to ensure that paths are correct.
2023-03-08 12:43:35 -05:00
Logger . LogInformation ( "Embedding source file information into PDB files..." ) ;
2024-05-22 13:17:22 -04:00
FileSet sourceFiles = Workspace . Filter ( "Engine/Source/...;Engine/Plugins/..." ) . Except ( "Engine/Source/ThirdParty/..." ) . Filter ( "*.c;*.h;*.cpp;*.hpp;*.inl" ) ;
// State.SrcSrv(BinaryFiles: Full, SourceFiles: SourceFiles);
_ = sourceFiles ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
if ( ! state . Get ( withFullDebugInfo ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
FileSet unstrippedFiles = outputFiles . Filter ( s_winStripFilter ) ;
outputFiles + = await StripAsync ( unstrippedFiles , UnrealTargetPlatform . Win64 , baseDir : RootDir , outputDir : TempMiscDir ) ;
outputFiles - = unstrippedFiles ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
if ( state . Get ( signExecutables ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
// FileSet UnsignedFiles = OutputFiles.Filter(WinSignFilter);
// FileSet FilesToCopy = UnsignedFiles.Except((new HashSet<FileReference>(UnsignedFiles.Where(x => !x.IsUnderDirectory(TempMiscDir)));
// UnsignedFiles += State.Copy(FilesToCopy.Flatten(TempMiscDir));
// UnsignedFiles.Sign();
// OutputFiles -= FilesToCopy;
// OutputFiles += UnsignedFiles;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
return outputFiles ;
2021-12-16 13:55:22 -05:00
}
/// <summary>
/// Builds the game target
/// </summary>
[BgNodeName("Compile UnrealGame Win64")]
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > CompileUnrealGameWin64Async ( BgContext state , BgList < BgEnum < UnrealTargetConfiguration > > configurations , BgBool embedSrcSrvInfo , BgBool withFullDebugInfo , BgBool signExecutables )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
_ = embedSrcSrvInfo ;
_ = withFullDebugInfo ;
_ = signExecutables ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
FileSet files = FileSet . Empty ;
List < UnrealTargetConfiguration > configurationsValue = state . Get ( configurations ) ;
foreach ( UnrealTargetConfiguration configuration in configurationsValue )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
files + = await CompileAsync ( "UnrealGame" , UnrealTargetPlatform . Win64 , configuration , arguments : "-precompile -allmodules -nolink" ) ;
files + = await CompileAsync ( "UnrealGame" , UnrealTargetPlatform . Win64 , configuration , arguments : "-precompile" , clean : false ) ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
return files ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > CompileRulesAssembliesAsync ( BgContext state )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
_ = state ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
FileReference unrealBuildToolDll = FileReference . Combine ( RootDir , "Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll" ) ;
await SpawnAsync ( Unreal . DotnetPath . FullName , arguments : $"\" { unrealBuildToolDll } \ " -Mode=QueryTargets" ) ;
2021-12-16 13:55:22 -05:00
return Workspace . Filter ( "Engine/Intermediate/Build/BuildRules/..." ) ;
}
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > BuildToolsWin64Async ( BgContext state , BgString crashReporterCompileArgs )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
string crashReportClientArgs = state . Get ( crashReporterCompileArgs ) ;
2021-12-16 13:55:22 -05:00
// State.Tag(Files: "#NotForLicensee Build Tools Win64", With: Files);
2024-05-22 13:17:22 -04:00
FileSet files = FileSet . Empty ;
files + = await CompileAsync ( "CrashReportClient" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Shipping , arguments : crashReportClientArgs ) ;
files + = await CompileAsync ( "CrashReportClientEditor" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Shipping , arguments : crashReportClientArgs ) ;
files + = await CompileAsync ( "ShaderCompileWorker" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "EpicWebHelper" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealInsights" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealFrontend" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealLightmass" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "InterchangeWorker" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealPak" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealMultiUserServer" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "UnrealRecoverySvc" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "LiveCodingConsole" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = await CompileAsync ( "BootstrapPackagedGame" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Shipping ) ;
files + = await CompileAsync ( "BuildPatchTool" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Shipping ) ;
files + = await CompileAsync ( "SwitchboardListener" , UnrealTargetPlatform . Win64 , UnrealTargetConfiguration . Development ) ;
files + = FileSet . FromFile ( RootDir , "Engine/Binaries/Win64/XGEControlWorker.exe" ) ;
files + = FileSet . FromFile ( RootDir , "Engine/Saved/UnrealBuildTool/BuildConfiguration.Schema.xsd" ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
return files ;
2021-12-16 13:55:22 -05:00
}
[BgNodeName("Build Tools CS")]
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > BuildToolsCsAsync ( BgContext state , BgBool signExecutables )
2021-12-16 13:55:22 -05:00
{
FileUtils . ForceDeleteDirectory ( TempCsToolsDir ) ;
// Copy Source and referenced libraries to a new location with Confidential folders removed
2024-05-22 13:17:22 -04:00
FileSet uatProjects = Workspace . Filter ( "Engine/Source/Programs/AutomationTool/....csproj" ) ;
_ = uatProjects ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
FileSet redistUatSource = Workspace . Filter ( "Engine/Binaries/DotNET/...;Engine/Binaries/ThirdParty/Newtonsoft/...;Engine/Binaries/ThirdParty/IOS/...;Engine/Binaries/ThirdParty/VisualStudio/...;Engine/Source/Programs/...;Engine/Platforms/*/Source/Programs/...;Engine/Source/Editor/SwarmInterface/..." ) ;
await redistUatSource . CopyToAsync ( Unreal . RootDirectory ) ;
2021-12-16 13:55:22 -05:00
// Compile all the tools
2024-05-22 13:17:22 -04:00
CsCompileOutput output = CsCompileOutput . Empty ;
2021-12-16 13:55:22 -05:00
if ( HostPlatform . Current . HostEditorPlatform = = UnrealTargetPlatform . Win64 )
{
2024-05-22 13:17:22 -04:00
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Programs/UnrealSwarm/SwarmCoordinator/SwarmCoordinator.csproj" ) , platform : "AnyCPU" , configuration : "Development" ) ;
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Programs/UnrealSwarm/Agent/Agent.csproj" ) , platform : "AnyCPU" , configuration : "Development" ) ;
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Editor/SwarmInterface/DotNET/SwarmInterface.csproj" ) , platform : "AnyCPU" , configuration : "Development" ) ;
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Programs/UnrealControls/UnrealControls.csproj" ) , platform : "AnyCPU" , configuration : "Development" ) ;
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Programs/IOS/iPhonePackager/iPhonePackager.csproj" ) , platform : "AnyCPU" , configuration : "Development" , arguments : "/verbosity:minimal /target:Rebuild" ) ;
output + = await CsCompileAsync ( FileReference . Combine ( TempCsToolsDir , "Engine/Source/Programs/NetworkProfiler/NetworkProfiler/NetworkProfiler.csproj" ) , platform : "AnyCPU" , configuration : "Development" ) ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
FileSet binaries = output . Binaries + output . References ;
2021-12-16 13:55:22 -05:00
// Tag AutomationTool and UnrealBuildTool folders recursively as NET Core dependencies are not currently handled by CsCompile
2024-05-22 13:17:22 -04:00
binaries + = FileSet . FromDirectory ( TempCsToolsDir ) . Filter ( "Engine/Binaries/DotNET/AutomationTool/..." ) ;
binaries + = FileSet . FromDirectory ( TempCsToolsDir ) . Filter ( "Engine/Binaries/DotNET/UnrealBuildTool/..." ) ;
2021-12-16 13:55:22 -05:00
// Tag AutomationTool Script module build records, so that prebuilt modules may be discovered in the absence of source code
2024-05-22 13:17:22 -04:00
binaries + = FileSet . FromDirectory ( TempCsToolsDir ) . Filter ( "Engine/Intermediate/ScriptModules/..." ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
if ( state . Get ( signExecutables ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
// Binaries.Sign();
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
return binaries ;
2021-12-16 13:55:22 -05:00
}
/// <summary>
/// Creates a DDC pack file for the supported platforms
/// </summary>
[BgNodeName("Build DDC Win64")]
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > BuildDdcWin64Async ( BgContext state , BgList < BgString > platforms , BgList < BgFileSet > dependencies )
2021-12-16 13:55:22 -05:00
{
// Build up a list of files needed to build DDC
2024-05-22 13:17:22 -04:00
FileSet toCopy = state . Get ( dependencies ) ;
toCopy + = await CsCompileAsync ( FileReference . Combine ( RootDir , "Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj" ) , platform : "AnyCPU" , configuration : "Development" , enumerateOnly : true ) . MergeAsync ( ) ;
toCopy + = await toCopy . Filter ( "*.target" ) . TagReceiptsAsync ( runtimeDependencies : true ) ;
toCopy + = FileSet . FromFile ( RootDir , "Engine/Binaries/DotNET/Ionic.Zip.Reduced.dll" ) ;
toCopy + = FileSet . FromFile ( RootDir , "Engine/Binaries/DotNET/OneSky.dll" ) ;
toCopy + = FileSet . FromDirectory ( RootDir ) . Filter ( "Templates/TemplateResources/..." ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
foreach ( DirectoryReference extensionDir in Unreal . GetExtensionDirs ( Unreal . EngineDirectory ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
toCopy + = FileSet . FromDirectory ( extensionDir ) . Filter ( "Content/..." ) . Except ( "....psd;....pdn;....fbx;....po" ) ;
toCopy + = FileSet . FromDirectory ( extensionDir ) . Filter ( "Config/..." ) . Except ( "....vdf" ) ;
toCopy + = FileSet . FromDirectory ( extensionDir ) . Filter ( "Shaders/..." ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
DirectoryReference extensionPluginsDir = DirectoryReference . Combine ( extensionDir , "Plugins" ) ;
toCopy + = FileSet . FromDirectory ( extensionPluginsDir ) . Filter ( "....uplugin;.../Config/...;.../Content/...;.../Resources/...;.../Shaders/...;.../Templates/..." ) . Except ( ".../TwitchLiveStreaming/..." ) ;
2021-12-16 13:55:22 -05:00
}
// Filter out the files not needed to build DDC. Removing confidential folders can affect DDC keys, so we want to be sure that we're making DDC with a build that can use it.
2024-05-22 13:17:22 -04:00
FileSet filteredCopyList = toCopy . Except ( ".../Source/...;.../Intermediate/..." ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
Dictionary < FileReference , FileReference > targetFileToSourceFile = new Dictionary < FileReference , FileReference > ( ) ;
MapFilesToOutputDir ( filteredCopyList , TempDdcDir , targetFileToSourceFile ) ;
2021-12-16 13:55:22 -05:00
FileUtils . ForceDeleteDirectoryContents ( TempDdcDir ) ;
2024-05-22 13:17:22 -04:00
await filteredCopyList . CopyToAsync ( TempDdcDir ) ;
2021-12-16 13:55:22 -05:00
// Run the DDC commandlet
2024-05-22 13:17:22 -04:00
List < string > arguments = new List < string > ( ) ;
arguments . Add ( $"-TempDir=\" { TempDdcDir } \ "" ) ;
arguments . Add ( $"-FeaturePacks=\" { String . Join ( ";" , GetDdcProjects ( UnrealTargetPlatform . Win64 ) ) } \ "" ) ;
arguments . Add ( $"-TargetPlatforms={String.Join(" + ", state.Get(platforms))}" ) ;
arguments . Add ( $"-HostPlatform=Win64" ) ;
await state . CommandAsync ( "BuildDerivedDataCache" , arguments : String . Join ( " " , arguments ) ) ;
2021-12-16 13:55:22 -05:00
// Return a tag for the output file
return FileSet . FromFile ( TempDdcDir , "Engine/DerivedDataCache/Compressed.ddp" ) ;
}
/// <summary>
/// Copy all the build artifacts to the output folder
/// </summary>
[BgNodeName("Make Installed Build Win64")]
2024-05-22 13:17:22 -04:00
static async Task < BgFileSet > MakeInstalledBuildWin64Async ( BgContext state , BgList < BgFileSet > inputFiles , BgString finalizeArgs , BgString outputDir )
2021-12-16 13:55:22 -05:00
{
// Find all the input files, and add any runtime dependencies from the receipts into the list
2024-05-22 13:17:22 -04:00
FileSet sourceFiles = state . Get ( inputFiles ) ;
sourceFiles + = await sourceFiles . Filter ( "*.target" ) . TagReceiptsAsync ( runtimeDependencies : true ) ;
2021-12-16 13:55:22 -05:00
// Include any files referenced by dependency lists
2024-05-22 13:17:22 -04:00
FileSet dependencyListFiles = sourceFiles . Filter ( ".../DependencyList.txt;.../DependencyList-AllModules.txt" ) ;
foreach ( FileReference dependencyListFile in dependencyListFiles )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
string [ ] lines = await FileReference . ReadAllLinesAsync ( dependencyListFile ) ;
foreach ( string line in lines )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
string trimLine = line . Trim ( ) ;
if ( trimLine . Length > 0 )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
sourceFiles + = FileSet . FromFile ( Unreal . RootDirectory , trimLine ) ;
2021-12-16 13:55:22 -05:00
}
}
}
2024-05-22 13:17:22 -04:00
sourceFiles - = dependencyListFiles ;
2021-12-16 13:55:22 -05:00
// Clear the output directory
2024-05-22 13:17:22 -04:00
DirectoryReference outputDirRef = new DirectoryReference ( state . Get ( outputDir ) ) ;
FileUtils . ForceDeleteDirectoryContents ( outputDirRef ) ;
FileSet installedFiles = await sourceFiles . CopyToAsync ( outputDirRef ) ;
2021-12-16 13:55:22 -05:00
// Run the finalize command
2024-05-22 13:17:22 -04:00
await state . CommandAsync ( "FinalizeInstalledBuild" , arguments : state . Get ( finalizeArgs ) ) ;
2021-12-16 13:55:22 -05:00
// Get the final list of files
2024-05-22 13:17:22 -04:00
installedFiles + = FileSet . FromFile ( outputDirRef , "Engine/Build/InstalledEngine.txt" ) ;
2021-12-16 13:55:22 -05:00
// Sanitize any receipts in the output directory
2024-05-22 13:17:22 -04:00
await installedFiles . Filter ( "*.target" ) . SanitizeReceiptsAsync ( ) ;
2021-12-16 13:55:22 -05:00
2024-05-22 13:17:22 -04:00
return installedFiles ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
static void MapFilesToOutputDir ( IEnumerable < FileReference > sourceFiles , DirectoryReference targetDir , Dictionary < FileReference , FileReference > targetFileToSourceFile )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
foreach ( FileReference sourceFile in sourceFiles )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
DirectoryReference baseDir ;
if ( sourceFile . IsUnderDirectory ( TempCsToolsDir ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
baseDir = TempCsToolsDir ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
else if ( sourceFile . IsUnderDirectory ( TempMiscDir ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
baseDir = TempMiscDir ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
else if ( sourceFile . IsUnderDirectory ( TempDdcDir ) )
2021-12-16 13:55:22 -05:00
{
2024-05-22 13:17:22 -04:00
baseDir = TempDdcDir ;
2021-12-16 13:55:22 -05:00
}
else
{
2024-05-22 13:17:22 -04:00
baseDir = Unreal . RootDirectory ;
2021-12-16 13:55:22 -05:00
}
2024-05-22 13:17:22 -04:00
FileReference targetFile = FileReference . Combine ( targetDir , sourceFile . MakeRelativeTo ( baseDir ) ) ;
targetFileToSourceFile [ targetFile ] = sourceFile ;
2021-12-16 13:55:22 -05:00
}
}
}
}