]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Fix a bug for Size incorrect of Void* Fixatbuild Pcd
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index ef2e3ebe853c1e129536f01e2e2dc4c694189c47..5940e88682edf3486abe0feabb9ba64fe3cce897 100644 (file)
@@ -46,6 +46,7 @@ import datetime
 import hashlib\r
 from GenVar import VariableMgr,var_info\r
 from collections import OrderedDict\r
+from collections import defaultdict\r
 \r
 ## Regular expression for splitting Dependency Expression string into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
@@ -364,9 +365,9 @@ class WorkspaceAutoGen(AutoGen):
                     MetaFile_cache = {}\r
                     for Arch in self.ArchList:\r
                         Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-                        MetaFile_cache[Arch] = []\r
-                        for Pkey in Platform_cache[Arch].Modules.keys():\r
-                            MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
+                        MetaFile_cache[Arch] = set()\r
+                        for Pkey in Platform_cache[Arch].Modules:\r
+                            MetaFile_cache[Arch].add(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
                     for Inf in self.FdfProfile.InfDict[key]:\r
                         ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
                         for Arch in self.ArchList:\r
@@ -381,9 +382,9 @@ class WorkspaceAutoGen(AutoGen):
                     for Arch in self.ArchList:\r
                         if Arch == key:\r
                             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-                            MetaFileList = []\r
-                            for Pkey in Platform.Modules.keys():\r
-                                MetaFileList.append(Platform.Modules[Pkey].MetaFile)\r
+                            MetaFileList = set()\r
+                            for Pkey in Platform.Modules:\r
+                                MetaFileList.add(Platform.Modules[Pkey].MetaFile)\r
                             for Inf in self.FdfProfile.InfDict[key]:\r
                                 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
                                 if ModuleFile in MetaFileList:\r
@@ -410,11 +411,6 @@ 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':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}\r
             BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}\r
             SourcePcdDict_Keys = SourcePcdDict.keys()\r
@@ -473,8 +469,6 @@ class WorkspaceAutoGen(AutoGen):
                             "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 Intersections])\r
                             )\r
-                    else:\r
-                        pass\r
 \r
             #\r
             # intersection the BinaryPCD for Mixed PCD\r
@@ -493,8 +487,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
@@ -513,8 +505,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
@@ -535,11 +525,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
@@ -558,11 +544,11 @@ class WorkspaceAutoGen(AutoGen):
                 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
                 PkgSet.update(ModuleData.Packages)\r
             Pkgs = list(PkgSet) + list(PGen.PackageList)\r
-            DecPcds = {}\r
+            DecPcds = set()\r
             DecPcdsKey = set()\r
             for Pkg in Pkgs:\r
                 for Pcd in Pkg.Pcds:\r
-                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
+                    DecPcds.add((Pcd[0], Pcd[1]))\r
                     DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
 \r
             Platform.SkuName = self.SkuId\r
@@ -1292,7 +1278,7 @@ class PlatformAutoGen(AutoGen):
             FixedAtBuildPcds = {}  \r
             ShareFixedAtBuildPcdsSameValue = {} \r
             for Module in LibAuto._ReferenceModules:                \r
-                for Pcd in Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds:\r
+                for Pcd in Module.FixedAtBuildPcds:\r
                     key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))  \r
                     if key not in FixedAtBuildPcds:\r
                         ShareFixedAtBuildPcdsSameValue[key] = True\r
@@ -1309,7 +1295,7 @@ class PlatformAutoGen(AutoGen):
                     if DscPcd.Type != "FixedAtBuild":\r
                         continue\r
                 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:                    \r
-                    LibAuto.ConstPcd[key] = Pcd.DefaultValue\r
+                    LibAuto.ConstPcd[key] = FixedAtBuildPcds[key]\r
 \r
     def CollectVariables(self, DynamicPcdSet):\r
 \r
@@ -1402,8 +1388,6 @@ class PlatformAutoGen(AutoGen):
 \r
         # for gathering error information\r
         NoDatumTypePcdList = set()\r
-        PcdNotInDb = []\r
-        self._GuidValue = {}\r
         FdfModuleList = []\r
         for InfName in self._AsBuildInfList:\r
             InfName = mws.join(self.WorkspaceDir, InfName)\r
@@ -1441,8 +1425,6 @@ class PlatformAutoGen(AutoGen):
                         if PcdFromModule.Type in GenC.gDynamicPcd and \\r
                             PcdFromModule.IsFromBinaryInf == False:\r
                             # Print warning message to let the developer make a determine.\r
-                            if PcdFromModule not in PcdNotInDb:\r
-                                PcdNotInDb.append(PcdFromModule)\r
                             continue\r
                         # If one of the Source built modules listed in the DSC is not listed in \r
                         # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
