// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Linq; using EpicGames.Core; namespace UnrealBuildTool { /// /// Information about a target, passed along when creating a module descriptor /// public class TargetInfo { /// /// Name of the target /// public readonly string Name; /// /// The platform that the target is being built for /// public readonly UnrealTargetPlatform Platform; /// /// The configuration being built /// public readonly UnrealTargetConfiguration Configuration; /// /// Architecture that the target is being built for /// public readonly UnrealArchitectures Architectures; /// /// Intermediate environment. Determines if the intermediates end up in a different folder than normal. /// public UnrealIntermediateEnvironment IntermediateEnvironment; /// /// The project containing the target /// public readonly FileReference? ProjectFile; /// /// The current build version /// public ReadOnlyBuildVersion Version => ReadOnlyBuildVersion.Current; /// /// Additional command line arguments for this target /// public CommandLineArguments? Arguments; /// /// Constructs a TargetInfo for passing to the TargetRules constructor. /// /// Name of the target being built /// The platform that the target is being built for /// The configuration being built /// The architectures being built for /// Path to the project file containing the target /// Additional command line arguments for this target /// Intermediate environment to use public TargetInfo(string Name, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, UnrealArchitectures? Architectures, FileReference? ProjectFile, CommandLineArguments? Arguments, UnrealIntermediateEnvironment IntermediateEnvironment = UnrealIntermediateEnvironment.Default) { this.Name = Name; this.Platform = Platform; this.Configuration = Configuration; this.IntermediateEnvironment = IntermediateEnvironment; this.ProjectFile = ProjectFile; this.Arguments = Arguments; if (Architectures == null) { this.Architectures = UnrealArchitectureConfig.ForPlatform(Platform).ActiveArchitectures(ProjectFile, Name); } else { this.Architectures = Architectures; } } /// /// Construct a TargetInfo from an archive on disk /// /// Archive to read from public TargetInfo(BinaryArchiveReader Reader) { Name = Reader.ReadString()!; Platform = UnrealTargetPlatform.Parse(Reader.ReadString()!); string ConfigurationStr = Reader.ReadString()!; Architectures = new UnrealArchitectures(Reader.ReadArray(() => Reader.ReadString()!)!); ProjectFile = Reader.ReadFileReferenceOrNull(); string[]? ArgumentStrs = Reader.ReadArray(() => Reader.ReadString()!); if (!UnrealTargetConfiguration.TryParse(ConfigurationStr, out Configuration)) { throw new BuildException(String.Format("The configration name {0} is not a valid configration name. Valid names are ({1})", Name, String.Join(",", Enum.GetValues(typeof(UnrealTargetConfiguration)).Cast().Select(x => x.ToString())))); } string? IntermediateEnvironmentStr = Reader.ReadString(); if (IntermediateEnvironmentStr != null) { UnrealIntermediateEnvironment.TryParse(IntermediateEnvironmentStr, out IntermediateEnvironment); } Arguments = ArgumentStrs == null ? null : new CommandLineArguments(ArgumentStrs); } /// /// Write a TargetInfo to an archive on disk /// /// Archive to write to public void Write(BinaryArchiveWriter Writer) { Writer.WriteString(Name); Writer.WriteString(Platform.ToString()); Writer.WriteString(Configuration.ToString()); Writer.WriteArray(Architectures.Architectures.ToArray(), Item => Writer.WriteString(Item.ToString())); Writer.WriteFileReference(ProjectFile); Writer.WriteArray(Arguments?.GetRawArray(), Item => Writer.WriteString(Item)); Writer.WriteString(IntermediateEnvironment.ToString()); } } }