]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Autogen - change from list to set
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 3384fdb70b7ef2b1f292db5992e88ab6ba4a35fc..ef2e3ebe853c1e129536f01e2e2dc4c694189c47 100644 (file)
@@ -45,10 +45,21 @@ import InfSectionParser
 import datetime\r
 import hashlib\r
 from GenVar import VariableMgr,var_info\r
+from collections import OrderedDict\r
 \r
 ## Regular expression for splitting Dependency Expression string into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
 \r
+## Regular expression for match: PCD(xxxx.yyy)\r
+gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")\r
+\r
+#\r
+# 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
+gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+\r
 #\r
 # Match name = variable\r
 #\r
@@ -404,8 +415,8 @@ class WorkspaceAutoGen(AutoGen):
 \r
 \r
 \r
-            SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
-            BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
+            SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}\r
+            BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}\r
             SourcePcdDict_Keys = SourcePcdDict.keys()\r
             BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
 \r
@@ -431,27 +442,21 @@ class WorkspaceAutoGen(AutoGen):
 \r
                         if 'DynamicEx' in BuildData.Pcds[key].Type:\r
                             if BuildData.IsBinaryModule:\r
-                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:\r
-                                    BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                BinaryPcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                             else:\r
-                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:\r
-                                    SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                SourcePcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
 \r
                         elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
                             if BuildData.MetaFile.Ext == '.inf':\r
                                 if BuildData.IsBinaryModule:\r
-                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:\r
-                                        BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                    BinaryPcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                                 else:\r
-                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:\r
-                                        SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                    SourcePcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
 \r
                         elif 'Dynamic' in BuildData.Pcds[key].Type:\r
-                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:\r
-                                SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                            SourcePcdDict['Dynamic'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                         elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
-                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:\r
-                                SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                            SourcePcdDict['FixedAtBuild'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                 else:\r
                     pass\r
             #\r
@@ -460,13 +465,13 @@ class WorkspaceAutoGen(AutoGen):
             for i in SourcePcdDict_Keys:\r
                 for j in SourcePcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(SourcePcdDict[i]).intersection(set(SourcePcdDict[j])))\r
-                        if len(IntersectionList) > 0:\r
+                        Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j])\r
+                        if len(Intersections) > 0:\r
                             EdkLogger.error(\r
                             'build',\r
                             FORMAT_INVALID,\r
                             "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),\r
-                            ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in IntersectionList])\r
+                            ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections])\r
                             )\r
                     else:\r
                         pass\r
@@ -477,8 +482,8 @@ class WorkspaceAutoGen(AutoGen):
             for i in BinaryPcdDict_Keys:\r
                 for j in BinaryPcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
-                        for item in IntersectionList:\r
+                        Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j])\r
+                        for item in Intersections:\r
                             NewPcd1 = (item[0] + '_' + i, item[1])\r
                             NewPcd2 = (item[0] + '_' + j, item[1])\r
                             if item not in GlobalData.MixedPcd:\r
@@ -497,8 +502,8 @@ class WorkspaceAutoGen(AutoGen):
             for i in SourcePcdDict_Keys:\r
                 for j in BinaryPcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
-                        for item in IntersectionList:\r
+                        Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j])\r
+                        for item in Intersections:\r
                             NewPcd1 = (item[0] + '_' + i, item[1])\r
                             NewPcd2 = (item[0] + '_' + j, item[1])\r
                             if item not in GlobalData.MixedPcd:\r
@@ -818,13 +823,11 @@ class WorkspaceAutoGen(AutoGen):
                         InfFoundFlag = False\r
 \r
                 if FfsFile.NameGuid is not None:\r
-                    _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
-\r
                     #\r
                     # If the NameGuid reference a PCD name. \r
                     # The style must match: PCD(xxxx.yyy)\r
                     #\r
-                    if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
+                    if gPCDAsGuidPattern.match(FfsFile.NameGuid):\r
                         #\r
                         # Replace the PCD value.\r
                         #\r
@@ -892,7 +895,7 @@ class WorkspaceAutoGen(AutoGen):
         ]\r
 \r
         # This dict store PCDs which are not used by any modules with specified arches\r
-        UnusedPcd = sdict()\r
+        UnusedPcd = OrderedDict()\r
         for Pa in self.AutoGenObjectList:\r
             # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
             for Pcd in Pa.Platform.Pcds:\r
@@ -2084,7 +2087,7 @@ class PlatformAutoGen(AutoGen):
     ## Generate Token Number for all PCD\r
     def _GetPcdTokenNumbers(self):\r
         if self._PcdTokenNumber is None:\r
-            self._PcdTokenNumber = sdict()\r
+            self._PcdTokenNumber = OrderedDict()\r
             TokenNumber = 1\r
             #\r
             # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
