]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/InfBuildData.py
BaseTools: replace string constants used for module types
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / InfBuildData.py
index ded8f610c9c190e0cd107830418452b2660408c2..f2d36d0ee0d45215188a3b21e0764e5d44afd3e3 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to create a database used by build tool\r
 #\r
-# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
@@ -17,6 +17,7 @@ from Common.DataType import *
 from Common.Misc import *\r
 from types import *\r
 from MetaFileParser import *\r
+from collections import OrderedDict\r
 \r
 from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClassObject, PcdClassObject\r
 ## Module build information from INF file\r
@@ -67,22 +68,22 @@ class InfBuildData(ModuleBuildClassObject):
 \r
     # dict used to convert Component type to Module type\r
     _MODULE_TYPE_ = {\r
-        "LIBRARY"               :   "BASE",\r
-        "SECURITY_CORE"         :   "SEC",\r
-        "PEI_CORE"              :   "PEI_CORE",\r
-        "COMBINED_PEIM_DRIVER"  :   "PEIM",\r
-        "PIC_PEIM"              :   "PEIM",\r
-        "RELOCATABLE_PEIM"      :   "PEIM",\r
-        "PE32_PEIM"             :   "PEIM",\r
-        "BS_DRIVER"             :   "DXE_DRIVER",\r
-        "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",\r
-        "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",\r
-        "DXE_SMM_DRIVER"        :   "DXE_SMM_DRIVER",\r
-    #    "SMM_DRIVER"            :   "DXE_SMM_DRIVER",\r
-    #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",\r
-    #    "BS_DRIVER"             :   "UEFI_DRIVER",\r
-        "APPLICATION"           :   "UEFI_APPLICATION",\r
-        "LOGO"                  :   "BASE",\r
+        "LIBRARY"               :   SUP_MODULE_BASE,\r
+        "SECURITY_CORE"         :   SUP_MODULE_SEC,\r
+        SUP_MODULE_PEI_CORE              :   SUP_MODULE_PEI_CORE,\r
+        "COMBINED_PEIM_DRIVER"  :   SUP_MODULE_PEIM,\r
+        "PIC_PEIM"              :   SUP_MODULE_PEIM,\r
+        "RELOCATABLE_PEIM"      :   SUP_MODULE_PEIM,\r
+        "PE32_PEIM"             :   SUP_MODULE_PEIM,\r
+        "BS_DRIVER"             :   SUP_MODULE_DXE_DRIVER,\r
+        "RT_DRIVER"             :   SUP_MODULE_DXE_RUNTIME_DRIVER,\r
+        "SAL_RT_DRIVER"         :   SUP_MODULE_DXE_SAL_DRIVER,\r
+        SUP_MODULE_DXE_SMM_DRIVER        :   SUP_MODULE_DXE_SMM_DRIVER,\r
+    #    "SMM_DRIVER"            :   SUP_MODULE_DXE_SMM_DRIVER,\r
+    #    "BS_DRIVER"             :   SUP_MODULE_DXE_SMM_DRIVER,\r
+    #    "BS_DRIVER"             :   SUP_MODULE_UEFI_DRIVER,\r
+        "APPLICATION"           :   SUP_MODULE_UEFI_APPLICATION,\r
+        "LOGO"                  :   SUP_MODULE_BASE,\r
     }\r
 \r
     # regular expression for converting XXX_FLAGS in [nmake] section to new type\r
@@ -106,7 +107,7 @@ class InfBuildData(ModuleBuildClassObject):
     #   @param      Platform        The name of platform employing this module\r
     #   @param      Macros          Macros used for replacement in DSC file\r
     #\r
-    def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Target=None, Toolchain=None):\r
+    def __init__(self, FilePath, RawData, BuildDatabase, Arch=TAB_ARCH_COMMON, Target=None, Toolchain=None):\r
         self.MetaFile = FilePath\r
         self._ModuleDir = FilePath.Dir\r
         self._RawData = RawData\r
@@ -114,7 +115,7 @@ class InfBuildData(ModuleBuildClassObject):
         self._Arch = Arch\r
         self._Target = Target\r
         self._Toolchain = Toolchain\r
-        self._Platform = 'COMMON'\r
+        self._Platform = TAB_COMMON\r
         self._SourceOverridePath = None\r
         if FilePath.Key in GlobalData.gOverrideDir:\r
             self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]\r
@@ -156,7 +157,7 @@ class InfBuildData(ModuleBuildClassObject):
         self._ModuleUnloadImageList = None\r
         self._ConstructorList       = None\r
         self._DestructorList        = None\r
-        self._Defs                  = None\r
+        self._Defs                  = OrderedDict()\r
         self._Binaries              = None\r
         self._Sources               = None\r
         self._LibraryClasses        = None\r
@@ -166,7 +167,7 @@ class InfBuildData(ModuleBuildClassObject):
         self._Ppis                  = None\r
         self._PpiComments           = None\r
         self._Guids                 = None\r
-        self._GuidsUsedByPcd        = sdict()\r
+        self._GuidsUsedByPcd        = OrderedDict()\r
         self._GuidComments          = None\r
         self._Includes              = None\r
         self._Packages              = None\r
@@ -246,8 +247,6 @@ class InfBuildData(ModuleBuildClassObject):
             # items defined _PROPERTY_ don't need additional processing\r
             if Name in self:\r
                 self[Name] = Value\r
-                if self._Defs is None:\r
-                    self._Defs = sdict()\r
                 self._Defs[Name] = Value\r
                 self._Macros[Name] = Value\r
             # some special items in [Defines] section need special treatment\r
@@ -255,7 +254,7 @@ class InfBuildData(ModuleBuildClassObject):
                 if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):\r
                     Name = 'UEFI_SPECIFICATION_VERSION'\r
                 if self._Specification is None:\r
-                    self._Specification = sdict()\r
+                    self._Specification = OrderedDict()\r
                 self._Specification[Name] = GetHexVerValue(Value)\r
                 if self._Specification[Name] is None:\r
                     EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
@@ -307,8 +306,6 @@ class InfBuildData(ModuleBuildClassObject):
                                         File=self.MetaFile, Line=Record[-1])\r
                     self._CustomMakefile[TokenList[0]] = TokenList[1]\r
             else:\r
-                if self._Defs is None:\r
-                    self._Defs = sdict()\r
                 self._Defs[Name] = Value\r
                 self._Macros[Name] = Value\r
 \r
@@ -337,14 +334,14 @@ class InfBuildData(ModuleBuildClassObject):
                     EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "MM_CORE_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File=self.MetaFile)\r
                 if self._ModuleType == SUP_MODULE_MM_STANDALONE:\r
                     EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "MM_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File=self.MetaFile)\r
-            if self._Defs and 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \\r
+            if 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \\r
                and 'PCI_CLASS_CODE' in self._Defs and 'PCI_REVISION' in self._Defs:\r
                 self._BuildType = 'UEFI_OPTIONROM'\r
                 if 'PCI_COMPRESS' in self._Defs:\r
                     if self._Defs['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):\r
                         EdkLogger.error("build", FORMAT_INVALID, "Expected TRUE/FALSE for PCI_COMPRESS: %s" % self.MetaFile)\r
 \r
-            elif self._Defs and 'UEFI_HII_RESOURCE_SECTION' in self._Defs \\r
+            elif 'UEFI_HII_RESOURCE_SECTION' in self._Defs \\r
                and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':\r
                 self._BuildType = 'UEFI_HII'\r
             else:\r
@@ -398,7 +395,7 @@ class InfBuildData(ModuleBuildClassObject):
 #                                       File=self.MetaFile, Line=LineNo)\r
                     else:\r
                         if self._BuildOptions is None:\r
-                            self._BuildOptions = sdict()\r
+                            self._BuildOptions = OrderedDict()\r
 \r
                         if ToolList[0] in self._TOOL_CODE_:\r
                             Tool = self._TOOL_CODE_[ToolList[0]]\r
@@ -464,9 +461,9 @@ class InfBuildData(ModuleBuildClassObject):
             if self._Header_ is None:\r
                 self._GetHeaderInfo()\r
             if self._ModuleType is None:\r
-                self._ModuleType = 'BASE'\r
+                self._ModuleType = SUP_MODULE_BASE\r
             if self._ModuleType not in SUP_MODULE_LIST:\r
-                self._ModuleType = "USER_DEFINED"\r
+                self._ModuleType = SUP_MODULE_USER_DEFINED\r
         return self._ModuleType\r
 \r
     ## Retrieve COMPONENT_TYPE\r
@@ -475,7 +472,7 @@ class InfBuildData(ModuleBuildClassObject):
             if self._Header_ is None:\r
                 self._GetHeaderInfo()\r
             if self._ComponentType is None:\r
-                self._ComponentType = 'USER_DEFINED'\r
+                self._ComponentType = SUP_MODULE_USER_DEFINED\r
         return self._ComponentType\r
 \r
     ## Retrieve "BUILD_TYPE"\r
@@ -484,7 +481,7 @@ class InfBuildData(ModuleBuildClassObject):
             if self._Header_ is None:\r
                 self._GetHeaderInfo()\r
             if not self._BuildType:\r
-                self._BuildType = "BASE"\r
+                self._BuildType = SUP_MODULE_BASE\r
         return self._BuildType\r
 \r
     ## Retrieve file guid\r
@@ -590,11 +587,8 @@ class InfBuildData(ModuleBuildClassObject):
 \r
     ## Retrieve definies other than above ones\r
     def _GetDefines(self):\r
-        if self._Defs is None:\r
-            if self._Header_ is None:\r
-                self._GetHeaderInfo()\r
-            if self._Defs is None:\r
-                self._Defs = sdict()\r
+        if len(self._Defs) == 0 and self._Header_ is None:\r
+            self._GetHeaderInfo()\r
         return self._Defs\r
 \r
     ## Retrieve binary files\r
@@ -608,7 +602,7 @@ class InfBuildData(ModuleBuildClassObject):
             for Record in RecordList:\r
                 FileType = Record[0]\r
                 LineNo = Record[-1]\r
-                Target = 'COMMON'\r
+                Target = TAB_COMMON\r
                 FeatureFlag = []\r
                 if Record[2]:\r
                     TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)\r
