BaseTools: Fix corner-cases of --hash feature

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1680

Re-order hashing operations so we don't do redundant hashes.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Christian Rodriguez <christian.rodriguez@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Rodriguez, Christian 2019-04-05 00:04:21 +08:00 committed by Feng, Bob C
parent 2914e8153d
commit 1b8caf0d87
1 changed files with 9 additions and 8 deletions

View File

@ -655,7 +655,7 @@ class WorkspaceAutoGen(AutoGen):
# #
# Generate Package level hash value # Generate Package level hash value
# #
GlobalData.gPackageHash[Arch] = {} GlobalData.gPackageHash = {}
if GlobalData.gUseHashCache: if GlobalData.gUseHashCache:
for Pkg in Pkgs: for Pkg in Pkgs:
self._GenPkgLevelHash(Pkg) self._GenPkgLevelHash(Pkg)
@ -741,7 +741,7 @@ class WorkspaceAutoGen(AutoGen):
return True return True
def _GenPkgLevelHash(self, Pkg): def _GenPkgLevelHash(self, Pkg):
if Pkg.PackageName in GlobalData.gPackageHash[Pkg.Arch]: if Pkg.PackageName in GlobalData.gPackageHash:
return return
PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName) PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)
@ -764,7 +764,7 @@ class WorkspaceAutoGen(AutoGen):
f.close() f.close()
m.update(Content) m.update(Content)
SaveFileOnChange(HashFile, m.hexdigest(), False) SaveFileOnChange(HashFile, m.hexdigest(), False)
GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest() GlobalData.gPackageHash[Pkg.PackageName] = m.hexdigest()
def _GetMetaFiles(self, Target, Toolchain, Arch): def _GetMetaFiles(self, Target, Toolchain, Arch):
AllWorkSpaceMetaFiles = set() AllWorkSpaceMetaFiles = set()
@ -4086,14 +4086,16 @@ class ModuleAutoGen(AutoGen):
def GenModuleHash(self): def GenModuleHash(self):
if self.Arch not in GlobalData.gModuleHash: if self.Arch not in GlobalData.gModuleHash:
GlobalData.gModuleHash[self.Arch] = {} GlobalData.gModuleHash[self.Arch] = {}
if self.Name in GlobalData.gModuleHash[self.Arch] and GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy():
return False
m = hashlib.md5() m = hashlib.md5()
# Add Platform level hash # Add Platform level hash
m.update(GlobalData.gPlatformHash.encode('utf-8')) m.update(GlobalData.gPlatformHash.encode('utf-8'))
# Add Package level hash # Add Package level hash
if self.DependentPackageList: if self.DependentPackageList:
for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName): for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName):
if Pkg.PackageName in GlobalData.gPackageHash[self.Arch]: if Pkg.PackageName in GlobalData.gPackageHash:
m.update(GlobalData.gPackageHash[self.Arch][Pkg.PackageName].encode('utf-8')) m.update(GlobalData.gPackageHash[Pkg.PackageName].encode('utf-8'))
# Add Library hash # Add Library hash
if self.LibraryAutoGenList: if self.LibraryAutoGenList:
@ -4118,9 +4120,8 @@ class ModuleAutoGen(AutoGen):
ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash") ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash")
if self.Name not in GlobalData.gModuleHash[self.Arch]: if self.Name not in GlobalData.gModuleHash[self.Arch]:
GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest() GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest()
if GlobalData.gBinCacheSource: if GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy():
if self.AttemptModuleCacheCopy(): return False
return False
return SaveFileOnChange(ModuleHashFile, m.hexdigest(), False) return SaveFileOnChange(ModuleHashFile, m.hexdigest(), False)
## Decide whether we can skip the ModuleAutoGen process ## Decide whether we can skip the ModuleAutoGen process