X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FAutoGen.py;h=56b5d399727e4f68af31d654c4115047286267c6;hp=4088fb9c8b7d641846e47600f603b0dcff6fa86f;hb=656d2539be34ea0ce356857ffd4f9decdf0476b2;hpb=c8802c3dccbead06fb69ec2e91a361d6ac1e93fb diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index 4088fb9c8b..56b5d39972 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -46,6 +46,7 @@ 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)") @@ -255,16 +256,10 @@ 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 - self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain] + self.Platform = self.BuildDatabase[self.MetaFile, TAB_COMMON, Target, Toolchain] GlobalData.gActivePlatform = self.Platform self.BuildTarget = Target self.ToolChain = Toolchain @@ -275,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 @@ -360,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: @@ -381,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: @@ -409,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() @@ -442,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 # @@ -471,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 @@ -488,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: @@ -499,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 @@ -508,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: @@ -519,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: @@ -541,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: @@ -564,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 @@ -788,7 +762,7 @@ class WorkspaceAutoGen(AutoGen): for Module in Pa.ModuleAutoGenList: if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName): InfFoundFlag = True - if not Module.Guid.upper() in _GuidDict.keys(): + if Module.Guid.upper() not in _GuidDict: _GuidDict[Module.Guid.upper()] = FfsFile break else: @@ -814,8 +788,8 @@ class WorkspaceAutoGen(AutoGen): # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use # BuildObject from one of AutoGenObjectList is enough. # - InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain] - if not InfObj.Guid.upper() in _GuidDict.keys(): + InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, TAB_COMMON, self.BuildTarget, self.ToolChain] + if InfObj.Guid.upper() not in _GuidDict: _GuidDict[InfObj.Guid.upper()] = FfsFile else: EdkLogger.error("build", @@ -863,7 +837,7 @@ class WorkspaceAutoGen(AutoGen): "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue), ExtraData=self.FdfFile) - if not _PcdGuidString.upper() in _GuidDict.keys(): + if _PcdGuidString.upper() not in _GuidDict: _GuidDict[_PcdGuidString.upper()] = FfsFile PcdFoundFlag = True break @@ -877,7 +851,7 @@ class WorkspaceAutoGen(AutoGen): FfsFile.NameGuid.upper()), ExtraData=self.FdfFile) - if not FfsFile.NameGuid.upper() in _GuidDict.keys(): + if FfsFile.NameGuid.upper() not in _GuidDict: _GuidDict[FfsFile.NameGuid.upper()] = FfsFile else: # @@ -1315,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): @@ -1364,7 +1338,7 @@ class PlatformAutoGen(AutoGen): EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath) NvStoreOffset = int(NvStoreOffset,16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset) - default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT") + default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT) maxsize = self.VariableInfo.VpdRegionSize - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(",")) var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize) @@ -1372,7 +1346,7 @@ class PlatformAutoGen(AutoGen): default_skuobj.DefaultValue = var_data PcdNvStoreDfBuffer[0].DefaultValue = var_data PcdNvStoreDfBuffer[0].SkuInfoList.clear() - PcdNvStoreDfBuffer[0].SkuInfoList['DEFAULT'] = default_skuobj + PcdNvStoreDfBuffer[0].SkuInfoList[TAB_DEFAULT] = default_skuobj PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(","))) return OrgVpdFile @@ -1408,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) @@ -1422,7 +1394,7 @@ class PlatformAutoGen(AutoGen): for PcdFromModule in M.ModulePcdList + M.LibraryPcdList: # make sure that the "VOID*" kind of datum has MaxDatumSize set - if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']: + if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']: NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F)) # Check the PCD from Binary INF or Source INF @@ -1430,10 +1402,8 @@ class PlatformAutoGen(AutoGen): PcdFromModule.IsFromBinaryInf = True # Check the PCD from DSC or not - if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys(): - PcdFromModule.IsFromDsc = True - else: - PcdFromModule.IsFromDsc = False + PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds + if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd: if F.Path not in FdfModuleList: # If one of the Source built modules listed in the DSC is not listed @@ -1447,8 +1417,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 @@ -1456,8 +1424,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, @@ -1482,13 +1448,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) @@ -1508,7 +1471,7 @@ class PlatformAutoGen(AutoGen): ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n" % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName)) # make sure that the "VOID*" kind of datum has MaxDatumSize set - if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']: + if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']: NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName)) if M.ModuleType in ["PEIM", "PEI_CORE"]: PcdFromModule.Phase = "PEI" @@ -1567,22 +1530,22 @@ class PlatformAutoGen(AutoGen): VpdFile = VpdInfoFile.VpdInfoFile() NeedProcessVpdMapFile = False - for pcd in self.Platform.Pcds.keys(): - if pcd not in self._PlatformPcds.keys(): + for pcd in self.Platform.Pcds: + if pcd not in self._PlatformPcds: self._PlatformPcds[pcd] = self.Platform.Pcds[pcd] for item in self._PlatformPcds: if self._PlatformPcds[item].DatumType and self._PlatformPcds[item].DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: - self._PlatformPcds[item].DatumType = "VOID*" + self._PlatformPcds[item].DatumType = TAB_VOID if (self.Workspace.ArchList[-1] == self.Arch): for Pcd in self._DynamicPcdList: # just pick the a value to determine whether is unicode string type - Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]] + Sku = Pcd.SkuInfoList.values()[0] Sku.VpdOffset = Sku.VpdOffset.strip() if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: - Pcd.DatumType = "VOID*" + Pcd.DatumType = TAB_VOID # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex # if found HII type PCD then insert to right of UnicodeIndex @@ -1612,12 +1575,12 @@ class PlatformAutoGen(AutoGen): PcdKey in VpdPcdDict: Pcd = VpdPcdDict[PcdKey] SkuValueMap = {} - DefaultSku = Pcd.SkuInfoList.get('DEFAULT') + DefaultSku = Pcd.SkuInfoList.get(TAB_DEFAULT) if DefaultSku: PcdValue = DefaultSku.DefaultValue if PcdValue not in SkuValueMap: SkuValueMap[PcdValue] = [] - VpdFile.Add(Pcd, 'DEFAULT',DefaultSku.VpdOffset) + VpdFile.Add(Pcd, TAB_DEFAULT,DefaultSku.VpdOffset) SkuValueMap[PcdValue].append(DefaultSku) for (SkuName,Sku) in Pcd.SkuInfoList.items(): @@ -1665,7 +1628,7 @@ class PlatformAutoGen(AutoGen): if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]: if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''): FoundFlag = False - for VpdPcd in VpdFile._VpdArray.keys(): + for VpdPcd in VpdFile._VpdArray: # This PCD has been referenced by module if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \ (VpdPcd.TokenCName == DscPcdEntry.TokenCName): @@ -1676,9 +1639,9 @@ class PlatformAutoGen(AutoGen): # just pick the a value to determine whether is unicode string type SkuValueMap = {} SkuObjList = DscPcdEntry.SkuInfoList.items() - DefaultSku = DscPcdEntry.SkuInfoList.get('DEFAULT') + DefaultSku = DscPcdEntry.SkuInfoList.get(TAB_DEFAULT) if DefaultSku: - defaultindex = SkuObjList.index(('DEFAULT',DefaultSku)) + defaultindex = SkuObjList.index((TAB_DEFAULT,DefaultSku)) SkuObjList[0],SkuObjList[defaultindex] = SkuObjList[defaultindex],SkuObjList[0] for (SkuName,Sku) in SkuObjList: Sku.VpdOffset = Sku.VpdOffset.strip() @@ -1700,7 +1663,7 @@ class PlatformAutoGen(AutoGen): DscPcdEntry.TokenValue = DecPcdEntry.TokenValue DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName] # Only fix the value while no value provided in DSC file. - if (Sku.DefaultValue == "" or Sku.DefaultValue==None): + if not Sku.DefaultValue: DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue if DscPcdEntry not in self._DynamicPcdList: @@ -1734,7 +1697,7 @@ class PlatformAutoGen(AutoGen): SkuValueMap[PcdValue].append(Sku) if not NeedProcessVpdMapFile and Sku.VpdOffset == "*": NeedProcessVpdMapFile = True - if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"): + if DscPcdEntry.DatumType == TAB_VOID and PcdValue.startswith("L"): UnicodePcdArray.add(DscPcdEntry) elif len(Sku.VariableName) > 0: HiiPcdArray.add(DscPcdEntry) @@ -1777,14 +1740,14 @@ class PlatformAutoGen(AutoGen): # Delete the DynamicPcdList At the last time enter into this function for Pcd in self._DynamicPcdList: # just pick the a value to determine whether is unicode string type - Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]] + Sku = Pcd.SkuInfoList.values()[0] Sku.VpdOffset = Sku.VpdOffset.strip() if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: - Pcd.DatumType = "VOID*" + Pcd.DatumType = TAB_VOID PcdValue = Sku.DefaultValue - if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"): + if Pcd.DatumType == TAB_VOID and PcdValue.startswith("L"): # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex UnicodePcdArray.add(Pcd) elif len(Sku.VariableName) > 0: @@ -1802,7 +1765,7 @@ class PlatformAutoGen(AutoGen): for (SkuName,SkuId) in allskuset: if type(SkuId) in (str,unicode) and eval(SkuId) == 0 or SkuId == 0: continue - pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList['DEFAULT']) + pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList[TAB_DEFAULT]) pcd.SkuInfoList[SkuName].SkuId = SkuId self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList @@ -1938,7 +1901,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"] = "" @@ -1959,9 +1921,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 @@ -2381,17 +2341,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: @@ -2410,7 +2369,7 @@ class PlatformAutoGen(AutoGen): ToPcd.validlists = FromPcd.validlists ToPcd.expressions = FromPcd.expressions - if FromPcd is not None and ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]: + if FromPcd is not None and ToPcd.DatumType == TAB_VOID and ToPcd.MaxDatumSize in ['', None]: EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \ % (ToPcd.TokenSpaceGuidCName, TokenCName)) Value = ToPcd.DefaultValue @@ -2429,7 +2388,7 @@ class PlatformAutoGen(AutoGen): if self.Platform.SkuName in self.Platform.SkuIds: SkuName = self.Platform.SkuName else: - SkuName = 'DEFAULT' + SkuName = TAB_DEFAULT ToPcd.SkuInfoList = { SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue) } @@ -2486,7 +2445,8 @@ class PlatformAutoGen(AutoGen): # use PCD value to calculate the MaxDatumSize when it is not specified for Name, Guid in Pcds: Pcd = Pcds[Name, Guid] - if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]: + if Pcd.DatumType == TAB_VOID and Pcd.MaxDatumSize in ['', None]: + Pcd.MaxSizeUserSet = None Value = Pcd.DefaultValue if Value in [None, '']: Pcd.MaxDatumSize = '1' @@ -2520,7 +2480,7 @@ class PlatformAutoGen(AutoGen): for LibraryName in M.Libraries: Library = self.Platform.LibraryClasses[LibraryName, ':dummy:'] if Library is None: - for Key in self.Platform.LibraryClasses.data.keys(): + for Key in self.Platform.LibraryClasses.data: if LibraryName.upper() == Key.upper(): Library = self.Platform.LibraryClasses[Key, ':dummy:'] break @@ -2717,40 +2677,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 @@ -2828,7 +2779,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) @@ -3152,7 +3103,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename) DepexExpresionList = InfObj.GetDepexExpresionList() for DepexExpresion in DepexExpresionList: - for key in DepexExpresion.keys(): + for key in DepexExpresion: Arch, ModuleType = key DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')] # the type of build module is USER_DEFINED. @@ -3170,7 +3121,7 @@ class ModuleAutoGen(AutoGen): #the type of build module is USER_DEFINED. if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED: for Depex in DepexList: - for key in Depex.keys(): + for key in Depex: DepexStr += '[Depex.%s.%s]\n' % key DepexStr += '\n'.join(['# '+ val for val in Depex[key]]) DepexStr += '\n\n' @@ -3280,7 +3231,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename) TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore() for TianoCoreUserExtent in TianoCoreUserExtenList: - for Section in TianoCoreUserExtent.keys(): + for Section in TianoCoreUserExtent: ItemList = Section.split(TAB_SPLIT) Arch = self.Arch if len(ItemList) == 4: @@ -3467,7 +3418,7 @@ class ModuleAutoGen(AutoGen): if self._BinaryFileList is None: self._BinaryFileList = [] for F in self.Module.Binaries: - if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget: + if F.Target not in [TAB_COMMON, '*'] and F.Target != self.BuildTarget: continue self._BinaryFileList.append(F) self._ApplyBuildRule(F, F.Type) @@ -3504,8 +3455,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): @@ -3542,8 +3493,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 @@ -3561,8 +3510,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: @@ -3581,8 +3528,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: @@ -3822,7 +3769,7 @@ class ModuleAutoGen(AutoGen): if not self.SourceFileList: return [] - NameGuids = [] + NameGuids = set() for SrcFile in self.SourceFileList: if SrcFile.Ext.lower() != '.vfr': continue @@ -3854,7 +3801,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 [] @@ -3929,7 +3876,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) # @@ -3948,7 +3894,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() @@ -3966,11 +3912,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 @@ -4089,8 +4035,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': @@ -4102,8 +4047,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']: @@ -4114,15 +4058,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)): @@ -4171,13 +4113,13 @@ class ModuleAutoGen(AutoGen): elif BoolValue == 'FALSE': Pcd.DefaultValue = '0' - if Pcd.DatumType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']: + if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES: HexFormat = '0x%02x' - if Pcd.DatumType == 'UINT16': + if Pcd.DatumType == TAB_UINT16: HexFormat = '0x%04x' - elif Pcd.DatumType == 'UINT32': + elif Pcd.DatumType == TAB_UINT32: HexFormat = '0x%08x' - elif Pcd.DatumType == 'UINT64': + elif Pcd.DatumType == TAB_UINT64: HexFormat = '0x%016x' PcdValue = HexFormat % int(Pcd.DefaultValue, 0) else: @@ -4206,9 +4148,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(',') + '}' @@ -4216,9 +4161,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 = '' @@ -4228,7 +4176,7 @@ class ModuleAutoGen(AutoGen): PcdItem = PcdComments + '\n ' + PcdItem AsBuiltInfDict['patchablepcd_item'].append(PcdItem) - HiiPcds = [] + HiiPcds = set() for Pcd in Pcds + VfrPcds: PcdComments = '' PcdCommentList = [] @@ -4251,8 +4199,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: