]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: use set instead of list for a variable to be used with in
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index b8d8d194156286154c4184a4e9688d60ceeb8876..a4e36d1a2fb4f3a47157f932157d7a7e8a86f222 100644 (file)
@@ -256,12 +256,6 @@ class WorkspaceAutoGen(AutoGen):
     def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
               BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
               Progress=None, BuildModule=None):\r
-        if Fds is None:\r
-            Fds = []\r
-        if Fvs is None:\r
-            Fvs = []\r
-        if Caps is None:\r
-            Caps = []\r
         self.BuildDatabase  = MetaFileDb\r
         self.MetaFile       = ActivePlatform\r
         self.WorkspaceDir   = WorkspaceDir\r
@@ -276,9 +270,9 @@ class WorkspaceAutoGen(AutoGen):
         self.TargetTxt      = BuildConfig\r
         self.ToolDef        = ToolDefinition\r
         self.FdfFile        = FlashDefinitionFile\r
-        self.FdTargetList   = Fds\r
-        self.FvTargetList   = Fvs\r
-        self.CapTargetList  = Caps\r
+        self.FdTargetList   = Fds if Fds else []\r
+        self.FvTargetList   = Fvs if Fvs else []\r
+        self.CapTargetList  = Caps if Caps else []\r
         self.AutoGenObjectList = []\r
         self._BuildDir      = None\r
         self._FvDir         = None\r
@@ -361,13 +355,12 @@ class WorkspaceAutoGen(AutoGen):
             # but the path (self.MetaFile.Path) is the real path\r
             for key in self.FdfProfile.InfDict:\r
                 if key == 'ArchTBD':\r
-                    Platform_cache = {}\r
                     MetaFile_cache = {}\r
                     for Arch in self.ArchList:\r
-                        Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
+                        Current_Platform_cache = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\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 Pkey in Current_Platform_cache.Modules:\r
+                            MetaFile_cache[Arch].add(Current_Platform_cache.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
@@ -410,7 +403,8 @@ class WorkspaceAutoGen(AutoGen):
         # apply SKU and inject PCDs from Flash Definition file\r
         for Arch in self.ArchList:\r
             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-\r
+            PlatformPcds = Platform.Pcds\r
+            self._GuidDict = Platform._GuidDict\r
             SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}\r
             BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}\r
             SourcePcdDict_Keys = SourcePcdDict.keys()\r
@@ -1295,7 +1289,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
@@ -1456,13 +1450,10 @@ class PlatformAutoGen(AutoGen):
                         self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
                         PcdFromModule.Pending = False\r
                         self._NonDynaPcdList_.append (PcdFromModule)\r
-        # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
-        DscModuleList = []\r
-        for ModuleInf in self.Platform.Modules.keys():\r
-            DscModuleList.append (os.path.normpath(ModuleInf.Path))\r
+        DscModuleSet = {os.path.normpath(ModuleInf.Path) for ModuleInf in self.Platform.Modules}\r
         # add the PCD from modules that listed in FDF but not in DSC to Database \r
         for InfName in FdfModuleList:\r
-            if InfName not in DscModuleList:\r
+            if InfName not in DscModuleSet:\r
                 InfClass = PathClass(InfName)\r
                 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
                 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
@@ -2352,17 +2343,16 @@ 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
+                ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize\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
@@ -2458,6 +2448,7 @@ class PlatformAutoGen(AutoGen):
         for Name, Guid in Pcds:\r
             Pcd = Pcds[Name, Guid]\r
             if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]:\r
+                Pcd.MaxSizeUserSet = None\r
                 Value = Pcd.DefaultValue\r
                 if Value in [None, '']:\r
                     Pcd.MaxDatumSize = '1'\r
@@ -2688,40 +2679,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
@@ -2799,7 +2781,7 @@ class ModuleAutoGen(AutoGen):
 \r
         self.Workspace = Workspace\r
         self.WorkspaceDir = Workspace.WorkspaceDir\r
-\r
+        self._GuidDict = Workspace._GuidDict\r
         self.MetaFile = ModuleFile\r
         self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
 \r
@@ -3789,7 +3771,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
@@ -3821,7 +3803,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
@@ -3896,7 +3878,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
@@ -3915,7 +3896,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
@@ -3933,11 +3914,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
@@ -4056,8 +4037,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
@@ -4069,8 +4049,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
@@ -4081,15 +4060,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
@@ -4173,9 +4150,12 @@ class ModuleAutoGen(AutoGen):
                             Padding = Padding * 2\r
                             ArraySize = ArraySize / 2\r
                         if ArraySize < (len(PcdValue) + 1):\r
-                            EdkLogger.error("build", AUTOGEN_ERROR,\r
+                            if Pcd.MaxSizeUserSet:\r
+                                EdkLogger.error("build", AUTOGEN_ERROR,\r
                                             "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                             )\r
+                            else:\r
+                                ArraySize = len(PcdValue) + 1\r
                         if ArraySize > len(PcdValue) + 1:\r
                             NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
                         PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
@@ -4183,9 +4163,12 @@ class ModuleAutoGen(AutoGen):
                         PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
                         PcdValue += '}'\r
                     else:\r
-                        EdkLogger.error("build", AUTOGEN_ERROR,\r
+                        if Pcd.MaxSizeUserSet:\r
+                            EdkLogger.error("build", AUTOGEN_ERROR,\r
                                         "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                         )\r
+                        else:\r
+                            ArraySize = len(PcdValue) + 1\r
                 PcdItem = '%s.%s|%s|0x%X' % \\r
                     (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
                 PcdComments = ''\r
@@ -4195,7 +4178,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
@@ -4218,8 +4201,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