2018-12-14 13:41:00 -05:00
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
2016-12-08 08:52:44 -05:00
using AutomationTool ;
2016-05-18 13:26:45 -04:00
using UnrealBuildTool ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.IO ;
2017-08-31 12:08:38 -04:00
using Tools.DotNETCommon ;
2016-05-18 13:26:45 -04:00
public class BuildDerivedDataCache : BuildCommand
{
public override void ExecuteBuild ( )
{
// Get the list of platform names
string [ ] FeaturePacks = ParseParamValue ( "FeaturePacks" ) . Split ( ';' ) ;
string TempDir = ParseParamValue ( "TempDir" ) ;
2018-10-05 11:15:17 -04:00
UnrealTargetPlatform HostPlatform = BuildHostPlatform . Current . Platform ;
2016-05-18 13:26:45 -04:00
string TargetPlatforms = ParseParamValue ( "TargetPlatforms" ) ;
string SavedDir = ParseParamValue ( "SavedDir" ) ;
2018-10-16 17:26:31 -04:00
string BackendName = ParseParamValue ( "BackendName" , "CreateInstalledEnginePak" ) ;
string RelativePakPath = ParseParamValue ( "RelativePakPath" , "Engine/DerivedDataCache/Compressed.ddp" ) ;
bool bSkipEngine = ParseParam ( "SkipEngine" ) ;
2016-05-18 13:26:45 -04:00
// Get paths to everything within the temporary directory
2016-08-18 20:28:33 -04:00
string EditorExe = CommandUtils . GetEditorCommandletExe ( TempDir , HostPlatform ) ;
2016-05-18 13:26:45 -04:00
string OutputPakFile = CommandUtils . CombinePaths ( TempDir , RelativePakPath ) ;
string OutputCsvFile = Path . ChangeExtension ( OutputPakFile , ".csv" ) ;
List < string > ProjectPakFiles = new List < string > ( ) ;
List < string > FeaturePackPaths = new List < string > ( ) ;
// loop through all the projects first and bail out if one of them doesn't exist.
foreach ( string FeaturePack in FeaturePacks )
{
2016-07-13 09:16:28 -04:00
if ( ! String . IsNullOrWhiteSpace ( FeaturePack ) )
2016-05-18 13:26:45 -04:00
{
2016-07-13 09:16:28 -04:00
string FeaturePackPath = CommandUtils . CombinePaths ( CommandUtils . RootDirectory . FullName , FeaturePack ) ;
if ( ! CommandUtils . FileExists ( FeaturePackPath ) )
{
throw new AutomationException ( "Could not find project: " + FeaturePack ) ;
}
FeaturePackPaths . Add ( FeaturePackPath ) ;
2016-05-18 13:26:45 -04:00
}
}
// loop through all the paths and generate ddc data for them
foreach ( string FeaturePackPath in FeaturePackPaths )
{
2016-08-18 20:28:33 -04:00
string ProjectSpecificPlatforms = TargetPlatforms ;
2016-05-18 13:26:45 -04:00
FileReference FileRef = new FileReference ( FeaturePackPath ) ;
string GameName = FileRef . GetFileNameWithoutAnyExtensions ( ) ;
2017-08-31 12:08:38 -04:00
ProjectDescriptor Project = ProjectDescriptor . FromFile ( FileRef ) ;
2016-05-18 13:26:45 -04:00
2016-08-18 20:28:33 -04:00
if ( Project . TargetPlatforms ! = null & & Project . TargetPlatforms . Length > 0 )
{
// Restrict target platforms used to those specified in project file
List < string > FilteredPlatforms = new List < string > ( ) ;
// Always include the editor platform for cooking
string EditorCookPlatform = Platform . GetPlatform ( HostPlatform ) . GetEditorCookPlatform ( ) ;
if ( TargetPlatforms . Contains ( EditorCookPlatform ) )
{
FilteredPlatforms . Add ( EditorCookPlatform ) ;
}
foreach ( string TargetPlatform in Project . TargetPlatforms )
{
if ( TargetPlatforms . Contains ( TargetPlatform ) )
{
FilteredPlatforms . Add ( TargetPlatform ) ;
}
}
2018-10-05 11:15:17 -04:00
if ( FilteredPlatforms . Count = = 0 )
{
LogInformation ( "Did not find any project specific platforms for FeaturePack {0} out of supplied TargetPlatforms {1}, skipping it!" , GameName , ProjectSpecificPlatforms ) ;
continue ;
}
2016-08-18 20:28:33 -04:00
ProjectSpecificPlatforms = CommandUtils . CombineCommandletParams ( FilteredPlatforms . Distinct ( ) . ToArray ( ) ) ;
}
2018-08-14 18:32:34 -04:00
CommandUtils . LogInformation ( "Generating DDC data for {0} on {1}" , GameName , ProjectSpecificPlatforms ) ;
2018-10-16 17:26:31 -04:00
CommandUtils . DDCCommandlet ( FileRef , EditorExe , null , ProjectSpecificPlatforms , String . Format ( "-fill -DDC={0} -ProjectOnly" , BackendName ) ) ;
2016-05-18 13:26:45 -04:00
string ProjectPakFile = CommandUtils . CombinePaths ( Path . GetDirectoryName ( OutputPakFile ) , String . Format ( "Compressed-{0}.ddp" , GameName ) ) ;
CommandUtils . DeleteFile ( ProjectPakFile ) ;
CommandUtils . RenameFile ( OutputPakFile , ProjectPakFile ) ;
string ProjectCsvFile = Path . ChangeExtension ( ProjectPakFile , ".csv" ) ;
CommandUtils . DeleteFile ( ProjectCsvFile ) ;
CommandUtils . RenameFile ( OutputCsvFile , ProjectCsvFile ) ;
ProjectPakFiles . Add ( Path . GetFileName ( ProjectPakFile ) ) ;
}
// Generate DDC for the editor, and merge all the other PAK files in
2018-08-14 18:32:34 -04:00
CommandUtils . LogInformation ( "Generating DDC data for engine content on {0}" , TargetPlatforms ) ;
2018-10-16 17:26:31 -04:00
CommandUtils . DDCCommandlet ( null , EditorExe , null , TargetPlatforms , String . Format ( "-fill -DDC={0} -MergePaks={1}{2}" , BackendName , CommandUtils . MakePathSafeToUseWithCommandLine ( String . Join ( "+" , ProjectPakFiles ) ) , bSkipEngine ? " -projectonly" : "" ) ) ;
2016-05-18 13:26:45 -04:00
string SavedPakFile = CommandUtils . CombinePaths ( SavedDir , RelativePakPath ) ;
CommandUtils . CopyFile ( OutputPakFile , SavedPakFile ) ;
}
}