]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Report error for incorrect hex value format
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 3b1ddc74e839ecc4c8dbf563c2308f115a5cd9ea..95370d182157243e04153cc0709a5c0b05a0fd94 100644 (file)
@@ -39,7 +39,6 @@ from Common.StringUtils import *
 import Common.GlobalData as GlobalData\r
 from GenFds.FdfParser import *\r
 from CommonDataClass.CommonClass import SkuInfoClass\r
-from Workspace.BuildClassObject import *\r
 from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
 import Common.VpdInfoFile as VpdInfoFile\r
 from .GenPcdDb import CreatePcdDatabaseCode\r
@@ -54,7 +53,7 @@ from collections import OrderedDict
 from collections import defaultdict\r
 from Workspace.WorkspaceCommon import OrderedListDict\r
 \r
-from Common.caching import cached_property\r
+from Common.caching import cached_property, cached_class_function\r
 \r
 ## Regular expression for splitting Dependency Expression string into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
@@ -80,7 +79,7 @@ gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")
 gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
 \r
 ## Mapping Makefile type\r
-gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
+gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}\r
 \r
 \r
 ## Build rule configuration file\r
@@ -870,7 +869,7 @@ class WorkspaceAutoGen(AutoGen):
         for Pa in self.AutoGenObjectList:\r
             for Package in Pa.PackageList:\r
                 PcdList = Package.Pcds.values()\r
-                PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0)))\r
+                PcdList.sort(key=lambda x: int(x.TokenValue, 0))\r
                 Count = 0\r
                 while (Count < len(PcdList) - 1) :\r
                     Item = PcdList[Count]\r
@@ -891,7 +890,7 @@ class WorkspaceAutoGen(AutoGen):
                         #\r
                         # Sort same token value PCD list with TokenGuid and TokenCName\r
                         #\r
-                        SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
+                        SameTokenValuePcdList.sort(key=lambda x: "%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName))\r
                         SameTokenValuePcdListCount = 0\r
                         while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
                             Flag = False\r
@@ -916,7 +915,7 @@ class WorkspaceAutoGen(AutoGen):
                     Count += 1\r
 \r
                 PcdList = Package.Pcds.values()\r
-                PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
+                PcdList.sort(key=lambda x: "%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName))\r
                 Count = 0\r
                 while (Count < len(PcdList) - 1) :\r
                     Item = PcdList[Count]\r
@@ -1092,7 +1091,7 @@ class PlatformAutoGen(AutoGen):
             for Inf in self._AsBuildInfList:\r
                 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
                 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
-                if not M.IsSupportedArch:\r
+                if not M.IsBinaryModule:\r
                     continue\r
                 self._AsBuildModuleList.append(InfClass)\r
         # get library/modules for build\r
@@ -1347,7 +1346,7 @@ class PlatformAutoGen(AutoGen):
                 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)\r
                 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.\r
                 # For binary module, if in current arch, we need to list the PCDs into database.\r
-                if not M.IsSupportedArch:\r
+                if not M.IsBinaryModule:\r
                     continue\r
                 # Override the module PCD setting by platform setting\r
                 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
@@ -1843,7 +1842,7 @@ class PlatformAutoGen(AutoGen):
                or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
                 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
                                    % self.ToolChain)\r
-                self._ToolChainFamily = "MSFT"\r
+                self._ToolChainFamily = TAB_COMPILER_MSFT\r
             else:\r
                 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
         return self._ToolChainFamily\r
@@ -1856,7 +1855,7 @@ class PlatformAutoGen(AutoGen):
                or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
                 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
                                    % self.ToolChain)\r
-                self._BuildRuleFamily = "MSFT"\r
+                self._BuildRuleFamily = TAB_COMPILER_MSFT\r
             else:\r
                 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
         return self._BuildRuleFamily\r
@@ -2549,7 +2548,6 @@ class ModuleAutoGen(AutoGen):
         self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
         self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
 \r