@@ -1450,8 +1432,6 @@ class PlatformAutoGen(AutoGen):
                         # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
                         # PCD to the Platform's PCD Database.\r
                         if PcdFromModule.Type in GenC.gDynamicExPcd:\r
-                            if PcdFromModule not in PcdNotInDb:\r
-                                PcdNotInDb.append(PcdFromModule)\r
                             continue\r
                     #\r
                     # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
@@ -1932,7 +1912,6 @@ class PlatformAutoGen(AutoGen):
                 self._ToolDefinitions[Tool][Attr] = Value\r
 \r
             ToolsDef = ''\r
-            MakePath = ''\r
             if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
                 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
                     self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
@@ -1953,9 +1932,7 @@ class PlatformAutoGen(AutoGen):
 \r
                     if Attr == "PATH":\r
                         # Don't put MAKE definition in the file\r
-                        if Tool == "MAKE":\r
-                            MakePath = Value\r
-                        else:\r
+                        if Tool != "MAKE":\r
                             ToolsDef += "%s = %s\n" % (Tool, Value)\r
                     elif Attr != "DLL":\r
                         # Don't put MAKE definition in the file\r
@@ -2375,17 +2352,15 @@ class PlatformAutoGen(AutoGen):
                                              ToPcd.Type, Module, FromPcd.Type),\r
                                           File=self.MetaFile)\r
 \r
-            if FromPcd.MaxDatumSize not in [None, '']:\r
+            if FromPcd.MaxDatumSize:\r
                 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
-            if FromPcd.DefaultValue not in [None, '']:\r
+            if FromPcd.DefaultValue:\r
                 ToPcd.DefaultValue = FromPcd.DefaultValue\r
-            if FromPcd.TokenValue not in [None, '']:\r
+            if FromPcd.TokenValue:\r
                 ToPcd.TokenValue = FromPcd.TokenValue\r
-            if FromPcd.MaxDatumSize not in [None, '']:\r
-                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
-            if FromPcd.DatumType not in [None, '']:\r
+            if FromPcd.DatumType:\r
                 ToPcd.DatumType = FromPcd.DatumType\r
-            if FromPcd.SkuInfoList not in [None, '', []]:\r
+            if FromPcd.SkuInfoList:\r
                 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
             # Add Flexible PCD format parse\r
             if ToPcd.DefaultValue:\r
@@ -2711,40 +2686,31 @@ class PlatformAutoGen(AutoGen):
         AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
                        PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
                        self.ToolDefinition.keys())\r
-        BuildOptions = {}\r
+        BuildOptions = defaultdict(lambda: defaultdict(str))\r
         for Tool in AllTools:\r
-            if Tool not in BuildOptions:\r
-                BuildOptions[Tool] = {}\r
-\r
             for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
                 if Tool not in Options:\r
                     continue\r
                 for Attr in Options[Tool]:\r
-                    Value = Options[Tool][Attr]\r
                     #\r
                     # Do not generate it in Makefile\r
                     #\r
                     if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
                         continue\r
-                    if Attr not in BuildOptions[Tool]:\r
-                        BuildOptions[Tool][Attr] = ""\r
+                    Value = Options[Tool][Attr]\r
                     # check if override is indicated\r
                     if Value.startswith('='):\r
-                        ToolPath = Value[1:]\r
-                        ToolPath = mws.handleWsMacro(ToolPath)\r
-                        BuildOptions[Tool][Attr] = ToolPath\r
+                        BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
                     else:\r
-                        Value = mws.handleWsMacro(Value)\r
                         if Attr != 'PATH':\r
-                            BuildOptions[Tool][Attr] += " " + Value\r
+                            BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
                         else:\r
-                            BuildOptions[Tool][Attr] = Value\r
+                            BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
+\r
         if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag is not None:\r
             #\r
             # Override UNI flag only for EDK module.\r
             #\r
-            if 'BUILD' not in BuildOptions:\r
-                BuildOptions['BUILD'] = {}\r
             BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
         return BuildOptions, BuildRuleOrder\r
 \r
@@ -3498,8 +3464,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:\r
             self._IntroBuildTargetList = set()\r
             self._FinalBuildTargetList = set()\r
-            self._BuildTargets = {}\r
-            self._FileTypes = {}\r
+            self._BuildTargets = defaultdict(set)\r
+            self._FileTypes = defaultdict(set)\r
 \r
         SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
         if not os.path.exists(SubDirectory):\r
@@ -3536,8 +3502,6 @@ class ModuleAutoGen(AutoGen):
                 break\r
 \r
             FileType = RuleObject.SourceFileType\r
-            if FileType not in self._FileTypes:\r
-                self._FileTypes[FileType] = set()\r
             self._FileTypes[FileType].add(Source)\r
 \r
             # stop at STATIC_LIBRARY for library\r
@@ -3555,8 +3519,6 @@ class ModuleAutoGen(AutoGen):
                 # Only do build for target with outputs\r
                 self._FinalBuildTargetList.add(Target)\r
 \r