@@ -688,7 +682,7 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve library classes employed by this module\r
     def _GetLibraryClassUses(self):\r
         if self._LibraryClasses is None:\r
-            self._LibraryClasses = sdict()\r
+            self._LibraryClasses = OrderedDict()\r
             RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 Lib = Record[0]\r
@@ -717,8 +711,8 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve protocols consumed/produced by this module\r
     def _GetProtocols(self):\r
         if self._Protocols is None:\r
-            self._Protocols = sdict()\r
-            self._ProtocolComments = sdict()\r
+            self._Protocols = OrderedDict()\r
+            self._ProtocolComments = OrderedDict()\r
             RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 CName = Record[0]\r
@@ -742,8 +736,8 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve PPIs consumed/produced by this module\r
     def _GetPpis(self):\r
         if self._Ppis is None:\r
-            self._Ppis = sdict()\r
-            self._PpiComments = sdict()\r
+            self._Ppis = OrderedDict()\r
+            self._PpiComments = OrderedDict()\r
             RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 CName = Record[0]\r
@@ -767,8 +761,8 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve GUIDs consumed/produced by this module\r
     def _GetGuids(self):\r
         if self._Guids is None:\r
-            self._Guids = sdict()\r
-            self._GuidComments = sdict()\r
+            self._Guids = OrderedDict()\r
+            self._GuidComments = OrderedDict()\r
             RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 CName = Record[0]\r
@@ -794,10 +788,7 @@ class InfBuildData(ModuleBuildClassObject):
                 self._Includes.append(self._SourceOverridePath)\r
 \r
             Macros = self._Macros\r
-            if 'PROCESSOR' in GlobalData.gEdkGlobal.keys():\r
-                Macros['PROCESSOR'] = GlobalData.gEdkGlobal['PROCESSOR']\r
-            else:\r
-                Macros['PROCESSOR'] = self._Arch\r
+            Macros['PROCESSOR'] = GlobalData.gEdkGlobal.get('PROCESSOR', self._Arch)\r
             RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 if Record[0].find('EDK_SOURCE') > -1:\r
@@ -869,8 +860,8 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve PCDs used in this module\r
     def _GetPcds(self):\r
         if self._Pcds is None:\r
-            self._Pcds = sdict()\r
-            self._PcdComments = sdict()\r
+            self._Pcds = OrderedDict()\r
+            self._PcdComments = OrderedDict()\r
             self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
             self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
             self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
@@ -881,7 +872,7 @@ class InfBuildData(ModuleBuildClassObject):
     ## Retrieve build options specific to this module\r
     def _GetBuildOptions(self):\r
         if self._BuildOptions is None:\r
