X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=BaseTools%2FSource%2FPython%2FWorkspace%2FDecBuildData.py;h=45beaebc63efe66737f4124a3ce85d80342b4d1d;hb=43fe4c4052922c6baa36cf4664ce63b8699d9176;hp=2266b0b7a623ccd16fd8cb869d6f8e15f3d244ed;hpb=e0db09cd1cd35a1e2ae627e305d903652555aef2;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/Workspace/DecBuildData.py b/BaseTools/Source/Python/Workspace/DecBuildData.py index 2266b0b7a6..45beaebc63 100644 --- a/BaseTools/Source/Python/Workspace/DecBuildData.py +++ b/BaseTools/Source/Python/Workspace/DecBuildData.py @@ -11,10 +11,11 @@ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. # -from Common.String import * +from Common.StringUtils import * from Common.DataType import * from Common.Misc import * from types import * +from collections import OrderedDict from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, PcdClassObject @@ -26,17 +27,17 @@ from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, Pc class DecBuildData(PackageBuildClassObject): # dict used to convert PCD type in database to string used by build tool _PCD_TYPE_STRING_ = { - MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild", - MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule", - MODEL_PCD_FEATURE_FLAG : "FeatureFlag", - MODEL_PCD_DYNAMIC : "Dynamic", - MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic", - MODEL_PCD_DYNAMIC_HII : "DynamicHii", - MODEL_PCD_DYNAMIC_VPD : "DynamicVpd", - MODEL_PCD_DYNAMIC_EX : "DynamicEx", - MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx", - MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii", - MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd", + MODEL_PCD_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD, + MODEL_PCD_PATCHABLE_IN_MODULE : TAB_PCDS_PATCHABLE_IN_MODULE, + MODEL_PCD_FEATURE_FLAG : TAB_PCDS_FEATURE_FLAG, + MODEL_PCD_DYNAMIC : TAB_PCDS_DYNAMIC, + MODEL_PCD_DYNAMIC_DEFAULT : TAB_PCDS_DYNAMIC, + MODEL_PCD_DYNAMIC_HII : TAB_PCDS_DYNAMIC_HII, + MODEL_PCD_DYNAMIC_VPD : TAB_PCDS_DYNAMIC_VPD, + MODEL_PCD_DYNAMIC_EX : TAB_PCDS_DYNAMIC_EX, + MODEL_PCD_DYNAMIC_EX_DEFAULT : TAB_PCDS_DYNAMIC_EX, + MODEL_PCD_DYNAMIC_EX_HII : TAB_PCDS_DYNAMIC_EX_HII, + MODEL_PCD_DYNAMIC_EX_VPD : TAB_PCDS_DYNAMIC_EX_VPD, } # dict used to convert part of [Defines] to members of DecBuildData directly @@ -62,7 +63,7 @@ class DecBuildData(PackageBuildClassObject): # @param Platform (not used for DecBuildData) # @param Macros Macros used for replacement in DSC file # - def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None): + def __init__(self, File, RawData, BuildDataBase, Arch=TAB_ARCH_COMMON, Target=None, Toolchain=None): self.MetaFile = File self._PackageDir = File.Dir self._RawData = RawData @@ -95,6 +96,7 @@ class DecBuildData(PackageBuildClassObject): self._Ppis = None self._Guids = None self._Includes = None + self._CommonIncludes = None self._LibraryClasses = None self._Pcds = None self.__Macros = None @@ -105,7 +107,7 @@ class DecBuildData(PackageBuildClassObject): ## Get current effective macros def _GetMacros(self): - if self.__Macros == None: + if self.__Macros is None: self.__Macros = {} self.__Macros.update(GlobalData.gGlobalDefines) return self.__Macros @@ -114,21 +116,6 @@ class DecBuildData(PackageBuildClassObject): def _GetArch(self): return self._Arch - ## Set architecture - # - # Changing the default ARCH to another may affect all other information - # because all information in a platform may be ARCH-related. That's - # why we need to clear all internal used members, in order to cause all - # information to be re-retrieved. - # - # @param Value The value of ARCH - # - def _SetArch(self, Value): - if self._Arch == Value: - return - self._Arch = Value - self._Clear() - ## Retrieve all information in [Defines] section # # (Retriving all [Defines] information in one-shot is just to save time.) @@ -143,34 +130,34 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve package name def _GetPackageName(self): - if self._PackageName == None: - if self._Header == None: + if self._PackageName is None: + if self._Header is None: self._GetHeaderInfo() - if self._PackageName == None: + if self._PackageName is None: EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.MetaFile) return self._PackageName ## Retrieve file guid def _GetFileGuid(self): - if self._Guid == None: - if self._Header == None: + if self._Guid is None: + if self._Header is None: self._GetHeaderInfo() - if self._Guid == None: + if self._Guid is None: EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.MetaFile) return self._Guid ## Retrieve package version def _GetVersion(self): - if self._Version == None: - if self._Header == None: + if self._Version is None: + if self._Header is None: self._GetHeaderInfo() - if self._Version == None: + if self._Version is None: self._Version = '' return self._Version ## Retrieve protocol definitions (name/value pairs) def _GetProtocol(self): - if self._Protocols == None: + if self._Protocols is None: # # tdict is a special kind of dict, used for selecting correct # protocol defition for given ARCH @@ -197,9 +184,9 @@ class DecBuildData(PackageBuildClassObject): if Name not in NameList: NameList.append(Name) ProtocolDict[Arch, Name] = Guid - # use sdict to keep the order - self._Protocols = sdict() - self._PrivateProtocols = sdict() + # use OrderedDict to keep the order + self._Protocols = OrderedDict() + self._PrivateProtocols = OrderedDict() for Name in NameList: # # limit the ARCH to self._Arch, if no self._Arch found, tdict @@ -212,7 +199,7 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve PPI definitions (name/value pairs) def _GetPpi(self): - if self._Ppis == None: + if self._Ppis is None: # # tdict is a special kind of dict, used for selecting correct # PPI defition for given ARCH @@ -239,9 +226,9 @@ class DecBuildData(PackageBuildClassObject): if Name not in NameList: NameList.append(Name) PpiDict[Arch, Name] = Guid - # use sdict to keep the order - self._Ppis = sdict() - self._PrivatePpis = sdict() + # use OrderedDict to keep the order + self._Ppis = OrderedDict() + self._PrivatePpis = OrderedDict() for Name in NameList: # # limit the ARCH to self._Arch, if no self._Arch found, tdict @@ -254,7 +241,7 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve GUID definitions (name/value pairs) def _GetGuid(self): - if self._Guids == None: + if self._Guids is None: # # tdict is a special kind of dict, used for selecting correct # GUID defition for given ARCH @@ -281,9 +268,9 @@ class DecBuildData(PackageBuildClassObject): if Name not in NameList: NameList.append(Name) GuidDict[Arch, Name] = Guid - # use sdict to keep the order - self._Guids = sdict() - self._PrivateGuids = sdict() + # use OrderedDict to keep the order + self._Guids = OrderedDict() + self._PrivateGuids = OrderedDict() for Name in NameList: # # limit the ARCH to self._Arch, if no self._Arch found, tdict @@ -296,7 +283,8 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve public include paths declared in this package def _GetInclude(self): - if self._Includes == None: + if self._Includes is None or self._CommonIncludes is None: + self._CommonIncludes = [] self._Includes = [] self._PrivateIncludes = [] PublicInclues = [] @@ -324,12 +312,13 @@ class DecBuildData(PackageBuildClassObject): PublicInclues.append(File) if File in self._PrivateIncludes: EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % File, File=self.MetaFile, Line=LineNo) - + if Record[3] == TAB_COMMON: + self._CommonIncludes.append(File) return self._Includes ## Retrieve library class declarations (not used in build at present) def _GetLibraryClass(self): - if self._LibraryClasses == None: + if self._LibraryClasses is None: # # tdict is a special kind of dict, used for selecting correct # library class declaration for given ARCH @@ -346,15 +335,15 @@ class DecBuildData(PackageBuildClassObject): EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) LibraryClassSet.add(LibraryClass) LibraryClassDict[Arch, LibraryClass] = File - self._LibraryClasses = sdict() + self._LibraryClasses = OrderedDict() for LibraryClass in LibraryClassSet: self._LibraryClasses[LibraryClass] = LibraryClassDict[self._Arch, LibraryClass] return self._LibraryClasses ## Retrieve PCD declarations def _GetPcds(self): - if self._Pcds == None: - self._Pcds = sdict() + if self._Pcds is None: + self._Pcds = OrderedDict() self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD)) self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE)) self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG)) @@ -364,17 +353,17 @@ class DecBuildData(PackageBuildClassObject): def ProcessStructurePcd(self, StructurePcdRawDataSet): - s_pcd_set = dict() - for s_pcd,LineNo in StructurePcdRawDataSet: + s_pcd_set = OrderedDict() + for s_pcd, LineNo in StructurePcdRawDataSet: if s_pcd.TokenSpaceGuidCName not in s_pcd_set: s_pcd_set[s_pcd.TokenSpaceGuidCName] = [] - s_pcd_set[s_pcd.TokenSpaceGuidCName].append((s_pcd,LineNo)) + s_pcd_set[s_pcd.TokenSpaceGuidCName].append((s_pcd, LineNo)) str_pcd_set = [] for pcdname in s_pcd_set: dep_pkgs = [] struct_pcd = StructurePcd() - for item,LineNo in s_pcd_set[pcdname]: + for item, LineNo in s_pcd_set[pcdname]: if "" in item.TokenCName: struct_pcd.StructuredPcdIncludeFile.append(item.DefaultValue) elif "" in item.TokenCName: @@ -385,18 +374,17 @@ class DecBuildData(PackageBuildClassObject): struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName = pcdname.split(".") struct_pcd.PcdDefineLineNo = LineNo struct_pcd.PkgPath = self.MetaFile.File + struct_pcd.SetDecDefaultValue(item.DefaultValue) else: - struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue,self.MetaFile.File,LineNo) + struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue, self.MetaFile.File, LineNo) struct_pcd.PackageDecs = dep_pkgs - str_pcd_set.append(struct_pcd) - return str_pcd_set ## Retrieve PCD declarations for given type def _GetPcd(self, Type): - Pcds = sdict() + Pcds = OrderedDict() # # tdict is a special kind of dict, used for selecting correct # PCD declaration for given ARCH @@ -409,7 +397,7 @@ class DecBuildData(PackageBuildClassObject): StrPcdSet = [] RecordList = self._RawData[Type, self._Arch] for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList: - PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting,Dummy2) + PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting, Dummy2) if not (PcdCName, TokenSpaceGuid) in PcdSet: PcdSet.append((PcdCName, TokenSpaceGuid)) @@ -418,16 +406,11 @@ class DecBuildData(PackageBuildClassObject): # limit the ARCH to self._Arch, if no self._Arch found, tdict # will automatically turn to 'common' ARCH and try again # - Setting,LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid] - if Setting == None: + Setting, LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid] + if Setting is None: continue DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting) - if DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: - StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$') - if StructPattern.match(DatumType) == None: - EdkLogger.error('build', FORMAT_INVALID, "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.", File=self.MetaFile, Line=LineNo) - validateranges, validlists, expressions = self._RawData.GetValidExpression(TokenSpaceGuid, PcdCName) PcdObj = PcdClassObject( PcdCName, @@ -444,20 +427,34 @@ class DecBuildData(PackageBuildClassObject): list(validlists), list(expressions) ) + PcdObj.DefinitionPosition = (self.MetaFile.File, LineNo) if "." in TokenSpaceGuid: - StrPcdSet.append((PcdObj,LineNo)) + StrPcdSet.append((PcdObj, LineNo)) else: Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdObj StructurePcds = self.ProcessStructurePcd(StrPcdSet) for pcd in StructurePcds: Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd + StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$') + for pcd in Pcds.values(): + if pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: + if StructPattern.match(pcd.DatumType) is None: + EdkLogger.error('build', FORMAT_INVALID, "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.", pcd.DefinitionPosition[0], pcd.DefinitionPosition[1]) + for struct_pcd in Pcds.values(): + if isinstance(struct_pcd, StructurePcd) and not struct_pcd.StructuredPcdIncludeFile: + EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "The structure Pcd %s.%s header file is not found in %s line %s \n" % (struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName, struct_pcd.DefinitionPosition[0], struct_pcd.DefinitionPosition[1] )) return Pcds + @property + def CommonIncludes(self): + if self._CommonIncludes is None: + self.Includes + return self._CommonIncludes _Macros = property(_GetMacros) - Arch = property(_GetArch, _SetArch) + Arch = property(_GetArch) PackageName = property(_GetPackageName) Guid = property(_GetFileGuid) Version = property(_GetVersion)