BaseTools: Move Build Cache related function out of CreateAsBuiltInf

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1932
There are two functions in current CreateAsBuiltInf, Copy Binary files
to build cache folder and create asbuild inf file.

This patch is to separate UpdateBuildCache and CreateAsBuiltInf into
two functions.

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Steven Shi <steven.shi@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Christian Rodriguez <christian.rodriguez@intel.com>
Reviewed-by: Steven Shi <steven.shi@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
Bob Feng 2019-06-24 09:51:44 +08:00 committed by Feng, Bob C
parent dc174cd9e5
commit b8ac0b7f28
2 changed files with 59 additions and 37 deletions

View File

@ -3579,19 +3579,37 @@ class ModuleAutoGen(AutoGen):
fInputfile.close () fInputfile.close ()
return OutputName return OutputName
@cached_property
def OutputFile(self):
retVal = set()
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('/')
retVal.add(File)
if self.DepexGenerated:
retVal.add(self.Name + '.depex')
Bin = self._GenOffsetBin()
if Bin:
retVal.add(Bin)
for Root, Dirs, Files in os.walk(OutputDir):
for File in Files:
if File.lower().endswith('.pdb'):
retVal.add(File)
return retVal
## Create AsBuilt INF file the module ## Create AsBuilt INF file the module
# #
def CreateAsBuiltInf(self): def CreateAsBuiltInf(self):
self.OutputFile = set()
if self.IsAsBuiltInfCreated: if self.IsAsBuiltInfCreated:
return return
# Skip INF file generation for libraries # Skip INF file generation for libraries
if self.IsLibrary: if self.IsLibrary:
# Only store the library cache if needed
if GlobalData.gBinCacheDest:
self.CopyModuleToCache()
return return
# Skip the following code for modules with no source files # Skip the following code for modules with no source files
@ -3712,7 +3730,6 @@ class ModuleAutoGen(AutoGen):
DebugDir = self.DebugDir.replace('\\', '/').strip('/') DebugDir = self.DebugDir.replace('\\', '/').strip('/')
for Item in self.CodaTargetList: for Item in self.CodaTargetList:
File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/') File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')
self.OutputFile.add(File)
if os.path.isabs(File): if os.path.isabs(File):
File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/') File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')
if Item.Target.Ext.lower() == '.aml': if Item.Target.Ext.lower() == '.aml':
@ -3728,7 +3745,6 @@ class ModuleAutoGen(AutoGen):
if os.path.exists(DepexFile): if os.path.exists(DepexFile):
self.DepexGenerated = True self.DepexGenerated = True
if self.DepexGenerated: if self.DepexGenerated:
self.OutputFile.add(self.Name + '.depex')
if self.ModuleType in [SUP_MODULE_PEIM]: if self.ModuleType in [SUP_MODULE_PEIM]:
AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex') AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex')
elif self.ModuleType in [SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]: elif self.ModuleType in [SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:
@ -3739,13 +3755,11 @@ class ModuleAutoGen(AutoGen):
Bin = self._GenOffsetBin() Bin = self._GenOffsetBin()
if Bin: if Bin:
AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin) AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin)
self.OutputFile.add(Bin)
for Root, Dirs, Files in os.walk(OutputDir): for Root, Dirs, Files in os.walk(OutputDir):
for File in Files: for File in Files:
if File.lower().endswith('.pdb'): if File.lower().endswith('.pdb'):
AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File) AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)
self.OutputFile.add(File)
HeaderComments = self.Module.HeaderComments HeaderComments = self.Module.HeaderComments
StartPos = 0 StartPos = 0
for Index in range(len(HeaderComments)): for Index in range(len(HeaderComments)):
@ -3914,8 +3928,6 @@ class ModuleAutoGen(AutoGen):
SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False) SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)
self.IsAsBuiltInfCreated = True self.IsAsBuiltInfCreated = True
if GlobalData.gBinCacheDest:
self.CopyModuleToCache()
def CopyModuleToCache(self): def CopyModuleToCache(self):
FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, 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)
@ -3923,30 +3935,24 @@ class ModuleAutoGen(AutoGen):
HashFile = path.join(self.BuildDir, self.Name + '.hash') HashFile = path.join(self.BuildDir, self.Name + '.hash')
if os.path.exists(HashFile): if os.path.exists(HashFile):
CopyFileOnChange(HashFile, FileDir) CopyFileOnChange(HashFile, FileDir)
if not self.IsLibrary: ModuleFile = path.join(self.OutputDir, self.Name + '.inf')
ModuleFile = path.join(self.OutputDir, self.Name + '.inf') if os.path.exists(ModuleFile):
if os.path.exists(ModuleFile): CopyFileOnChange(ModuleFile, FileDir)
CopyFileOnChange(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: if not self.OutputFile:
Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain] Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
self.OutputFile = Ma.Binaries self.OutputFile = Ma.Binaries
if self.OutputFile:
for File in self.OutputFile: for File in self.OutputFile:
File = str(File) File = str(File)
if not os.path.isabs(File): if not os.path.isabs(File):
File = os.path.join(self.OutputDir, File) File = os.path.join(self.OutputDir, File)
if os.path.exists(File): if os.path.exists(File):
sub_dir = os.path.relpath(File, self.OutputDir) sub_dir = os.path.relpath(File, self.OutputDir)
destination_file = os.path.join(FileDir, sub_dir) destination_file = os.path.join(FileDir, sub_dir)
destination_dir = os.path.dirname(destination_file) destination_dir = os.path.dirname(destination_file)
CreateDirectory(destination_dir) CreateDirectory(destination_dir)
CopyFileOnChange(File, destination_dir) CopyFileOnChange(File, destination_dir)
def AttemptModuleCacheCopy(self): def AttemptModuleCacheCopy(self):
# If library or Module is binary do not skip by hash # If library or Module is binary do not skip by hash

