Skip to content

Commit b8ac0b7

Browse files
committed
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 <[email protected]> Cc: Steven Shi <[email protected]> Cc: Liming Gao <[email protected]> Cc: Christian Rodriguez <[email protected]> Reviewed-by: Steven Shi <[email protected]> Reviewed-by: Jaben Carsey <[email protected]>
1 parent dc174cd commit b8ac0b7

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

BaseTools/Source/Python/AutoGen/AutoGen.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,19 +3579,37 @@ def _GenOffsetBin(self):
35793579
fInputfile.close ()
35803580
return OutputName
35813581

3582+
@cached_property
3583+
def OutputFile(self):
3584+
retVal = set()
3585+
OutputDir = self.OutputDir.replace('\\', '/').strip('/')
3586+
DebugDir = self.DebugDir.replace('\\', '/').strip('/')
3587+
for Item in self.CodaTargetList:
3588+
File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')
3589+
retVal.add(File)
3590+
if self.DepexGenerated:
3591+
retVal.add(self.Name + '.depex')
3592+
3593+
Bin = self._GenOffsetBin()
3594+
if Bin:
3595+
retVal.add(Bin)
3596+
3597+
for Root, Dirs, Files in os.walk(OutputDir):
3598+
for File in Files:
3599+
if File.lower().endswith('.pdb'):
3600+
retVal.add(File)
3601+
3602+
return retVal
3603+
35823604
## Create AsBuilt INF file the module
35833605
#
35843606
def CreateAsBuiltInf(self):
3585-
self.OutputFile = set()
35863607

35873608
if self.IsAsBuiltInfCreated:
35883609
return
35893610

35903611
# Skip INF file generation for libraries
35913612
if self.IsLibrary:
3592-
# Only store the library cache if needed
3593-
if GlobalData.gBinCacheDest:
3594-
self.CopyModuleToCache()
35953613
return
35963614

35973615
# Skip the following code for modules with no source files
@@ -3712,7 +3730,6 @@ def CreateAsBuiltInf(self):
37123730
DebugDir = self.DebugDir.replace('\\', '/').strip('/')
37133731
for Item in self.CodaTargetList:
37143732
File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')
3715-
self.OutputFile.add(File)
37163733
if os.path.isabs(File):
37173734
File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')
37183735
if Item.Target.Ext.lower() == '.aml':
@@ -3728,7 +3745,6 @@ def CreateAsBuiltInf(self):
37283745
if os.path.exists(DepexFile):
37293746
self.DepexGenerated = True
37303747
if self.DepexGenerated:
3731-
self.OutputFile.add(self.Name + '.depex')
37323748
if self.ModuleType in [SUP_MODULE_PEIM]:
37333749
AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex')
37343750
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 @@ def CreateAsBuiltInf(self):
37393755
Bin = self._GenOffsetBin()
37403756
if Bin:
37413757
AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin)
3742-
self.OutputFile.add(Bin)
37433758

37443759
for Root, Dirs, Files in os.walk(OutputDir):
37453760
for File in Files:
37463761
if File.lower().endswith('.pdb'):
37473762
AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)
3748-
self.OutputFile.add(File)
37493763
HeaderComments = self.Module.HeaderComments
37503764
StartPos = 0
37513765
for Index in range(len(HeaderComments)):
@@ -3914,39 +3928,31 @@ def CreateAsBuiltInf(self):
39143928
SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)
39153929

39163930
self.IsAsBuiltInfCreated = True
3917-
if GlobalData.gBinCacheDest:
3918-
self.CopyModuleToCache()
39193931

39203932
def CopyModuleToCache(self):
39213933
FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)
39223934
CreateDirectory (FileDir)
39233935
HashFile = path.join(self.BuildDir, self.Name + '.hash')
39243936
if os.path.exists(HashFile):
39253937
CopyFileOnChange(HashFile, FileDir)
3926-
if not self.IsLibrary:
3927-
ModuleFile = path.join(self.OutputDir, self.Name + '.inf')
3928-
if os.path.exists(ModuleFile):
3929-
CopyFileOnChange(ModuleFile, FileDir)
3930-
else:
3931-
OutputDir = self.OutputDir.replace('\\', '/').strip('/')
3932-
DebugDir = self.DebugDir.replace('\\', '/').strip('/')
3933-
for Item in self.CodaTargetList:
3934-
File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')
3935-
self.OutputFile.add(File)
3938+
ModuleFile = path.join(self.OutputDir, self.Name + '.inf')
3939+
if os.path.exists(ModuleFile):
3940+
CopyFileOnChange(ModuleFile, FileDir)
3941+
39363942
if not self.OutputFile:
39373943
Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
39383944
self.OutputFile = Ma.Binaries
3939-
if self.OutputFile:
3940-
for File in self.OutputFile:
3941-
File = str(File)
3942-
if not os.path.isabs(File):
3943-
File = os.path.join(self.OutputDir, File)
3944-
if os.path.exists(File):
3945-
sub_dir = os.path.relpath(File, self.OutputDir)
3946-
destination_file = os.path.join(FileDir, sub_dir)
3947-
destination_dir = os.path.dirname(destination_file)
3948-
CreateDirectory(destination_dir)
3949-
CopyFileOnChange(File, destination_dir)
3945+
3946+
for File in self.OutputFile:
3947+
File = str(File)
3948+
if not os.path.isabs(File):
3949+
File = os.path.join(self.OutputDir, File)
3950+
if os.path.exists(File):
3951+
sub_dir = os.path.relpath(File, self.OutputDir)
3952+
destination_file = os.path.join(FileDir, sub_dir)
3953+
destination_dir = os.path.dirname(destination_file)
3954+
CreateDirectory(destination_dir)
3955+
CopyFileOnChange(File, destination_dir)
39503956

