BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1923 The GenFds multi-thread will build fail if enable the build cache. 1. First, produce the build cache: edk2>build -p OvmfPkg\OvmfPkgIa32X64.dsc -a IA32 -a X64 -t VS2015x86 -n 5 --genfds-multi-thread --hash --binary-destination=BinCache 2. Remove the build folder: edk2>rmdir Build /s /q 3. Clean build with build cache and GenFds multi-thread enabled together: edk2>build -p OvmfPkg\OvmfPkgIa32X64.dsc -a IA32 -a X64 -t VS2015x86 -n 5 --genfds-multi-thread --hash --binary-source=BinCache If disable GenFds multi-thread, the build cache can work well This patch is going to fix that issue. Cc: Bob Feng Cc: Liming Gao Cc: Steven Shi Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/AutoGen/ModuleAutoGen.py | 41 +++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py index 36bbaffa56..4bb72eb10d 100644 --- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py @@ -1249,6 +1249,7 @@ class ModuleAutoGen(AutoGen): retVal = set() OutputDir = self.OutputDir.replace('\\', '/').strip('/') DebugDir = self.DebugDir.replace('\\', '/').strip('/') + FfsOutputDir = self.FfsOutputDir.replace('\\', '/').rstrip('/') for Item in self.CodaTargetList: File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/') retVal.add(File) @@ -1264,6 +1265,11 @@ class ModuleAutoGen(AutoGen): if File.lower().endswith('.pdb'): retVal.add(File) + for Root, Dirs, Files in os.walk(FfsOutputDir): + for File in Files: + if File.lower().endswith('.ffs'): + retVal.add(File) + return retVal ## Create AsBuilt INF file the module @@ -1594,8 +1600,16 @@ class ModuleAutoGen(AutoGen): self.IsAsBuiltInfCreated = True + def CacheCopyFile(self, OriginDir, CopyDir, File): + sub_dir = os.path.relpath(File, CopyDir) + destination_file = os.path.join(OriginDir, sub_dir) + destination_dir = os.path.dirname(destination_file) + CreateDirectory(destination_dir) + CopyFileOnChange(File, destination_dir) + def CopyModuleToCache(self): FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.Name, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName) + FfsDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name) CreateDirectory (FileDir) HashFile = path.join(self.BuildDir, self.Name + '.hash') if os.path.exists(HashFile): @@ -1609,13 +1623,15 @@ class ModuleAutoGen(AutoGen): for File in self.OutputFile: File = str(File) if not os.path.isabs(File): - File = os.path.join(self.OutputDir, File) + NewFile = os.path.join(self.OutputDir, File) + if not os.path.exists(NewFile): + NewFile = os.path.join(self.FfsOutputDir, File) + File = NewFile if os.path.exists(File): - sub_dir = os.path.relpath(File, self.OutputDir) - destination_file = os.path.join(FileDir, sub_dir) - destination_dir = os.path.dirname(destination_file) - CreateDirectory(destination_dir) - CopyFileOnChange(File, destination_dir) + if File.endswith('.ffs'): + self.CacheCopyFile(FfsDir, self.FfsOutputDir, File) + else: + self.CacheCopyFile(FileDir, self.OutputDir, File) def AttemptModuleCacheCopy(self): # If library or Module is binary do not skip by hash @@ -1626,6 +1642,7 @@ class ModuleAutoGen(AutoGen): 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) + FfsDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name) HashFile = path.join(FileDir, self.Name + '.hash') if os.path.exists(HashFile): f = open(HashFile, 'r') @@ -1640,11 +1657,13 @@ class ModuleAutoGen(AutoGen): CopyFileOnChange(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) - CopyFileOnChange(File, destination_dir) + self.CacheCopyFile(self.OutputDir, FileDir, File) + if GlobalData.gEnableGenfdsMultiThread and os.path.exists(FfsDir): + for root, dir, files in os.walk(FfsDir): + for f in files: + File = path.join(root, f) + self.CacheCopyFile(self.FfsOutputDir, FfsDir, File) + if self.Name == "PcdPeim" or self.Name == "PcdDxe": CreatePcdDatabaseCode(self, TemplateString(), TemplateString()) return True -- 2.14.1.windows.1