-        self.IsMakeFileCreated = False\r
         self.IsCodeFileCreated = False\r
         self.IsAsBuiltInfCreated = False\r
         self.DepexGenerated = False\r
@@ -2856,80 +2854,74 @@ class ModuleAutoGen(AutoGen):
         if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
             return {}\r
 \r
-        RetVal = {self.ModuleType:[]}\r
-\r
-        for ModuleType in RetVal:\r
-            DepexList = RetVal[ModuleType]\r
-            #\r
-            # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
-            #\r
-            for M in [self.Module] + self.DependentLibraryList:\r
-                Inherited = False\r
-                for D in M.Depex[self.Arch, ModuleType]:\r
-                    if DepexList != []:\r
-                        DepexList.append('AND')\r
-                    DepexList.append('(')\r
-                    #replace D with value if D is FixedAtBuild PCD\r
-                    NewList = []\r
-                    for item in D:\r
-                        if '.' not in item:\r
-                            NewList.append(item)\r
+        DepexList = []\r
+        #\r
+        # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
+        #\r
+        for M in [self.Module] + self.DependentLibraryList:\r
+            Inherited = False\r
+            for D in M.Depex[self.Arch, self.ModuleType]:\r
+                if DepexList != []:\r
+                    DepexList.append('AND')\r
+                DepexList.append('(')\r
+                #replace D with value if D is FixedAtBuild PCD\r
+                NewList = []\r
+                for item in D:\r
+                    if '.' not in item:\r
+                        NewList.append(item)\r
+                    else:\r
+                        if item not in self._FixedPcdVoidTypeDict:\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
-                            if item not in self._FixedPcdVoidTypeDict:\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._FixedPcdVoidTypeDict[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
-                                NewList.append(Value)\r
-                    DepexList.extend(NewList)\r
-                    if DepexList[-1] == 'END':  # no need of a END at this time\r
-                        DepexList.pop()\r
-                    DepexList.append(')')\r
-                    Inherited = True\r
-                if Inherited:\r
-                    EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
-                if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
-                    break\r
-                if len(DepexList) > 0:\r
-                    EdkLogger.verbose('')\r
-        return RetVal\r
+                            Value = self._FixedPcdVoidTypeDict[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
+                            NewList.append(Value)\r
+                DepexList.extend(NewList)\r
+                if DepexList[-1] == 'END':  # no need of a END at this time\r
+                    DepexList.pop()\r
+                DepexList.append(')')\r
+                Inherited = True\r
+            if Inherited:\r
+                EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
+            if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
+                break\r
+            if len(DepexList) > 0:\r
+                EdkLogger.verbose('')\r
+        return {self.ModuleType:DepexList}\r
 \r
     ## Merge dependency expression\r
     #\r
     #   @retval     list    The token list of the dependency expression after parsed\r
     #\r
     @cached_property\r
-    def DepexExpressionTokenList(self):\r
+    def DepexExpressionDict(self):\r
         if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
             return {}\r
 \r
-        RetVal = {self.ModuleType:''}\r
+        DepexExpressionString = ''\r
+        #\r
+        # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
+        #\r
+        for M in [self.Module] + self.DependentLibraryList:\r
+            Inherited = False\r
+            for D in M.DepexExpression[self.Arch, self.ModuleType]:\r
+                if DepexExpressionString != '':\r
+                    DepexExpressionString += ' AND '\r
+                DepexExpressionString += '('\r
+                DepexExpressionString += D\r
+                DepexExpressionString = DepexExpressionString.rstrip('END').strip()\r
+                DepexExpressionString += ')'\r
+                Inherited = True\r
+            if Inherited:\r
+                EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))\r
+            if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:\r
+                break\r
+        if len(DepexExpressionString) > 0:\r
+            EdkLogger.verbose('')\r
 \r
