Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/System/PrecompiledHeaderTemplate.cs
bryan sefcik 5fcc1c97a3 Updated the shared pch logic to traverse the dependency tree to find the best shared pch for each module. The logic before would only look at the direct dependencies which if changed could result in possibly worse compile times because a less optimal pch could be picked.
Note: There however are occasions where the old logic can give better shared pchs because it doesn't check whether there is a circular dependency. The new logic does check for circular dependencies so it can sometimes return a safer but less optimal shared PCH. If we find the old logic gives a better shared pch then we go ahead and use it. This will be removed after some of the circular dependencies are resolved.

#rb joe.kirchoff
#preflight 6477e3b87f02573726be946c

[CL 25720154 by bryan sefcik in ue5-main branch]
2023-05-31 23:29:01 -04:00

89 lines
2.8 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
using EpicGames.Core;
using UnrealBuildBase;
namespace UnrealBuildTool
{
/// <summary>
/// A template for creating a shared PCH. Instances of it are created depending on the configurations required.
/// </summary>
class PrecompiledHeaderTemplate
{
/// <summary>
/// Module providing this PCH.
/// </summary>
public UEBuildModuleCPP Module;
/// <summary>
/// The base compile environment, including all the public compile environment that all consuming modules inherit.
/// </summary>
public CppCompileEnvironment BaseCompileEnvironment;
/// <summary>
/// The header file
/// </summary>
public FileItem HeaderFile;
/// <summary>
/// Output directory for instances of this PCH.
/// </summary>
public DirectoryReference OutputDir;
/// <summary>
/// Instances of this PCH
/// </summary>
public List<PrecompiledHeaderInstance> Instances = new List<PrecompiledHeaderInstance>();
/// <summary>
/// All the module dependencies this template has
/// </summary>
public HashSet<UEBuildModule> ModuleDependencies = new HashSet<UEBuildModule>();
/// <summary>
/// Constructor
/// </summary>
/// <param name="Module">The module with a valid shared PCH</param>
/// <param name="BaseCompileEnvironment">The compile environment to use</param>
/// <param name="HeaderFile">The header file to generate a PCH from</param>
/// <param name="OutputDir">Output directory for instances of this PCH</param>
/// <param name="ModuleDependencies">All the module dependencies this template has</param>
public PrecompiledHeaderTemplate(UEBuildModuleCPP Module, CppCompileEnvironment BaseCompileEnvironment, FileItem HeaderFile, DirectoryReference OutputDir, HashSet<UEBuildModule> ModuleDependencies)
{
this.Module = Module;
this.BaseCompileEnvironment = BaseCompileEnvironment;
this.HeaderFile = HeaderFile;
this.OutputDir = OutputDir;
this.ModuleDependencies = ModuleDependencies;
}
/// <summary>
/// Checks whether this template is valid for the given compile environment
/// </summary>
/// <param name="CompileEnvironment">Compile environment to check with</param>
/// <returns>True if the template is compatible with the given compile environment</returns>
public bool IsValidFor(CppCompileEnvironment CompileEnvironment)
{
if (CompileEnvironment.bIsBuildingDLL != BaseCompileEnvironment.bIsBuildingDLL)
{
return false;
}
if (CompileEnvironment.bIsBuildingLibrary != BaseCompileEnvironment.bIsBuildingLibrary)
{
return false;
}
return true;
}
/// <summary>
/// Return a string representation of this object for debugging
/// </summary>
/// <returns>String representation of the object</returns>
public override string ToString()
{
return HeaderFile.AbsolutePath;
}
}
}