View File

@ -1250,6 +1250,9 @@ class Build():
BuildCommand = BuildCommand + [Target] BuildCommand = BuildCommand + [Target]
LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir) LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
self.CreateAsBuiltInf() self.CreateAsBuiltInf()
if GlobalData.gBinCacheDest:
self.UpdateBuildCache()
self.BuildModules = []
return True return True
# build library # build library
@ -1268,6 +1271,9 @@ class Build():
NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Mod, makefile)), 'pbuild'] NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Mod, makefile)), 'pbuild']
LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir) LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
self.CreateAsBuiltInf() self.CreateAsBuiltInf()
if GlobalData.gBinCacheDest:
self.UpdateBuildCache()
self.BuildModules = []
return True return True
# cleanlib # cleanlib
@ -1361,6 +1367,9 @@ class Build():
BuildCommand = BuildCommand + [Target] BuildCommand = BuildCommand + [Target]
AutoGenObject.BuildTime = LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir) AutoGenObject.BuildTime = LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
self.CreateAsBuiltInf() self.CreateAsBuiltInf()
if GlobalData.gBinCacheDest:
self.UpdateBuildCache()
self.BuildModules = []
return True return True
# genfds # genfds
@ -1874,6 +1883,9 @@ class Build():
ExitFlag.set() ExitFlag.set()
BuildTask.WaitForComplete() BuildTask.WaitForComplete()
self.CreateAsBuiltInf() self.CreateAsBuiltInf()
if GlobalData.gBinCacheDest:
self.UpdateBuildCache()
self.BuildModules = []
self.MakeTime += int(round((time.time() - MakeContiue))) self.MakeTime += int(round((time.time() - MakeContiue)))
if BuildTask.HasError(): if BuildTask.HasError():
self.invalidateHash() self.invalidateHash()
@ -2074,6 +2086,9 @@ class Build():
ExitFlag.set() ExitFlag.set()
BuildTask.WaitForComplete() BuildTask.WaitForComplete()
self.CreateAsBuiltInf() self.CreateAsBuiltInf()
if GlobalData.gBinCacheDest:
self.UpdateBuildCache()
self.BuildModules = []
self.MakeTime += int(round((time.time() - MakeContiue))) self.MakeTime += int(round((time.time() - MakeContiue)))
# #
# Check for build error, and raise exception if one # Check for build error, and raise exception if one
@ -2213,24 +2228,25 @@ class Build():
RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True) RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)
def CreateAsBuiltInf(self): def CreateAsBuiltInf(self):
for Module in self.BuildModules:
Module.CreateAsBuiltInf()
def UpdateBuildCache(self):
all_lib_set = set() all_lib_set = set()
all_mod_set = set() all_mod_set = set()
for Module in self.BuildModules: for Module in self.BuildModules:
Module.CreateAsBuiltInf() Module.CopyModuleToCache()
all_mod_set.add(Module) all_mod_set.add(Module)
for Module in self.HashSkipModules: for Module in self.HashSkipModules:
if GlobalData.gBinCacheDest: Module.CopyModuleToCache()
Module.CopyModuleToCache()
all_mod_set.add(Module) all_mod_set.add(Module)
for Module in all_mod_set: for Module in all_mod_set:
for lib in Module.LibraryAutoGenList: for lib in Module.LibraryAutoGenList:
all_lib_set.add(lib) all_lib_set.add(lib)
for lib in all_lib_set: for lib in all_lib_set:
if GlobalData.gBinCacheDest: lib.CopyModuleToCache()
lib.CopyModuleToCache()
all_lib_set.clear() all_lib_set.clear()
all_mod_set.clear() all_mod_set.clear()
self.BuildModules = []
self.HashSkipModules = [] self.HashSkipModules = []
## Do some clean-up works when error occurred ## Do some clean-up works when error occurred
def Relinquish(self): def Relinquish(self):