-            self._BuildOptions = sdict()\r
+            self._BuildOptions = OrderedDict()\r
             RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]\r
             for Record in RecordList:\r
                 ToolChainFamily = Record[0]\r
@@ -908,19 +899,19 @@ class InfBuildData(ModuleBuildClassObject):
 \r
             # PEIM and DXE drivers must have a valid [Depex] section\r
             if len(self.LibraryClass) == 0 and len(RecordList) == 0:\r
-                if self.ModuleType == 'DXE_DRIVER' or self.ModuleType == 'PEIM' or self.ModuleType == 'DXE_SMM_DRIVER' or \\r
-                    self.ModuleType == 'DXE_SAL_DRIVER' or self.ModuleType == 'DXE_RUNTIME_DRIVER':\r
+                if self.ModuleType == SUP_MODULE_DXE_DRIVER or self.ModuleType == SUP_MODULE_PEIM or self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER or \\r
+                    self.ModuleType == SUP_MODULE_DXE_SAL_DRIVER or self.ModuleType == SUP_MODULE_DXE_RUNTIME_DRIVER:\r
                     EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \\r
                                     % self.ModuleType, File=self.MetaFile)\r
 \r
-            if len(RecordList) != 0 and self.ModuleType == 'USER_DEFINED':\r
+            if len(RecordList) != 0 and self.ModuleType == SUP_MODULE_USER_DEFINED:\r
                 for Record in RecordList:\r
-                    if Record[4] not in ['PEIM', 'DXE_DRIVER', 'DXE_SMM_DRIVER']:\r
+                    if Record[4] not in [SUP_MODULE_PEIM, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER]:\r
                         EdkLogger.error('build', FORMAT_INVALID,\r
                                         "'%s' module must specify the type of [Depex] section" % self.ModuleType,\r
                                         File=self.MetaFile)\r
 \r
-            Depex = sdict()\r
+            Depex = OrderedDict()\r
             for Record in RecordList:\r
                 DepexStr = ReplaceMacro(Record[0], self._Macros, False)\r
                 Arch = Record[3]\r
@@ -961,7 +952,7 @@ class InfBuildData(ModuleBuildClassObject):
         if self._DepexExpression is None:\r
             self._DepexExpression = tdict(False, 2)\r
             RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]\r
-            DepexExpression = sdict()\r
+            DepexExpression = OrderedDict()\r
             for Record in RecordList:\r
                 DepexStr = ReplaceMacro(Record[0], self._Macros, False)\r
                 Arch = Record[3]\r
@@ -979,7 +970,7 @@ class InfBuildData(ModuleBuildClassObject):
         return self._GuidsUsedByPcd\r
     ## Retrieve PCD for given type\r
     def _GetPcd(self, Type):\r
-        Pcds = sdict()\r
+        Pcds = OrderedDict()\r
         PcdDict = tdict(True, 4)\r
         PcdList = []\r
         RecordList = self._RawData[Type, self._Arch, self._Platform]\r
@@ -1003,6 +994,7 @@ class InfBuildData(ModuleBuildClassObject):
             self._PcdComments[TokenSpaceGuid, PcdCName] = Comments\r
 \r
         # resolve PCD type, value, datum info, etc. by getting its definition from package\r
+        _GuidDict = self.Guids.copy()\r
         for PcdCName, TokenSpaceGuid in PcdList:\r
             PcdRealName = PcdCName\r
             Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]\r
@@ -1056,6 +1048,7 @@ class InfBuildData(ModuleBuildClassObject):
                 #\r
                 #   "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"\r
                 #\r
+                _GuidDict.update(Package.Guids)\r
                 PcdType = self._PCD_TYPE_STRING_[Type]\r
                 if Type == MODEL_PCD_DYNAMIC:\r
                     Pcd.Pending = True\r
@@ -1147,7 +1140,7 @@ class InfBuildData(ModuleBuildClassObject):
                         Pcd.DefaultValue = PcdInPackage.DefaultValue\r
                     else:\r
                         try:\r
-                            Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, self.Guids)(True)\r
+                            Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, _GuidDict)(True)\r
                         except BadExpression, Value:\r
                             EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, Value),\r
                                             File=self.MetaFile, Line=LineNo)\r