/// <summary> /// Creates and deserializes the dependency cache at the passed in location /// </summary> /// <param name="CachePath">Name of the cache file to deserialize</param> public static DependencyCache Create(FileReference CacheFile) { // See whether the cache file exists. if (CacheFile.Exists()) { if (BuildConfiguration.bPrintPerformanceInfo) { Log.TraceInformation("Loading existing IncludeFileCache: " + CacheFile.FullName); } DateTime TimerStartTime = DateTime.UtcNow; // Deserialize cache from disk if there is one. DependencyCache Result = Load(CacheFile); if (Result != null) { // Successfully serialize, create the transient variables and return cache. Result.UpdateTimeUtc = DateTime.UtcNow; TimeSpan TimerDuration = DateTime.UtcNow - TimerStartTime; if (BuildConfiguration.bPrintPerformanceInfo) { Log.TraceInformation("Loading IncludeFileCache took " + TimerDuration.TotalSeconds + "s"); } //Telemetry.SendEvent("LoadIncludeDependencyCacheStats.2", "TotalDuration", TimerDuration.TotalSeconds.ToString("0.00")); return(Result); } } // Fall back to a clean cache on error or non-existance. return(new DependencyCache(CacheFile)); }
/// <summary> /// Loads the cache from the passed in file. /// </summary> /// <param name="Cache">File to deserialize from</param> public static DependencyCache Load(FileReference CacheFile) { DependencyCache Result = null; try { string CacheBuildMutexPath = CacheFile.FullName + ".buildmutex"; // If the .buildmutex file for the cache is present, it means that something went wrong between loading // and saving the cache last time (most likely the UBT process being terminated), so we don't want to load // it. if (!File.Exists(CacheBuildMutexPath)) { using (File.Create(CacheBuildMutexPath)) { } using (BinaryReader Reader = new BinaryReader(new FileStream(CacheFile.FullName, FileMode.Open, FileAccess.Read))) { if (Reader.ReadInt32() == FileSignature) { Result = DependencyCache.Deserialize(Reader); } } } } catch (Exception Ex) { Console.Error.WriteLine("Failed to read dependency cache: {0}", Ex.Message); CacheFile.Delete(); } return(Result); }
/// <summary> /// Deserialize the dependency cache from a binary reader /// </summary> /// <param name="Reader">Reader for the cache data</param> /// <returns>New dependency cache object</returns> static DependencyCache Deserialize(BinaryReader Reader) { DependencyCache Cache = new DependencyCache(Reader.ReadFileReference()); Cache.CreationTimeUtc = DateTime.FromBinary(Reader.ReadInt64()); int NumEntries = Reader.ReadInt32(); Cache.DependencyMap = new Dictionary <FileReference, List <DependencyInclude> >(NumEntries); List <FileReference> UniqueFiles = new List <FileReference>(); for (int Idx = 0; Idx < NumEntries; Idx++) { FileReference File = Reader.ReadFileReference(); int NumIncludes = Reader.ReadInt32(); List <DependencyInclude> Includes = new List <DependencyInclude>(NumIncludes); for (int IncludeIdx = 0; IncludeIdx < NumIncludes; IncludeIdx++) { DependencyInclude Include = new DependencyInclude(Reader.ReadString()); Include.HasAttemptedResolve = Reader.ReadBoolean(); Include.IncludeResolvedNameIfSuccessful = Reader.ReadFileReference(UniqueFiles); Includes.Add(Include); } Cache.DependencyMap.Add(File, Includes); } Cache.CreateFileExistsInfo(); Cache.ResetUnresolvedDependencies(); return(Cache); }
/** * Creates and deserializes the dependency cache at the passed in location * * @param CachePath Name of the cache file to deserialize */ public static DependencyCache Create(string CachePath) { // See whether the cache file exists. FileItem Cache = FileItem.GetItemByPath(CachePath); if (Cache.bExists) { if (BuildConfiguration.bPrintPerformanceInfo) { Log.TraceInformation("Loading existing IncludeFileCache: " + Cache.AbsolutePath); } var TimerStartTime = DateTime.UtcNow; // Deserialize cache from disk if there is one. DependencyCache Result = Load(Cache); if (Result != null) { // Successfully serialize, create the transient variables and return cache. Result.CachePath = CachePath; Result.CacheUpdateDate = DateTimeOffset.Now; var TimerDuration = DateTime.UtcNow - TimerStartTime; if (BuildConfiguration.bPrintPerformanceInfo) { Log.TraceInformation("Loading IncludeFileCache took " + TimerDuration.TotalSeconds + "s"); } Telemetry.SendEvent("LoadIncludeDependencyCacheStats.2", "TotalDuration", TimerDuration.TotalSeconds.ToString("0.00")); return(Result); } } // Fall back to a clean cache on error or non-existance. return(new DependencyCache(Cache)); }
/** * Loads the cache from the passed in file. * * @param Cache File to deserialize from */ public static DependencyCache Load(FileItem Cache) { DependencyCache Result = null; try { using (FileStream Stream = new FileStream(Cache.AbsolutePath, FileMode.Open, FileAccess.Read)) { BinaryFormatter Formatter = new BinaryFormatter(); Result = Formatter.Deserialize(Stream) as DependencyCache; } Result.CreateFileExistsInfo(); Result.ResetUnresolvedDependencies(); } catch (Exception Ex) { // Don't bother logging this expected error. // It's due to a change in the CacheCreateDate type. if (Ex.Message != "Object of type 'System.DateTime' cannot be converted to type 'System.DateTimeOffset'" && Ex.Message != "Object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.String]]' cannot be converted to type 'System.Collections.Generic.Dictionary`2[System.String,UnrealBuildTool.DependencyInfo]'.") // To catch serialization differences added when we added the DependencyInfo struct { Console.Error.WriteLine("Failed to read dependency cache: {0}", Ex.Message); } } return(Result); }
public static List <FileItem> FindAndCacheAllIncludedFiles(UEBuildTarget Target, FileItem SourceFile, UEBuildPlatform BuildPlatform, CPPIncludeInfo CPPIncludeInfo, bool bOnlyCachedDependencies) { List <FileItem> Result = null; if (CPPIncludeInfo.IncludeFileSearchDictionary == null) { CPPIncludeInfo.IncludeFileSearchDictionary = new Dictionary <string, FileItem>(); } bool bUseFlatCPPIncludeDependencyCache = BuildConfiguration.bUseUBTMakefiles && UnrealBuildTool.IsAssemblingBuild; if (bOnlyCachedDependencies && bUseFlatCPPIncludeDependencyCache) { Result = FlatCPPIncludeDependencyCache[Target].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.ContainsKey(Target)) { IncludeDependencyCache.Add(Target, DependencyCache.Create(DependencyCache.GetDependencyCachePathForTarget(Target))); } } Result = new List <FileItem>(); IncludedFilesSet IncludedFileList = new IncludedFilesSet(); CPPEnvironment.FindAndCacheAllIncludedFiles(Target, SourceFile, BuildPlatform, CPPIncludeInfo, 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[Target].SetDependenciesForFile(SourceFile.Reference, PCHName, Dependencies); } } 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.Location); if (Result == null) { // Nothing cached for this file! It is new to us. This is the expected flow when our CPPIncludeDepencencyCache is missing. } } else { // 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); } } // Get the headers Result = FindAndCacheIncludedFiles(SourceFile, IncludePaths, bOnlyCachedDependencies); // Update cache if (bUseFlatCPPIncludeDependencyCache && !bOnlyCachedDependencies) { List <FileReference> Dependencies = new List <FileReference>(); foreach (FileItem IncludedFile in Result) { Dependencies.Add(IncludedFile.Location); } FileReference PCHName = SourceFile.PrecompiledHeaderIncludeFilename; FlatCPPIncludeDependencyCache.SetDependenciesForFile(SourceFile.Location, PCHName, Dependencies); } } return(Result); }
/** * Loads the cache from the passed in file. * * @param Cache File to deserialize from */ public static DependencyCache Load(FileItem Cache) { DependencyCache Result = null; try { string CacheBuildMutexPath = Cache.AbsolutePath + ".buildmutex"; // If the .buildmutex file for the cache is present, it means that something went wrong between loading // and saving the cache last time (most likely the UBT process being terminated), so we don't want to load // it. if (!File.Exists(CacheBuildMutexPath)) { using (File.Create(CacheBuildMutexPath)) { } using (FileStream Stream = new FileStream(Cache.AbsolutePath, FileMode.Open, FileAccess.Read)) { BinaryFormatter Formatter = new BinaryFormatter(); Result = Formatter.Deserialize(Stream) as DependencyCache; } Result.CreateFileExistsInfo(); Result.ResetUnresolvedDependencies(); } } catch (Exception Ex) { // Don't bother logging this expected error. // It's due to a change in the CacheCreateDate type. if (Ex.Message != "Object of type 'System.DateTime' cannot be converted to type 'System.DateTimeOffset'" && Ex.Message != "Object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.String]]' cannot be converted to type 'System.Collections.Generic.Dictionary`2[System.String,UnrealBuildTool.DependencyInfo]'.") // To catch serialization differences added when we added the DependencyInfo struct { Console.Error.WriteLine("Failed to read dependency cache: {0}", Ex.Message); } } return(Result); }
/// <summary> /// Deserialize the dependency cache from a binary reader /// </summary> /// <param name="Reader">Reader for the cache data</param> /// <returns>New dependency cache object</returns> static DependencyCache Deserialize(BinaryReader Reader) { DependencyCache Cache = new DependencyCache(Reader.ReadFileReference()); Cache.CreationTimeUtc = DateTime.FromBinary(Reader.ReadInt64()); int NumEntries = Reader.ReadInt32(); Cache.DependencyMap = new Dictionary<FileReference, List<DependencyInclude>>(NumEntries); List<FileReference> UniqueFiles = new List<FileReference>(); for (int Idx = 0; Idx < NumEntries; Idx++) { FileReference File = Reader.ReadFileReference(); int NumIncludes = Reader.ReadInt32(); List<DependencyInclude> Includes = new List<DependencyInclude>(NumIncludes); for (int IncludeIdx = 0; IncludeIdx < NumIncludes; IncludeIdx++) { DependencyInclude Include = new DependencyInclude(Reader.ReadString()); Include.HasAttemptedResolve = Reader.ReadBoolean(); Include.IncludeResolvedNameIfSuccessful = Reader.ReadFileReference(UniqueFiles); Includes.Add(Include); } Cache.DependencyMap.Add(File, Includes); } Cache.CreateFileExistsInfo(); Cache.ResetUnresolvedDependencies(); return Cache; }