]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: small cleanup
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 3865827f26df751814d3eda57f2636641b7ec082..6b47aa2a8f904c98ca650992566f1ab65ab4acae 100644 (file)
@@ -50,6 +50,16 @@ from collections import OrderedDict
 ## 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
@@ -400,13 +410,8 @@ class WorkspaceAutoGen(AutoGen):
         for Arch in self.ArchList:\r
             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
 \r
-\r
-\r
-\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
@@ -432,27 +437,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
@@ -461,16 +460,14 @@ 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
 \r
             #\r
             # intersection the BinaryPCD for Mixed PCD\r
@@ -478,8 +475,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
@@ -489,8 +486,6 @@ class WorkspaceAutoGen(AutoGen):
                                     GlobalData.MixedPcd[item].append(NewPcd1)\r
                                 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
                                     GlobalData.MixedPcd[item].append(NewPcd2)\r
-                    else:\r
-                        pass\r
 \r
             #\r
             # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
@@ -498,8 +493,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
@@ -509,8 +504,6 @@ class WorkspaceAutoGen(AutoGen):
                                     GlobalData.MixedPcd[item].append(NewPcd1)\r
                                 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
                                     GlobalData.MixedPcd[item].append(NewPcd2)\r
-                    else:\r
-                        pass\r
 \r
             for BuildData in PGen.BuildDatabase._CACHE_.values():\r
                 if BuildData.Arch != Arch:\r
@@ -531,11 +524,7 @@ class WorkspaceAutoGen(AutoGen):
                                     del BuildData.Pcds[key]\r
                                     BuildData.Pcds[newkey] = Value\r
                                     break\r
-                                else:\r
-                                    pass\r
                             break\r
-                        else:\r
-                            pass\r
 \r
             # handle the mixed pcd in FDF file\r
             for key in PcdSet:\r
@@ -819,13 +808,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
@@ -3316,9 +3303,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
@@ -3335,13 +3322,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