Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/ProjectFiles/PlatformProjectGeneratorCollection.cs
Chris Gagnon 1dd3e0189f Merging //UE4/Dev-Main to Dev-Editor (//UE4/Dev-Editor)
#rb none

[CL 4730305 by Chris Gagnon in Dev-Editor branch]
2019-01-15 18:47:22 -05:00

122 lines
4.9 KiB
C#

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tools.DotNETCommon;
namespace UnrealBuildTool
{
/// <summary>
/// Stores all the registered platform project generators
/// </summary>
class PlatformProjectGeneratorCollection
{
Dictionary<UnrealTargetPlatform, PlatformProjectGenerator> ProjectGeneratorDictionary = new Dictionary<UnrealTargetPlatform, PlatformProjectGenerator>();
/// <summary>
/// Register the given platforms UEPlatformProjectGenerator instance
/// </summary>
/// <param name="InPlatform"> The UnrealTargetPlatform to register with</param>
/// <param name="InProjectGenerator">The UEPlatformProjectGenerator instance to use for the InPlatform</param>
public void RegisterPlatformProjectGenerator(UnrealTargetPlatform InPlatform, PlatformProjectGenerator InProjectGenerator)
{
// Make sure the build platform is legal
UEBuildPlatform BuildPlatform = UEBuildPlatform.GetBuildPlatform(InPlatform, true);
if (BuildPlatform != null)
{
if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true)
{
Log.TraceInformation("RegisterPlatformProjectGenerator Warning: Registering project generator {0} for {1} when it is already set to {2}",
InProjectGenerator.ToString(), InPlatform.ToString(), ProjectGeneratorDictionary[InPlatform].ToString());
ProjectGeneratorDictionary[InPlatform] = InProjectGenerator;
}
else
{
ProjectGeneratorDictionary.Add(InPlatform, InProjectGenerator);
}
}
else
{
Log.TraceVerbose("Skipping project file generator registration for {0} due to no valid BuildPlatform.", InPlatform.ToString());
}
}
/// <summary>
/// Retrieve the UEPlatformProjectGenerator instance for the given TargetPlatform
/// </summary>
/// <param name="InPlatform"> The UnrealTargetPlatform being built</param>
/// <param name="bInAllowFailure"> If true, do not throw an exception and return null</param>
/// <returns>UEPlatformProjectGenerator The instance of the project generator</returns>
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 {0}", InPlatform.ToString());
}
/// <summary>
/// Allow various platform project generators to generate stub projects if required
/// </summary>
/// <param name="InGenerator"></param>
/// <param name="InTargetName"></param>
/// <param name="InTargetFilepath"></param>
/// <param name="InTargetRules"></param>
/// <param name="InPlatforms"></param>
/// <param name="InConfigurations"></param>
/// <returns></returns>
public bool GenerateGameProjectStubs(ProjectFileGenerator InGenerator, string InTargetName, string InTargetFilepath, TargetRules InTargetRules,
List<UnrealTargetPlatform> InPlatforms, List<UnrealTargetConfiguration> InConfigurations)
{
foreach (KeyValuePair<UnrealTargetPlatform, PlatformProjectGenerator> Entry in ProjectGeneratorDictionary)
{
PlatformProjectGenerator ProjGen = Entry.Value;
ProjGen.GenerateGameProjectStub(InGenerator, InTargetName, InTargetFilepath, InTargetRules, InPlatforms, InConfigurations);
}
return true;
}
/// <summary>
/// Allow various platform project generators to generate any special project properties if required
/// </summary>
/// <param name="InPlatform"></param>
/// <param name="Configuration"></param>
/// <param name="TargetType"></param>
/// <param name="VCProjectFileContent"></param>
/// <param name="RootDirectory"></param>
/// <param name="TargetFilePath"></param>
/// <returns></returns>
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<UnrealTargetPlatform> InPlatforms, List<UnrealTargetConfiguration> InConfigurations)
{
bool bRequiresVSUserFileGeneration = false;
foreach (KeyValuePair<UnrealTargetPlatform, PlatformProjectGenerator> Entry in ProjectGeneratorDictionary)
{
if (InPlatforms.Contains(Entry.Key))
{
PlatformProjectGenerator ProjGen = Entry.Value;
bRequiresVSUserFileGeneration |= ProjGen.RequiresVSUserFileGeneration();
}
}
return bRequiresVSUserFileGeneration;
}
}
}