Files
UnrealEngineUWP/Engine/Source/Programs/UnrealBuildTool/System/CPPHeaders.cs
Josh Adams 60b019520c Copying //UE4/Dev-Platform to //UE4/Dev-Main (Source: //UE4/Dev-Platform @ 3295257)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3235199 on 2016/12/14 by Joe.Barnes

	Fix new compile error for missing #define

Change 3235340 on 2016/12/14 by Arciel.Rekman

	Linux: refactor of some PlatformMisc functions.

	- RootDir() removed since it was a no-op.
	- Old EngineDir() implementation removed in favor of more generic one that should handle foreign engine dir.
	- Change by CengizT,

Change 3237014 on 2016/12/15 by Michael.Trepka

	Fixed a crash in FChunkCacheWorker constructor

Change 3238305 on 2016/12/16 by Josh.Adams

	- Added a None option to the FKey customization, unless the FKey property had NoClear on it

Change 3240823 on 2016/12/20 by Josh.Stoddard

	Device profiles don't work for iPadPro 9.7 and 12.9

	#jira UE-39943

Change 3241103 on 2016/12/20 by Alicia.Cano

	Android support from Visual Studio
	#jira UEPLAT-1421
	#android

Change 3241357 on 2016/12/20 by Chris.Babcock

	Add gameActivityOnNewIntentAddtions section to Android UPL
	#jira UE-38986
	#PR #2969
	#ue4
	#android

Change 3241941 on 2016/12/21 by Alicia.Cano

	Build Fix

Change 3249832 on 2017/01/06 by Nick.Shin

	refetch on timed out GET/POST requests

	#jira UE-39992  Quicklaunch UFE HTML5 fails with "NS_ERROR_Failure"

Change 3249837 on 2017/01/06 by Nick.Shin

	black box issues fixed:

	use device pixel ratio during width and height checks
	and use canvas dimensions if in full screen -- otherwise store SDL_window dimensions for future use

	#jira UE-36341  HTML5 - View is incorrectly drawn
	#jira UE-32311  Templates on Firefox/Chrome on HTML5 are not full screen during Launch On

Change 3249988 on 2017/01/06 by Josh.Adams

	- Disable the HeartBeat() function on platforms that don't actually want to use the HeartbeatThread
	#jira UE-40305, UE-39291, UE-40113

Change 3253720 on 2017/01/11 by Josh.Adams

	- Added support for a config class to use a specific platform's config hierarchy, so that the editor can read NDA'd platform default settings without needing the settings to in Base*.ini
	  - See SwitchRuntimeSettings.h / GetConfigOverridePlatform()
	- Addiontally made it so that NDAd platforms are saved to Project/Platform/Platform*.ini, instead of Project/Default*.ini (to keep samples .ini files free of NDAd platform settings).
	  - See UObject::GetDefaultConfigFilename()
	- Updated some minor ShooterGame switch settings while cleaning this up

Change 3254162 on 2017/01/11 by Daniel.Lamb

	Avoid trying to load empty package names.
	Fixed issue with iterative ini files being unparseable if they inlcude a colon in them.
	#jira UE-40257, UE-35001
	#test Cook QAGame

Change 3255309 on 2017/01/12 by Daniel.Lamb

	In the derived datacache commandlet wait for texture building to finish before we GC.
	#test DDC QAGame

Change 3255311 on 2017/01/12 by Daniel.Lamb

	Removed debug logging for shader compilation.
	Issue hasn't occured in a while and the logging is annoying.
	#test Cook QAGame

Change 3257024 on 2017/01/13 by Josh.Adams

	- Reread in the target RHIs array every time the list of shader types is needed, instead of caching, because the user could change the settings in the editor, then click cook.
	#jira UE-38691

Change 3259636 on 2017/01/16 by Josh.Adams

	- Fixed split screen render issue with payer 2 getting no geometry
	#jira UE-40684

Change 3260159 on 2017/01/17 by Ben.Marsh

	Added extra logging when deleting a directory fails during ReconcileWorkspace.

Change 3260300 on 2017/01/17 by Ben.Marsh

	More logging for cleaning workspaces.

Change 3261056 on 2017/01/17 by Daniel.Lamb

	Cook on the fly builds now resolve string asset references.
	#test Trivial

Change 3262803 on 2017/01/18 by Joe.Graf

	Added missing support for compiling plugins external to Engine/Plugins & Game/Plugins

Change 3262852 on 2017/01/18 by Joe.Graf

	Fixed the bad robomerge
	Don't try to regenerate projects when adding a content only plugin to a content only project

Change 3264930 on 2017/01/19 by Joe.Barnes

	#include some header files needed when building UFE.

Change 3265728 on 2017/01/20 by Will.Fissler

	PlatformShowcase - Added TestBed_MobileFeatures .umap and related test content.

Change 3267188 on 2017/01/21 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3267439 on 2017/01/22 by Arciel.Rekman

	Fix Dev-Platform build.

	- Fixed just to have it compile; perhaps a proper fix is needed.
	- Seems to be caused by CL 3265587 (delegate was changed to return an array of search results instead of a single one).

Change 3267556 on 2017/01/23 by Arciel.Rekman

	Linux: fix MoveFile to work across file systems.

	- PR #3141 with slight changes.

Change 3267843 on 2017/01/23 by Arciel.Rekman

	Remove name collision (macro vs libc++).

	- Redoing CL 3259310.

