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 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 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 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 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
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 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 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
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 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
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
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
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
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 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