-            if FileType not in self._BuildTargets:\r
-                self._BuildTargets[FileType] = set()\r
             self._BuildTargets[FileType].add(Target)\r
 \r
             if not Source.IsBinary and Source == File:\r
@@ -3575,8 +3537,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:\r
             self._IntroBuildTargetList = set()\r
             self._FinalBuildTargetList = set()\r
-            self._BuildTargets = {}\r
-            self._FileTypes = {}\r
+            self._BuildTargets = defaultdict(set)\r
+            self._FileTypes = defaultdict(set)\r
 \r
         #TRICK: call _GetSourceFileList to apply build rule for source files\r
         if self.SourceFileList:\r
@@ -3816,7 +3778,7 @@ class ModuleAutoGen(AutoGen):
         if not self.SourceFileList:\r
             return []\r
 \r
-        NameGuids = []\r
+        NameGuids = set()\r
         for SrcFile in self.SourceFileList:\r
             if SrcFile.Ext.lower() != '.vfr':\r
                 continue\r
@@ -3848,7 +3810,7 @@ class ModuleAutoGen(AutoGen):
                 if not Guid:\r
                     break\r
                 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
-                NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
+                NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
                 Pos = Content.find('efivarstore', Name.end())\r
         if not NameGuids:\r
             return []\r
@@ -3923,7 +3885,6 @@ class ModuleAutoGen(AutoGen):
                 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
                 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
                 fStringIO.write(''.join(VfrGuid))                   \r
-                type (Item[1]) \r
                 VfrValue = pack ('Q', int (Item[1], 16))\r
                 fStringIO.write (VfrValue)\r
         #\r
@@ -3942,7 +3903,7 @@ class ModuleAutoGen(AutoGen):
     ## Create AsBuilt INF file the module\r
     #\r
     def CreateAsBuiltInf(self, IsOnlyCopy = False):\r
-        self.OutputFile = []\r
+        self.OutputFile = set()\r
         if IsOnlyCopy:\r
             if GlobalData.gBinCacheDest:\r
                 self.CopyModuleToCache()\r
@@ -3960,11 +3921,11 @@ class ModuleAutoGen(AutoGen):
             return\r
             \r
         # Skip the following code for modules with no source files\r
-        if self.SourceFileList is None or self.SourceFileList == []:\r
+        if not self.SourceFileList:\r
             return\r
 \r
         # Skip the following code for modules without any binary files\r
-        if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
+        if not self.BinaryFileList:\r
             return\r
             \r
         ### TODO: How to handles mixed source and binary modules\r
@@ -4083,8 +4044,7 @@ class ModuleAutoGen(AutoGen):
         DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
         for Item in self.CodaTargetList:\r
             File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
-            if File not in self.OutputFile:\r
-                self.OutputFile.append(File)\r
+            self.OutputFile.add(File)\r
             if os.path.isabs(File):\r
                 File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
             if Item.Target.Ext.lower() == '.aml':\r
@@ -4096,8 +4056,7 @@ class ModuleAutoGen(AutoGen):
             else:\r
                 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
         if self.DepexGenerated:\r
-            if self.Name + '.depex' not in self.OutputFile:\r
-                self.OutputFile.append(self.Name + '.depex')\r
+            self.OutputFile.add(self.Name + '.depex')\r
             if self.ModuleType in ['PEIM']:\r
                 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
             if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:\r
@@ -4108,15 +4067,13 @@ class ModuleAutoGen(AutoGen):
         Bin = self._GenOffsetBin()\r
         if Bin:\r
             AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]\r
-            if Bin not in self.OutputFile:\r
-                self.OutputFile.append(Bin)\r
+            self.OutputFile.add(Bin)\r
 \r
         for Root, Dirs, Files in os.walk(OutputDir):\r
             for File in Files:\r
                 if File.lower().endswith('.pdb'):\r
                     AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]\r
-                    if File not in self.OutputFile:\r
-                        self.OutputFile.append(File)\r
+                    self.OutputFile.add(File)\r
         HeaderComments = self.Module.HeaderComments\r
         StartPos = 0\r
         for Index in range(len(HeaderComments)):\r
@@ -4222,7 +4179,7 @@ class ModuleAutoGen(AutoGen):
                     PcdItem = PcdComments + '\n  ' + PcdItem\r
                 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
 \r
-        HiiPcds = []\r
+        HiiPcds = set()\r
         for Pcd in Pcds + VfrPcds:\r
             PcdComments = ''\r
             PcdCommentList = []\r
@@ -4245,8 +4202,7 @@ class ModuleAutoGen(AutoGen):
                 #\r
                 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:\r
                     continue\r
-                else:\r
-                    HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                HiiPcds.add((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
             if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
                 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
             if HiiInfo:\r