BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1958 Current build cache cannot generate the offset file for hii/vfr module Reproduce steps on OVMF: 1. Generate the build cache and save the build folder as Build1: $ source edksetup.sh $ build -p OvmfPkg/OvmfPkgIa32X64.dsc -a IA32 -a X64 -t GCC5 -b NOOPT --hash --binary-destination=BinCache $ mv Build/ Build1 2. Consume the build cache and save the build folder as Build2: $ build -p OvmfPkg/OvmfPkgIa32X64.dsc -a IA32 -a X64 -t GCC5 -b NOOPT --hash --binary-source=BinCache $ mv Build Build2 Compare the hii/vfr module ffs folder, e.g. UiApp as below, in the Build1 and Build2, you will find the *.offset, *.raw, *.raw.txt, *.map files are missing. This Patch is going to add these content to Cache Cc: Bob Feng Cc: Liming Gao Cc: Steven Shi Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/AutoGen/ModuleAutoGen.py | 38 ++++++++++++++++++++++-- BaseTools/Source/Python/build/build.py | 9 +++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py index 4bb72eb10d..d9baad9c62 100644 --- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py @@ -1244,6 +1244,19 @@ class ModuleAutoGen(AutoGen): fStringIO.close () fInputfile.close () return OutputName + + @cached_property + def OutputFfsFile(self): + retVal = set() + FfsOutputDir = self.FfsOutputDir.replace('\\', '/').rstrip('/') + for Root, Dirs, Files in os.walk(FfsOutputDir): + for File in Files: + if File.lower().endswith('.ffs') or File.lower().endswith('.offset') or File.lower().endswith('.raw') \ + or File.lower().endswith('.raw.txt') or File.lower().endswith('.map'): + retVal.add(File) + + return retVal + @cached_property def OutputFile(self): retVal = set() @@ -1267,7 +1280,8 @@ class ModuleAutoGen(AutoGen): for Root, Dirs, Files in os.walk(FfsOutputDir): for File in Files: - if File.lower().endswith('.ffs'): + if File.lower().endswith('.ffs') or File.lower().endswith('.offset') or File.lower().endswith('.raw') \ + or File.lower().endswith('.raw.txt') or File.lower().endswith('.map'): retVal.add(File) return retVal @@ -1607,6 +1621,23 @@ class ModuleAutoGen(AutoGen): CreateDirectory(destination_dir) CopyFileOnChange(File, destination_dir) + def CopyFfsToCache(self): + FfsDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name) + for File in self.OutputFfsFile: + File = str(File) + if not os.path.isabs(File): + FfsFile = os.path.join(FfsDir, File) + NewFile = os.path.join(self.FfsOutputDir, File) + File = NewFile + else: + sub_dir = os.path.relpath(File, self.FfsOutputDir) + destination_file = os.path.join(FfsDir, sub_dir) + FfsFile = os.path.dirname(destination_file) + if os.path.exists(File) and not os.path.exists(FfsFile): + if File.lower().endswith('.ffs') or File.lower().endswith('.offset') or File.lower().endswith('.raw') \ + or File.lower().endswith('.raw.txt') or File.lower().endswith('.map'): + self.CacheCopyFile(FfsDir, self.FfsOutputDir, File) + 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) @@ -1628,7 +1659,8 @@ class ModuleAutoGen(AutoGen): NewFile = os.path.join(self.FfsOutputDir, File) File = NewFile if os.path.exists(File): - if File.endswith('.ffs'): + if File.lower().endswith('.ffs') or File.lower().endswith('.offset') or File.lower().endswith('.raw') \ + or File.lower().endswith('.raw.txt') or File.lower().endswith('.map'): self.CacheCopyFile(FfsDir, self.FfsOutputDir, File) else: self.CacheCopyFile(FileDir, self.OutputDir, File) @@ -1658,7 +1690,7 @@ class ModuleAutoGen(AutoGen): else: File = path.join(root, f) self.CacheCopyFile(self.OutputDir, FileDir, File) - if GlobalData.gEnableGenfdsMultiThread and os.path.exists(FfsDir): + if os.path.exists(FfsDir): for root, dir, files in os.walk(FfsDir): for f in files: File = path.join(root, f) diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index dc92495f3f..153c77aec8 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -2084,7 +2084,6 @@ class Build(): BuildTask.WaitForComplete() if GlobalData.gBinCacheDest: self.UpdateBuildCache() - self.BuildModules = [] self.MakeTime += int(round((time.time() - MakeContiue))) # # Check for build error, and raise exception if one @@ -2136,6 +2135,9 @@ class Build(): # Save MAP buffer into MAP file. # self._SaveMapFile(MapBuffer, Wa) + if not GlobalData.gEnableGenfdsMultiThread and GlobalData.gBinCacheDest: + self.UpdateBuildFfsCache() + self.BuildModules = [] self.invalidateHash() ## Generate GuidedSectionTools.txt in the FV directories. @@ -2244,6 +2246,11 @@ class Build(): all_lib_set.clear() all_mod_set.clear() self.HashSkipModules = [] + + def UpdateBuildFfsCache(self): + for Module in self.BuildModules: + Module.CopyFfsToCache() + ## Do some clean-up works when error occurred def Relinquish(self): OldLogLevel = EdkLogger.GetLevel() -- 2.14.1.windows.1