39513957
def AttemptModuleCacheCopy(self):
39523958
# If library or Module is binary do not skip by hash

BaseTools/Source/Python/build/build.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,9 @@ def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMak
12501250
BuildCommand = BuildCommand + [Target]
12511251
LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
12521252
self.CreateAsBuiltInf()
1253+
if GlobalData.gBinCacheDest:
1254+
self.UpdateBuildCache()
1255+
self.BuildModules = []
12531256
return True
12541257

12551258
# build library
@@ -1268,6 +1271,9 @@ def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMak
12681271
NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Mod, makefile)), 'pbuild']
12691272
LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
12701273
self.CreateAsBuiltInf()
1274+
if GlobalData.gBinCacheDest:
1275+
self.UpdateBuildCache()
1276+
self.BuildModules = []
12711277
return True
12721278

12731279
# cleanlib
@@ -1361,6 +1367,9 @@ def _Build(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeF
13611367
BuildCommand = BuildCommand + [Target]
13621368
AutoGenObject.BuildTime = LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
13631369
self.CreateAsBuiltInf()
1370+
if GlobalData.gBinCacheDest:
1371+
self.UpdateBuildCache()
1372+
self.BuildModules = []
13641373
return True
13651374

13661375
# genfds
@@ -1874,6 +1883,9 @@ def _BuildModule(self):
18741883
ExitFlag.set()
18751884
BuildTask.WaitForComplete()
18761885
self.CreateAsBuiltInf()
1886+
if GlobalData.gBinCacheDest:
1887+
self.UpdateBuildCache()
1888+
self.BuildModules = []
18771889
self.MakeTime += int(round((time.time() - MakeContiue)))
18781890
if BuildTask.HasError():
18791891
self.invalidateHash()
@@ -2074,6 +2086,9 @@ def _MultiThreadBuildPlatform(self):
20742086
ExitFlag.set()
20752087
BuildTask.WaitForComplete()
20762088
self.CreateAsBuiltInf()
2089+
if GlobalData.gBinCacheDest:
2090+
self.UpdateBuildCache()
2091+
self.BuildModules = []
20772092
self.MakeTime += int(round((time.time() - MakeContiue)))
20782093
#
20792094
# Check for build error, and raise exception if one
@@ -2213,24 +2228,25 @@ def Launch(self):
22132228
RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)
22142229

22152230
def CreateAsBuiltInf(self):
2231+
for Module in self.BuildModules:
2232+
Module.CreateAsBuiltInf()
2233+
2234+
def UpdateBuildCache(self):
22162235
all_lib_set = set()
22172236
all_mod_set = set()
22182237
for Module in self.BuildModules:
2219-
Module.CreateAsBuiltInf()
2238+
Module.CopyModuleToCache()
22202239
all_mod_set.add(Module)
22212240
for Module in self.HashSkipModules:
2222-
if GlobalData.gBinCacheDest:
2223-
Module.CopyModuleToCache()
2241+
Module.CopyModuleToCache()
22242242
all_mod_set.add(Module)
22252243
for Module in all_mod_set:
22262244
for lib in Module.LibraryAutoGenList:
22272245
all_lib_set.add(lib)
22282246
for lib in all_lib_set:
2229-
if GlobalData.gBinCacheDest:
2230-
lib.CopyModuleToCache()
2247+
lib.CopyModuleToCache()
22312248
all_lib_set.clear()
22322249
all_mod_set.clear()
2233-
self.BuildModules = []
22342250
self.HashSkipModules = []
22352251
## Do some clean-up works when error occurred
22362252
def Relinquish(self):

0 commit comments

Comments
 (0)