]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Fix corner-cases of --hash feature
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 8c7c20a3860e927c6b68ed09cc9ab2a6d3f4fa93..8648fc40ed8f7297188469f611827bc95f4203af 100644 (file)
@@ -5,13 +5,7 @@
 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
 # Copyright (c) 2019, American Megatrends, Inc. All rights reserved.<BR>\r
 #\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ## Import Modules\r
@@ -661,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
@@ -747,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
@@ -770,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
@@ -3906,9 +3900,11 @@ class ModuleAutoGen(AutoGen):
         FileDir = path.join(GlobalData.gBinCacheDest, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
         CreateDirectory (FileDir)\r
         HashFile = path.join(self.BuildDir, self.Name + '.hash')\r
-        ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
         if os.path.exists(HashFile):\r
             shutil.copy2(HashFile, FileDir)\r
+        if self.IsLibrary:\r
+            return\r
+        ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
         if os.path.exists(ModuleFile):\r
             shutil.copy2(ModuleFile, FileDir)\r
         if not self.OutputFile:\r
@@ -3920,11 +3916,20 @@ class ModuleAutoGen(AutoGen):
                 if not os.path.isabs(File):\r
                     File = os.path.join(self.OutputDir, File)\r
                 if os.path.exists(File):\r
-                    shutil.copy2(File, FileDir)\r
+                    sub_dir = os.path.relpath(File, self.OutputDir)\r
+                    destination_file = os.path.join(FileDir, sub_dir)\r
+                    destination_dir = os.path.dirname(destination_file)\r
+                    CreateDirectory(destination_dir)\r
+                    shutil.copy2(File, destination_dir)\r
 \r
     def AttemptModuleCacheCopy(self):\r
+        # If library or Module is binary do not skip by hash\r
         if self.IsBinaryModule:\r
             return False\r
+        # .inc is contains binary information so do not skip by hash as well\r
+        for f_ext in self.SourceFileList:\r
+            if '.inc' in str(f_ext):\r
+                return False\r
         FileDir = path.join(GlobalData.gBinCacheSource, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
         HashFile = path.join(FileDir, self.Name + '.hash')\r
         if os.path.exists(HashFile):\r
@@ -3939,7 +3944,11 @@ class ModuleAutoGen(AutoGen):
                                 shutil.copy2(HashFile, self.BuildDir)\r
                             else:\r
                                 File = path.join(root, f)\r
-                                shutil.copy2(File, self.OutputDir)\r
+                                sub_dir = os.path.relpath(File, FileDir)\r
+                                destination_file = os.path.join(self.OutputDir, sub_dir)\r
+                                destination_dir = os.path.dirname(destination_file)\r
+                                CreateDirectory(destination_dir)\r
+                                shutil.copy2(File, destination_dir)\r
                     if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
                         CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
                     return True\r
@@ -4087,14 +4096,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
@@ -4119,14 +4130,22 @@ 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
     def CanSkipbyHash(self):\r
+        # If library or Module is binary do not skip by hash\r
+        if self.IsBinaryModule:\r
+            return False\r
+        # .inc is contains binary information so do not skip by hash as well\r
+        for f_ext in self.SourceFileList:\r
+            if '.inc' in str(f_ext):\r
+                return False\r
         if GlobalData.gUseHashCache:\r
+            # If there is a valid hash or function generated a valid hash; function will return False\r
+            # and the statement below will return True\r
             return not self.GenModuleHash()\r
         return False\r
 \r