<?xml version='1.0' ?>
<BuildGraph xmlns="http://www.epicgames.com/BuildGraph" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.epicgames.com/BuildGraph ../../../../Engine/Build/Graph/Schema.xsd" >

	<!-- TODO NDarnell Add documentation -->
	<!-- "-Target=BuildAndTestInternalExtended Lyra" -->


	<!-- Project Info -->
	<!-- @TODO: Can we derive these somehow instead of hardcoding them? Will be an issue when turned into a launcher sample. -->
	<Property Name="ProjectName" Value="Lyra" />
	<Property Name="ProjectPath" Value="Samples/Games/Lyra" />
	<Option Name="TargetName" DefaultValue="LyraGame" Restrict="LyraGame|LyraGameEOS" Description="The project target configuration we're building, like if we're building Lyra with EOS (Epic Online Services) compiled in." />
	

	<Property Name="Versioned" Value="$(IsBuildMachine)" />
	<Property Name="PublishHashedStagingData" Value="$(IsBuildMachine)" />

	<Option Name="UploadArtifactId" DefaultValue="" Description="ID of the artifact to chunked and uploaded. Upload is ignored if no ID is specified." />
	<Option Name="UploadTargetPlatform" DefaultValue="" Description="Platform build to upload, i.e. Win64" />
	<Option Name="UploadConfiguration" DefaultValue="" Description="Configuration to upload, if applicable." />
	<Option Name="UploadLaunchArgs" DefaultValue="" Description="Arguments to be passed when launching the uploaded app."/>

	<Option Name="SkipUpdateAuditCollections" DefaultValue="false" Description="Whether to skip updating the audit collections (showing which files got cooked)" />

	<Option Name="SymbolServerPath" DefaultValue="" Description="A shared symbols server for your office, debugging shipped builds."/>

	<!-- Turn off defaults so we can set out own -->
	<Property Name="WithBATDefaults" Value="false" />

	<!-- Set defaults for people running this script with no arguments. These can still be overriden with -set:TargetPlatforms= etc) -->
	<Property Name="DefaultEditorPlatforms" Value="Win64" />
	<Property Name="DefaultTargetPlatforms" Value="Win64"/>
	<Property Name="DefaultTargetConfigurations" Value="Development" />
	<Property Name="DefaultEditorTestList" Value="UE.EditorAutomation(RunTest=Project.Maps.PIE)" />
	<Property Name="DefaultTargetTestList" Value="" />
	<Property Name="NetworkTempRootOverride" Value="" />
	<Property Name="NetworkPublishRootOverride" Value="" />
	<Property Name="NetworkReportRootOverride" Value="" />

	<!-- If a build machine, turn off all defaults. Settings should be specified via the website UI -->
	<Do If="$(IsBuildMachine)">
		<Property Name="DefaultEditorPlatforms" Value="" />
		<Property Name="DefaultTargetPlatforms" Value=""/>
		<Property Name="DefaultTargetConfigurations" Value="" />
		<Property Name="DefaultEditorTestList" Value="" />
		<Property Name="DefaultTargetTestList" Value="" />
	</Do>
	
	<Property Name="ExtraStageAndPackageArguments" Value="-target=&quot;$(TargetName)&quot; -compressed -CrashReporter" />


	<!-- =============================================================================== -->
	<!-- Setup -->
	<!-- =============================================================================== -->

	<!-- This will declare an aggregate called BuildAndTest Lyra -->
	<Include Script="../../../../Engine/Build/Graph/Tasks/BuildAndTestProject.xml" />

	<!-- Add BuildAndTest project target node as the base requirement.  We append items to BuildAndTestExtendedRequirements, that need to be performed. -->
	<Property Name="BuildAndTestExtendedRequirements" Value="BuildAndTest $(ProjectName)" />

	<!-- =============================================================================== -->
	<!-- CONTENT VALIDATION -->
	<!-- =============================================================================== -->
	
	<Agent Name="Lyra Content Validation" Type="Win64">
		<Node Name="Lyra Content Validation" Requires="Compile $(ProjectName)Editor Win64">
			<Property Name="RefExtensionsTypelist" Value=".uasset,.umap,.cpp,.c,.h,.inl,.ini,.uproject,.uplugin,.json"/>

			<Property Name="CLArgs" Value="-CL=$(Change) -LastGoodContentCLPath=$(NetworkOutputDirectory)/AutoTest/LastGoodContentCL"/>
			<Property Name="CLArgs" Value="-CL=$(PreflightChange) -shelved" If="$(IsPreflight)" />
			<Property Name="CLArgs" Value="-opened" If="!$(IsBuildMachine)" />

			<Property Name="CheckAssetReferencesArgs" Value="-Branch=$(Branch) $(CLArgs) -ExtTypeList=&quot;$(RefExtensionsTypelist)&quot; -MaxPackagesToLoad=3000" />
			<Command Name="LyraContentValidation" Arguments="$(CheckAssetReferencesArgs)"/>
		</Node>
		<Label Category="Test" Name="Content Validation" Requires="Lyra Content Validation" />
	</Agent>

	<Do If="!$(SkipTest)">
		<!-- Append Content Validation to the list of things to do -->
		<Property Name="BuildAndTestExtendedRequirements" Value="$(BuildAndTestExtendedRequirements);Lyra Content Validation"/>
	</Do>

	<!-- =============================================================================== -->
	<!-- LOCALIZATION -->
	<!-- =============================================================================== -->
	<Option Name="SkipLocalization" DefaultValue="false" Description="Should we skip performing a localization gather?"/>
	
	<Do If="!$(SkipLocalization)">

		<Property Name="ProjectsIncludedInLocalization" Value="Game,EngineOverrides"/>
		
		<!-- This an example setup for using either XLoc or Crowdin providers to localize your game. -->
		
		<!-- XLoc Example -->

		<Option Name="XLoc_Server" DefaultValue="" Description="XLoc Server"/>
		<Option Name="XLoc_APIKey" DefaultValue="" Description="XLoc API Key"/>
		<Option Name="XLoc_APISecret" DefaultValue="" Description="XLoc API Secret"/>
		<Option Name="XLoc_LocalizationId" DefaultValue="" Description="XLoc LocalizationId"/>

		<Do If="'$(XLoc_Server)' != '' And '$(XLoc_APIKey)' != '' And '$(XLoc_APISecret)' != '' And '$(XLoc_LocalizationId)' != ''">
			<Agent Name="Localization" Type="Loc;Win64">
				<Node Name="Localize" Requires="Compile $(ProjectName)Editor Win64">
					<Command Name="Localize" Arguments="-LocalizationProvider=XLoc_Sample -UEProjectDirectory=$(ProjectPath) -UEProjectName=$(ProjectName) -LocalizationProjectNames=$(ProjectsIncludedInLocalization) -LocalizationBranch=&quot;$(EscapedBranch)&quot; -Server=&quot;$(XLoc_Server)&quot; -APIKey=&quot;$(XLoc_APIKey)&quot; -APISecret=&quot;$(XLoc_APISecret)&quot; -LocalizationId=&quot;$(XLoc_LocalizationId)&quot;" />
				</Node>
			</Agent>

			<!-- Append Localize to the list of things to do. -->
			<Label Category="Localize" Name="Localize" Requires="Localize" />
			<Property Name="BuildAndTestExtendedRequirements" Value="$(BuildAndTestExtendedRequirements);Localize"/>
		</Do>

		<!-- Crowdin Example -->

		<Option Name="Crowdin_ProjectId" DefaultValue="" Description="Crowdin ProjectId"/>
		<Option Name="Crowdin_AccessToken" DefaultValue="" Description="Crowdin AccessToken"/>

		<Do If="'$(Crowdin_ProjectId)' != '' And '$(Crowdin_AccessToken)' != ''">
			<Agent Name="Localization" Type="Loc;Win64">
				<Node Name="Localize" Requires="Compile $(ProjectName)Editor Win64">
					<Command Name="Localize" Arguments="-LocalizationProvider=Crowdin_Sample -UEProjectDirectory=$(ProjectPath) -UEProjectName=$(ProjectName) -LocalizationProjectNames=$(ProjectsIncludedInLocalization) -LocalizationBranch=&quot;$(EscapedBranch)&quot; -ProjectId=&quot;$(Crowdin_ProjectId)&quot; -AccessToken=&quot;$(Crowdin_AccessToken)&quot;" />
				</Node>
			</Agent>

			<!-- Append Localize to the list of things to do. -->
			<Label Category="Localize" Name="Localize" Requires="Localize" />
			<Property Name="BuildAndTestExtendedRequirements" Value="$(BuildAndTestExtendedRequirements);Localize"/>
		</Do>

	</Do>
	
	<!-- =============================================================================== -->
	<!-- UPDATE ASSET AUDIT COLLECTIONS -->
	<!-- =============================================================================== -->

	<Do If="!$(SkipUpdateAuditCollections) and ContainsItem('$(TargetPlatforms)', 'Win64', '+')">
		<Agent Name="UpdateAuditCollections" Type="Win64">
			<Node Name="UpdateAuditCollections" After="Stage $(TargetName) Win64" Produces="#AuditInCookCollection">
				<Property Name="UpdateAuditCollectionsArgs" Value="" />
				<Copy Files="Manifest_UFSFiles_Win64.txt" From="$(NetworkOutputDirectory)/Windows/Staged" To="$(RootDir)/Engine/Programs/AutomationTool/Saved"/>
				<Command Name="Lyra_UpdateAuditCollections" Arguments="$(UpdateAuditCollectionsArgs)"/>
				<Tag Files="$(RootDir)/$(ProjectPath)/Content/Collections/Audit_InCook.collection" With="#AuditInCookCollection"/>
			</Node>
			<Label Category="Stage" Name="UpdateAuditCollections" Requires="UpdateAuditCollections"/>
		</Agent>
		<!-- Append Update Audit Collections to the list of things to do -->
		<Property Name="BuildAndTestExtendedRequirements" Value="$(BuildAndTestExtendedRequirements);UpdateAuditCollections"/>
	</Do>

	<!-- =============================================================================== -->
	<!-- DEPLOY TO EPIC GAME STORE -->
	<!-- =============================================================================== -->

	<Option Name="EpicGameStore_BuildPackageTool_Credentials_Path" DefaultValue="" Description="Epic Games Store's Build Package File Credentials File Path"/>

	<Do If="'$(UploadArtifactId)' != '' And '$(EpicGameStore_BuildPackageTool_Credentials_Path)' != ''">

		<Warning If="!Exists('$(EpicGameStore_BuildPackageTool_Credentials_Path)')" Message="EpicGameStore BuildPackageTool Credentials File Not Found!" />
		<Warning If="UploadTargetPlatform == ''" Message="You did not specify the 'UploadTargetPlatform' for the deploying to the Epic Game Store." />

		<!-- Declare the property, for some reason I have to do it outside the agent? -->
		<Property Name="UploadNodeName" Value="" />
			
		<Agent Name="Upload $(DisplayTargetName)" Type="Win64">
			<Property Name="PublishNodeName" Value="Publish Staged $(DisplayTargetName) $(UploadTargetPlatform)" />
		
			<!-- Set UploadPlatform since it isn't always the same as the target -->
			<Property Name="UploadPlatform" Value="$(UploadTargetPlatform)" />
			<Property Name="UploadPlatform" Value="Windows" If="'$(UploadTargetPlatform)' == 'Win64'"/>

			<Property Name="UploadNodeName" Value="Upload $(TargetName) $(UploadTargetPlatform)" />
		
			<Node Name="$(UploadNodeName)" Requires="$(PublishNodeName)">
				<Property Name="ConfigurationSuffix" Value="" />
				<Property Name="ConfigurationSuffix" Value="-$(UploadTargetPlatform)-$(UploadConfiguration)" If="'$(UploadConfiguration)' != 'Development' and '$(UploadConfiguration)' != ''" />	
				<Property Name="Launch" Value="$(ProjectName)/Binaries/$(UploadTargetPlatform)/$(TargetName)$(ConfigurationSuffix).exe"/>

				<!-- Copy published files to local agent and tag them for upload -->
				<Copy From="$(NetworkOutputDirectory)/$(UploadPlatform)/Staged/..." To="$(ProjectOutputDirectory)/$(UploadPlatform)/..."  />
				<Tag Files="$(ProjectOutputDirectory)/$(UploadPlatform)/..." Except="*.pdb" With="#MainGameFiles"/>
				<Tag Files="$(ProjectOutputDirectory)/$(UploadPlatform)/..." Filter="*.pdb" With="#MainGameSymbols"/>
				<Delete Files="#MainGameSymbols"/>
				
				<Property Name="BuildRoot" Value="$(ProjectOutputDirectory)/$(UploadPlatform)"/>
				<Property Name="CloudDir" Value="$(ProjectOutputDirectory)/CloudDir/$(UploadPlatform)"/>
				<Property Name="BuildVersion" Value="$(BuildName)"/>
				<Property Name="AppLaunch" Value="$(Launch)"/>
				<Property Name="AppArgs" Value="-installed -GpuPreference=0"/>
				<Property Name="FileAttributeList" Value=""/>
				<Property Name="FileIgnoreList" Value=""/>
				<Property Name="Label" Value="Live"/>
				<Property Name="Platform" Value="Windows"/>
				<Property Name="CommandLineFile" Value="$(EpicGameStore_BuildPackageTool_Credentials_Path)"/>
			
				<Command Name="DeployToEpicGameStore" Arguments="-ArtifactId=&quot;$(UploadArtifactId)&quot; -BuildRoot=&quot;$(BuildRoot)&quot; -CloudDir=&quot;$(CloudDir)&quot; -BuildVersion=&quot;$(BuildVersion)&quot; -AppLaunch=&quot;$(AppLaunch)&quot; -AppArgs=&quot;$(AppArgs)&quot; -FileAttributeList=&quot;$(FileAttributeList)&quot; -FileIgnoreList=&quot;$(FileIgnoreList)&quot; -Label=&quot;$(Label)&quot; -Platform=&quot;$(Platform)&quot; -CommandLineFile=&quot;$(CommandLineFile)&quot;" />
			</Node>
			<Label Category="Package" Name="Publish $(DisplayTargetName) To Store" Requires="$(UploadNodeName)" />
		</Agent>
	
		<!-- Just upload? -->
		<!-- TODO, should we just move these inside the agent? -->
		<Aggregate Name="BuildAndTestWithUpload $(ProjectName)" Requires="BuildAndTest $(ProjectName);$(UploadNodeName)" />
		<Label Category="Upload" Name="Upload $(DisplayTargetName) $(UploadTargetPlatform)" Requires="$(UploadNodeName)" />
	
		<Property Name="BuildAndTestExtendedRequirements" Value="$(BuildAndTestExtendedRequirements);$(UploadNodeName)" If="'$(UploadNodeName)' != ''"/>
	</Do>
	
	<!-- =============================================================================== -->
	<!-- =============================================================================== -->
	
	<!-- Finally this defines the actual aggregated build command that will run all the requirements. -->
	<Aggregate Name="BuildAndTestExtended $(ProjectName)" Requires="$(BuildAndTestExtendedRequirements)" />

</BuildGraph>