Change 3267850 on 2017/01/23 by Arciel.Rekman

	Fix wrong always true condition.

	- PLATFORM_LINUX is always defined, but can be 0.

Change 3268048 on 2017/01/23 by Daniel.Lamb

	Integrated fix for rebuild lighting commandlet from Greg Korman @ Impulse Gear.
	#test Rebuild lighting Paragon

Change 3268403 on 2017/01/23 by Josh.Adams

	#BUILDUPGRADENOTES
	- Moved XboxOne and PS4 settings into platform specific .ini files (after using GetConfigOverridePlatform() in their class delcarations)
	- Licensee games that have PS4, XboxOne, Switch settings in DefaultEngine.ini will have those settings saved in the platform version next time the project settings are edited. DOCUMENT THIS!

Change 3272441 on 2017/01/25 by Chris.Babcock

	Fixed documentation error in UnrealPluginLanguage
	#ue4
	#android

Change 3272478 on 2017/01/25 by Chris.Babcock

	Fix another documentation error in UnrealPluginLanguage
	#ue4

Change 3272826 on 2017/01/25 by Chris.Babcock

	Google Cloud Messaging plugin for Android
	#jira UEPLAT-1458
	#ue4
	#android

Change 3272839 on 2017/01/25 by Chris.Babcock

	Fix name of Google Cloud Messaging Sender ID
	#ue4
	#android

Change 3273837 on 2017/01/26 by Daniel.Lamb

	Added check to ensure editor never saves source texture data which has had ReleaseSourceMemory called on it.
	Instead crash as this is a loss of content situation.
	#test Cook paragon cook qagame

Change 3274122 on 2017/01/26 by Alicia.Cano

	Runtime permissions support on Android
	- Removing certain permissions
	#jira UE-38512
	#android

Change 3274311 on 2017/01/26 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3274794 on 2017/01/27 by Arciel.Rekman

	Linux: fix installed SDK check (UE-40392).

	- Pull request #3111 by rubu.

Change 3274803 on 2017/01/27 by Arciel.Rekman

	Linux: added few more exceptions to .gitignore (UE-39612).

	- Pull request #3026 by ardneran.

Change 3276247 on 2017/01/27 by Nick.Shin

	HTML5 HeapSize settings - make use of it from UE4 Editor:Platforms:HTML5:Memory:HeapSize

	note: emscripten says this is really no longer needed when using [ -s ALLOW_MEMORY_GROWTH=1 ] -- but tests have shown when using that, the game load/compile times takes longer

	#jira UE-34753  Zen Garden cannot compile in HTML5
	#jira UE-40815  Launching QAGame for HTML5 creates an 'uncaught exception: out of memory'.

Change 3276347 on 2017/01/27 by dan.reynolds

	Android Streaming Test Content

Change 3276682 on 2017/01/29 by Nick.Shin

	HTML5 thirdparty build scripts

	- fix up what looks like a bad merge
	- allow linux to also build these  libs
	- fixed harfbuzz to use freetype2-2.6 when building HTML5 libs

	- tested on mac, linux, and windows (git-bash)

Change 3276796 on 2017/01/29 by Nick.Shin

	HTML5 thirdparty (python) build scripts

	- linux patches from mozilla's jukka

	- tested on mac and, linux, and windows (git-bash)

	part of:
	#jira UEPLAT-1437  (4.16)  Switch [to] web assembly

Change 3276803 on 2017/01/29 by Nick.Shin

	HTML5 thirdparty build scripts

	- getting ready to build with (new toolchain that has) wasm support
	- minor fix to handle whitespace in project path

	- tested on mac and, linux, and windows (git-bash)

	part of:
	#jira UEPLAT-1437  (4.16)  Switch [to] web assembly

Change 3278007 on 2017/01/30 by Arciel.Rekman

	SteamVR: whitelist for Linux.

	- Makes Blueprint functions available in Linux builds, even if stubbed.
	- Can be probably whitelisted for Mac too.

Change 3278172 on 2017/01/30 by Arciel.Rekman

	Do not rebuild UnrealPak locally (UE-41285).

Change 3279873 on 2017/01/31 by Brent.Pease

	 + Implement streaming in Vorbis
	 + Add streaming to Android audio
	 + Fix audio streaming chunk race condition

Change 3280063 on 2017/01/31 by Brent.Pease

	GitHub 2949 : Fix for crashes when backgrounding/sleeping on iOS metal devices

	#2949
	#jira UE-38829

Change 3280072 on 2017/01/31 by Brent.Pease

	PR #2889: Add -distribution when iOS distribution Packaging. with IPhonePackage.exe (Contributed by sangpan)
	https://github.com/EpicGames/UnrealEngine/pull/2889

	#jira ue-37874
	#2889

Change 3280091 on 2017/01/31 by Arciel.Rekman

	Linux: fix "unable to make writable" toast (UE-37228).

	- Also fixed other platforms that returned inverted the error result.

Change 3280624 on 2017/01/31 by Brent.Pease

	PR #2891: iOS IDFV string allocation fix (Contributed by robertfsegal)
	https://github.com/EpicGames/UnrealEngine/pull/2891

	#2891
	#jira ue-37891

Change 3280625 on 2017/01/31 by Brent.Pease

	GitHub 2576 - Fix UIImagePickerController crash

	#2576
	#jira UE-328888

