def GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName): for InfFile in GetInfsFromWorkSpace(WorkSpace): try: if InfFile.strip().upper() == CurrentInfFileName.strip().upper(): continue InfFile = InfFile.replace('\\', '/') if InfFile not in GlobalData.gLIBINSTANCEDICT: InfFileObj = open(InfFile, "rb", 0) GlobalData.gLIBINSTANCEDICT[InfFile] = InfFileObj else: InfFileObj = GlobalData.gLIBINSTANCEDICT[InfFile] except BaseException: Logger.Error("InfParser", ToolError.FILE_READ_FAILURE, ST.ERR_FILE_OPEN_FAILURE, File=InfFile) try: FileLinesList = InfFileObj.readlines() FileLinesList = ProcessLineExtender(FileLinesList) ReFindFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$") ReFindVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$") for Line in FileLinesList: if ReFindFileGuidPattern.match(Line): FileGuidString = Line if ReFindVerStringPattern.match(Line): VerString = Line if FileGuidString: FileGuidString = GetSplitValueList(FileGuidString, '=', 1)[1] if VerString: VerString = GetSplitValueList(VerString, '=', 1)[1] if FileGuidString.strip().upper() == Guid.upper() and \ VerString.strip().upper() == Version.upper(): return Guid, Version except BaseException: Logger.Error("InfParser", ToolError.FILE_READ_FAILURE, ST.ERR_FILE_OPEN_FAILURE, File=InfFile) finally: InfFileObj.close() return '', ''
def ParseDefine(LineValue, StartLine, Table, FileID, SectionName, \ SectionModel, Arch): Logger.Debug(Logger.DEBUG_2, ST.MSG_DEFINE_STATEMENT_FOUND % (LineValue, \ SectionName)) Define = \ GetSplitValueList(CleanString\ (LineValue[LineValue.upper().\ find(DataType.TAB_DEFINE.upper() + ' ') + \ len(DataType.TAB_DEFINE + ' ') : ]), \ DataType.TAB_EQUAL_SPLIT, 1) Table.Insert(DataType.MODEL_META_DATA_DEFINE, Define[0], Define[1], '', \ '', '', Arch, SectionModel, FileID, StartLine, -1, \ StartLine, -1, 0)
def GetBuildOption(String, File, LineNo=-1): (Family, ToolChain, Flag) = ('', '', '') if String.find(DataType.TAB_EQUAL_SPLIT) < 0: RaiseParserError(String, 'BuildOptions', File, \ '[<Family>:]<ToolFlag>=Flag', LineNo) else: List = GetSplitValueList(String, DataType.TAB_EQUAL_SPLIT, MaxSplit=1) if List[0].find(':') > -1: Family = List[0][:List[0].find(':')].strip() ToolChain = List[0][List[0].find(':') + 1:].strip() else: ToolChain = List[0].strip() Flag = List[1].strip() return (Family, ToolChain, Flag)
def GetBinary(Item, ContainerFile, LineNo=-1): ItemNew = Item + DataType.TAB_VALUE_SPLIT List = GetSplitValueList(ItemNew) if len(List) < 3 or len(List) > 5: RaiseParserError(Item, 'Binaries', ContainerFile, \ "<FileType>|<Filename>[|<Target>\ [|<TokenSpaceGuidCName>.<PcdCName>]]" , LineNo) if len(List) >= 4: if List[3] != '': CheckPcdTokenInfo(List[3], 'Binaries', ContainerFile, LineNo) return (List[0], List[1], List[2], List[3]) elif len(List) == 3: return (List[0], List[1], List[2], '')
def GetSource(Item, ContainerFile, FileRelativePath, LineNo=-1): ItemNew = Item + DataType.TAB_VALUE_SPLIT * 4 List = GetSplitValueList(ItemNew) if len(List) < 5 or len(List) > 9: RaiseParserError(Item, 'Sources', ContainerFile, \ '<Filename>[|<Family>[|<TagName>[|<ToolCode>\ [|<PcdFeatureFlag>]]]]' , LineNo) List[0] = NormPath(List[0]) CheckFileExist(FileRelativePath, List[0], ContainerFile, 'Sources', \ Item, LineNo) if List[4] != '': CheckPcdTokenInfo(List[4], 'Sources', ContainerFile, LineNo) return (List[0], List[1], List[2], List[3], List[4])
def testErrorCase2(self): TestCommentLines = \ '''## BASE INVALID_MODULE_TYPE #hello world''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) try: ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest') except Logger.FatalError: pass
def testNormalCase1(self): TestCommentLines = \ '''# hello world''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) HelptxtObj = ParseGenericComment(TestCommentLinesList, 'testNormalCase1') self.failIf(not HelptxtObj) self.assertEqual(HelptxtObj.GetString(), 'hello world') self.assertEqual(HelptxtObj.GetLang(), TAB_LANGUAGE_EN_US)
def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo=-1): List = GetSplitValueList(Item[0]) SupMod = DataType.SUP_MODULE_LIST_STRING if len(List) != 2: RaiseParserError(Item[0], 'LibraryClasses', ContainerFile, \ '<LibraryClassKeyWord>|<LibraryInstance>') else: CheckFileType(List[1], '.Inf', ContainerFile, \ 'library class instance', Item[0], LineNo) CheckFileExist(WorkspaceDir, List[1], ContainerFile, \ 'LibraryClasses', Item[0], LineNo) if Item[1] != '': SupMod = Item[1] return (List[0], List[1], SupMod)
def SetLibraryClass(self, LibraryClass, Comments): ValueList = GetSplitValueList(LibraryClass) Name = ValueList[0] if IsValidWord(Name): InfDefineLibraryItemObj = InfDefineLibraryItem() InfDefineLibraryItemObj.SetLibraryName(Name) InfDefineLibraryItemObj.Comments = Comments if len(ValueList) == 2: Type = ValueList[1] TypeList = GetSplitValueList(Type, ' ') TypeList = [Type for Type in TypeList if Type != ''] for Item in TypeList: if Item not in DT.MODULE_LIST: ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Item), LineInfo=self.CurrentLine) return False InfDefineLibraryItemObj.SetTypes(TypeList) self.LibraryClass.append(InfDefineLibraryItemObj) else: ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Name), LineInfo=self.CurrentLine) return False return True
def testNormalCase6(self): TestCommentLines = \ '''#''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) (HelpTxt, PcdErr) = \ ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest') self.assertEqual(HelpTxt, '\n') self.failIf(PcdErr)
def ParseDecPcdTailComment (TailCommentList, ContainerFile): assert(len(TailCommentList) == 1) TailComment = TailCommentList[0][0] LineNum = TailCommentList[0][1] Comment = TailComment.lstrip(" #") ReFindFirstWordRe = re.compile(r"""^([^ #]*)""", re.DOTALL) # # get first word and compare with SUP_MODULE_LIST # MatchObject = ReFindFirstWordRe.match(Comment) if not (MatchObject and MatchObject.group(1) in SUP_MODULE_LIST): return None, Comment # # parse line, it must have supported module type specified # if Comment.find(TAB_COMMENT_SPLIT) == -1: Comment += TAB_COMMENT_SPLIT SupMode, HelpStr = GetSplitValueList(Comment, TAB_COMMENT_SPLIT, 1) SupModuleList = [] for Mod in GetSplitValueList(SupMode, TAB_SPACE_SPLIT): if not Mod: continue elif Mod not in SUP_MODULE_LIST: Logger.Error("UPT", FORMAT_INVALID, ST.WRN_INVALID_MODULE_TYPE%Mod, ContainerFile, LineNum) else: SupModuleList.append(Mod) return SupModuleList, HelpStr
def GenAsBuiltPacthPcdSections(ModuleObject): PatchPcdDict = {} for BinaryFile in ModuleObject.GetBinaryFileList(): if not BinaryFile.AsBuiltList: continue for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList: TokenSpaceName = '' PcdCName = PatchPcd.CName PcdValue = PatchPcd.DefaultValue PcdOffset = PatchPcd.Offset TokenSpaceGuidValue = PatchPcd.TokenSpaceGuidValue Token = PatchPcd.Token HelpTextList = PatchPcd.HelpTextList HelpString = '' for HelpStringItem in HelpTextList: for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'): HelpString += '## ' + HelpLine + '\n' TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName( ModuleObject.PackageDependencyList, TokenSpaceGuidValue, Token) if TokenSpaceName == '' or PcdCName == '': Logger.Error("Upt", ToolError.RESOURCE_NOT_AVAILABLE, ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token), File=ModuleObject.GetFullPath()) Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \ PcdOffset + DT.TAB_SPACE_SPLIT # # Use binary file's Arch to be Pcd's Arch # ArchList = [] FileNameObjList = BinaryFile.GetFileNameList() if FileNameObjList: ArchList = FileNameObjList[0].GetSupArchList() if len(ArchList) == 0: if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON): if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]: PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement) else: PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement] else: for Arch in ArchList: if PatchPcdDict.has_key(Arch): if Statement not in PatchPcdDict[Arch]: PatchPcdDict[Arch].append(Statement) else: PatchPcdDict[Arch] = [Statement] return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)
def testNormalCase5(self): TestCommentLines = \ ''' # 1 = 128MB, 2 = 256MB, 3 = MAX''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) (SupModeList, HelpStr) = \ ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest') self.failIf(not HelpStr) self.assertEqual(HelpStr, '1 = 128MB, 2 = 256MB, 3 = MAX') self.failIf(SupModeList)
def testNormalCase4(self): TestCommentLines = \ '''## BASE UEFI_APPLICATION''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) (SupModeList, HelpStr) = \ ParseDecPcdTailComment(TestCommentLinesList, 'UnitTest') self.failIf(HelpStr) self.failIf(not SupModeList) self.assertEqual(SupModeList, ['BASE', 'UEFI_APPLICATION'])
def FromXml(self, Item, Key): self.UserId = XmlAttribute(XmlNode(Item, '%s' % Key), 'UserId') self.Identifier = XmlAttribute(XmlNode(Item, '%s' % Key), 'Identifier') DefineItem = XmlNode(Item, '%s/Define' % Key) for SubItem in XmlList(DefineItem, 'Define/Statement'): Statement = XmlElement(SubItem, '%s/Statement' % Key) self.DefineDict[Statement] = "" BuildOptionItem = XmlNode(Item, '%s/BuildOption' % Key) for SubItem in XmlList(BuildOptionItem, 'BuildOption/Statement'): Statement = XmlElement(SubItem, '%s/Statement' % Key) Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList') self.BuildOptionDict[Arch] = Statement IncludesItem = XmlNode(Item, '%s/Includes' % Key) for SubItem in XmlList(IncludesItem, 'Includes/Statement'): Statement = XmlElement(SubItem, '%s/Statement' % Key) Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList') self.IncludesDict[Statement] = Arch SourcesItem = XmlNode(Item, '%s/Sources' % Key) Tmp = UserExtensionSourceXml() SourceDict = Tmp.FromXml(SourcesItem, 'Sources') self.SourcesDict = SourceDict BinariesItem = XmlNode(Item, '%s/Binaries' % Key) Tmp = UserExtensionBinaryXml() BinariesDict = Tmp.FromXml(BinariesItem, 'Binaries') self.BinariesDict = BinariesDict self.Statement = XmlElement(Item, 'UserExtensions') SupArch = XmlAttribute(XmlNode(Item, '%s' % Key), 'SupArchList') self.SupArchList = [Arch for Arch in GetSplitValueList(SupArch, DataType.TAB_SPACE_SPLIT) if Arch] UserExtension = UserExtensionObject() UserExtension.SetUserID(self.UserId) UserExtension.SetIdentifier(self.Identifier) UserExtension.SetStatement(self.Statement) UserExtension.SetSupArchList(self.SupArchList) UserExtension.SetDefinesDict(self.DefineDict) UserExtension.SetBuildOptionDict(self.BuildOptionDict) UserExtension.SetIncludesDict(self.IncludesDict) UserExtension.SetSourcesDict(self.SourcesDict) UserExtension.SetBinariesDict(self.BinariesDict) return UserExtension
def ValidatePcdValueOnDatumType(Value, Type): Value = Value.strip() # # Boolean type only allow 0x00 or 0x01 as value per INF spec # if Type == 'BOOLEAN': if not (Value == '0x00' or Value == '0x01'): return False elif Type == 'VOID*': if not Value.startswith("{"): return False if not Value.endswith("}"): return False # # Strip "{" at head and "}" at tail. # Value = Value[1:-1] ValueList = GetSplitValueList(Value, DT.TAB_COMMA_SPLIT) ReIsValidHexByte = re.compile("^0x[0-9a-f]{1,2}$", re.IGNORECASE) for ValueItem in ValueList: if not ReIsValidHexByte.match(ValueItem): return False elif Type == 'UINT8' or Type == 'UINT16' or Type == 'UINT32' or Type == 'UINT64': ReIsValidUint8z = re.compile('^0[x|X][a-fA-F0-9]{2}$') ReIsValidUint16z = re.compile('^0[x|X][a-fA-F0-9]{4}$') ReIsValidUint32z = re.compile('^0[x|X][a-fA-F0-9]{8}$') ReIsValidUint64z = re.compile('^0[x|X][a-fA-F0-9]{16}$') if not ReIsValidUint8z.match(Value) and Type == 'UINT8': return False elif not ReIsValidUint16z.match(Value) and Type == 'UINT16': return False elif not ReIsValidUint32z.match(Value) and Type == 'UINT32': return False elif not ReIsValidUint64z.match(Value) and Type == 'UINT64': return False else: # # Since we assume the DEC file always correct, should never go to here. # pass return True
def IsValidNormalizedString(String): if String == '': return True for Char in String: if Char == '\t': return False StringList = GetSplitValueList(String, TAB_SPACE_SPLIT) for Item in StringList: if not Item: continue if not IsValidWord(Item): return False return True
def testNormalCase1(self): TestCommentLines = \ '''## hello world # second line''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) (HelpTxt, PcdErr) = \ ParseDecPcdGenericComment(TestCommentLinesList, 'testNormalCase1') self.failIf(not HelpTxt) self.failIf(PcdErr) self.assertEqual(HelpTxt, 'hello world\n' + 'second line')
def _ParseItem(self): Line = self._RawData.CurrentLine TokenList = GetSplitValueList(Line, DT.TAB_EQUAL_SPLIT, 1) if TokenList[0] == DT.TAB_DEC_DEFINES_PKG_UNI_FILE: self.DefineValidation[TokenList[0]](TokenList[1]) elif len(TokenList) < 2: self._LoggerError(ST.ERR_DECPARSE_DEFINE_FORMAT) elif TokenList[0] not in self.DefineValidation: self._LoggerError(ST.ERR_DECPARSE_DEFINE_UNKNOWKEY % TokenList[0]) else: self.DefineValidation[TokenList[0]](TokenList[1]) DefineItem = DecDefineItemObject() DefineItem.Key = TokenList[0] DefineItem.Value = TokenList[1] self.ItemObject.AddItem(DefineItem, self._RawData.CurrentScope) return DefineItem
def testNormalCase5(self): TestCommentLines = \ '''# @Expression LT 1 AND GT 2''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) (HelpTxt, PcdErr) = \ ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest') self.failIf(HelpTxt) self.failIf(not PcdErr) self.assertEqual(PcdErr.GetExpression().strip(), 'LT 1 AND GT 2') self.failIf(PcdErr.GetValidValueRange()) self.failIf(PcdErr.GetValidValue())
def testNormalCase6(self): TestCommentLines = \ ''' ## @file # Abstract # # Description # # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2010, FOO1 Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2010, FOO2 Corporation. All rights reserved.<BR> # # License # ##''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) Abstract, Description, Copyright, License = \ ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile") ExpectedAbstract = 'Abstract' self.assertEqual(Abstract, ExpectedAbstract) ExpectedDescription = 'Description' self.assertEqual(Description, ExpectedDescription) ExpectedCopyright = \ 'Copyright (c) 2007 - 2010, Intel Corporation.'\ ' All rights reserved.<BR>\n'\ 'Copyright (c) 2007 - 2010, FOO1 Corporation.'\ ' All rights reserved.<BR>\n'\ 'Copyright (c) 2007 - 2010, FOO2 Corporation.'\ ' All rights reserved.<BR>' self.assertEqual(Copyright, ExpectedCopyright) ExpectedLicense = \ 'License' self.assertEqual(License, ExpectedLicense)
def testErrorCase1(self): TestCommentLines = \ '''## hello world # second line # @ValidList 1, 2, 3 # @Expression LT 1 AND GT 2 # other line''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) try: ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest') except Logger.FatalError: pass
def GetHelpStringByRemoveHashKey(String): ReturnString = '' PattenRemoveHashKey = re.compile(r"^[#+\s]+", re.DOTALL) String = String.strip() if String == '': return String LineList = GetSplitValueList(String, END_OF_LINE) for Line in LineList: ValueList = PattenRemoveHashKey.split(Line) if len(ValueList) == 1: ReturnString += ValueList[0] + END_OF_LINE else: ReturnString += ValueList[1] + END_OF_LINE if ReturnString.endswith('\n') and not ReturnString.endswith('\n\n') and ReturnString != '\n': ReturnString = ReturnString[:-1] return ReturnString
def GenGenericCommentF(CommentLines, NumOfPound=1): if not CommentLines: return '' EndOfLine = "\n" # # if comment end with '\n', then remove it to prevent one extra line # generate later on # if CommentLines.endswith(EndOfLine): CommentLines = CommentLines[:-1] CommentLineList = GetSplitValueList(CommentLines, EndOfLine) CommentStr = '' for Line in CommentLineList: if Line == '': CommentStr += '#' * NumOfPound + '\n' else: CommentStr += '#' * NumOfPound + ' ' + Line + '\n' return CommentStr
def GenAsBuiltPcdExSections(ModuleObject): PcdExDict = {} for BinaryFile in ModuleObject.GetBinaryFileList(): if not BinaryFile.AsBuiltList: continue for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList: TokenSpaceName = '' PcdCName = PcdExItem.CName PcdValue = PcdExItem.DefaultValue TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue Token = PcdExItem.Token HelpTextList = PcdExItem.HelpTextList HelpString = '' for HelpStringItem in HelpTextList: for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'): HelpString += '# ' + HelpLine + '\n' TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName( ModuleObject.PackageDependencyList, TokenSpaceGuidValue, Token) if TokenSpaceName == '' or PcdCName == '': Logger.Error("Upt", ToolError.RESOURCE_NOT_AVAILABLE, ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token), File=ModuleObject.GetFullPath()) Statement = HelpString[: -3] + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue if len(BinaryFile.SupArchList) == 0: if PcdExDict.has_key('COMMON'): PcdExDict['COMMON'].append(Statement) else: PcdExDict['COMMON'] = [Statement] else: for Arch in BinaryFile.SupArchList: if PcdExDict.has_key(Arch): PcdExDict[Arch].append(Statement) else: PcdExDict[Arch] = [Statement] return GenSection('PcdEx', PcdExDict)
def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo=-1): ItemList = GetSplitValueList((Item[0] + DataType.TAB_VALUE_SPLIT * 2)) SupMod = DataType.SUP_MODULE_LIST_STRING if len(ItemList) > 5: RaiseParserError\ (Item[0], 'LibraryClasses', ContainerFile, \ '<LibraryClassKeyWord>[|<LibraryInstance>]\ [|<TokenSpaceGuidCName>.<PcdCName>]' ) else: CheckFileType(ItemList[1], '.Inf', ContainerFile, 'LibraryClasses', \ Item[0], LineNo) CheckFileExist(WorkspaceDir, ItemList[1], ContainerFile, \ 'LibraryClasses', Item[0], LineNo) if ItemList[2] != '': CheckPcdTokenInfo(ItemList[2], 'LibraryClasses', \ ContainerFile, LineNo) if Item[1] != '': SupMod = Item[1] return (ItemList[0], ItemList[1], ItemList[2], SupMod)
def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo=-1): List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT) if len(List) != 2: RaiseParserError(Item, Type, ContainerFile, '<CName>=<GuidValue>', \ LineNo) # #convert C-Format Guid to Register Format # if List[1][0] == '{' and List[1][-1] == '}': RegisterFormatGuid = GuidStructureStringToGuidString(List[1]) if RegisterFormatGuid == '': RaiseParserError(Item, Type, ContainerFile, \ 'CFormat or RegisterFormat', LineNo) else: if CheckGuidRegFormat(List[1]): RegisterFormatGuid = List[1] else: RaiseParserError(Item, Type, ContainerFile, \ 'CFormat or RegisterFormat', LineNo) return (List[0], RegisterFormatGuid)
def testErrorCase1(self): TestCommentLines = \ ''' ## @file # Abstract # # Description # # License # ##''' CommentList = GetSplitValueList(TestCommentLines, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) self.assertRaises(Logger.FatalError, ParseHeaderCommentSection, TestCommentLinesList, "PhonyFile")
def testNormalCase3(self): TestCommentLines3 = \ ''' # License1 # License2 # ## @file # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR> # # License3 Line1 # License3 Line2 ##''' CommentList = GetSplitValueList(TestCommentLines3, "\n") LineNum = 0 TestCommentLinesList = [] for Comment in CommentList: LineNum += 1 TestCommentLinesList.append((Comment, LineNum)) Abstract, Description, Copyright, License = \ ParseHeaderCommentSection(TestCommentLinesList, "PhonyFile") ExpectedAbstract = '' self.assertEqual(Abstract, ExpectedAbstract) ExpectedDescription = '' self.assertEqual(Description, ExpectedDescription) ExpectedCopyright = \ 'Copyright (c) 2007 - 2010,'\ ' Intel Corporation. All rights reserved.<BR>' self.assertEqual(Copyright, ExpectedCopyright) ExpectedLicense = \ 'License1\n' \ 'License2\n\n' \ 'License3 Line1\n' \ 'License3 Line2' self.assertEqual(License, ExpectedLicense)
def ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList): # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' if PcdTypeItem1.upper != DT.TAB_INF_FEATURE_PCD.upper(): ArchList = GetSplitValueList(ArchItem, ' ') for ArchItemNew in ArchList: if not IsValidArch(ArchItemNew): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (ArchItemNew), File=GlobalData.gINF_MODULE_NAME, Line=LineNo, ExtraData=ArchItemNew) SupArchDict[PcdTypeItem1] = ArchList else: SupArchList.append(ArchItem) return SupArchList, SupArchDict
def SectionHeaderParser(self, SectionString, FileName, LineNo): _Scope = [] _SectionName = '' ArchList = set() _ValueList = [] _PcdNameList = [DT.TAB_INF_FIXED_PCD.upper(), DT.TAB_INF_FEATURE_PCD.upper(), DT.TAB_INF_PATCH_PCD.upper(), DT.TAB_INF_PCD.upper(), DT.TAB_INF_PCD_EX.upper() ] SectionString = SectionString.strip() for Item in GetSplitValueList(SectionString[1:-1], DT.TAB_COMMA_SPLIT): if Item == '': Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) ItemList = GetSplitValueList(Item, DT.TAB_SPLIT) # # different section should not mix in one section # Allow different PCD type sections mixed together # if _SectionName.upper() not in _PcdNameList: if _SectionName != '' and _SectionName.upper() != ItemList[0].upper(): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_SECTION_NAME_DUPLICATE, File=FileName, Line=LineNo, ExtraData=SectionString) elif _PcdNameList[1] in [_SectionName.upper(), ItemList[0].upper()] and \ (_SectionName.upper()!= ItemList[0].upper()): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) _SectionName = ItemList[0] if _SectionName.upper() in gINF_SECTION_DEF: self._SectionType = gINF_SECTION_DEF[_SectionName.upper()] else: self._SectionType = DT.MODEL_UNKNOWN Logger.Error("Parser", FORMAT_INVALID, ST.ERR_INF_PARSER_UNKNOWN_SECTION, File=FileName, Line=LineNo, ExtraData=SectionString) # # Get Arch # Str1, ArchList = GetArch(ItemList, ArchList, FileName, LineNo, SectionString) # # For [Defines] section, do special check. # if ItemList[0].upper() == DT.TAB_COMMON_DEFINES.upper(): if len(ItemList) != 1: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) # # For [UserExtension] section, do special check. # if ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): RetValue = ProcessUseExtHeader(ItemList) if not RetValue[0]: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) else: ItemList = RetValue[1] if len(ItemList) == 3: ItemList.append('COMMON') Str1 = ItemList[1] # # For Library classes, need to check module type. # if ItemList[0].upper() == DT.TAB_LIBRARY_CLASSES.upper() and len(ItemList) == 3: if ItemList[2] != '': ModuleTypeList = GetSplitValueList(ItemList[2], DT.TAB_VALUE_SPLIT) for Item in ModuleTypeList: if Item.strip() not in DT.MODULE_LIST: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID % (Item), File=FileName, Line=LineNo, ExtraData=SectionString) # # GetSpecialStr2 # Str2 = GetSpecialStr2(ItemList, FileName, LineNo, SectionString) _Scope.append([Str1, Str2]) _NewValueList = [] _AppendFlag = True if _SectionName.upper() in _PcdNameList: for ValueItem in _ValueList: if _SectionName.upper() == ValueItem[0].upper() and Str1.upper() not in ValueItem[1].split(): ValueItem[1] = ValueItem[1] + " " + Str1 _AppendFlag = False elif _SectionName.upper() == ValueItem[0].upper() and Str1.upper() in ValueItem[1].split(): _AppendFlag = False _NewValueList.append(ValueItem) _ValueList = _NewValueList if _AppendFlag: if not ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): _ValueList.append([_SectionName, Str1, Str2, LineNo]) else: if len(ItemList) == 4: _ValueList.append([_SectionName, Str1, Str2, ItemList[3], LineNo]) self.SectionHeaderContent = deepcopy(_ValueList)