@@ -2207,8 +2210,8 @@ class PlatformAutoGen(AutoGen):
         # EdkII module\r
         LibraryConsumerList = [Module]\r
         Constructor         = []\r
-        ConsumedByList      = sdict()\r
-        LibraryInstance     = sdict()\r
+        ConsumedByList      = OrderedDict()\r
+        LibraryInstance     = OrderedDict()\r
 \r
         EdkLogger.verbose("")\r
         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
@@ -2880,14 +2883,14 @@ class ModuleAutoGen(AutoGen):
         self._DerivedPackageList      = None\r
         self._ModulePcdList           = None\r
         self._LibraryPcdList          = None\r
-        self._PcdComments = sdict()\r
+        self._PcdComments = OrderedDict()\r
         self._GuidList                = None\r
         self._GuidsUsedByPcd = None\r
-        self._GuidComments = sdict()\r
+        self._GuidComments = OrderedDict()\r
         self._ProtocolList            = None\r
-        self._ProtocolComments = sdict()\r
+        self._ProtocolComments = OrderedDict()\r
         self._PpiList                 = None\r
-        self._PpiComments = sdict()\r
+        self._PpiComments = OrderedDict()\r
         self._DepexList               = None\r
         self._DepexExpressionList     = None\r
         self._BuildOption             = None\r
@@ -2943,7 +2946,7 @@ class ModuleAutoGen(AutoGen):
     # Macros could be used in build_rule.txt (also Makefile)\r
     def _GetMacros(self):\r
         if self._Macro is None:\r
-            self._Macro = sdict()\r
+            self._Macro = OrderedDict()\r
             self._Macro["WORKSPACE"             ] = self.WorkspaceDir\r
             self._Macro["MODULE_NAME"           ] = self.Name\r
             self._Macro["MODULE_NAME_GUID"      ] = self._GetUniqueBaseName()\r
@@ -3315,9 +3318,9 @@ class ModuleAutoGen(AutoGen):
             # is the former use /I , the Latter used -I to specify include directories\r
             #\r
             if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r
             elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r
             else:\r
                 #\r
                 # New ToolChainFamily, don't known whether there is option to specify include directories\r
@@ -3334,13 +3337,13 @@ class ModuleAutoGen(AutoGen):
                     FlagOption = ''\r
                 \r
                 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
-                    IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
+                    IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r
                 else:\r
                     #\r
                     # RVCT may specify a list of directory seperated by commas\r
                     #\r
                     IncPathList = []\r
-                    for Path in gBuildOptIncludePattern.findall(FlagOption):\r
+                    for Path in BuildOptIncludeRegEx.findall(FlagOption):\r
                         PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
                         IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
 \r
@@ -3695,7 +3698,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetLibraryPcdList(self):\r
         if self._LibraryPcdList is None:\r
-            Pcds = sdict()\r
+            Pcds = OrderedDict()\r
             if not self.IsLibrary:\r
                 # get PCDs from dependent libraries\r
                 for Library in self.DependentLibraryList:\r
@@ -3717,7 +3720,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetGuidList(self):\r
         if self._GuidList is None:\r
-            self._GuidList = sdict()\r
+            self._GuidList = OrderedDict()\r
             self._GuidList.update(self.Module.Guids)\r
             for Library in self.DependentLibraryList:\r
                 self._GuidList.update(Library.Guids)\r
@@ -3727,7 +3730,7 @@ class ModuleAutoGen(AutoGen):
 \r
     def GetGuidsUsedByPcd(self):\r
         if self._GuidsUsedByPcd is None:\r
-            self._GuidsUsedByPcd = sdict()\r
+            self._GuidsUsedByPcd = OrderedDict()\r
             self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
             for Library in self.DependentLibraryList:\r
                 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
@@ -3738,7 +3741,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetProtocolList(self):\r
         if self._ProtocolList is None:\r
-            self._ProtocolList = sdict()\r
+            self._ProtocolList = OrderedDict()\r
             self._ProtocolList.update(self.Module.Protocols)\r
             for Library in self.DependentLibraryList:\r
                 self._ProtocolList.update(Library.Protocols)\r
@@ -3752,7 +3755,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetPpiList(self):\r
         if self._PpiList is None:\r
-            self._PpiList = sdict()\r
+            self._PpiList = OrderedDict()\r
             self._PpiList.update(self.Module.Ppis)\r
             for Library in self.DependentLibraryList:\r
                 self._PpiList.update(Library.Ppis)\r
@@ -3983,7 +3986,7 @@ class ModuleAutoGen(AutoGen):
                     PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))\r
                     PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))\r
                     PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
-        GuidList = sdict()\r
+        GuidList = OrderedDict()\r
         GuidList.update(self.GuidList)\r
         for TokenSpace in self.GetGuidsUsedByPcd():\r
             # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r