def __init__(self): self.Binaries = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} InfSectionCommonDef.__init__(self)
def __init__(self): self.Header = DistributionPackageHeaderObject() # # {(Guid, Version, Path) : PackageObj} # self.PackageSurfaceArea = Sdict() # # {(Guid, Version, Name, Path) : ModuleObj} # self.ModuleSurfaceArea = Sdict() self.Tools = MiscFileObject() self.MiscellaneousFiles = MiscFileObject() self.UserExtensions = [] self.FileList = []
def GenDepex(ModuleObject): # # generate [Depex] section # NewSectionDict = Sdict() Content = '' for Depex in ModuleObject.GetPeiDepex() + ModuleObject.GetDxeDepex( ) + ModuleObject.GetSmmDepex(): HelpTextList = Depex.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) SupArchList = Depex.GetSupArchList() SupModList = Depex.GetModuleType() Expression = Depex.GetDepex() Statement = CommentStr + Expression SupArchList.sort() KeyList = [] if not SupArchList: SupArchList.append(DT.TAB_ARCH_COMMON.lower()) if not SupModList: KeyList = SupArchList else: for ModuleType in SupModList: for Arch in SupArchList: KeyList.append( ConvertArchForInstall(Arch) + '.' + ModuleType) for Key in KeyList: if Key in NewSectionDict: NewSectionDict[Key] = NewSectionDict[Key] + [Statement] else: NewSectionDict[Key] = [Statement] Content += GenSection('Depex', NewSectionDict, False) return Content
def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleList, PackageList): NewDict = Sdict() for Guid, Version, Path in DistPkg.PackageSurfaceArea: PackagePath = Path Package = DistPkg.PackageSurfaceArea[Guid, Version, Path] Logger.Info(ST.MSG_INSTALL_PACKAGE % Package.GetName()) # if Dep.CheckPackageExists(Guid, Version): # Logger.Info(ST.WRN_PACKAGE_EXISTED %(Guid, Version)) if Options.UseGuidedPkgPath: GuidedPkgPath = "%s_%s_%s" % (Package.GetName(), Guid, Version) NewPackagePath = InstallNewPackage(WorkspaceDir, GuidedPkgPath, Options.CustomPath) else: NewPackagePath = InstallNewPackage(WorkspaceDir, PackagePath, Options.CustomPath) InstallPackageContent(PackagePath, NewPackagePath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList, DistPkg.Header.ReadOnly) PackageList.append(Package) NewDict[Guid, Version, Package.GetPackagePath()] = Package # # Now generate meta-data files, first generate all dec for package # dec should be generated before inf, and inf should be generated after # all packages installed, else hard to resolve modules' package # dependency (Hard to get the location of the newly installed package) # for Package in PackageList: FilePath = PackageToDec(Package, DistPkg.Header) Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) return NewDict
def GenGuidSections(GuidObjList): # # generate [Guids] section # Content = '' GuidDict = Sdict() for Guid in GuidObjList: HelpTextList = Guid.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Guid.GetCName() FFE = Guid.GetFeatureFlag() Statement = CName if FFE: Statement += '|' + FFE Usage = Guid.GetUsage() GuidType = Guid.GetGuidTypeList()[0] VariableName = Guid.GetVariableName() # # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first # if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: Comment = '## ' + Usage + Comment elif GuidType == 'Variable': Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment else: Comment = '## ' + Usage + ' ## ' + GuidType + Comment if Comment: Comment += '\n' # # merge duplicate items # ArchList = Guid.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment = GuidDict[Statement, SortedArch] Comment = PreviousComment + Comment GuidDict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID') # # generate the section contents # if NewSectionDict: Content = GenSection('Guids', NewSectionDict) return Content
def __init__(self): IdentificationObject.__init__(self) CommonHeaderObject.__init__(self) # # LibraryClassObject # self.LibraryClassList = [] # # FileObject # self.IncludePathList = [] # # StandardIncludeFileObject # self.StandardIncludeFileList = [] # # PackageIncludeFileObject # self.PackageIncludeFileList = [] # # Include and Arch List, item is (IncludePath, SupArchList-List of Arch), used during install package # self.IncludeArchList = [] # # ProtocolObject # self.ProtocolList = [] # # PpiObject # self.PpiList = [] # # GuidObject # self.GuidList = [] # # (PcdObject, PcdErrorObject) # self.PcdList = [] # # UserExtensionObject # self.UserExtensionList = [] # # MiscFileObject # self.MiscFileList = [] self.ModuleDict = Sdict() # # ClonedRecordObject # self.ClonedFromList = [] # # string object # self.ModuleFileList = [] self.PcdChecks = []
def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList): # # ModulePathList will keep track of the standalone module path that # we just installed. If a new module's path in that list # (only multiple INF in one directory will be so), we will # install them directly. If not, we will try to create a new directory # for it. # ModulePathList = [] # # Check module exist and install # Module = None NewDict = Sdict() for Guid, Version, Name, Path in DistPkg.ModuleSurfaceArea: ModulePath = Path Module = DistPkg.ModuleSurfaceArea[Guid, Version, Name, Path] Logger.Info(ST.MSG_INSTALL_MODULE % Module.GetName()) if Dep.CheckModuleExists(Guid, Version, Name, Path): Logger.Quiet(ST.WRN_MODULE_EXISTED %Path) # # here check for the multiple inf share the same module path cases: # they should be installed into the same directory # ModuleFullPath = \ os.path.normpath(os.path.join(WorkspaceDir, ModulePath)) if ModuleFullPath not in ModulePathList: NewModulePath = InstallNewModule(WorkspaceDir, ModulePath, ModulePathList) NewModuleFullPath = os.path.normpath(os.path.join(WorkspaceDir, NewModulePath)) ModulePathList.append(NewModuleFullPath) else: NewModulePath = ModulePath InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None, DistPkg.Header.ReadOnly) # # Update module # Module.SetModulePath(Module.GetModulePath().replace(Path, NewModulePath, 1)) NewDict[Guid, Version, Name, Module.GetModulePath()] = Module # # generate all inf for modules # for (Module, Package) in ModuleList: FilePath = ModuleToInf(Module) Md5Sigature = md5.new(open(str(FilePath), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if Package: if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) else: if (FilePath, Md5Sum) not in Module.FileList: Module.FileList.append((FilePath, Md5Sum)) return NewDict
def GenProtocolPPiSections(ObjList, IsProtocol): Content = '' Dict = Sdict() for Object in ObjList: HelpTextList = Object.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Object.GetCName() FFE = Object.GetFeatureFlag() Statement = CName if FFE: Statement += '|' + FFE Usage = Object.GetUsage() Notify = Object.GetNotify() # # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together # if Usage == DT.ITEM_UNDEFINED and Notify == '': # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '': Comment = '' else: if Notify: Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment else: Comment = '## ' + Usage + Comment if Comment: Comment += '\n' # # merge duplicate items # ArchList = Object.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL') # # generate the section contents # if NewSectionDict: if IsProtocol: Content = GenSection('Protocols', NewSectionDict) else: Content = GenSection('Ppis', NewSectionDict) return Content
def __init__(self, PkgFullName): _DecComments.__init__(self) # # Key is combined with (Arch, SectionType) # Default is common # self.ValueDict = Sdict() self._PkgFullName = PkgFullName self._PackagePath, self._FileName = os.path.split(PkgFullName) self._SecName = ''
def GenPackages(ModuleObject): Content = '' # # generate [Packages] section # NewSectionDict = Sdict() WorkspaceDir = getenv('WORKSPACE') for PackageDependency in ModuleObject.GetPackageDependencyList(): # # Generate generic comment # CommentStr = '' HelpText = PackageDependency.GetHelpText() if HelpText: HelpStr = HelpText.GetString() CommentStr = GenGenericCommentF(HelpStr) Statement = CommentStr Guid = PackageDependency.GetGuid() Version = PackageDependency.GetVersion() FFE = PackageDependency.GetFeatureFlag() # # find package path/name # for PkgInfo in GlobalData.gWSPKG_LIST: if Guid == PkgInfo[1]: if (not Version) or (Version == PkgInfo[2]): Path = PkgInfo[3] break # # get relative path # RelaPath = Path[Path.upper().find(WorkspaceDir.upper()) + len(WorkspaceDir) + 1:] Statement += RelaPath.replace('\\', '/') if FFE: Statement += '|' + FFE ArchList = PackageDependency.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [ Statement ] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Packages', NewSectionDict) return Content
class InfSpecialCommentObject(InfSectionCommonDef): def __init__(self): self.SpecialComments = Sdict() InfSectionCommonDef.__init__(self) def SetSpecialComments(self, SepcialSectionList = None, Type = ''): if Type == DT.TYPE_HOB_SECTION or \ Type == DT.TYPE_EVENT_SECTION or \ Type == DT.TYPE_BOOTMODE_SECTION: for Item in SepcialSectionList: if self.SpecialComments.has_key(Type): ObjList = self.SpecialComments[Type] ObjList.append(Item) self.SpecialComments[Type] = ObjList else: ObjList = [] ObjList.append(Item) self.SpecialComments[Type] = ObjList return True def GetSpecialComments(self): return self.SpecialComments
class InfSpecialCommentObject(InfSectionCommonDef): def __init__(self): self.SpecialComments = Sdict() InfSectionCommonDef.__init__(self) def SetSpecialComments(self, SepcialSectionList=None, Type=''): if Type == DT.TYPE_HOB_SECTION or \ Type == DT.TYPE_EVENT_SECTION or \ Type == DT.TYPE_BOOTMODE_SECTION: for Item in SepcialSectionList: if self.SpecialComments.has_key(Type): ObjList = self.SpecialComments[Type] ObjList.append(Item) self.SpecialComments[Type] = ObjList else: ObjList = [] ObjList.append(Item) self.SpecialComments[Type] = ObjList return True def GetSpecialComments(self): return self.SpecialComments
class InfSourcesObject(InfSectionCommonDef): def __init__(self): self.Sources = Sdict() InfSectionCommonDef.__init__(self) def SetSources(self, SourceList, Arch=None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in SourceList: ItemObj = InfSourcesItemObject() CurrentLineOfItem = Item[2] Item = Item[0] ItemObj = GenSourceInstance(Item, CurrentLineOfItem, ItemObj) ItemObj.SetSupArchList(__SupArchList) if self.Sources.has_key((ItemObj)): SourceContent = self.Sources[ItemObj] SourceContent.append(ItemObj) self.Sources[ItemObj] = SourceContent else: SourceContent = [] SourceContent.append(ItemObj) self.Sources[ItemObj] = SourceContent return True def GetSources(self): return self.Sources
class InfSourcesObject(InfSectionCommonDef): def __init__(self): self.Sources = Sdict() InfSectionCommonDef.__init__(self) def SetSources(self, SourceList, Arch = None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in SourceList: ItemObj = InfSourcesItemObject() CurrentLineOfItem = Item[2] Item = Item[0] ItemObj = GenSourceInstance(Item, CurrentLineOfItem, ItemObj) ItemObj.SetSupArchList(__SupArchList) if self.Sources.has_key((ItemObj)): SourceContent = self.Sources[ItemObj] SourceContent.append(ItemObj) self.Sources[ItemObj] = SourceContent else: SourceContent = [] SourceContent.append(ItemObj) self.Sources[ItemObj] = SourceContent return True def GetSources(self): return self.Sources
class InfBinariesObject(InfSectionCommonDef): def __init__(self): self.Binaries = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} InfSectionCommonDef.__init__(self) ## CheckVer # # def CheckVer(self, Ver, __SupArchList): # # Check Ver # for VerItem in Ver: IsValidFileFlag = False VerContent = VerItem[0] VerComment = VerItem[1] VerCurrentLine = VerItem[2] GlobalData.gINF_CURRENT_LINE = VerCurrentLine InfBianryVerItemObj = None # # Should not less than 2 elements # if len(VerContent) < 2: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (VerContent[0], 2), File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) return False if len(VerContent) > 4: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (VerContent[0], 4), File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) return False if len(VerContent) >= 2: # # Create a Ver Object. # InfBianryVerItemObj = InfBianryVerItem() if VerContent[0] != DT.BINARY_FILE_TYPE_VER: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_VER_TYPE % DT.BINARY_FILE_TYPE_VER, File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) InfBianryVerItemObj.SetVerTypeName(VerContent[0]) InfBianryVerItemObj.SetType(VerContent[0]) # # Verify File exist or not # FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR, VerContent[1]))) if not (ValidFile(FullFileName) or ValidFile(VerContent[1])): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (VerContent[1]), File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) # # Validate file exist/format. # if IsValidPath(VerContent[1], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (VerContent[1]), File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) return False if IsValidFileFlag: VerContent[0] = ConvPathFromAbsToRel(VerContent[0], GlobalData.gINF_MODULE_DIR) InfBianryVerItemObj.SetFileName(VerContent[1]) if len(VerContent) >= 3: # # Add Target information # InfBianryVerItemObj.SetTarget(VerContent[2]) if len(VerContent) == 4: if VerContent[3].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(VerContent[3].\ strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=VerCurrentLine.GetFileName(), Line=VerCurrentLine.GetLineNo(), ExtraData=VerCurrentLine.GetLineString()) InfBianryVerItemObj.SetFeatureFlagExp(VerContent[3]) InfBianryVerItemObj.SetSupArchList(__SupArchList) # # Determine binary file name duplicate. Follow below rule: # # A binary filename must not be duplicated within # a [Binaries] section. A binary filename may appear in # multiple architectural [Binaries] sections. A binary # filename listed in an architectural [Binaries] section # must not be listed in the common architectural # [Binaries] section. # # NOTE: This check will not report error now. # for Item in self.Binaries: if Item.GetFileName() == InfBianryVerItemObj.GetFileName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for VerItemObjArch in __SupArchList: if ItemArch == VerItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or VerItemObjArch.upper() == 'COMMON': # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if InfBianryVerItemObj is not None: if self.Binaries.has_key((InfBianryVerItemObj)): BinariesList = self.Binaries[InfBianryVerItemObj] BinariesList.append((InfBianryVerItemObj, VerComment)) self.Binaries[InfBianryVerItemObj] = BinariesList else: BinariesList = [] BinariesList.append((InfBianryVerItemObj, VerComment)) self.Binaries[InfBianryVerItemObj] = BinariesList ## ParseCommonBinary # # ParseCommonBinary # def ParseCommonBinary(self, CommonBinary, __SupArchList): # # Check common binary definitions # Type | FileName | Target | Family | TagName | FeatureFlagExp # for Item in CommonBinary: IsValidFileFlag = False ItemContent = Item[0] ItemComment = Item[1] CurrentLineOfItem = Item[2] GlobalData.gINF_CURRENT_LINE = CurrentLineOfItem InfBianryCommonItemObj = None if ItemContent[0] == 'SUBTYPE_GUID': if len(ItemContent) < 3: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (ItemContent[0], 3), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) return False else: if len(ItemContent) < 2: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (ItemContent[0], 2), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) return False if len(ItemContent) > 7: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (ItemContent[0], 7), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) return False if len(ItemContent) >= 2: # # Create a Common Object. # InfBianryCommonItemObj = InfBianryCommonItem() # # Convert Binary type. # BinaryFileType = ItemContent[0].strip() if BinaryFileType == 'RAW' or BinaryFileType == 'ACPI' or BinaryFileType == 'ASL': BinaryFileType = 'BIN' if BinaryFileType not in DT.BINARY_FILE_TYPE_LIST: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \ (DT.BINARY_FILE_TYPE_LIST.__str__()), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) if BinaryFileType == 'SUBTYPE_GUID': BinaryFileType = 'FREEFORM' if BinaryFileType == 'LIB' or BinaryFileType == 'UEFI_APP': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \ (DT.BINARY_FILE_TYPE_LIST.__str__()), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) InfBianryCommonItemObj.SetType(BinaryFileType) InfBianryCommonItemObj.SetCommonType(ItemContent[0]) FileName = '' if BinaryFileType == 'FREEFORM': InfBianryCommonItemObj.SetGuidValue(ItemContent[1]) if len(ItemContent) >= 3: FileName = ItemContent[2] else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FILENAME_NOT_EXIST, File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) else: FileName = ItemContent[1] # # Verify File exist or not # FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR, FileName))) if not (ValidFile(FullFileName) or ValidFile(FileName)): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (FileName), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) # # Validate file exist/format. # if IsValidPath(FileName, GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (FileName), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) return False if IsValidFileFlag: ItemContent[0] = ConvPathFromAbsToRel(ItemContent[0], GlobalData.gINF_MODULE_DIR) InfBianryCommonItemObj.SetFileName(FileName) if len(ItemContent) >= 3: # # Add Target information # if BinaryFileType != 'FREEFORM': InfBianryCommonItemObj.SetTarget(ItemContent[2]) if len(ItemContent) >= 4: # # Add Family information # if BinaryFileType != 'FREEFORM': InfBianryCommonItemObj.SetFamily(ItemContent[3]) else: InfBianryCommonItemObj.SetTarget(ItemContent[3]) if len(ItemContent) >= 5: # # TagName entries are build system specific. If there # is content in the entry, the tool must exit # gracefully with an error message that indicates build # system specific content cannot be distributed using # the UDP # if BinaryFileType != 'FREEFORM': if ItemContent[4].strip() != '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (ItemContent[4]), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) else: InfBianryCommonItemObj.SetFamily(ItemContent[4]) if len(ItemContent) >= 6: # # Add FeatureFlagExp # if BinaryFileType != 'FREEFORM': if ItemContent[5].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[5].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[5]) else: if ItemContent[5].strip() != '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (ItemContent[5]), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) if len(ItemContent) == 7: if ItemContent[6].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[6].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem.GetFileName(), Line=CurrentLineOfItem.GetLineNo(), ExtraData=CurrentLineOfItem.GetLineString()) InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[6]) InfBianryCommonItemObj.SetSupArchList(__SupArchList) # # Determine binary file name duplicate. Follow below rule: # # A binary filename must not be duplicated within # a [Binaries] section. A binary filename may appear in # multiple architectural [Binaries] sections. A binary # filename listed in an architectural [Binaries] section # must not be listed in the common architectural # [Binaries] section. # # NOTE: This check will not report error now. # # for Item in self.Binaries: # if Item.GetFileName() == InfBianryCommonItemObj.GetFileName(): # ItemSupArchList = Item.GetSupArchList() # for ItemArch in ItemSupArchList: # for ComItemObjArch in __SupArchList: # if ItemArch == ComItemObjArch: # # # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # # # pass # # if ItemArch.upper() == 'COMMON' or ComItemObjArch.upper() == 'COMMON': # # # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # # # pass if InfBianryCommonItemObj is not None: if self.Binaries.has_key((InfBianryCommonItemObj)): BinariesList = self.Binaries[InfBianryCommonItemObj] BinariesList.append((InfBianryCommonItemObj, ItemComment)) self.Binaries[InfBianryCommonItemObj] = BinariesList else: BinariesList = [] BinariesList.append((InfBianryCommonItemObj, ItemComment)) self.Binaries[InfBianryCommonItemObj] = BinariesList def SetBinary(self, UiInf=None, Ver=None, CommonBinary=None, ArchList=None): __SupArchList = [] for ArchItem in ArchList: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) if UiInf is not None: if len(UiInf) > 0: # # Check UI # for UiItem in UiInf: IsValidFileFlag = False InfBianryUiItemObj = None UiContent = UiItem[0] UiComment = UiItem[1] UiCurrentLine = UiItem[2] GlobalData.gINF_CURRENT_LINE = deepcopy(UiItem[2]) # # Should not less than 2 elements # if len(UiContent) < 2: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (UiContent[0], 2), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) return False if len(UiContent) > 4: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (UiContent[0], 4), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) return False if len(UiContent) >= 2: # # Create an Ui Object. # InfBianryUiItemObj = InfBianryUiItem() if UiContent[0] != 'UI': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_VER_TYPE % ('UI'), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) InfBianryUiItemObj.SetUiTypeName(UiContent[0]) InfBianryUiItemObj.SetType(UiContent[0]) # # Verify File exist or not # FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR, UiContent[1]))) if not (ValidFile(FullFileName) or ValidFile(UiContent[1])): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (UiContent[1]), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) # # Validate file exist/format. # if IsValidPath(UiContent[1], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (UiContent[1]), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) return False if IsValidFileFlag: UiContent[0] = ConvPathFromAbsToRel(UiContent[0], GlobalData.gINF_MODULE_DIR) InfBianryUiItemObj.SetFileName(UiContent[1]) if len(UiContent) >= 3: # # Add Target information # InfBianryUiItemObj.SetTarget(UiContent[2]) if len(UiContent) == 4: if UiContent[3].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(UiContent[3].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=UiCurrentLine.GetFileName(), Line=UiCurrentLine.GetLineNo(), ExtraData=UiCurrentLine.GetLineString()) InfBianryUiItemObj.SetFeatureFlagExp(UiContent[3]) InfBianryUiItemObj.SetSupArchList(__SupArchList) # # Determine binary file name duplicate. Follow below rule: # # A binary filename must not be duplicated within # a [Binaries] section. A binary filename may appear in # multiple architectural [Binaries] sections. A binary # filename listed in an architectural [Binaries] section # must not be listed in the common architectural # [Binaries] section. # # NOTE: This check will not report error now. # # for Item in self.Binaries: # if Item.GetFileName() == InfBianryUiItemObj.GetFileName(): # ItemSupArchList = Item.GetSupArchList() # for ItemArch in ItemSupArchList: # for UiItemObjArch in __SupArchList: # if ItemArch == UiItemObjArch: # # # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # # # pass # if ItemArch.upper() == 'COMMON' or UiItemObjArch.upper() == 'COMMON': # # # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # # # pass if InfBianryUiItemObj is not None: if self.Binaries.has_key((InfBianryUiItemObj)): BinariesList = self.Binaries[InfBianryUiItemObj] BinariesList.append((InfBianryUiItemObj, UiComment)) self.Binaries[InfBianryUiItemObj] = BinariesList else: BinariesList = [] BinariesList.append((InfBianryUiItemObj, UiComment)) self.Binaries[InfBianryUiItemObj] = BinariesList if Ver is not None and len(Ver) > 0: self.CheckVer(Ver, __SupArchList) if CommonBinary and len(CommonBinary) > 0: self.ParseCommonBinary(CommonBinary, __SupArchList) return True def GetBinary(self): return self.Binaries
def __init__(self): self.Defines = Sdict() InfSectionCommonDef.__init__(self)
def __init__(self): self.Protocols = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {}
def __init__(self): self.Guids = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {}
class InfProtocolObject(): def __init__(self): self.Protocols = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetProtocol( self, ProtocolContent, Arch=None, ): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in ProtocolContent: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1], CurrentLineOfItem[0]) Item = Item[0] InfProtocolItemObj = InfProtocolItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]), LineInfo=LineInfo) if (Item[0] != ''): InfProtocolItemObj.SetName(Item[0]) else: ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING, LineInfo=LineInfo) if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" # <FeatureFlagExpress>] # For Protocol Object # if Item[1].strip() == '': ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, LineInfo=LineInfo) # # Validate Feature Flag Express for Item[1] # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: ErrorInInf( ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), LineInfo=LineInfo) InfProtocolItemObj.SetFeatureFlagExp(Item[1]) if len(Item) < 1 or len(Item) > 2: # # Invalid format of Protocols statement # ErrorInInf( ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, LineInfo=LineInfo) # # Get/Set Usage and HelpString for Protocol entry # if CommentsList != None and len(CommentsList) != 0: InfProtocolItemObj = ParseProtocolComment( CommentsList, InfProtocolItemObj) else: CommentItemIns = InfProtocolItemCommentContent() CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfProtocolItemObj.SetCommentList([CommentItemIns]) InfProtocolItemObj.SetSupArchList(__SupArchList) # # Determine protocol name duplicate. Follow below rule: # # A protocol must not be duplicated within a [Protocols] section. # A protocol may appear in multiple architectural [Protocols] # sections. A protocol listed in an architectural [Protocols] # section must not be listed in the common architectural # [Protocols] section. # # NOTE: This check will not report error now. # for Item in self.Protocols: if Item.GetName() == InfProtocolItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for ProtocolItemObjArch in __SupArchList: if ItemArch == ProtocolItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or ProtocolItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Protocols.has_key((InfProtocolItemObj)): ProcotolList = self.Protocols[InfProtocolItemObj] ProcotolList.append(InfProtocolItemObj) self.Protocols[InfProtocolItemObj] = ProcotolList else: ProcotolList = [] ProcotolList.append(InfProtocolItemObj) self.Protocols[InfProtocolItemObj] = ProcotolList return True def GetProtocol(self): return self.Protocols
def __init__(self, FileName): self.Pcds = Sdict() self.FileName = FileName
def ValidatePS1(Package): # # Check DistributionPackage -> PackageSurfaceArea -> Header # XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'Header'] CheckDict = Sdict() CheckDict['Name'] = Package.GetName() CheckDict['BaseName'] = Package.GetBaseName() CheckDict['GUID'] = Package.GetGuid() CheckDict['Version'] = Package.GetVersion() CheckDict['PackagePath'] = Package.GetPackagePath() IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not IsValidInstallPath(Package.GetPackagePath()): Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Package.GetPackagePath()) # # Check DistributionPackage -> PackageSurfaceArea -> ClonedFrom # XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ClonedFrom'] for Item in Package.GetClonedFromList(): if Item is None: CheckDict = Sdict() CheckDict['GUID'] = '' IsRequiredItemListNull(CheckDict, XmlTreeLevel) CheckDict = Sdict() CheckDict['GUID'] = Item.GetPackageGuid() CheckDict['Version'] = Item.GetPackageVersion() IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> LibraryClassDeclarations -> LibraryClass # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations' ] for Item in Package.GetLibraryClassList(): if Item is None: CheckDict = {'LibraryClass': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations', 'LibraryClass' ] for Item in Package.GetLibraryClassList(): CheckDict = { 'Keyword': Item.GetLibraryClass(), 'HeaderFile': Item.GetIncludeHeader() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> IndustryStandardIncludes -> IndustryStandardHeader # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes' ] for Item in Package.GetStandardIncludeFileList(): if Item is None: CheckDict = {'IndustryStandardHeader': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes', 'IndustryStandardHeader' ] for Item in Package.GetStandardIncludeFileList(): CheckDict = {'HeaderFile': Item.GetFilePath()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> PackageIncludes -> PackageHeader # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes' ] for Item in Package.GetPackageIncludeFileList(): if Item is None: CheckDict = {'PackageHeader': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes', 'PackageHeader' ] for Item in Package.GetPackageIncludeFileList(): CheckDict = {'HeaderFile': Item.GetFilePath()} IsRequiredItemListNull(CheckDict, XmlTreeLevel)
def __init__(self): self.Sources = Sdict() InfSectionCommonDef.__init__(self)
class InfPpiObject(): def __init__(self): self.Ppis = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetPpi(self, PpiList, Arch = None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in PpiList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfPpiItemObj = InfPpiItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfPpiItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Have FeatureFlag information # if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # Item[1] should not be empty # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express for PPI entry # Item[1] contain FFE information # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfPpiItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of Ppi statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Get/Set Usage and HelpString for PPI entry # if CommentsList is not None and len(CommentsList) != 0: InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj) else: CommentItemIns = InfPpiItemCommentContent() CommentItemIns.SetUsage(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfPpiItemObj.SetCommentList([CommentItemIns]) InfPpiItemObj.SetSupArchList(__SupArchList) # # Determine PPI name duplicate. Follow below rule: # # A PPI must not be duplicated within a [Ppis] section. # A PPI may appear in multiple architectural [Ppis] # sections. A PPI listed in an architectural [Ppis] # section must not be listed in the common architectural # [Ppis] section. # # NOTE: This check will not report error now. # for Item in self.Ppis: if Item.GetName() == InfPpiItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PpiItemObjArch in __SupArchList: if ItemArch == PpiItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or PpiItemObjArch.upper() == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Ppis.has_key((InfPpiItemObj)): PpiList = self.Ppis[InfPpiItemObj] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList else: PpiList = [] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList return True def GetPpi(self): return self.Ppis
def ValidateMS2(Module, TopXmlTreeLevel): # # Check Header # XmlTreeLevel = TopXmlTreeLevel + ['Header'] CheckDict = Sdict() CheckDict['Name'] = Module.GetName() CheckDict['BaseName'] = Module.GetBaseName() CheckDict['GUID'] = Module.GetGuid() CheckDict['Version'] = Module.GetVersion() IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] CheckDict = { 'ModuleType': Module.GetModuleType(), 'Path': Module.GetModulePath() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not IsValidInstallPath(Module.GetModulePath()): Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Module.GetModulePath()) # # Check ModuleProperties->BootMode # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['BootMode'] for Item in Module.GetBootModeList(): CheckDict = { 'Usage': Item.GetUsage(), 'SupportedBootModes': Item.GetSupportedBootModes() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties->Event # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['Event'] for Item in Module.GetEventList(): CheckDict = { 'Usage': Item.GetUsage(), 'EventType': Item.GetEventType() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties->Hob # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['HOB'] for Item in Module.GetHobList(): CheckDict = {'Usage': Item.GetUsage(), 'HobType': Item.GetHobType()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # The UDP Specification supports the module type of UEFI_RUNTIME_DRIVER, which is not present in the EDK II INF # File Specification v. 1.23, so UPT must perform the following translation that include the generation of a # [Depex] section. # if Module.ModuleType == "UEFI_RUNTIME_DRIVER": Module.ModuleType = "DXE_RUNTIME_DRIVER" DxeObj = DepexObject() DxeObj.SetDepex("gEfiBdsArchProtocolGuid AND \ngEfiCpuArchProtocolGuid AND\n" + \ "gEfiMetronomeArchProtocolGuid AND \ngEfiMonotonicCounterArchProtocolGuid AND\n" + \ "gEfiRealTimeClockArchProtocolGuid AND \ngEfiResetArchProtocolGuid AND\n" + \ "gEfiRuntimeArchProtocolGuid AND \ngEfiSecurityArchProtocolGuid AND\n" + \ "gEfiTimerArchProtocolGuid AND \ngEfiVariableWriteArchProtocolGuid AND\n" + \ "gEfiVariableArchProtocolGuid AND \ngEfiWatchdogTimerArchProtocolGuid") DxeObj.SetModuleType(['DXE_RUNTIME_DRIVER']) Module.PeiDepex = [] Module.DxeDepex = [] Module.SmmDepex = [] Module.DxeDepex.append(DxeObj) # # Check LibraryClassDefinitions -> LibraryClass # XmlTreeLevel = TopXmlTreeLevel + ['LibraryClassDefinitions'] for Item in Module.GetLibraryClassList(): if Item is None: CheckDict = {'LibraryClass': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = TopXmlTreeLevel + [ 'LibraryClassDefinitions', 'LibraryClass' ] IsLibraryModule = False LibrarySupModList = [] for Item in Module.GetLibraryClassList(): CheckDict = { 'Keyword': Item.GetLibraryClass(), 'Usage': Item.GetUsage() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # If the LibraryClass:SupModList is not "UNDEFINED" the LIBRARY_CLASS entry must have the list # appended using the format: # LIBRARY_CLASS = <ClassName> ["|" <Edk2ModuleTypeList>] # # Edk2ModuleTypeList ::= <ModuleType> [" " <ModuleType>]{0,} # <ModuleTypes> ::= {"BASE"} {"SEC"} {"PEI_CORE"} {"PEIM"} # {"DXE_CORE"} {"DXE_DRIVER"} {"SMM_CORE"} # {"DXE_SMM_DRIVER"} {"DXE_RUNTIME_DRIVER"} # {"DXE_SAL_DRIVER"} {"UEFI_DRIVER"} # {"UEFI_APPLICATION"} {"USER_DEFINED"} # if len(Item.SupModuleList) > 0: for SupModule in Item.SupModuleList: if not IsValidInfMoudleType(SupModule): Logger.Error('\nUPT', PARSER_ERROR, ERR_XML_INVALID_LIB_SUPMODLIST % (Item.LibraryClass, str(SupModule)), RaiseError=True) if Item.Usage == 'PRODUCES' or Item.Usage == 'SOMETIMES_PRODUCES': IsLibraryModule = True LibrarySupModList = Item.SupModuleList # # For Library modules (indicated by a LIBRARY_CLASS statement in the [Defines] section) # If the SupModList attribute of the CONSTRUCTOR or DESTRUCTOR element does not match the Supported Module # Types listed after "LIBRARY_CLASS = <Keyword> |", the tool should gracefully exit with an error message # stating that there is a conflict in the module types the CONSTRUCTOR/DESTRUCTOR is to be used with and # the Module types this Library supports. # if IsLibraryModule: for Item in Module.GetExternList(): if Item.Constructor or Item.Destructor: if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \ not IsEqualList(Item.SupModList, LibrarySupModList): Logger.Error( '\nUPT', PARSER_ERROR, ERR_XML_INVALID_EXTERN_SUPMODLIST % (str(Item.SupModList), str(LibrarySupModList)), RaiseError=True) # # If the module is not a library module, the MODULE_TYPE listed in the ModuleSurfaceArea.Header must match the # SupModList attribute. If these conditions cannot be met, the tool must exit gracefully, informing the user # that the EDK II Build system does not currently support the features required by this Module. # if not IsLibraryModule: for Item in Module.GetExternList(): if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \ not IsEqualList(Item.SupModList, [Module.ModuleType]): Logger.Error('\nUPT', PARSER_ERROR, ERR_XML_INVALID_EXTERN_SUPMODLIST_NOT_LIB % (str(Module.ModuleType), str(Item.SupModList)), RaiseError=True) # # Check SourceFiles # XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles'] for Item in Module.GetSourceFileList(): if Item is None: CheckDict = {'Filename': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles'] for Item in Module.GetSourceFileList(): CheckDict = {'Filename': Item.GetSourceFile()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) for ItemCount in range(len(Module.GetBinaryFileList())): Item = Module.GetBinaryFileList()[ItemCount] if Item and len(Item.FileNamList ) > 0 and Item.FileNamList[0].FileType == 'FREEFORM': Item.FileNamList[0].FileType = 'SUBTYPE_GUID' Module.GetBinaryFileList()[ItemCount] = Item
def ValidateDistributionPackage(self): XmlTreeLevel = ['DistributionPackage'] if self.DistP: # # Check DistributionPackage -> DistributionHeader # XmlTreeLevel = ['DistributionPackage', ''] CheckDict = {'DistributionHeader': self.DistP.Header} IsRequiredItemListNull(CheckDict, XmlTreeLevel) if self.DistP.Header: DpHeader = self.DistP.Header XmlTreeLevel = ['DistributionPackage', 'DistributionHeader'] CheckDict = Sdict() if DpHeader.GetAbstract(): DPAbstract = DpHeader.GetAbstract()[0][1] else: DPAbstract = '' if DpHeader.GetCopyright(): DPCopyright = DpHeader.GetCopyright()[0][1] else: DPCopyright = '' if DpHeader.GetLicense(): DPLicense = DpHeader.GetLicense()[0][1] else: DPLicense = '' CheckDict['Name'] = DpHeader.GetName() CheckDict['GUID'] = DpHeader.GetGuid() CheckDict['Version'] = DpHeader.GetVersion() CheckDict['Copyright'] = DPCopyright CheckDict['License'] = DPLicense CheckDict['Abstract'] = DPAbstract CheckDict['Vendor'] = DpHeader.GetVendor() CheckDict['Date'] = DpHeader.GetDate() CheckDict['XmlSpecification'] = DpHeader.GetXmlSpecification() IsRequiredItemListNull(CheckDict, XmlTreeLevel) else: XmlTreeLevel = ['DistributionPackage', 'DistributionHeader'] CheckDict = CheckDict = { 'DistributionHeader': '', } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check Each Package # for Key in self.DistP.PackageSurfaceArea: ValidatePackageSurfaceArea(self.DistP.PackageSurfaceArea[Key]) # # Check Each Module # for Key in self.DistP.ModuleSurfaceArea: ValidateMS(self.DistP.ModuleSurfaceArea[Key], ['DistributionPackage', 'ModuleSurfaceArea']) # # Check Each Tool # if self.DistP.Tools: XmlTreeLevel = ['DistributionPackage', 'Tools', 'Header'] CheckDict = { 'Name': self.DistP.Tools.GetName(), } IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not self.DistP.Tools.GetFileList(): XmlTreeLevel = ['DistributionPackage', 'Tools'] CheckDict = { 'FileName': None, } IsRequiredItemListNull(CheckDict, XmlTreeLevel) for Item in self.DistP.Tools.GetFileList(): XmlTreeLevel = ['DistributionPackage', 'Tools'] CheckDict = { 'FileName': Item.GetURI(), } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check Each Misc File # if self.DistP.MiscellaneousFiles: XmlTreeLevel = [ 'DistributionPackage', 'MiscellaneousFiles', 'Header' ] CheckDict = { 'Name': self.DistP.MiscellaneousFiles.GetName(), } IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not self.DistP.MiscellaneousFiles.GetFileList(): XmlTreeLevel = [ 'DistributionPackage', 'MiscellaneousFiles' ] CheckDict = { 'FileName': None, } IsRequiredItemListNull(CheckDict, XmlTreeLevel) for Item in self.DistP.MiscellaneousFiles.GetFileList(): XmlTreeLevel = [ 'DistributionPackage', 'MiscellaneousFiles' ] CheckDict = { 'FileName': Item.GetURI(), } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check Each Distribution Level User Extension # for Item in self.DistP.UserExtensions: XmlTreeLevel = ['DistributionPackage', 'UserExtensions'] CheckDict = { 'UserId': Item.GetUserID(), } IsRequiredItemListNull(CheckDict, XmlTreeLevel)
def __init__(self): self.SpecialComments = Sdict() InfSectionCommonDef.__init__(self)
class InfPcdObject(): def __init__(self, FileName): self.Pcds = Sdict() self.FileName = FileName def SetPcds(self, PcdContent, KeysList=None, PackageInfo=None): if GlobalData.gIS_BINARY_INF: self.SetAsBuildPcds(PcdContent, KeysList, PackageInfo) return True # # Validate Arch # SupArchList = [] SupArchDict = {} PcdTypeItem = '' for (PcdTypeItem1, ArchItem, LineNo) in KeysList: SupArchList, SupArchDict = ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList) # # Validate PcdType # if (PcdTypeItem1 == '' or PcdTypeItem1 == None): return False else: if not IsValidPcdType(PcdTypeItem1): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_SECTION_TYPE_ERROR % (DT.PCD_USAGE_TYPE_LIST_OF_MODULE), File=GlobalData.gINF_MODULE_NAME, Line=LineNo, ExtraData=PcdTypeItem1) return False PcdTypeItem = PcdTypeItem1 for PcdItem in PcdContent: PcdItemObj = InfPcdItem() CommentList = PcdItem[1] CurrentLineOfPcdItem = PcdItem[2] PcdItem = PcdItem[0] if CommentList != None and len(CommentList) != 0: PcdItemObj = ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj) else: CommentItemIns = InfPcdItemCommentContent() CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED) PcdItemObj.SetHelpStringList([CommentItemIns]) if len(PcdItem) >= 1 and len(PcdItem) <= 3: PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj) if len(PcdItem) >= 2 and len(PcdItem) <= 3: # # Contain PcdName and Value, validate value. # if IsValidPcdValue(PcdItem[1]) or PcdItem[1].strip() == "": PcdItemObj.SetDefaultValue(PcdItem[1]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_VALUE_INVALID, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=PcdItem[1]) if len(PcdItem) == 3: # # Contain PcdName, value, and FeatureFlag express # # # Validate Feature Flag Express # if PcdItem[2].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(PcdItem[2].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) PcdItemObj.SetFeatureFlagExp(PcdItem[2]) if len(PcdItem) < 1 or len(PcdItem) > 3: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_SECTION_CONTENT_ERROR, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) return False if PcdTypeItem.upper != DT.TAB_INF_FEATURE_PCD.upper(): PcdItemObj.SetSupportArchList(SupArchDict[PcdTypeItem]) else: PcdItemObj.SetSupportArchList(SupArchList) if self.Pcds.has_key((PcdTypeItem, PcdItemObj)): PcdsList = self.Pcds[PcdTypeItem, PcdItemObj] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList else: PcdsList = [] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList return True def SetAsBuildPcds(self, PcdContent, KeysList=None, PackageInfo=None): for PcdItem in PcdContent: PcdItemObj = InfPcdItem() CommentList = PcdItem[1] CurrentLineOfPcdItem = PcdItem[2] PcdItem = PcdItem[0] CommentString = '' for CommentLine in CommentList: CommentString = GetHelpStringByRemoveHashKey(CommentLine) CommentItemIns = InfPcdItemCommentContent() CommentItemIns.SetHelpStringItem(CommentString) CommentItemIns.SetUsageItem(CommentString) PcdItemObj.SetHelpStringList(PcdItemObj.GetHelpStringList() + [CommentItemIns]) if PcdItemObj.GetValidUsage(): PcdItemObj.SetValidUsage(PcdItemObj.GetValidUsage() + DT.TAB_VALUE_SPLIT + CommentString) else: PcdItemObj.SetValidUsage(CommentString) PcdItemObj.SetItemType(KeysList[0][0]) # # Set PcdTokenSpaceCName and CName # PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj) # # Set Value/DatumType/OffSet/Token # PcdItemObj = SetValueDatumTypeMaxSizeToken(PcdItem, CurrentLineOfPcdItem, PcdItemObj, KeysList[0][1], PackageInfo) PcdTypeItem = KeysList[0][0] if self.Pcds.has_key((PcdTypeItem, PcdItemObj)): PcdsList = self.Pcds[PcdTypeItem, PcdItemObj] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList else: PcdsList = [] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList def GetPcds(self): return self.Pcds
class InfPackageObject(): def __init__(self): self.Packages = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetPackages(self, PackageData, Arch = None): IsValidFileFlag = False SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' SupArchList.append(ArchItem) for PackageItem in PackageData: PackageItemObj = InfPackageItem() HelpStringObj = PackageItem[1] CurrentLineOfPackItem = PackageItem[2] PackageItem = PackageItem[0] if HelpStringObj != None: HelpString = HelpStringObj.HeaderComments + HelpStringObj.TailComments PackageItemObj.SetHelpString(HelpString) if len(PackageItem) >= 1: # # Validate file exist/format. # if IsValidPath(PackageItem[0], ''): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gWORKSPACE): IsValidFileFlag = True else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(PackageItem[0]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) return False if IsValidFileFlag: PackageItemObj.SetPackageName(PackageItem[0]) if len(PackageItem) == 2: # # Validate Feature Flag Express # if PackageItem[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(PackageItem[1].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetFeatureFlagExp(PackageItem[1].strip()) if len(PackageItem) > 2: # # Invalid format of Package statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PACKAGE_SECTION_CONTENT_ERROR, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetSupArchList(SupArchList) # # Determine package file name duplicate. Follow below rule: # # A package filename must not be duplicated within a [Packages] # section. Package filenames may appear in multiple architectural # [Packages] sections. A package filename listed in an # architectural [Packages] section must not be listed in the common # architectural [Packages] section. # # NOTE: This check will not report error now. # for Item in self.Packages: if Item.GetPackageName() == PackageItemObj.GetPackageName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PackageItemObjArch in SupArchList: if ItemArch == PackageItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or PackageItemObjArch.upper() == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Packages.has_key((PackageItemObj)): PackageList = self.Packages[PackageItemObj] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList else: PackageList = [] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList return True def GetPackages(self, Arch = None): if Arch == None: return self.Packages
class InfLibraryClassObject(): def __init__(self): self.LibraryClasses = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} ##SetLibraryClasses # # # @param HelpString: It can be a common comment or contain a recommend # instance. # def SetLibraryClasses(self, LibContent, KeyList=None): # # Validate Arch # (__SupArchList, __SupModuleList) = GetArchModuleType(KeyList) for LibItem in LibContent: LibItemObj = InfLibraryClassItem() if not GlobalData.gIS_BINARY_INF: HelpStringObj = LibItem[1] LibItemObj.CurrentLine.SetFileName(LibItem[2][2]) LibItemObj.CurrentLine.SetLineNo(LibItem[2][1]) LibItemObj.CurrentLine.SetLineString(LibItem[2][0]) LibItem = LibItem[0] if HelpStringObj != None: LibItemObj.SetHelpString(HelpStringObj) if len(LibItem) >= 1: if LibItem[0].strip() != '': if IsValidLibName(LibItem[0].strip()): if LibItem[0].strip() != 'NULL': LibItemObj.SetLibName(LibItem[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_LIB_NAME_INVALID, File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (LibItem[0]), File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_LIBRARY_SECTION_LIBNAME_MISSING, File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) if len(LibItem) == 2: if LibItem[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(LibItem[1].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) LibItemObj.SetFeatureFlagExp(LibItem[1].strip()) # # Invalid strings # if len(LibItem) < 1 or len(LibItem) > 2: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_LIBRARY_SECTION_CONTENT_ERROR, File=GlobalData.gINF_MODULE_NAME, Line=LibItemObj.CurrentLine.GetLineNo(), ExtraData=LibItemObj.CurrentLine.GetLineString()) LibItemObj.SetSupArchList(__SupArchList) LibItemObj.SetSupModuleList(__SupModuleList) # # Determine Library class duplicate. Follow below rule: # # A library class keyword must not be duplicated within a # [LibraryClasses] section. Library class keywords may appear in # multiple architectural and module type [LibraryClasses] sections. # A library class keyword listed in an architectural or module type # [LibraryClasses] section must not be listed in the common # architectural or module type [LibraryClasses] section. # # NOTE: This check will not report error now. But keep code for future enhancement. # # for Item in self.LibraryClasses: # if Item.GetLibName() == LibItemObj.GetLibName(): # ItemSupArchList = Item.GetSupArchList() # ItemSupModuleList = Item.GetSupModuleList() # for ItemArch in ItemSupArchList: # for ItemModule in ItemSupModuleList: # for LibItemObjArch in __SupArchList: # for LibItemObjModule in __SupModuleList: # if ItemArch == LibItemObjArch and LibItemObjModule == ItemModule: # # # # ERR_INF_PARSER_ITEM_DUPLICATE # # # pass # if (ItemArch.upper() == 'COMMON' or LibItemObjArch.upper() == 'COMMON') \ # and LibItemObjModule == ItemModule: # # # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # # # pass else: # # Assume the file GUID is well formatted. # LibItemObj.SetFileGuid(LibItem[0]) LibItemObj.SetVersion(LibItem[1]) if self.LibraryClasses.has_key((LibItemObj)): LibraryList = self.LibraryClasses[LibItemObj] LibraryList.append(LibItemObj) self.LibraryClasses[LibItemObj] = LibraryList else: LibraryList = [] LibraryList.append(LibItemObj) self.LibraryClasses[LibItemObj] = LibraryList return True def GetLibraryClasses(self): return self.LibraryClasses
class InfGuidObject(): def __init__(self): self.Guids = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetGuid(self, GuidList, Arch = None): __SupportArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupportArchList.append(ArchItem) for Item in GuidList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfGuidItemObj = InfGuidItem() if len(Item) >= 1 and len(Item) <= 2: # # Only GuildName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfGuidItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # For GUID entry. # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfGuidItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of GUID statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfGuidItemObj = ParseGuidComment(CommentsList, InfGuidItemObj) InfGuidItemObj.SetSupArchList(__SupportArchList) # # Determine GUID name duplicate. Follow below rule: # # A GUID must not be duplicated within a [Guids] section. # A GUID may appear in multiple architectural [Guids] # sections. A GUID listed in an architectural [Guids] # section must not be listed in the common architectural # [Guids] section. # # NOTE: This check will not report error now. # for Item in self.Guids: if Item.GetName() == InfGuidItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for GuidItemObjArch in __SupportArchList: if ItemArch == GuidItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or GuidItemObjArch.upper() == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Guids.has_key((InfGuidItemObj)): GuidList = self.Guids[InfGuidItemObj] GuidList.append(InfGuidItemObj) self.Guids[InfGuidItemObj] = GuidList else: GuidList = [] GuidList.append(InfGuidItemObj) self.Guids[InfGuidItemObj] = GuidList return True def GetGuid(self): return self.Guids
class InfUserExtensionObject(): def __init__(self): self.UserExtension = Sdict() def SetUserExtension(self, UserExtensionCont, IdContent=None, LineNo=None): if not UserExtensionCont or UserExtensionCont == '': return True # # IdContent is a list contain UserId and IdString # For this call the general section header parser, if no definition of # IdString/UserId, it will return 'COMMON' # for IdContentItem in IdContent: InfUserExtensionItemObj = InfUserExtensionItem() if IdContentItem[0] == 'COMMON': UserId = '' else: UserId = IdContentItem[0] if IdContentItem[1] == 'COMMON': IdString = '' else: IdString = IdContentItem[1] # # Fill UserExtensionObj members. # InfUserExtensionItemObj.SetUserId(UserId) InfUserExtensionItemObj.SetIdString(IdString) InfUserExtensionItemObj.SetContent(UserExtensionCont) InfUserExtensionItemObj.SetSupArchList(IdContentItem[2]) # for CheckItem in self.UserExtension: # if IdContentItem[0] == CheckItem[0] and IdContentItem[1] == CheckItem[1]: # if IdContentItem[2].upper() == 'COMMON' or CheckItem[2].upper() == 'COMMON': # # # # For COMMON ARCH type, do special check. # # # Logger.Error('InfParser', # ToolError.FORMAT_INVALID, # ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\ # (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]), # File=GlobalData.gINF_MODULE_NAME, # Line=LineNo, # ExtraData=None) if self.UserExtension.has_key(IdContentItem): # # Each UserExtensions section header must have a unique set # of UserId, IdString and Arch values. # This means that the same UserId can be used in more than one # section header, provided the IdString or Arch values are # different. The same IdString values can be used in more than # one section header if the UserId or Arch values are # different. The same UserId and the same IdString can be used # in a section header if the Arch values are different in each # of the section headers. # Logger.Error('InfParser', ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\ (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]), File=GlobalData.gINF_MODULE_NAME, Line=LineNo, ExtraData=None) else: UserExtensionList = [] UserExtensionList.append(InfUserExtensionItemObj) self.UserExtension[IdContentItem] = UserExtensionList return True def GetUserExtension(self): return self.UserExtension
class InfProtocolObject(): def __init__(self): self.Protocols = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetProtocol(self, ProtocolContent, Arch = None,): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in ProtocolContent: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1], CurrentLineOfItem[0]) Item = Item[0] InfProtocolItemObj = InfProtocolItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]), LineInfo=LineInfo) if (Item[0] != ''): InfProtocolItemObj.SetName(Item[0]) else: ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING, LineInfo=LineInfo) if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" # <FeatureFlagExpress>] # For Protocol Object # if Item[1].strip() == '': ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, LineInfo=LineInfo) # # Validate Feature Flag Express for Item[1] # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]), LineInfo=LineInfo) InfProtocolItemObj.SetFeatureFlagExp(Item[1]) if len(Item) < 1 or len(Item) > 2: # # Invalid format of Protocols statement # ErrorInInf(ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, LineInfo=LineInfo) # # Get/Set Usage and HelpString for Protocol entry # if CommentsList != None and len(CommentsList) != 0: InfProtocolItemObj = ParseProtocolComment(CommentsList, InfProtocolItemObj) else: CommentItemIns = InfProtocolItemCommentContent() CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfProtocolItemObj.SetCommentList([CommentItemIns]) InfProtocolItemObj.SetSupArchList(__SupArchList) # # Determine protocol name duplicate. Follow below rule: # # A protocol must not be duplicated within a [Protocols] section. # A protocol may appear in multiple architectural [Protocols] # sections. A protocol listed in an architectural [Protocols] # section must not be listed in the common architectural # [Protocols] section. # # NOTE: This check will not report error now. # for Item in self.Protocols: if Item.GetName() == InfProtocolItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for ProtocolItemObjArch in __SupArchList: if ItemArch == ProtocolItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper() == 'COMMON' or ProtocolItemObjArch.upper() == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Protocols.has_key((InfProtocolItemObj)): ProcotolList = self.Protocols[InfProtocolItemObj] ProcotolList.append(InfProtocolItemObj) self.Protocols[InfProtocolItemObj] = ProcotolList else: ProcotolList = [] ProcotolList.append(InfProtocolItemObj) self.Protocols[InfProtocolItemObj] = ProcotolList return True def GetProtocol(self): return self.Protocols
def __init__(self): self.UserExtension = Sdict()
class InfDefObject(InfSectionCommonDef): def __init__(self): self.Defines = Sdict() InfSectionCommonDef.__init__(self) def SetDefines(self, DefineContent, Arch = None): # # Validate Arch # HasFoundInfVersionFalg = False LineInfo = ['', -1, ''] ArchListString = ' '.join(Arch) # # Parse Define items. # for InfDefMemberObj in DefineContent: ProcessFunc = None Name = InfDefMemberObj.GetName() Value = InfDefMemberObj.GetValue() if Name == DT.TAB_INF_DEFINES_MODULE_UNI_FILE: ValidateUNIFilePath(Value) Value = os.path.join(os.path.dirname(InfDefMemberObj.CurrentLine.FileName), Value) if not os.path.isfile(Value) or not os.path.exists(Value): LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Name), LineInfo=LineInfo) InfLineCommentObj = InfLineCommentObject() InfLineCommentObj.SetHeaderComments(InfDefMemberObj.Comments.GetHeaderComments()) InfLineCommentObj.SetTailComments(InfDefMemberObj.Comments.GetTailComments()) if Name == 'COMPONENT_TYPE': ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ErrorCode=ToolError.EDK1_INF_ERROR, RaiseError=True) if Name == DT.TAB_INF_DEFINES_INF_VERSION: HasFoundInfVersionFalg = True if not (Name == '' or Name == None): # # Process "SPEC" Keyword definition. # ReName = re.compile(r"SPEC ", re.DOTALL) if ReName.match(Name): SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip() Name = "SPEC" Value = SpecValue + " = " + Value if self.Defines.has_key(ArchListString): DefineList = self.Defines[ArchListString] LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() DefineList.CurrentLine = LineInfo # # Found the process function from mapping table. # if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys(): ErrorInInf(ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID%(Name), LineInfo=LineInfo) else: ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[Name] if (ProcessFunc != None): ProcessFunc(DefineList, Value, InfLineCommentObj) self.Defines[ArchListString] = DefineList else: DefineList = InfDefSection() LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() DefineList.CurrentLine = LineInfo # # Found the process function from mapping table. # if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys(): ErrorInInf(ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID%(Name), LineInfo=LineInfo) # # Found the process function from mapping table. # else: ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[Name] if (ProcessFunc != None): ProcessFunc(DefineList, Value, InfLineCommentObj) self.Defines[ArchListString] = DefineList # # After set, check whether INF_VERSION defined. # if not HasFoundInfVersionFalg: ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ErrorCode=ToolError.EDK1_INF_ERROR, RaiseError=True) return True def GetDefines(self): return self.Defines
class InfPpiObject(): def __init__(self): self.Ppis = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetPpi(self, PpiList, Arch=None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in PpiList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfPpiItemObj = InfPpiItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfPpiItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Have FeatureFlag information # if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # Item[1] should not be empty # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express for PPI entry # Item[1] contain FFE information # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfPpiItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of Ppi statement # Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Get/Set Usage and HelpString for PPI entry # if CommentsList != None and len(CommentsList) != 0: InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj) else: CommentItemIns = InfPpiItemCommentContent() CommentItemIns.SetUsage(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfPpiItemObj.SetCommentList([CommentItemIns]) InfPpiItemObj.SetSupArchList(__SupArchList) # # Determine PPI name duplicate. Follow below rule: # # A PPI must not be duplicated within a [Ppis] section. # A PPI may appear in multiple architectural [Ppis] # sections. A PPI listed in an architectural [Ppis] # section must not be listed in the common architectural # [Ppis] section. # # NOTE: This check will not report error now. # for Item in self.Ppis: if Item.GetName() == InfPpiItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PpiItemObjArch in __SupArchList: if ItemArch == PpiItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or PpiItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Ppis.has_key((InfPpiItemObj)): PpiList = self.Ppis[InfPpiItemObj] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList else: PpiList = [] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList return True def GetPpi(self): return self.Ppis
class InfDefObject(InfSectionCommonDef): def __init__(self): self.Defines = Sdict() InfSectionCommonDef.__init__(self) def SetDefines(self, DefineContent, Arch=None): # # Validate Arch # HasFoundInfVersionFalg = False LineInfo = ['', -1, ''] ArchListString = ' '.join(Arch) # # Parse Define items. # for InfDefMemberObj in DefineContent: ProcessFunc = None Name = InfDefMemberObj.GetName() Value = InfDefMemberObj.GetValue() if Name == DT.TAB_INF_DEFINES_MODULE_UNI_FILE: ValidateUNIFilePath(Value) Value = os.path.join( os.path.dirname(InfDefMemberObj.CurrentLine.FileName), Value) if not os.path.isfile(Value) or not os.path.exists(Value): LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() ErrorInInf( ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (Name), LineInfo=LineInfo) InfLineCommentObj = InfLineCommentObject() InfLineCommentObj.SetHeaderComments( InfDefMemberObj.Comments.GetHeaderComments()) InfLineCommentObj.SetTailComments( InfDefMemberObj.Comments.GetTailComments()) if Name == 'COMPONENT_TYPE': ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ErrorCode=ToolError.EDK1_INF_ERROR, RaiseError=True) if Name == DT.TAB_INF_DEFINES_INF_VERSION: HasFoundInfVersionFalg = True if not (Name == '' or Name == None): # # Process "SPEC" Keyword definition. # ReName = re.compile(r"SPEC ", re.DOTALL) if ReName.match(Name): SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip() Name = "SPEC" Value = SpecValue + " = " + Value if self.Defines.has_key(ArchListString): DefineList = self.Defines[ArchListString] LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() DefineList.CurrentLine = LineInfo # # Found the process function from mapping table. # if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys(): ErrorInInf( ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID % (Name), LineInfo=LineInfo) else: ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[ Name] if (ProcessFunc != None): ProcessFunc(DefineList, Value, InfLineCommentObj) self.Defines[ArchListString] = DefineList else: DefineList = InfDefSection() LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString() DefineList.CurrentLine = LineInfo # # Found the process function from mapping table. # if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys(): ErrorInInf( ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID % (Name), LineInfo=LineInfo) # # Found the process function from mapping table. # else: ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[ Name] if (ProcessFunc != None): ProcessFunc(DefineList, Value, InfLineCommentObj) self.Defines[ArchListString] = DefineList # # After set, check whether INF_VERSION defined. # if not HasFoundInfVersionFalg: ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ErrorCode=ToolError.EDK1_INF_ERROR, RaiseError=True) return True def GetDefines(self): return self.Defines
class InfPackageObject(): def __init__(self): self.Packages = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {} def SetPackages(self, PackageData, Arch=None): IsValidFileFlag = False SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' SupArchList.append(ArchItem) for PackageItem in PackageData: PackageItemObj = InfPackageItem() HelpStringObj = PackageItem[1] CurrentLineOfPackItem = PackageItem[2] PackageItem = PackageItem[0] if HelpStringObj != None: HelpString = HelpStringObj.HeaderComments + HelpStringObj.TailComments PackageItemObj.SetHelpString(HelpString) if len(PackageItem) >= 1: # # Validate file exist/format. # if IsValidPath(PackageItem[0], ''): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gWORKSPACE): IsValidFileFlag = True else: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (PackageItem[0]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) return False if IsValidFileFlag: PackageItemObj.SetPackageName(PackageItem[0]) if len(PackageItem) == 2: # # Validate Feature Flag Express # if PackageItem[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(PackageItem[1].strip()) if not FeatureFlagRtv[0]: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetFeatureFlagExp(PackageItem[1].strip()) if len(PackageItem) > 2: # # Invalid format of Package statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PACKAGE_SECTION_CONTENT_ERROR, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetSupArchList(SupArchList) # # Determine package file name duplicate. Follow below rule: # # A package filename must not be duplicated within a [Packages] # section. Package filenames may appear in multiple architectural # [Packages] sections. A package filename listed in an # architectural [Packages] section must not be listed in the common # architectural [Packages] section. # # NOTE: This check will not report error now. # for Item in self.Packages: if Item.GetPackageName() == PackageItemObj.GetPackageName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PackageItemObjArch in SupArchList: if ItemArch == PackageItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or PackageItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Packages.has_key((PackageItemObj)): PackageList = self.Packages[PackageItemObj] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList else: PackageList = [] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList return True def GetPackages(self, Arch=None): if Arch == None: return self.Packages
def GenPcdSections(ModuleObject): Content = '' if not GlobalData.gIS_BINARY_INF: # # for each Pcd Itemtype, maintain a dict so the same type will be grouped # together # ItemTypeDict = {} for Pcd in ModuleObject.GetPcdList(): HelpTextList = Pcd.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) Statement = '' CName = Pcd.GetCName() TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName() DefaultValue = Pcd.GetDefaultValue() ItemType = Pcd.GetItemType() if ItemType in ItemTypeDict: Dict = ItemTypeDict[ItemType] else: Dict = Sdict() ItemTypeDict[ItemType] = Dict FFE = Pcd.GetFeatureFlag() Statement += TokenSpaceGuidCName + '.' + CName if DefaultValue: Statement += '|' + DefaultValue if FFE: Statement += '|' + FFE elif FFE: Statement += '||' + FFE # # Generate comment # Usage = Pcd.GetValidUsage() # # if FeatureFlag Pcd, then assume all Usage is CONSUMES # if ItemType == DT.TAB_INF_FEATURE_PCD: Usage = DT.USAGE_ITEM_CONSUMES if Usage == DT.ITEM_UNDEFINED or (ItemType == DT.TAB_INF_FEATURE_PCD): # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' Comment = '## ' + Usage + Comment if Comment: Comment += '\n' # # Merge duplicate entries # ArchList = Pcd.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment for ItemType in ItemTypeDict: # # First we need to transfer the Dict to use SortedArch as key # Dict = ItemTypeDict[ItemType] NewSectionDict = GenMetaFileMisc.TransferDict(Dict) if NewSectionDict: Content += GenSection(ItemType, NewSectionDict) # # For AsBuild INF files # else: Content += GenAsBuiltPacthPcdSections(ModuleObject) Content += GenAsBuiltPcdExSections(ModuleObject) return Content
def GenIncludes(self, ContainerFile): if ContainerFile: pass Logger.Debug(2, "Generate %s ..." % TAB_INCLUDES) IncludesDict = Sdict() IncObj = self.DecParser.GetIncludeSectionObject() for Item in IncObj.GetAllIncludes(): IncludePath = os.path.normpath(Item.File) if platform.system() != 'Windows' and platform.system() != 'Microsoft': IncludePath = IncludePath.replace('\\', '/') if IncludePath in IncludesDict: if Item.GetArchList() == [TAB_ARCH_COMMON] or IncludesDict[IncludePath] == [TAB_ARCH_COMMON]: IncludesDict[IncludePath] = [TAB_ARCH_COMMON] else: IncludesDict[IncludePath] = IncludesDict[IncludePath] + Item.GetArchList() else: IncludesDict[IncludePath] = Item.GetArchList() # # get the standardIncludeFileList(industry), packageIncludeFileList # (others) for PackageObject # PackagePath = os.path.split(self.GetFullPath())[0] IncludePathList = \ sorted([os.path.normpath(Path) + sep for Path in IncludesDict.keys()]) # # get a non-overlap set of include path, IncludePathList should be # sorted, and path should be end with path separator '\' # NonOverLapList = [] for Path1 in IncludePathList: for Path2 in NonOverLapList: if Path1.startswith(Path2): break else: NonOverLapList.append(Path1) # # revert the list so the longest path shown first in list, also need # to remove the extra path separator '\' # as this list is used to search the supported Arch info # for IndexN in range (0, len(IncludePathList)): IncludePathList[IndexN] = os.path.normpath(IncludePathList[IndexN]) IncludePathList.sort() IncludePathList.reverse() # # save the include path list for later usage # self.SetIncludePathList(IncludePathList) StandardIncludeFileList = [] PackageIncludeFileList = [] IncludeFileList = [] for Path in NonOverLapList: FileList = GetFiles(os.path.join(PackagePath, Path), ['CVS', '.svn'], False) IncludeFileList += [os.path.normpath(os.path.join(Path, File)) for File in FileList] for Includefile in IncludeFileList: ExtName = os.path.splitext(Includefile)[1] if ExtName.upper() == '.DEC' and self.CheckMulDec: Logger.Error('MkPkg', UPT_MUL_DEC_ERROR, ST.ERR_MUL_DEC_ERROR%(os.path.dirname(ContainerFile), os.path.basename(ContainerFile), Includefile)) FileCombinePath = os.path.dirname(Includefile) Include = IncludeObject() for Path in IncludePathList: if FileCombinePath.startswith(Path): SupArchList = IncludesDict[Path] break Include.SetFilePath(Includefile) Include.SetSupArchList(SupArchList) if Includefile.find('IndustryStandard') != -1: StandardIncludeFileList.append(Include) else: PackageIncludeFileList.append(Include) self.SetStandardIncludeFileList(StandardIncludeFileList) # # put include path into the PackageIncludeFileList # PackagePathList = [] IncObj = self.DecParser.GetIncludeSectionObject() for Item in IncObj.GetAllIncludes(): IncludePath = Item.File Include = IncludeObject() Include.SetFilePath(IncludePath) Include.SetSupArchList(Item.GetArchList()) PackagePathList.append(Include) self.SetPackageIncludeFileList(PackagePathList + PackageIncludeFileList)
def __init__(self): self.LibraryClasses = Sdict() # # Macro defined in this section should be only used in this section. # self.Macros = {}