X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FAutoGen.py;h=a4e36d1a2fb4f3a47157f932157d7a7e8a86f222;hp=3384fdb70b7ef2b1f292db5992e88ab6ba4a35fc;hb=1563349a967d7e02c43492ba853babb9c660a083;hpb=4231a8193ec0d52df7e0a101d96c51b1a2b7a996 diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index 3384fdb70b..a4e36d1a2f 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -45,10 +45,22 @@ import InfSectionParser import datetime import hashlib from GenVar import VariableMgr,var_info +from collections import OrderedDict +from collections import defaultdict ## Regular expression for splitting Dependency Expression string into tokens gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)") +## Regular expression for match: PCD(xxxx.yyy) +gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$") + +# +# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT +# is the former use /I , the Latter used -I to specify include directories +# +gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL) +gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL) + # # Match name = variable # @@ -244,12 +256,6 @@ class WorkspaceAutoGen(AutoGen): def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb, BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None, Progress=None, BuildModule=None): - if Fds is None: - Fds = [] - if Fvs is None: - Fvs = [] - if Caps is None: - Caps = [] self.BuildDatabase = MetaFileDb self.MetaFile = ActivePlatform self.WorkspaceDir = WorkspaceDir @@ -264,9 +270,9 @@ class WorkspaceAutoGen(AutoGen): self.TargetTxt = BuildConfig self.ToolDef = ToolDefinition self.FdfFile = FlashDefinitionFile - self.FdTargetList = Fds - self.FvTargetList = Fvs - self.CapTargetList = Caps + self.FdTargetList = Fds if Fds else [] + self.FvTargetList = Fvs if Fvs else [] + self.CapTargetList = Caps if Caps else [] self.AutoGenObjectList = [] self._BuildDir = None self._FvDir = None @@ -349,13 +355,12 @@ class WorkspaceAutoGen(AutoGen): # but the path (self.MetaFile.Path) is the real path for key in self.FdfProfile.InfDict: if key == 'ArchTBD': - Platform_cache = {} MetaFile_cache = {} for Arch in self.ArchList: - Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain] - MetaFile_cache[Arch] = [] - for Pkey in Platform_cache[Arch].Modules.keys(): - MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile) + Current_Platform_cache = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain] + MetaFile_cache[Arch] = set() + for Pkey in Current_Platform_cache.Modules: + MetaFile_cache[Arch].add(Current_Platform_cache.Modules[Pkey].MetaFile) for Inf in self.FdfProfile.InfDict[key]: ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch) for Arch in self.ArchList: @@ -370,9 +375,9 @@ class WorkspaceAutoGen(AutoGen): for Arch in self.ArchList: if Arch == key: Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain] - MetaFileList = [] - for Pkey in Platform.Modules.keys(): - MetaFileList.append(Platform.Modules[Pkey].MetaFile) + MetaFileList = set() + for Pkey in Platform.Modules: + MetaFileList.add(Platform.Modules[Pkey].MetaFile) for Inf in self.FdfProfile.InfDict[key]: ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch) if ModuleFile in MetaFileList: @@ -398,14 +403,10 @@ class WorkspaceAutoGen(AutoGen): # apply SKU and inject PCDs from Flash Definition file for Arch in self.ArchList: Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain] - - - - - - - SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]} - BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]} + PlatformPcds = Platform.Pcds + self._GuidDict = Platform._GuidDict + SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()} + BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()} SourcePcdDict_Keys = SourcePcdDict.keys() BinaryPcdDict_Keys = BinaryPcdDict.keys() @@ -431,27 +432,21 @@ class WorkspaceAutoGen(AutoGen): if 'DynamicEx' in BuildData.Pcds[key].Type: if BuildData.IsBinaryModule: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']: - BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + BinaryPcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) else: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']: - SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + SourcePcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) elif 'PatchableInModule' in BuildData.Pcds[key].Type: if BuildData.MetaFile.Ext == '.inf': if BuildData.IsBinaryModule: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']: - BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + BinaryPcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) else: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']: - SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + SourcePcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) elif 'Dynamic' in BuildData.Pcds[key].Type: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']: - SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + SourcePcdDict['Dynamic'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) elif 'FixedAtBuild' in BuildData.Pcds[key].Type: - if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']: - SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) + SourcePcdDict['FixedAtBuild'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName)) else: pass # @@ -460,16 +455,14 @@ class WorkspaceAutoGen(AutoGen): for i in SourcePcdDict_Keys: for j in SourcePcdDict_Keys: if i != j: - IntersectionList = list(set(SourcePcdDict[i]).intersection(set(SourcePcdDict[j]))) - if len(IntersectionList) > 0: + Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j]) + if len(Intersections) > 0: EdkLogger.error( 'build', FORMAT_INVALID, "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), - ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in IntersectionList]) + ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections]) ) - else: - pass # # intersection the BinaryPCD for Mixed PCD @@ -477,8 +470,8 @@ class WorkspaceAutoGen(AutoGen): for i in BinaryPcdDict_Keys: for j in BinaryPcdDict_Keys: if i != j: - IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j]))) - for item in IntersectionList: + Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j]) + for item in Intersections: NewPcd1 = (item[0] + '_' + i, item[1]) NewPcd2 = (item[0] + '_' + j, item[1]) if item not in GlobalData.MixedPcd: @@ -488,8 +481,6 @@ class WorkspaceAutoGen(AutoGen): GlobalData.MixedPcd[item].append(NewPcd1) if NewPcd2 not in GlobalData.MixedPcd[item]: GlobalData.MixedPcd[item].append(NewPcd2) - else: - pass # # intersection the SourcePCD and BinaryPCD for Mixed PCD @@ -497,8 +488,8 @@ class WorkspaceAutoGen(AutoGen): for i in SourcePcdDict_Keys: for j in BinaryPcdDict_Keys: if i != j: - IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j]))) - for item in IntersectionList: + Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j]) + for item in Intersections: NewPcd1 = (item[0] + '_' + i, item[1]) NewPcd2 = (item[0] + '_' + j, item[1]) if item not in GlobalData.MixedPcd: @@ -508,8 +499,6 @@ class WorkspaceAutoGen(AutoGen): GlobalData.MixedPcd[item].append(NewPcd1) if NewPcd2 not in GlobalData.MixedPcd[item]: GlobalData.MixedPcd[item].append(NewPcd2) - else: - pass for BuildData in PGen.BuildDatabase._CACHE_.values(): if BuildData.Arch != Arch: @@ -530,11 +519,7 @@ class WorkspaceAutoGen(AutoGen): del BuildData.Pcds[key] BuildData.Pcds[newkey] = Value break - else: - pass break - else: - pass # handle the mixed pcd in FDF file for key in PcdSet: @@ -553,11 +538,11 @@ class WorkspaceAutoGen(AutoGen): ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain] PkgSet.update(ModuleData.Packages) Pkgs = list(PkgSet) + list(PGen.PackageList) - DecPcds = {} + DecPcds = set() DecPcdsKey = set() for Pkg in Pkgs: for Pcd in Pkg.Pcds: - DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd] + DecPcds.add((Pcd[0], Pcd[1])) DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2])) Platform.SkuName = self.SkuId @@ -818,13 +803,11 @@ class WorkspaceAutoGen(AutoGen): InfFoundFlag = False if FfsFile.NameGuid is not None: - _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$") - # # If the NameGuid reference a PCD name. # The style must match: PCD(xxxx.yyy) # - if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid): + if gPCDAsGuidPattern.match(FfsFile.NameGuid): # # Replace the PCD value. # @@ -892,7 +875,7 @@ class WorkspaceAutoGen(AutoGen): ] # This dict store PCDs which are not used by any modules with specified arches - UnusedPcd = sdict() + UnusedPcd = OrderedDict() for Pa in self.AutoGenObjectList: # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid for Pcd in Pa.Platform.Pcds: @@ -1306,7 +1289,7 @@ class PlatformAutoGen(AutoGen): if DscPcd.Type != "FixedAtBuild": continue if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]: - LibAuto.ConstPcd[key] = Pcd.DefaultValue + LibAuto.ConstPcd[key] = FixedAtBuildPcds[key] def CollectVariables(self, DynamicPcdSet): @@ -1399,8 +1382,6 @@ class PlatformAutoGen(AutoGen): # for gathering error information NoDatumTypePcdList = set() - PcdNotInDb = [] - self._GuidValue = {} FdfModuleList = [] for InfName in self._AsBuildInfList: InfName = mws.join(self.WorkspaceDir, InfName) @@ -1438,8 +1419,6 @@ class PlatformAutoGen(AutoGen): if PcdFromModule.Type in GenC.gDynamicPcd and \ PcdFromModule.IsFromBinaryInf == False: # Print warning message to let the developer make a determine. - if PcdFromModule not in PcdNotInDb: - PcdNotInDb.append(PcdFromModule) continue # If one of the Source built modules listed in the DSC is not listed in # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx @@ -1447,8 +1426,6 @@ class PlatformAutoGen(AutoGen): # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the # PCD to the Platform's PCD Database. if PcdFromModule.Type in GenC.gDynamicExPcd: - if PcdFromModule not in PcdNotInDb: - PcdNotInDb.append(PcdFromModule) continue # # If a dynamic PCD used by a PEM module/PEI module & DXE module, @@ -1473,13 +1450,10 @@ class PlatformAutoGen(AutoGen): self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index]) PcdFromModule.Pending = False self._NonDynaPcdList_.append (PcdFromModule) - # Parse the DynamicEx PCD from the AsBuild INF module list of FDF. - DscModuleList = [] - for ModuleInf in self.Platform.Modules.keys(): - DscModuleList.append (os.path.normpath(ModuleInf.Path)) + DscModuleSet = {os.path.normpath(ModuleInf.Path) for ModuleInf in self.Platform.Modules} # add the PCD from modules that listed in FDF but not in DSC to Database for InfName in FdfModuleList: - if InfName not in DscModuleList: + if InfName not in DscModuleSet: InfClass = PathClass(InfName) M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain] # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) @@ -1929,7 +1903,6 @@ class PlatformAutoGen(AutoGen): self._ToolDefinitions[Tool][Attr] = Value ToolsDef = '' - MakePath = '' if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions: if "FLAGS" not in self._ToolDefinitions["MAKE"]: self._ToolDefinitions["MAKE"]["FLAGS"] = "" @@ -1950,9 +1923,7 @@ class PlatformAutoGen(AutoGen): if Attr == "PATH": # Don't put MAKE definition in the file - if Tool == "MAKE": - MakePath = Value - else: + if Tool != "MAKE": ToolsDef += "%s = %s\n" % (Tool, Value) elif Attr != "DLL": # Don't put MAKE definition in the file @@ -2084,7 +2055,7 @@ class PlatformAutoGen(AutoGen): ## Generate Token Number for all PCD def _GetPcdTokenNumbers(self): if self._PcdTokenNumber is None: - self._PcdTokenNumber = sdict() + self._PcdTokenNumber = OrderedDict() TokenNumber = 1 # # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. @@ -2207,8 +2178,8 @@ class PlatformAutoGen(AutoGen): # EdkII module LibraryConsumerList = [Module] Constructor = [] - ConsumedByList = sdict() - LibraryInstance = sdict() + ConsumedByList = OrderedDict() + LibraryInstance = OrderedDict() EdkLogger.verbose("") EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch)) @@ -2372,17 +2343,16 @@ class PlatformAutoGen(AutoGen): ToPcd.Type, Module, FromPcd.Type), File=self.MetaFile) - if FromPcd.MaxDatumSize not in [None, '']: + if FromPcd.MaxDatumSize: ToPcd.MaxDatumSize = FromPcd.MaxDatumSize - if FromPcd.DefaultValue not in [None, '']: + ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize + if FromPcd.DefaultValue: ToPcd.DefaultValue = FromPcd.DefaultValue - if FromPcd.TokenValue not in [None, '']: + if FromPcd.TokenValue: ToPcd.TokenValue = FromPcd.TokenValue - if FromPcd.MaxDatumSize not in [None, '']: - ToPcd.MaxDatumSize = FromPcd.MaxDatumSize - if FromPcd.DatumType not in [None, '']: + if FromPcd.DatumType: ToPcd.DatumType = FromPcd.DatumType - if FromPcd.SkuInfoList not in [None, '', []]: + if FromPcd.SkuInfoList: ToPcd.SkuInfoList = FromPcd.SkuInfoList # Add Flexible PCD format parse if ToPcd.DefaultValue: @@ -2478,6 +2448,7 @@ class PlatformAutoGen(AutoGen): for Name, Guid in Pcds: Pcd = Pcds[Name, Guid] if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]: + Pcd.MaxSizeUserSet = None Value = Pcd.DefaultValue if Value in [None, '']: Pcd.MaxDatumSize = '1' @@ -2708,40 +2679,31 @@ class PlatformAutoGen(AutoGen): AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + ModuleTypeOptions.keys() + self.ToolDefinition.keys()) - BuildOptions = {} + BuildOptions = defaultdict(lambda: defaultdict(str)) for Tool in AllTools: - if Tool not in BuildOptions: - BuildOptions[Tool] = {} - for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]: if Tool not in Options: continue for Attr in Options[Tool]: - Value = Options[Tool][Attr] # # Do not generate it in Makefile # if Attr == TAB_TOD_DEFINES_BUILDRULEORDER: continue - if Attr not in BuildOptions[Tool]: - BuildOptions[Tool][Attr] = "" + Value = Options[Tool][Attr] # check if override is indicated if Value.startswith('='): - ToolPath = Value[1:] - ToolPath = mws.handleWsMacro(ToolPath) - BuildOptions[Tool][Attr] = ToolPath + BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:]) else: - Value = mws.handleWsMacro(Value) if Attr != 'PATH': - BuildOptions[Tool][Attr] += " " + Value + BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value) else: - BuildOptions[Tool][Attr] = Value + BuildOptions[Tool][Attr] = mws.handleWsMacro(Value) + if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag is not None: # # Override UNI flag only for EDK module. # - if 'BUILD' not in BuildOptions: - BuildOptions['BUILD'] = {} BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag return BuildOptions, BuildRuleOrder @@ -2819,7 +2781,7 @@ class ModuleAutoGen(AutoGen): self.Workspace = Workspace self.WorkspaceDir = Workspace.WorkspaceDir - + self._GuidDict = Workspace._GuidDict self.MetaFile = ModuleFile self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch) @@ -2880,14 +2842,14 @@ class ModuleAutoGen(AutoGen): self._DerivedPackageList = None self._ModulePcdList = None self._LibraryPcdList = None - self._PcdComments = sdict() + self._PcdComments = OrderedDict() self._GuidList = None self._GuidsUsedByPcd = None - self._GuidComments = sdict() + self._GuidComments = OrderedDict() self._ProtocolList = None - self._ProtocolComments = sdict() + self._ProtocolComments = OrderedDict() self._PpiList = None - self._PpiComments = sdict() + self._PpiComments = OrderedDict() self._DepexList = None self._DepexExpressionList = None self._BuildOption = None @@ -2943,7 +2905,7 @@ class ModuleAutoGen(AutoGen): # Macros could be used in build_rule.txt (also Makefile) def _GetMacros(self): if self._Macro is None: - self._Macro = sdict() + self._Macro = OrderedDict() self._Macro["WORKSPACE" ] = self.WorkspaceDir self._Macro["MODULE_NAME" ] = self.Name self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName() @@ -3315,9 +3277,9 @@ class ModuleAutoGen(AutoGen): # is the former use /I , the Latter used -I to specify include directories # if self.PlatformInfo.ToolChainFamily in ('MSFT'): - gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL) + BuildOptIncludeRegEx = gBuildOptIncludePatternMsft elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'): - gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL) + BuildOptIncludeRegEx = gBuildOptIncludePatternOther else: # # New ToolChainFamily, don't known whether there is option to specify include directories @@ -3334,13 +3296,13 @@ class ModuleAutoGen(AutoGen): FlagOption = '' if self.PlatformInfo.ToolChainFamily != 'RVCT': - IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)] + IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)] else: # # RVCT may specify a list of directory seperated by commas # IncPathList = [] - for Path in gBuildOptIncludePattern.findall(FlagOption): + for Path in BuildOptIncludeRegEx.findall(FlagOption): PathList = GetSplitList(Path, TAB_COMMA_SPLIT) IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList] @@ -3495,8 +3457,8 @@ class ModuleAutoGen(AutoGen): if self._BuildTargets is None: self._IntroBuildTargetList = set() self._FinalBuildTargetList = set() - self._BuildTargets = {} - self._FileTypes = {} + self._BuildTargets = defaultdict(set) + self._FileTypes = defaultdict(set) SubDirectory = os.path.join(self.OutputDir, File.SubDir) if not os.path.exists(SubDirectory): @@ -3533,8 +3495,6 @@ class ModuleAutoGen(AutoGen): break FileType = RuleObject.SourceFileType - if FileType not in self._FileTypes: - self._FileTypes[FileType] = set() self._FileTypes[FileType].add(Source) # stop at STATIC_LIBRARY for library @@ -3552,8 +3512,6 @@ class ModuleAutoGen(AutoGen): # Only do build for target with outputs self._FinalBuildTargetList.add(Target) - if FileType not in self._BuildTargets: - self._BuildTargets[FileType] = set() self._BuildTargets[FileType].add(Target) if not Source.IsBinary and Source == File: @@ -3572,8 +3530,8 @@ class ModuleAutoGen(AutoGen): if self._BuildTargets is None: self._IntroBuildTargetList = set() self._FinalBuildTargetList = set() - self._BuildTargets = {} - self._FileTypes = {} + self._BuildTargets = defaultdict(set) + self._FileTypes = defaultdict(set) #TRICK: call _GetSourceFileList to apply build rule for source files if self.SourceFileList: @@ -3695,7 +3653,7 @@ class ModuleAutoGen(AutoGen): # def _GetLibraryPcdList(self): if self._LibraryPcdList is None: - Pcds = sdict() + Pcds = OrderedDict() if not self.IsLibrary: # get PCDs from dependent libraries for Library in self.DependentLibraryList: @@ -3717,7 +3675,7 @@ class ModuleAutoGen(AutoGen): # def _GetGuidList(self): if self._GuidList is None: - self._GuidList = sdict() + self._GuidList = OrderedDict() self._GuidList.update(self.Module.Guids) for Library in self.DependentLibraryList: self._GuidList.update(Library.Guids) @@ -3727,7 +3685,7 @@ class ModuleAutoGen(AutoGen): def GetGuidsUsedByPcd(self): if self._GuidsUsedByPcd is None: - self._GuidsUsedByPcd = sdict() + self._GuidsUsedByPcd = OrderedDict() self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd()) for Library in self.DependentLibraryList: self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd()) @@ -3738,7 +3696,7 @@ class ModuleAutoGen(AutoGen): # def _GetProtocolList(self): if self._ProtocolList is None: - self._ProtocolList = sdict() + self._ProtocolList = OrderedDict() self._ProtocolList.update(self.Module.Protocols) for Library in self.DependentLibraryList: self._ProtocolList.update(Library.Protocols) @@ -3752,7 +3710,7 @@ class ModuleAutoGen(AutoGen): # def _GetPpiList(self): if self._PpiList is None: - self._PpiList = sdict() + self._PpiList = OrderedDict() self._PpiList.update(self.Module.Ppis) for Library in self.DependentLibraryList: self._PpiList.update(Library.Ppis) @@ -3813,7 +3771,7 @@ class ModuleAutoGen(AutoGen): if not self.SourceFileList: return [] - NameGuids = [] + NameGuids = set() for SrcFile in self.SourceFileList: if SrcFile.Ext.lower() != '.vfr': continue @@ -3845,7 +3803,7 @@ class ModuleAutoGen(AutoGen): if not Guid: break NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"') - NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1)))) + NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1)))) Pos = Content.find('efivarstore', Name.end()) if not NameGuids: return [] @@ -3920,7 +3878,6 @@ class ModuleAutoGen(AutoGen): VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2] VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid] fStringIO.write(''.join(VfrGuid)) - type (Item[1]) VfrValue = pack ('Q', int (Item[1], 16)) fStringIO.write (VfrValue) # @@ -3939,7 +3896,7 @@ class ModuleAutoGen(AutoGen): ## Create AsBuilt INF file the module # def CreateAsBuiltInf(self, IsOnlyCopy = False): - self.OutputFile = [] + self.OutputFile = set() if IsOnlyCopy: if GlobalData.gBinCacheDest: self.CopyModuleToCache() @@ -3957,11 +3914,11 @@ class ModuleAutoGen(AutoGen): return # Skip the following code for modules with no source files - if self.SourceFileList is None or self.SourceFileList == []: + if not self.SourceFileList: return # Skip the following code for modules without any binary files - if self.BinaryFileList <> None and self.BinaryFileList <> []: + if not self.BinaryFileList: return ### TODO: How to handles mixed source and binary modules @@ -3983,7 +3940,7 @@ class ModuleAutoGen(AutoGen): PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx')) PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic')) PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName) - GuidList = sdict() + GuidList = OrderedDict() GuidList.update(self.GuidList) for TokenSpace in self.GetGuidsUsedByPcd(): # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list @@ -4080,8 +4037,7 @@ class ModuleAutoGen(AutoGen): DebugDir = self.DebugDir.replace('\\', '/').strip('/') for Item in self.CodaTargetList: File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/') - if File not in self.OutputFile: - self.OutputFile.append(File) + self.OutputFile.add(File) if os.path.isabs(File): File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/') if Item.Target.Ext.lower() == '.aml': @@ -4093,8 +4049,7 @@ class ModuleAutoGen(AutoGen): else: AsBuiltInfDict['binary_item'] += ['BIN|' + File] if self.DepexGenerated: - if self.Name + '.depex' not in self.OutputFile: - self.OutputFile.append(self.Name + '.depex') + self.OutputFile.add(self.Name + '.depex') if self.ModuleType in ['PEIM']: AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex'] if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']: @@ -4105,15 +4060,13 @@ class ModuleAutoGen(AutoGen): Bin = self._GenOffsetBin() if Bin: AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin] - if Bin not in self.OutputFile: - self.OutputFile.append(Bin) + self.OutputFile.add(Bin) for Root, Dirs, Files in os.walk(OutputDir): for File in Files: if File.lower().endswith('.pdb'): AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File] - if File not in self.OutputFile: - self.OutputFile.append(File) + self.OutputFile.add(File) HeaderComments = self.Module.HeaderComments StartPos = 0 for Index in range(len(HeaderComments)): @@ -4197,9 +4150,12 @@ class ModuleAutoGen(AutoGen): Padding = Padding * 2 ArraySize = ArraySize / 2 if ArraySize < (len(PcdValue) + 1): - EdkLogger.error("build", AUTOGEN_ERROR, + if Pcd.MaxSizeUserSet: + EdkLogger.error("build", AUTOGEN_ERROR, "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName) ) + else: + ArraySize = len(PcdValue) + 1 if ArraySize > len(PcdValue) + 1: NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1) PcdValue = NewValue + Padding.strip().rstrip(',') + '}' @@ -4207,9 +4163,12 @@ class ModuleAutoGen(AutoGen): PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(','))) PcdValue += '}' else: - EdkLogger.error("build", AUTOGEN_ERROR, + if Pcd.MaxSizeUserSet: + EdkLogger.error("build", AUTOGEN_ERROR, "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName) ) + else: + ArraySize = len(PcdValue) + 1 PcdItem = '%s.%s|%s|0x%X' % \ (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1]) PcdComments = '' @@ -4219,7 +4178,7 @@ class ModuleAutoGen(AutoGen): PcdItem = PcdComments + '\n ' + PcdItem AsBuiltInfDict['patchablepcd_item'].append(PcdItem) - HiiPcds = [] + HiiPcds = set() for Pcd in Pcds + VfrPcds: PcdComments = '' PcdCommentList = [] @@ -4242,8 +4201,7 @@ class ModuleAutoGen(AutoGen): # if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds: continue - else: - HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)) + HiiPcds.add((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)) if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments: PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:] if HiiInfo: