BaseTools: Fix corner-cases of --hash feature
authorRodriguez, Christian <christian.rodriguez@intel.com>
Thu, 4 Apr 2019 16:04:21 +0000 (00:04 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Wed, 10 Apr 2019 05:32:12 +0000 (13:32 +0800)
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>
BaseTools/Source/Python/AutoGen/AutoGen.py

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