// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace UnrealBuildTool
{
///
/// Stores all the registered platform project generators
///
class PlatformProjectGeneratorCollection
{
Dictionary ProjectGeneratorDictionary = new Dictionary();
///
/// Returns the list of platforms that have been registered in this collection
///
/// Registered platforms
public List GetRegisteredPlatforms()
{
return ProjectGeneratorDictionary.Keys.ToList();
}
///
/// Register the given platforms UEPlatformProjectGenerator instance
///
/// The UnrealTargetPlatform to register with
/// The UEPlatformProjectGenerator instance to use for the InPlatform
/// Logger for output
public void RegisterPlatformProjectGenerator(UnrealTargetPlatform InPlatform, PlatformProjectGenerator InProjectGenerator, ILogger Logger)
{
// Make sure the build platform is legal
UEBuildPlatform? BuildPlatform;
if (UEBuildPlatform.TryGetBuildPlatform(InPlatform, out BuildPlatform))
{
if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true)
{
Logger.LogInformation("RegisterPlatformProjectGenerator Warning: Registering project generator {Generator} for {Platform} when it is already set to {ExistingGenerator}",
InProjectGenerator.ToString(), InPlatform.ToString(), ProjectGeneratorDictionary[InPlatform].ToString());
ProjectGeneratorDictionary[InPlatform] = InProjectGenerator;
}
else
{
ProjectGeneratorDictionary.Add(InPlatform, InProjectGenerator);
}
}
else
{
Logger.LogDebug("Skipping project file generator registration for {Platform} due to no valid BuildPlatform.", InPlatform.ToString());
}
}
///
/// Retrieve the UEPlatformProjectGenerator instance for the given TargetPlatform
///
/// The UnrealTargetPlatform being built
/// If true, do not throw an exception and return null
/// UEPlatformProjectGenerator The instance of the project generator
public PlatformProjectGenerator? GetPlatformProjectGenerator(UnrealTargetPlatform InPlatform, bool bInAllowFailure = false)
{
if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true)
{
return ProjectGeneratorDictionary[InPlatform];
}
if (bInAllowFailure == true)
{
return null;
}
throw new BuildException("GetPlatformProjectGenerator: No PlatformProjectGenerator found for {Platform}", InPlatform.ToString());
}
///
/// Allow various platform project generators to generate stub projects if required
///
///
///
///
///
///
///
///
public bool GenerateGameProjectStubs(ProjectFileGenerator InGenerator, string InTargetName, string InTargetFilepath, TargetRules InTargetRules,
List InPlatforms, List InConfigurations)
{
foreach (KeyValuePair Entry in ProjectGeneratorDictionary)
{
PlatformProjectGenerator ProjGen = Entry.Value;
ProjGen.GenerateGameProjectStub(InGenerator, InTargetName, InTargetFilepath, InTargetRules, InPlatforms, InConfigurations);
}
return true;
}
///
/// Allow various platform project generators to generate any special project properties if required
///
///
///
///
///
///
///
///
public bool GenerateGamePlatformSpecificProperties(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration Configuration, TargetType TargetType, StringBuilder VCProjectFileContent, DirectoryReference RootDirectory, FileReference TargetFilePath)
{
if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true)
{
ProjectGeneratorDictionary[InPlatform].GenerateGameProperties(Configuration, VCProjectFileContent, TargetType, RootDirectory, TargetFilePath);
}
return true;
}
public bool PlatformRequiresVSUserFileGeneration(List InPlatforms, List InConfigurations)
{
bool bRequiresVSUserFileGeneration = false;
foreach (KeyValuePair Entry in ProjectGeneratorDictionary)
{
if (InPlatforms.Contains(Entry.Key))
{
PlatformProjectGenerator ProjGen = Entry.Value;
bRequiresVSUserFileGeneration |= ProjGen.RequiresVSUserFileGeneration();
}
}
return bRequiresVSUserFileGeneration;
}
}
}