Change 3281618 on 2017/02/01 by Josh.Adams

	- Fixed hopeful compile error with missing inlcude
	#jira UE-41415

Change 3282277 on 2017/02/01 by Josh.Adams

	- Support 0.12.16 and 1.1.1 (the first versions that can share Oasis)

Change 3282441 on 2017/02/01 by Arciel.Rekman

	Fix Linux editor splash screen (UE-28123).

Change 3282580 on 2017/02/01 by Nick.Shin

	HTML5 - fix "firefox nighly" issue with:

	failed to compile wasm module: CompileError: at offset XXX: initial memory size too big:

	WARNING: this greatly impacts (in browser) compile times

Change 3285991 on 2017/02/03 by Chris.Babcock

	Fix executable path for stripping Android debug symbols (handle non-Windows properly)
	#jira UE-41238
	#ue4
	#android

Change 3286406 on 2017/02/03 by Chris.Babcock

	Save and restore texture filtering for movie playback in all cases
	#jira UE-41565
	#ue4
	#android

Change 3286800 on 2017/02/04 by Chris.Babcock

	Fix executable path for stripping Android debug symbols (handle non-Windows properly)
	#jira UE-41238
	#ue4
	#android

Change 3288598 on 2017/02/06 by Arciel.Rekman

	CodeLite fixes.

	- Use *-Linux-Debug binary for Debug configuration.
	- Fix virtual paths.

Change 3288864 on 2017/02/06 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
	- Note, Switch is known to not boot with this, fix coming next

Change 3289364 on 2017/02/06 by Josh.Adams

	[BUILDUPGRADENOTES] - Fixed the "type" of the desktop device profiles to be Windows, not WindowsNoEditor, etc. It should be the platform, not a random string.
	- Updated how DeviceProfiles are loaded, especially in the editor, so that we can have NDAd platforms have their default DP values in platform-hidden files
	- This makes use of the ability for a class to override the platform hierarchy in the editor (like we do with other editor-exposed platform objects)
	- Added Config/[PS4|XboxOne|Switch]/ConfidentialPlatform.ini files so that the DP loading code knows to look in their directories for DPs. See FGenericPlatformMisc::GetConfidentialPlatforms() for more information
	- Note that saving still saves the entire DP to the .ini. Next DP change is to have them properly save against their 2(!) parents - the .ini file earlier in the hierarchy, and the parent DP object. Makes it tricky, for sure.
	- Added FConfigFile::GetArray (previous was only on FConfigCacheIni)

Change 3289796 on 2017/02/07 by Arciel.Rekman

	Linux: remove leftover CEF build script.

Change 3289872 on 2017/02/07 by Arciel.Rekman

	Linux: install MIME types (UE-40954).

	- Pull request #3154 by RicardoEPRodrigues.

Change 3289915 on 2017/02/07 by Josh.Adams

	- Fixed CIS warnings

Change 3289916 on 2017/02/07 by Arciel.Rekman

	Linux: remove -opengl4 from the default invocation.

Change 3290009 on 2017/02/07 by Gil.Gribb

	UE4 - Fixed boot time EDL causing some issues even when it wasn't being used.

Change 3290120 on 2017/02/07 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3290948 on 2017/02/07 by Arciel.Rekman

	Linux: fix crash when clicking on question mark (UE-41634).

	- Symbol interposition problem (proper fix is still to be investigated).

	(Edigrating part of CL 3290683 from Release-4.15 to Dev-Platform)

Change 3291074 on 2017/02/07 by Arciel.Rekman

	Speculative build fix.

Change 3292028 on 2017/02/08 by Josh.Adams

	- Fixed Incremental CIS build failures

Change 3292105 on 2017/02/08 by Nick.Shin

	emcc.py - change warning to info

	#jira UE-41747 //UE4/Dev-Platform Compile UE4Game HTML5 completed with 50 warnings

Change 3292201 on 2017/02/08 by JohnHenry.Carawon

	Change comment to fix XML warning when generating project files on Linux

Change 3292242 on 2017/02/08 by Arciel.Rekman

	Linux: avoid unnecessary dependency on CEF (UE-41634).

	- Do not apply CEF workaround to monolithic builds (eg. stock Game/Server targets).
	- Also disable CEF compilation for ShaderCompileWorker.
	- Based on CL 3292077 in 4.15.

Change 3292559 on 2017/02/08 by Josh.Adams

	- Added more platforms to disable the file handle caching (all the ones that use MANAGED_FILE_HANDLES)

Change 3294333 on 2017/02/09 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3294506 on 2017/02/09 by Josh.Adams

	- Fixed GoogleCloudMessaging.uplugin to fix the Installed flag. Every other plugin had false, this one had true, which caused various checks to go haywire
	#jira UE-41710

Change 3294984 on 2017/02/09 by Josh.Adams

	- Worked around the remote compiling issue with code-based projects on a different drive than the engine
	#jira UE-41704

Change 3295056 on 2017/02/09 by Josh.Adams

	- Fixed the remote compiling issue by unconverting the path back to host when reading from the module filename

Change 3295161 on 2017/02/09 by Josh.Adams

	- Fixed new bug when buildin native ios that was caused by a remote compile break

Change 3295229 on 2017/02/09 by Josh.Adams

	- Fixed a crash in clothing on platforms that don't support clothing
	#jira UE-41830

[CL 3295859 by Josh Adams in Main branch]
2017-02-09 19:20:55 -05:00

