using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnrealBuildTool
{
///
/// Contains information about a target required to deploy it. Written at build time, and read back in when UBT needs to run the deploy step.
///
class UEBuildDeployTarget
{
///
/// Path to the project file
///
public readonly FileReference ProjectFile;
///
/// Path to the .target.cs
///
public readonly FileReference TargetFile;
///
/// The shared app name for this target (eg. UE4Editor)
///
public readonly string AppName;
///
/// The name of this target
///
public readonly string TargetName;
///
/// Type of the target to build
///
public readonly TargetType TargetType;
///
/// The platform being built
///
public readonly UnrealTargetPlatform Platform;
///
/// The configuration being built
///
public readonly UnrealTargetConfiguration Configuration;
///
/// The output path
///
public FileReference OutputPath
{
get
{
if (OutputPaths.Count != 1)
{
throw new BuildException("Attempted to use UEBuildDeployTarget.OutputPath property, but there are multiple (or no) OutputPaths. You need to handle multiple in the code that called this (size = {0})", OutputPaths.Count);
}
return OutputPaths[0];
}
}
///
/// The full list of output paths, for platforms that support building multiple binaries simultaneously
///
public readonly List OutputPaths;
///
/// Path to the directory for engine intermediates. May be under the project directory if not being built for the shared build environment.
///
public readonly DirectoryReference EngineIntermediateDirectory;
///
/// The project directory, or engine directory for targets without a project file.
///
public readonly DirectoryReference ProjectDirectory;
///
/// Path to the generated build receipt.
///
public readonly string BuildReceiptFileName;
///
/// Whether to output build products to the Engine/Binaries folder.
///
public readonly bool bOutputToEngineBinaries;
///
/// If true, then a stub IPA will be generated when compiling is done (minimal files needed for a valid IPA)
///
public readonly bool bCreateStubIPA;
///
/// Which architectures to deploy for on Android
///
public readonly string[] AndroidArchitectures;
///
/// Which GPU architectures to deploy for on Android
///
public readonly string[] AndroidGPUArchitectures;
///
/// Construct the deployment info from a target
///
/// The target being built
public UEBuildDeployTarget(UEBuildTarget Target)
{
this.ProjectFile = Target.ProjectFile;
this.TargetFile = Target.TargetCsFilename;
this.AppName = Target.AppName;
this.TargetName = Target.TargetName;
this.TargetType = Target.TargetType;
this.Platform = Target.Platform;
this.Configuration = Target.Configuration;
this.OutputPaths = new List(Target.OutputPaths);
this.EngineIntermediateDirectory = Target.EngineIntermediateDirectory;
this.ProjectDirectory = Target.ProjectDirectory;
this.BuildReceiptFileName = Target.BuildReceiptFileName;
this.bOutputToEngineBinaries = Target.Rules.bOutputToEngineBinaries;
this.bCreateStubIPA = Target.Rules.bCreateStubIPA;
this.AndroidArchitectures = Target.Rules.AndroidPlatform.Architectures.ToArray();
this.AndroidGPUArchitectures = Target.Rules.AndroidPlatform.GPUArchitectures.ToArray();
}
///
/// Read the deployment info from a file on disk
///
/// Path to the file to read
public UEBuildDeployTarget(FileReference Location)
{
using (BinaryReader Reader = new BinaryReader(File.Open(Location.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
ProjectFile = Reader.ReadFileReference();
TargetFile = Reader.ReadFileReference();
AppName = Reader.ReadString();
TargetName = Reader.ReadString();
TargetType = (TargetType)Reader.ReadInt32();
Platform = (UnrealTargetPlatform)Reader.ReadInt32();
Configuration = (UnrealTargetConfiguration)Reader.ReadInt32();
OutputPaths = Reader.ReadList(x => x.ReadFileReference());
EngineIntermediateDirectory = Reader.ReadDirectoryReference();
ProjectDirectory = Reader.ReadDirectoryReference();
BuildReceiptFileName = Reader.ReadString();
bOutputToEngineBinaries = Reader.ReadBoolean();
bCreateStubIPA = Reader.ReadBoolean();
AndroidArchitectures = Reader.ReadArray(x => x.ReadString());
AndroidGPUArchitectures = Reader.ReadArray(x => x.ReadString());
}
}
///
/// Write the deployment info to a file on disk
///
/// File to write to
public void Write(FileReference Location)
{
DirectoryReference.CreateDirectory(Location.Directory);
using (BinaryWriter Writer = new BinaryWriter(File.Open(Location.FullName, FileMode.Create, FileAccess.Write, FileShare.Read)))
{
Writer.Write(ProjectFile);
Writer.Write(TargetFile);
Writer.Write(AppName);
Writer.Write(TargetName);
Writer.Write((Int32)TargetType);
Writer.Write((Int32)Platform);
Writer.Write((Int32)Configuration);
Writer.Write(OutputPaths, (x, i) => x.Write(i));
Writer.Write(EngineIntermediateDirectory);
Writer.Write(ProjectDirectory);
Writer.Write(BuildReceiptFileName);
Writer.Write(bOutputToEngineBinaries);
Writer.Write(bCreateStubIPA);
Writer.Write(AndroidArchitectures, (w, e) => w.Write(e));
Writer.Write(AndroidGPUArchitectures, (w, e) => w.Write(e));
}
}
}
}