]> 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 f71e08d7154dbff37595a63b4b3dd8d8732ca1f3..57992d5886804a4a89d9ed54f8cbb7087ac9e2f8 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
@@ -1141,7 +1135,6 @@ class PlatformAutoGen(AutoGen):
         self.BuildTarget = Target\r
         self.Arch = Arch\r
         self.SourceDir = PlatformFile.SubDir\r
-        self.SourceOverrideDir = None\r
         self.FdTargetList = self.Workspace.FdTargetList\r
         self.FvTargetList = self.Workspace.FvTargetList\r
         # get the original module/package/platform objects\r
@@ -2559,11 +2552,6 @@ class ModuleAutoGen(AutoGen):
         self.SourceDir = self.MetaFile.SubDir\r
         self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
 \r
-        self.SourceOverrideDir = None\r
-        # use overridden path defined in DSC file\r
-        if self.MetaFile.Key in GlobalData.gOverrideDir:\r
-            self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
-\r
         self.ToolChain = Toolchain\r
         self.BuildTarget = Target\r
         self.Arch = Arch\r
@@ -2768,12 +2756,7 @@ class ModuleAutoGen(AutoGen):
         RetVal = {}\r
         for Type in self.Module.CustomMakefile:\r
             MakeType = gMakeTypeMap[Type] if Type in gMakeTypeMap else 'nmake'\r
-            if self.SourceOverrideDir is not None:\r
-                File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
-                if not os.path.exists(File):\r
-                    File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
-            else:\r
-                File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
+            File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
             RetVal[MakeType] = File\r
         return RetVal\r
 \r
@@ -2892,10 +2875,16 @@ class ModuleAutoGen(AutoGen):
                     if '.' not in item:\r
                         NewList.append(item)\r
                     else:\r
-                        if item not in self.FixedVoidTypePcds:\r
+                        FixedVoidTypePcds = {}\r
+                        if item in self.FixedVoidTypePcds:\r
+                            FixedVoidTypePcds = self.FixedVoidTypePcds\r
+                        elif M in self.PlatformInfo.LibraryAutoGenList:\r
+                            Index = self.PlatformInfo.LibraryAutoGenList.index(M)\r
+                            FixedVoidTypePcds = self.PlatformInfo.LibraryAutoGenList[Index].FixedVoidTypePcds\r
+                        if item not in FixedVoidTypePcds:\r
                             EdkLogger.error("build", FORMAT_INVALID, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item))\r
                         else:\r
-                            Value = self.FixedVoidTypePcds[item]\r
+                            Value = FixedVoidTypePcds[item]\r
                             if len(Value.split(',')) != 16:\r
                                 EdkLogger.error("build", FORMAT_INVALID,\r
                                                 "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item))\r
@@ -3031,13 +3020,14 @@ class ModuleAutoGen(AutoGen):
             # EDK II modules must not reference header files outside of the packages they depend on or\r
             # within the module's directory tree. Report error if violation.\r
             #\r
-            for Path in IncPathList:\r
-                if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
-                    ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
-                    EdkLogger.error("build",\r
-                                    PARAMETER_INVALID,\r
-                                    ExtraData=ErrMsg,\r
-                                    File=str(self.MetaFile))\r
+            if GlobalData.gDisableIncludePathCheck == False:\r
+                for Path in IncPathList:\r
+                    if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
+                        ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
+                        EdkLogger.error("build",\r
+                                        PARAMETER_INVALID,\r
+                                        ExtraData=ErrMsg,\r
+                                        File=str(self.MetaFile))\r
             RetVal += IncPathList\r
         return RetVal\r
 \r
@@ -3927,8 +3917,13 @@ class ModuleAutoGen(AutoGen):
                     shutil.copy2(File, FileDir)\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
@@ -4091,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
@@ -4123,14 +4120,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