-        for ModuleType in RetVal:\r
-            DepexExpressionString = RetVal[ModuleType]\r
-            #\r
-            # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
-            #\r
-            for M in [self.Module] + self.DependentLibraryList:\r
-                Inherited = False\r
-                for D in M.DepexExpression[self.Arch, ModuleType]:\r
-                    if DepexExpressionString != '':\r
-                        DepexExpressionString += ' AND '\r
-                    DepexExpressionString += '('\r
-                    DepexExpressionString += D\r
-                    DepexExpressionString = DepexExpressionString.rstrip('END').strip()\r
-                    DepexExpressionString += ')'\r
-                    Inherited = True\r
-                if Inherited:\r
-                    EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))\r
-                if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:\r
-                    break\r
-            if len(DepexExpressionString) > 0:\r
-                EdkLogger.verbose('')\r
-            RetVal[ModuleType] = DepexExpressionString\r
-        return RetVal\r
+        return {self.ModuleType:DepexExpressionString}\r
 \r
     # Get the tiano core user extension, it is contain dependent library.\r
     # @retval: a list contain tiano core userextension.\r
@@ -2985,7 +2977,7 @@ class ModuleAutoGen(AutoGen):
         # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
         # is the former use /I , the Latter used -I to specify include directories\r
         #\r
-        if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
+        if self.PlatformInfo.ToolChainFamily in (TAB_COMPILER_MSFT):\r
             BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r
         elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
             BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r
@@ -3956,13 +3948,31 @@ class ModuleAutoGen(AutoGen):
     #   @param      CreateLibraryMakeFile   Flag indicating if or not the makefiles of\r
     #                                       dependent libraries will be created\r
     #\r
+    @cached_class_function\r
     def CreateMakeFile(self, CreateLibraryMakeFile=True, GenFfsList = []):\r
+        # nest this function inside it's only caller.\r
+        def CreateTimeStamp():\r
+            FileSet = {self.MetaFile.Path}\r
+\r
+            for SourceFile in self.Module.Sources:\r
+                FileSet.add (SourceFile.Path)\r
+\r
+            for Lib in self.DependentLibraryList:\r
+                FileSet.add (Lib.MetaFile.Path)\r
+\r
+            for f in self.AutoGenDepSet:\r
+                FileSet.add (f.Path)\r
+\r
+            if os.path.exists (self.TimeStampPath):\r
+                os.remove (self.TimeStampPath)\r
+            with open(self.TimeStampPath, 'w+') as file:\r
+                for f in FileSet:\r
+                    print(f, file=file)\r
+\r
         # Ignore generating makefile when it is a binary module\r
         if self.IsBinaryModule:\r
             return\r
 \r
-        if self.IsMakeFileCreated:\r
-            return\r
         self.GenFfsList = GenFfsList\r
         if not self.IsLibrary and CreateLibraryMakeFile:\r
             for LibraryAutoGen in self.LibraryAutoGenList:\r
@@ -3982,8 +3992,7 @@ class ModuleAutoGen(AutoGen):
             EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
                             (self.Name, self.Arch))\r
 \r
-        self.CreateTimeStamp()\r
-        self.IsMakeFileCreated = True\r
+        CreateTimeStamp()\r
 \r
     def CopyBinaryFiles(self):\r
         for File in self.Module.Binaries:\r
@@ -4156,21 +4165,3 @@ class ModuleAutoGen(AutoGen):
     @cached_property\r
     def TimeStampPath(self):\r
         return os.path.join(self.MakeFileDir, 'AutoGenTimeStamp')\r
-\r
-    def CreateTimeStamp(self):\r
-        FileSet = {self.MetaFile.Path}\r
-\r
-        for SourceFile in self.Module.Sources:\r
-            FileSet.add (SourceFile.Path)\r
-\r
-        for Lib in self.DependentLibraryList:\r
-            FileSet.add (Lib.MetaFile.Path)\r
-\r
-        for f in self.AutoGenDepSet:\r
-            FileSet.add (f.Path)\r
-\r
-        if os.path.exists (self.TimeStampPath):\r
-            os.remove (self.TimeStampPath)\r
-        with open(self.TimeStampPath, 'w+') as file:\r
-            for f in FileSet:\r
-                print(f, file=file)\r