672 lines
26 KiB
C#

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Runtime.Serialization;
using System.Linq;
using Tools.DotNETCommon.FileContentsCacheType;
namespace UnrealBuildTool
{
/// <summary>
/// For C++ source file items, this structure is used to cache data that will be used for include dependency scanning
/// </summary>
[Serializable]
class CppIncludePaths : ISerializable
{
/// <summary>
/// Ordered list of include paths for the module
/// </summary>
public HashSet<string> UserIncludePaths;
/// <summary>
/// The include paths where changes to contained files won't cause dependent C++ source files to
/// be recompiled, unless BuildConfiguration.bCheckSystemHeadersForModification==true.
/// </summary>
public HashSet<string> SystemIncludePaths;
/// <summary>
/// Whether headers in system paths should be checked for modification when determining outdated actions.
/// </summary>
public bool bCheckSystemHeadersForModification;
/// <summary>
/// Contains a mapping from filename to the full path of the header in this environment. This is used to optimized include path lookups at runtime for any given single module.
/// </summary>
public Dictionary<string, FileItem> IncludeFileSearchDictionary = new Dictionary<string, FileItem>();
/// <summary>
/// Construct an empty set of include paths
/// </summary>
public CppIncludePaths()
{
UserIncludePaths = new HashSet<string>();
SystemIncludePaths = new HashSet<string>();
}
/// <summary>
/// Copy constructor
/// </summary>
/// <param name="Other">Duplicate another instance's settings</param>
public CppIncludePaths(CppIncludePaths Other)
{
UserIncludePaths = new HashSet<string>(Other.UserIncludePaths);
SystemIncludePaths = new HashSet<string>(Other.SystemIncludePaths);
bCheckSystemHeadersForModification = Other.bCheckSystemHeadersForModification;
}
/// <summary>
/// Deserialize the include paths from the given context
/// </summary>
/// <param name="Info">Serialization info</param>
/// <param name="Context">Serialization context</param>
public CppIncludePaths(SerializationInfo Info, StreamingContext Context)
{
UserIncludePaths = new HashSet<string>((string[])Info.GetValue("ip", typeof(string[])));
SystemIncludePaths = new HashSet<string>((string[])Info.GetValue("sp", typeof(string[])));
bCheckSystemHeadersForModification = Info.GetBoolean("cs");
}
/// <summary>
/// Serialize this instance
/// </summary>
/// <param name="Info">Serialization info</param>
/// <param name="Context">Serialization context</param>
public void GetObjectData(SerializationInfo Info, StreamingContext Context)
{
Info.AddValue("ip", UserIncludePaths.ToArray());
Info.AddValue("sp", SystemIncludePaths.ToArray());
Info.AddValue("cs", bCheckSystemHeadersForModification);
}
/// <summary>
/// Given a C++ source file, returns a list of include paths we should search to resolve #includes for this path
/// </summary>
/// <param name="SourceFile">C++ source file we're going to check #includes for.</param>
/// <returns>Ordered list of paths to search</returns>
public List<string> GetPathsToSearch(FileReference SourceFile)
{
List<string> IncludePathsToSearch = new List<string>();
IncludePathsToSearch.Add(SourceFile.Directory.FullName);
IncludePathsToSearch.AddRange(UserIncludePaths);
if (bCheckSystemHeadersForModification)
{
IncludePathsToSearch.AddRange(SystemIncludePaths);
}
return IncludePathsToSearch;
}
}
/// <summary>
/// List of all files included in a file and helper class for handling circular dependencies.
/// </summary>
class IncludedFilesSet : HashSet<FileItem>
{
/// <summary>
/// Whether this file list has been fully initialized or not.
/// </summary>
public bool bIsInitialized;
/// <summary>
/// List of files which include this file in one of its includes.
/// </summary>
public List<FileItem> CircularDependencies = new List<FileItem>();
}
class CPPHeaders
{
/// <summary>
/// The project that we're caching headers for
/// </summary>
public FileReference ProjectFile;
/// <summary>
/// Path to the dependency cache for this target
/// </summary>
public FileReference DependencyCacheFile;
/// <summary>
/// Contains a cache of include dependencies (direct and indirect), one for each target we're building.
/// </summary>
public DependencyCache IncludeDependencyCache = null;
/// <summary>
/// Contains a cache of include dependencies (direct and indirect), one for each target we're building.
/// </summary>
public FlatCPPIncludeDependencyCache FlatCPPIncludeDependencyCache = null;
/// <summary>
///
/// </summary>
public static int TotalFindIncludedFileCalls = 0;
/// <summary>
///
/// </summary>
public static int IncludePathSearchAttempts = 0;
/// <summary>
/// A cache of the list of other files that are directly or indirectly included by a C++ file.
/// </summary>
Dictionary<FileItem, IncludedFilesSet> ExhaustiveIncludedFilesMap = new Dictionary<FileItem, IncludedFilesSet>();
/// <summary>
/// A cache of all files included by a C++ file, but only has files that we knew about from a previous session, loaded from a cache at startup
/// </summary>
Dictionary<FileItem, IncludedFilesSet> OnlyCachedIncludedFilesMap = new Dictionary<FileItem, IncludedFilesSet>();
/// <summary>
///
/// </summary>
public bool bUseUBTMakefiles;
/// <summary>
///
/// </summary>
public bool bUseFlatCPPIncludeDependencyCache;
/// <summary>
///
/// </summary>
public bool bUseIncludeDependencyResolveCache;
/// <summary>
///
/// </summary>
public bool bTestIncludeDependencyResolveCache;
public CPPHeaders(FileReference ProjectFile, FileReference DependencyCacheFile, bool bUseUBTMakefiles, bool bUseFlatCPPIncludeDependencyCache, bool bUseIncludeDependencyResolveCache, bool bTestIncludeDependencyResolveCache)
{
this.ProjectFile = ProjectFile;
this.DependencyCacheFile = DependencyCacheFile;
this.bUseUBTMakefiles = bUseUBTMakefiles;
this.bUseFlatCPPIncludeDependencyCache = bUseFlatCPPIncludeDependencyCache;
this.bUseIncludeDependencyResolveCache = bUseIncludeDependencyResolveCache;
this.bTestIncludeDependencyResolveCache = bTestIncludeDependencyResolveCache;
}
/// <summary>
/// Finds the header file that is referred to by a partial include filename.
/// </summary>
/// <param name="FromFile">The file containing the include directory</param>
/// <param name="RelativeIncludePath">path relative to the project</param>
/// <param name="IncludePaths">Include paths to search</param>
public static FileItem FindIncludedFile(FileReference FromFile, string RelativeIncludePath, CppIncludePaths IncludePaths)
{
FileItem Result = null;
++TotalFindIncludedFileCalls;
// Only search for the include file if the result hasn't been cached.
string InvariantPath = RelativeIncludePath.ToLowerInvariant();
if (!IncludePaths.IncludeFileSearchDictionary.TryGetValue(InvariantPath, out Result))
{
int SearchAttempts = 0;
if (Path.IsPathRooted(RelativeIncludePath))
{
FileReference Reference = new FileReference(RelativeIncludePath);
if (DirectoryLookupCache.FileExists(Reference))
{
Result = FileItem.GetItemByFileReference(Reference);
}
++SearchAttempts;
}
else
{
// Find the first include path that the included file exists in.
List<string> IncludePathsToSearch = IncludePaths.GetPathsToSearch(FromFile);
foreach (string IncludePath in IncludePathsToSearch)
{
++SearchAttempts;
string RelativeFilePath = "";
try
{
RelativeFilePath = Path.Combine(IncludePath, RelativeIncludePath);
}
catch (ArgumentException Exception)
{
throw new BuildException(Exception, "Failed to combine null or invalid include paths.");
}
FileReference FullFilePath = null;
try
{
FullFilePath = new FileReference(RelativeFilePath);
}
catch (Exception)
{
}
if (FullFilePath != null && DirectoryLookupCache.FileExists(FullFilePath))
{
Result = FileItem.GetItemByFileReference(FullFilePath);
break;
}
}
}
IncludePathSearchAttempts += SearchAttempts;
if (UnrealBuildTool.bPrintPerformanceInfo)
{
// More than two search attempts indicates:
// - Include path was not relative to the directory that the including file was in
// - Include path was not relative to the project's base
if (SearchAttempts > 2)
{
Log.TraceVerbose(" Cache miss: " + RelativeIncludePath + " found after " + SearchAttempts.ToString() + " attempts: " + (Result != null ? Result.AbsolutePath : "NOT FOUND!"));
}
}
// Cache the result of the include path search.
IncludePaths.IncludeFileSearchDictionary.Add(InvariantPath, Result);
}
// @todo ubtmake: The old UBT tried to skip 'external' (STABLE) headers here. But it didn't work. We might want to do this though! Skip system headers and source/thirdparty headers!
if (Result != null)
{
Log.TraceVerbose("Resolved included file \"{0}\" to: {1}", RelativeIncludePath, Result.AbsolutePath);
}
else
{
Log.TraceVerbose("Couldn't resolve included file \"{0}\"", RelativeIncludePath);
}
return Result;
}
public List<FileItem> FindAndCacheAllIncludedFiles(FileItem SourceFile, CppIncludePaths IncludePaths, bool bOnlyCachedDependencies)
{
List<FileItem> Result = null;
if (IncludePaths.IncludeFileSearchDictionary == null)
{
IncludePaths.IncludeFileSearchDictionary = new Dictionary<string, FileItem>();
}
if (bOnlyCachedDependencies && bUseFlatCPPIncludeDependencyCache)
{
Result = FlatCPPIncludeDependencyCache.GetDependenciesForFile(SourceFile.Reference);
if (Result == null)
{
// Nothing cached for this file! It is new to us. This is the expected flow when our CPPIncludeDepencencyCache is missing.
}
}
else
{
// @todo ubtmake: HeaderParser.h is missing from the include set for Module.UnrealHeaderTool.cpp (failed to find include using: FileItem DirectIncludeResolvedFile = CPPEnvironment.FindIncludedFile(DirectInclude.IncludeName, !BuildConfiguration.bCheckExternalHeadersForModification, IncludePathsToSearch, IncludeFileSearchDictionary );)
// If we're doing an exhaustive include scan, make sure that we have our include dependency cache loaded and ready
if (!bOnlyCachedDependencies)
{
if (IncludeDependencyCache == null)
{
IncludeDependencyCache = DependencyCache.Create(DependencyCacheFile);
}
}
Result = new List<FileItem>();
IncludedFilesSet IncludedFileList = new IncludedFilesSet();
FindAndCacheAllIncludedFiles(SourceFile, IncludePaths, ref IncludedFileList, bOnlyCachedDependencies: bOnlyCachedDependencies);
foreach (FileItem IncludedFile in IncludedFileList)
{
Result.Add(IncludedFile);
}
// Update cache
if (bUseFlatCPPIncludeDependencyCache && !bOnlyCachedDependencies)
{
List<FileReference> Dependencies = new List<FileReference>();
foreach (FileItem IncludedFile in Result)
{
Dependencies.Add(IncludedFile.Reference);
}
FileReference PCHName = SourceFile.PrecompiledHeaderIncludeFilename;
FlatCPPIncludeDependencyCache.SetDependenciesForFile(SourceFile.Reference, PCHName, Dependencies);
}
}
return Result;
}
/// <summary>
/// Finds the files directly or indirectly included by the given C++ file.
/// </summary>
/// <param name="CPPFile">C++ file to get the dependencies for.</param>
/// <param name="IncludePaths"></param>
/// <param name="bOnlyCachedDependencies"></param>
/// <param name="Result">List of CPPFile dependencies.</param>
/// <returns>false if CPPFile is still being processed further down the callstack, true otherwise.</returns>
public bool FindAndCacheAllIncludedFiles(FileItem CPPFile, CppIncludePaths IncludePaths, ref IncludedFilesSet Result, bool bOnlyCachedDependencies)
{
IncludedFilesSet IncludedFileList;
Dictionary<FileItem, IncludedFilesSet> IncludedFilesMap = bOnlyCachedDependencies ? OnlyCachedIncludedFilesMap : ExhaustiveIncludedFilesMap;
if (!IncludedFilesMap.TryGetValue(CPPFile, out IncludedFileList))
{
DateTime TimerStartTime = DateTime.UtcNow;
IncludedFileList = new IncludedFilesSet();
// Add an uninitialized entry for the include file to avoid infinitely recursing on include file loops.
IncludedFilesMap.Add(CPPFile, IncludedFileList);
// Gather a list of names of files directly included by this C++ file.
List<DependencyInclude> DirectIncludes = GetDirectIncludeDependencies(CPPFile, bOnlyCachedDependencies: bOnlyCachedDependencies);
// Build a list of the unique set of files that are included by this file.
HashSet<FileItem> DirectlyIncludedFiles = new HashSet<FileItem>();
// require a for loop here because we need to keep track of the index in the list.
for (int DirectlyIncludedFileNameIndex = 0; DirectlyIncludedFileNameIndex < DirectIncludes.Count; ++DirectlyIncludedFileNameIndex)
{
// Resolve the included file name to an actual file.
DependencyInclude DirectInclude = DirectIncludes[DirectlyIncludedFileNameIndex];
if (!DirectInclude.HasAttemptedResolve ||
// ignore any preexisting resolve cache if we are not configured to use it.
!bUseIncludeDependencyResolveCache ||
// if we are testing the resolve cache, we force UBT to resolve every time to look for conflicts
bTestIncludeDependencyResolveCache
)
{
++TotalDirectIncludeResolveCacheMisses;
// search the include paths to resolve the file
FileItem DirectIncludeResolvedFile = CPPHeaders.FindIncludedFile(CPPFile.Reference, DirectInclude.IncludeName, IncludePaths);
if (DirectIncludeResolvedFile != null)
{
DirectlyIncludedFiles.Add(DirectIncludeResolvedFile);
}
IncludeDependencyCache.CacheResolvedIncludeFullPath(CPPFile, DirectlyIncludedFileNameIndex, DirectIncludeResolvedFile != null ? DirectIncludeResolvedFile.Reference : null, bUseIncludeDependencyResolveCache, bTestIncludeDependencyResolveCache);
}
else
{
// we might have cached an attempt to resolve the file, but couldn't actually find the file (system headers, etc).
if (DirectInclude.IncludeResolvedNameIfSuccessful != null)
{
DirectlyIncludedFiles.Add(FileItem.GetItemByFileReference(DirectInclude.IncludeResolvedNameIfSuccessful));
}
}
}
TotalDirectIncludeResolves += DirectIncludes.Count;
// Convert the dictionary of files included by this file into a list.
foreach (FileItem DirectlyIncludedFile in DirectlyIncludedFiles)
{
// Add the file we're directly including
IncludedFileList.Add(DirectlyIncludedFile);
// Also add all of the indirectly included files!
if (FindAndCacheAllIncludedFiles(DirectlyIncludedFile, IncludePaths, ref IncludedFileList, bOnlyCachedDependencies: bOnlyCachedDependencies) == false)
{
// DirectlyIncludedFile is a circular dependency which is still being processed
// further down the callstack. Add this file to its circular dependencies list
// so that it can update its dependencies later.
IncludedFilesSet DirectlyIncludedFileIncludedFileList;
if (IncludedFilesMap.TryGetValue(DirectlyIncludedFile, out DirectlyIncludedFileIncludedFileList))
{
DirectlyIncludedFileIncludedFileList.CircularDependencies.Add(CPPFile);
}
}
}
// All dependencies have been processed by now so update all circular dependencies
// with the full list.
foreach (FileItem CircularDependency in IncludedFileList.CircularDependencies)
{
IncludedFilesSet CircularDependencyIncludedFiles = IncludedFilesMap[CircularDependency];
foreach (FileItem IncludedFile in IncludedFileList)
{
CircularDependencyIncludedFiles.Add(IncludedFile);
}
}
// No need to keep this around anymore.
IncludedFileList.CircularDependencies.Clear();
// Done collecting files.
IncludedFileList.bIsInitialized = true;
TimeSpan TimerDuration = DateTime.UtcNow - TimerStartTime;
TotalTimeSpentGettingIncludes += TimerDuration.TotalSeconds;
}
if (IncludedFileList.bIsInitialized)
{
// Copy the list of files included by this file into the result list.
foreach (FileItem IncludedFile in IncludedFileList)
{
// If the result list doesn't contain this file yet, add the file and the files it includes.
// NOTE: For some reason in .NET 4, Add() is over twice as fast as calling UnionWith() on the set
Result.Add(IncludedFile);
}
return true;
}
else
{
// The IncludedFileList.bIsInitialized was false because we added a dummy entry further down the call stack. We're already processing
// the include list for this header elsewhere in the stack frame, so we don't need to add anything here.
return false;
}
}
public FileItem CachePCHUsageForCPPFile(FileItem CPPFile, CppIncludePaths IncludePaths, CppPlatform Platform)
{
// @todo ubtmake: We don't really need to scan every file looking for PCH headers, just need one. The rest is just for error checking.
// @todo ubtmake: We don't need all of the direct includes either. We just need the first, unless we want to check for errors.
List<DependencyInclude> DirectIncludeFilenames = GetDirectIncludeDependencies(CPPFile, bOnlyCachedDependencies: false);
if (UnrealBuildTool.bPrintDebugInfo)
{
Log.TraceVerbose("Found direct includes for {0}: {1}", Path.GetFileName(CPPFile.AbsolutePath), string.Join(", ", DirectIncludeFilenames.Select(F => F.IncludeName)));
}
if (DirectIncludeFilenames.Count == 0)
{
return null;
}
DependencyInclude FirstInclude = DirectIncludeFilenames[0];
// Resolve the PCH header to an absolute path.
// Check NullOrEmpty here because if the file could not be resolved we need to throw an exception
if (FirstInclude.IncludeResolvedNameIfSuccessful != null &&
// ignore any preexisting resolve cache if we are not configured to use it.
bUseIncludeDependencyResolveCache &&
// if we are testing the resolve cache, we force UBT to resolve every time to look for conflicts
!bTestIncludeDependencyResolveCache)
{
CPPFile.PrecompiledHeaderIncludeFilename = FirstInclude.IncludeResolvedNameIfSuccessful;
return FileItem.GetItemByFileReference(CPPFile.PrecompiledHeaderIncludeFilename);
}
// search the include paths to resolve the file.
string FirstIncludeName = FirstInclude.IncludeName;
UEBuildPlatform BuildPlatform = UEBuildPlatform.GetBuildPlatformForCPPTargetPlatform(Platform);
// convert back from relative to host path if needed
if (!BuildPlatform.UseAbsolutePathsInUnityFiles())
{
FirstIncludeName = RemoteExports.UnconvertPath(FirstIncludeName);
}
FileItem PrecompiledHeaderIncludeFile = CPPHeaders.FindIncludedFile(CPPFile.Reference, FirstIncludeName, IncludePaths);
if (PrecompiledHeaderIncludeFile == null)
{
FirstIncludeName = RemoteExports.UnconvertPath(FirstInclude.IncludeName);
throw new BuildException("The first include statement in source file '{0}' is trying to include the file '{1}' as the precompiled header, but that file could not be located in any of the module's include search paths.", CPPFile.AbsolutePath, FirstIncludeName);
}
IncludeDependencyCache.CacheResolvedIncludeFullPath(CPPFile, 0, PrecompiledHeaderIncludeFile.Reference, bUseIncludeDependencyResolveCache, bTestIncludeDependencyResolveCache);
CPPFile.PrecompiledHeaderIncludeFilename = PrecompiledHeaderIncludeFile.Reference;
return PrecompiledHeaderIncludeFile;
}
public static double TotalTimeSpentGettingIncludes = 0.0;
public static int TotalIncludesRequested = 0;
public static double DirectIncludeCacheMissesTotalTime = 0.0;
public static int TotalDirectIncludeCacheMisses = 0;
public static int TotalDirectIncludeResolveCacheMisses = 0;
public static int TotalDirectIncludeResolves = 0;
/// <summary>
/// Regex that matches #include statements.
/// </summary>
static readonly Regex CPPHeaderRegex = new Regex("(([ \t]*#[ \t]*include[ \t]*[<\"](?<HeaderFile>[^\">]*)[\">][^\n]*\n*)|([^\n]*\n*))*",
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
static readonly Regex MMHeaderRegex = new Regex("(([ \t]*#[ \t]*import[ \t]*[<\"](?<HeaderFile>[^\">]*)[\">][^\n]*\n*)|([^\n]*\n*))*",
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
/// <summary>
/// Regex that matches C++ code with UObject declarations which we will need to generated code for.
/// </summary>
static readonly Regex UObjectRegex = new Regex("^\\s*U(CLASS|STRUCT|ENUM|INTERFACE|DELEGATE)\\b", RegexOptions.Compiled | RegexOptions.Multiline);
// Maintains a cache of file contents
private static FileContentsCacheType FileContentsCache = new FileContentsCacheType();
// Checks if a file contains UObjects
public static bool DoesFileContainUObjects(string Filename)
{
string Contents = FileContentsCache.GetContents(Filename);
return UObjectRegex.IsMatch(Contents);
}
/// <summary>
/// Finds the names of files directly included by the given C++ file, and also whether the file contains any UObjects
/// </summary>
public List<DependencyInclude> GetDirectIncludeDependencies(FileItem CPPFile, bool bOnlyCachedDependencies)
{
// Try to fulfill request from cache first.
List<DependencyInclude> Info = IncludeDependencyCache.GetCachedDependencyInfo(CPPFile);
if (Info != null)
{
return Info;
}
List<DependencyInclude> Result = new List<DependencyInclude>();
if (bOnlyCachedDependencies)
{
return Result;
}
DateTime TimerStartTime = DateTime.UtcNow;
++CPPHeaders.TotalDirectIncludeCacheMisses;
Result = GetUncachedDirectIncludeDependencies(CPPFile, ProjectFile);
// Populate cache with results.
IncludeDependencyCache.SetDependencyInfo(CPPFile, Result);
CPPHeaders.DirectIncludeCacheMissesTotalTime += (DateTime.UtcNow - TimerStartTime).TotalSeconds;
return Result;
}
public static List<DependencyInclude> GetUncachedDirectIncludeDependencies(FileItem CPPFile, FileReference ProjectFile)
{
List<DependencyInclude> Result = new List<DependencyInclude>();
// Get the adjusted filename
string FileToRead = CPPFile.AbsolutePath;
// Read lines from the C++ file.
string FileContents = FileContentsCache.GetContents(FileToRead);
if (string.IsNullOrEmpty(FileContents))
{
return Result;
}
// Note: This depends on UBT executing w/ a working directory of the Engine/Source folder!
string EngineSourceFolder = Directory.GetCurrentDirectory();
string InstalledFolder = EngineSourceFolder;
Int32 EngineSourceIdx = EngineSourceFolder.IndexOf("\\Engine\\Source");
if (EngineSourceIdx != -1)
{
InstalledFolder = EngineSourceFolder.Substring(0, EngineSourceIdx);
}
if (Utils.IsRunningOnMono)
{
// Mono crashes when running a regex on a string longer than about 5000 characters, so we parse the file in chunks
int StartIndex = 0;
const int SafeTextLength = 4000;
while (StartIndex < FileContents.Length)
{
int EndIndex = StartIndex + SafeTextLength < FileContents.Length ? FileContents.IndexOf("\n", StartIndex + SafeTextLength) : FileContents.Length;
if (EndIndex == -1)
{
EndIndex = FileContents.Length;
}
Result.AddRange(CollectHeaders(ProjectFile, CPPFile, FileToRead, FileContents, InstalledFolder, StartIndex, EndIndex));
StartIndex = EndIndex + 1;
}
}
else
{
Result = CollectHeaders(ProjectFile, CPPFile, FileToRead, FileContents, InstalledFolder, 0, FileContents.Length);
}
return Result;
}
/// <summary>
/// Collects all header files included in a CPPFile
/// </summary>
/// <param name="ProjectFile"></param>
/// <param name="CPPFile"></param>
/// <param name="FileToRead"></param>
/// <param name="FileContents"></param>
/// <param name="InstalledFolder"></param>
/// <param name="StartIndex"></param>
/// <param name="EndIndex"></param>
private static List<DependencyInclude> CollectHeaders(FileReference ProjectFile, FileItem CPPFile, string FileToRead, string FileContents, string InstalledFolder, int StartIndex, int EndIndex)
{
List<DependencyInclude> Result = new List<DependencyInclude>();
Match M = CPPHeaderRegex.Match(FileContents, StartIndex, EndIndex - StartIndex);
CaptureCollection Captures = M.Groups["HeaderFile"].Captures;
Result.Capacity = Result.Count;
foreach (Capture C in Captures)
{
string HeaderValue = C.Value;
if (HeaderValue.IndexOfAny(Path.GetInvalidPathChars()) != -1)
{
throw new BuildException("In {0}: An #include statement contains invalid characters. You might be missing a double-quote character. (\"{1}\")", FileToRead, C.Value);
}
//@TODO: The intermediate exclusion is to work around autogenerated absolute paths in Module.SomeGame.cpp style files
bool bCheckForBackwardSlashes = FileToRead.StartsWith(InstalledFolder) || ((ProjectFile != null) && new FileReference(FileToRead).IsUnderDirectory(ProjectFile.Directory));
if (bCheckForBackwardSlashes && !FileToRead.Contains("Intermediate") && !FileToRead.Contains("ThirdParty") && HeaderValue.IndexOf('\\', 0) >= 0)
{
throw new BuildException("In {0}: #include \"{1}\" contains backslashes ('\\'), please use forward slashes ('/') instead.", FileToRead, C.Value);
}
HeaderValue = Utils.CleanDirectorySeparators(HeaderValue);
Result.Add(new DependencyInclude(HeaderValue));
}
// also look for #import in objective C files
string Ext = Path.GetExtension(CPPFile.AbsolutePath).ToUpperInvariant();
if (Ext == ".MM" || Ext == ".M")
{
M = MMHeaderRegex.Match(FileContents, StartIndex, EndIndex - StartIndex);
Captures = M.Groups["HeaderFile"].Captures;
Result.Capacity += Captures.Count;
foreach (Capture C in Captures)
{
Result.Add(new DependencyInclude(C.Value));
}
}
return Result;
}
}
}