X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FAutoGen.py;h=f59a8038d5a7cf7a5ffa82e2cb6ec235559f7ddf;hb=ede54e3588173178ec054b5c4dc181d3c63872b2;hp=c174b5a0bb8c8c523fd0985a7b22548fd3aae1ab;hpb=66b845ae06f1e48c693158ee0b8b4f610d5ada4a;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index c174b5a0bb..f59a8038d5 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -3569,8 +3569,11 @@ class ModuleAutoGen(AutoGen): if self.IsAsBuiltInfCreated: return - # Skip the following code for libraries + # Skip INF file generation for libraries if self.IsLibrary: + # Only store the library cache if needed + if GlobalData.gBinCacheDest: + self.CopyModuleToCache() return # Skip the following code for modules with no source files @@ -3897,7 +3900,7 @@ class ModuleAutoGen(AutoGen): self.CopyModuleToCache() def CopyModuleToCache(self): - FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.Name, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName) + FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName) CreateDirectory (FileDir) HashFile = path.join(self.BuildDir, self.Name + '.hash') if os.path.exists(HashFile): @@ -3906,6 +3909,12 @@ class ModuleAutoGen(AutoGen): ModuleFile = path.join(self.OutputDir, self.Name + '.inf') if os.path.exists(ModuleFile): shutil.copy2(ModuleFile, FileDir) + else: + OutputDir = self.OutputDir.replace('\\', '/').strip('/') + DebugDir = self.DebugDir.replace('\\', '/').strip('/') + for Item in self.CodaTargetList: + File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/') + self.OutputFile.add(File) if not self.OutputFile: Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain] self.OutputFile = Ma.Binaries @@ -3929,25 +3938,26 @@ class ModuleAutoGen(AutoGen): for f_ext in self.SourceFileList: if '.inc' in str(f_ext): return False - FileDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.Name, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName) + FileDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName) HashFile = path.join(FileDir, self.Name + '.hash') if os.path.exists(HashFile): f = open(HashFile, 'r') CacheHash = f.read() f.close() + self.GenModuleHash() if GlobalData.gModuleHash[self.Arch][self.Name]: if CacheHash == GlobalData.gModuleHash[self.Arch][self.Name]: for root, dir, files in os.walk(FileDir): for f in files: if self.Name + '.hash' in f: - shutil.copy2(HashFile, self.BuildDir) + shutil.copy(HashFile, self.BuildDir) else: File = path.join(root, f) sub_dir = os.path.relpath(File, FileDir) destination_file = os.path.join(self.OutputDir, sub_dir) destination_dir = os.path.dirname(destination_file) CreateDirectory(destination_dir) - shutil.copy2(File, destination_dir) + shutil.copy(File, destination_dir) if self.Name == "PcdPeim" or self.Name == "PcdDxe": CreatePcdDatabaseCode(self, TemplateString(), TemplateString()) return True @@ -3988,7 +3998,8 @@ class ModuleAutoGen(AutoGen): for LibraryAutoGen in self.LibraryAutoGenList: LibraryAutoGen.CreateMakeFile() - if self.CanSkip(): + # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping + if not GlobalData.gUseHashCache and self.CanSkip(): return if len(self.CustomMakefile) == 0: @@ -4031,7 +4042,8 @@ class ModuleAutoGen(AutoGen): for LibraryAutoGen in self.LibraryAutoGenList: LibraryAutoGen.CreateCodeFile() - if self.CanSkip(): + # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping + if not GlobalData.gUseHashCache and self.CanSkip(): return AutoGenList = [] @@ -4093,13 +4105,20 @@ class ModuleAutoGen(AutoGen): return RetVal def GenModuleHash(self): + # Initialize a dictionary for each arch type if self.Arch not in GlobalData.gModuleHash: GlobalData.gModuleHash[self.Arch] = {} - if self.Name in GlobalData.gModuleHash[self.Arch] and GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy(): - return False + + # Early exit if module or library has been hashed and is in memory + if self.Name in GlobalData.gModuleHash[self.Arch]: + return GlobalData.gModuleHash[self.Arch][self.Name].encode('utf-8') + + # Initialze hash object m = hashlib.md5() + # Add Platform level hash m.update(GlobalData.gPlatformHash.encode('utf-8')) + # Add Package level hash if self.DependentPackageList: for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName): @@ -4118,6 +4137,7 @@ class ModuleAutoGen(AutoGen): Content = f.read() f.close() m.update(Content) + # Add Module's source files if self.SourceFileList: for File in sorted(self.SourceFileList, key=lambda x: str(x)): @@ -4126,27 +4146,45 @@ class ModuleAutoGen(AutoGen): f.close() m.update(Content) - ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash") - if self.Name not in GlobalData.gModuleHash[self.Arch]: - GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest() - if GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy(): - return False - return SaveFileOnChange(ModuleHashFile, m.hexdigest(), False) + GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest() + + return GlobalData.gModuleHash[self.Arch][self.Name].encode('utf-8') ## Decide whether we can skip the ModuleAutoGen process def CanSkipbyHash(self): + # Hashing feature is off + if not GlobalData.gUseHashCache: + return False + + # Initialize a dictionary for each arch type + if self.Arch not in GlobalData.gBuildHashSkipTracking: + GlobalData.gBuildHashSkipTracking[self.Arch] = dict() + # If library or Module is binary do not skip by hash if self.IsBinaryModule: return False + # .inc is contains binary information so do not skip by hash as well for f_ext in self.SourceFileList: if '.inc' in str(f_ext): return False - if GlobalData.gUseHashCache: - # If there is a valid hash or function generated a valid hash; function will return False - # and the statement below will return True - return not self.GenModuleHash() - return False + + # Use Cache, if exists and if Module has a copy in cache + if GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy(): + return True + + # Early exit for libraries that haven't yet finished building + HashFile = path.join(self.BuildDir, self.Name + ".hash") + if self.IsLibrary and not os.path.exists(HashFile): + return False + + # Return a Boolean based on if can skip by hash, either from memory or from IO. + if self.Name not in GlobalData.gBuildHashSkipTracking[self.Arch]: + # If hashes are the same, SaveFileOnChange() will return False. + GlobalData.gBuildHashSkipTracking[self.Arch][self.Name] = not SaveFileOnChange(HashFile, self.GenModuleHash(), True) + return GlobalData.gBuildHashSkipTracking[self.Arch][self.Name] + else: + return GlobalData.gBuildHashSkipTracking[self.Arch][self.Name] ## Decide whether we can skip the ModuleAutoGen process # If any source file is newer than the module than we cannot skip