Example #1
0
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, "r")
                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 testNormalCase3(self):
        TestCommentLines = \
        '''## BASE  UEFI_APPLICATION #hello world'''

        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.failIf(not SupModeList)
        self.assertEqual(HelpStr, 'hello world')
        self.assertEqual(SupModeList, ['BASE', 'UEFI_APPLICATION'])
    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')
Example #4
0
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 testNormalCase3(self):
        TestCommentLines = \
        '''## hello world
        This is not comment line'''

        CommentList = GetSplitValueList(TestCommentLines, "\n")
        LineNum = 0
        TestCommentLinesList = []
        for Comment in CommentList:
            LineNum += 1
            TestCommentLinesList.append((Comment, LineNum))

        HelptxtObj = ParseGenericComment(TestCommentLinesList,
                                         'testNormalCase3')
        self.failIf(not HelptxtObj)
        self.assertEqual(HelptxtObj.GetString(), 'hello world\n\n')
        self.assertEqual(HelptxtObj.GetLang(), TAB_LANGUAGE_EN_US)
Example #6
0
    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 - 2018, 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 - 2018, 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)
Example #9
0
File: Misc.py Project: syscase/edk2
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 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
Example #11
0
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, "r")
                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 '', ''
Example #12
0
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)
Example #13
0
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 - 2018, 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)
Example #16
0
def GenGenericCommentF(CommentLines,
                       NumOfPound=1,
                       IsPrompt=False,
                       IsInfLibraryClass=False):
    if not CommentLines:
        return ''
    #
    # if comment end with '\n', then remove it to prevent one extra line
    # generate later on
    #
    if CommentLines.endswith(END_OF_LINE):
        CommentLines = CommentLines[:-1]
    CommentStr = ''
    if IsPrompt:
        CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + TAB_PCD_PROMPT + TAB_SPACE_SPLIT + \
        CommentLines.replace(END_OF_LINE, '') + END_OF_LINE
    else:
        CommentLineList = GetSplitValueList(CommentLines, END_OF_LINE)
        FindLibraryClass = False
        for Line in CommentLineList:
            # If this comment is for @libraryclass and it has multiple lines
            # make sure the second lines align to the first line after @libraryclass as below
            #
            # ## @libraryclass XYZ FIRST_LINE
            # ##               ABC SECOND_LINE
            #
            if IsInfLibraryClass and Line.find(u'@libraryclass ') > -1:
                FindLibraryClass = True
            if Line == '':
                CommentStr += TAB_COMMENT_SPLIT * NumOfPound + END_OF_LINE
            else:
                if FindLibraryClass and Line.find(u'@libraryclass ') > -1:
                    CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE
                elif FindLibraryClass:
                    CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT * 16 + Line + END_OF_LINE
                else:
                    CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE

    return CommentStr
    def testErrorCase2(self):
        TestCommentLines = \
        '''
        ## @file
        # Abstract
        #
        this is invalid line
        # Description
        #
        # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
        # 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):
        TestCommentLines = \
        '''## hello world
        # second line
        # @ValidRange LT 1 AND GT 2
        # other line'''

        CommentList = GetSplitValueList(TestCommentLines, "\n")
        LineNum = 0
        TestCommentLinesList = []
        for Comment in CommentList:
            LineNum += 1
            TestCommentLinesList.append((Comment, LineNum))

        (HelpTxt, PcdErr) = \
            ParseDecPcdGenericComment(TestCommentLinesList, 'UnitTest')
        self.failIf(not HelpTxt)
        self.failIf(not PcdErr)
        self.assertEqual(HelpTxt,
                         'hello world\n' + 'second line\n' + 'other line')
        self.assertEqual(PcdErr.GetValidValueRange().strip(), 'LT 1 AND GT 2')
        self.failIf(PcdErr.GetExpression())
        self.failIf(PcdErr.GetValidValue())
Example #19
0
def ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList):
    #
    # Validate Arch
    #
    if (ArchItem == '' or ArchItem is 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
Example #20
0
    def _ParseItem(self):
        Line = self._RawData.CurrentLine
        TokenList = GetSplitValueList(Line, DT.TAB_EQUAL_SPLIT, 1)
        if len(TokenList) < 2:
            self._LoggerError(ST.ERR_DECPARSE_CGUID)
        if TokenList[0] == '':
            self._LoggerError(ST.ERR_DECPARSE_CGUID_NAME)
        if TokenList[1] == '':
            self._LoggerError(ST.ERR_DECPARSE_CGUID_GUID)
        if not IsValidToken(CVAR_PATTERN, TokenList[0]):
            self._LoggerError(ST.ERR_DECPARSE_PCD_CVAR_GUID)

        self._CheckReDefine(TokenList[0])

        if TokenList[1][0] != '{':
            if not CheckGuidRegFormat(TokenList[1]):
                self._LoggerError(ST.ERR_DECPARSE_DEFINE_PKGGUID)
            GuidString = TokenList[1]
        else:
            #
            # Convert C format GUID to GUID string and Simple error check
            #
            GuidString = GuidStructureStringToGuidString(TokenList[1])
            if TokenList[1][0] != '{' or TokenList[1][
                    -1] != '}' or GuidString == '':
                self._LoggerError(ST.ERR_DECPARSE_CGUID_GUIDFORMAT)

            #
            # Check C format GUID
            #
            if not IsValidCFormatGuid(TokenList[1]):
                self._LoggerError(ST.ERR_DECPARSE_CGUID_GUIDFORMAT)

        Item = DecGuidItemObject(TokenList[0], TokenList[1], GuidString)
        ItemObject = self.ObjectDict[self._RawData.CurrentScope[0][0]]
        ItemObject.AddItem(Item, self._RawData.CurrentScope)
        return Item
Example #21
0
 def SetCustomMakefile(self, CustomMakefile, Comments):
     if not (CustomMakefile == '' or CustomMakefile is None):
         ValueList = GetSplitValueList(CustomMakefile)
         if len(ValueList) == 1:
             FileName = ValueList[0]
             Family = ''
         else:
             Family = ValueList[0]
             FileName = ValueList[1]
         Family = Family.strip()
         if Family != '':
             if not IsValidFamily(Family):
                 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                            (Family),
                            LineInfo=self.CurrentLine)
                 return False
         #
         # The MakefileName specified file should exist
         #
         IsValidFileFlag = False
         ModulePath = os.path.split(self.CurrentLine[0])[0]
         if IsValidPath(FileName, ModulePath):
             IsValidFileFlag = True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                        (FileName),
                        LineInfo=self.CurrentLine)
             return False
         if IsValidFileFlag:
             FileName = ConvPathFromAbsToRel(FileName,
                                             GlobalData.gINF_MODULE_DIR)
             self.CustomMakefile.append((Family, FileName, Comments))
             IsValidFileFlag = False
         return True
     else:
         return False
Example #22
0
    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)
Example #23
0
def MacroParser(Line, FileName, SectionType, FileLocalMacros):
    MacroDefPattern = re.compile("^(DEFINE)[ \t]+")
    LineContent = Line[0]
    LineNo = Line[1]
    Match = MacroDefPattern.match(LineContent)
    if not Match:
        #
        # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
        #
        return None, None

    TokenList = GetSplitValueList(LineContent[Match.end(1):], \
                                  DataType.TAB_EQUAL_SPLIT, 1)
    #
    # Syntax check
    #
    if not TokenList[0]:
        Logger.Error('Parser',
                     FORMAT_INVALID,
                     ST.ERR_MACRONAME_NOGIVEN,
                     ExtraData=LineContent,
                     File=FileName,
                     Line=LineNo)
    if len(TokenList) < 2:
        Logger.Error('Parser',
                     FORMAT_INVALID,
                     ST.ERR_MACROVALUE_NOGIVEN,
                     ExtraData=LineContent,
                     File=FileName,
                     Line=LineNo)

    Name, Value = TokenList

    #
    # DEFINE defined macros
    #
    if SectionType == DataType.MODEL_META_DATA_HEADER:
        FileLocalMacros[Name] = Value

    ReIsValidMacroName = re.compile(r"^[A-Z][A-Z0-9_]*$", re.DOTALL)
    if ReIsValidMacroName.match(Name) is None:
        Logger.Error('Parser',
                     FORMAT_INVALID,
                     ST.ERR_MACRONAME_INVALID % (Name),
                     ExtraData=LineContent,
                     File=FileName,
                     Line=LineNo)

    # Validate MACRO Value
    #
    # <MacroDefinition> ::=  [<Comments>]{0,}
    #                       "DEFINE" <MACRO> "=" [{<PATH>} {<VALUE>}] <EOL>
    # <Value>           ::=  {<NumVal>} {<Boolean>} {<AsciiString>} {<GUID>}
    #                        {<CString>} {<UnicodeString>} {<CArray>}
    #
    # The definition of <NumVal>, <PATH>, <Boolean>, <GUID>, <CString>,
    # <UnicodeString>, <CArray> are subset of <AsciiString>.
    #
    ReIsValidMacroValue = re.compile(r"^[\x20-\x7e]*$", re.DOTALL)
    if ReIsValidMacroValue.match(Value) is None:
        Logger.Error('Parser',
                     FORMAT_INVALID,
                     ST.ERR_MACROVALUE_INVALID % (Value),
                     ExtraData=LineContent,
                     File=FileName,
                     Line=LineNo)

    return Name, Value
Example #24
0
def GetGuidsProtocolsPpisOfInf(Item):
    ItemNew = Item + DataType.TAB_VALUE_SPLIT
    List = GetSplitValueList(ItemNew)
    return (List[0], List[1])
Example #25
0
    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)
Example #26
0
    def _GenModuleHeader(self):
        Logger.Debug(2, "Generate ModuleHeader ...")
        #
        # Get all defines information form InfParser Object
        #
        RecordSet = self.Parser.InfDefSection.Defines
        #
        # Should only have one ArchString Item.
        #
        ArchString = list(RecordSet.keys())[0]
        ArchList = GetSplitValueList(ArchString, ' ')
        ArchList = ConvertArchList(ArchList)
        HasCalledFlag = False
        #
        # Get data from Sdict()
        #
        ValueList = RecordSet[ArchString]
        self.SetFileName(self.FileName)
        self.SetFullPath(self.FullPath)
        #
        # The INF's filename (without the directory path or the extension)
        # must be used for the value of the
        # ModuleSurfaceArea.Header.Name element
        #
        self.SetName(os.path.splitext(os.path.basename(self.FileName))[0])
        self.WorkspaceDir = " "
        #
        # CombinePath and ModulePath
        #
        CombinePath = GetRelativePath(self.FullPath, self.WorkSpace)
        self.SetCombinePath(CombinePath)
        ModulePath = os.path.split(CombinePath)[0]
        ModuleRelativePath = ModulePath
        if self.GetPackagePath() != '':
            ModuleRelativePath = GetRelativePath(ModulePath, self.GetPackagePath())
        self.SetModulePath(ModuleRelativePath)
        #
        # For Define Seciton Items.
        #
        DefineObj = ValueList
        #
        # Convert UEFI/PI version to decimal number
        #
        if DefineObj.GetUefiSpecificationVersion() is not None:
            __UefiVersion = DefineObj.GetUefiSpecificationVersion().GetValue()
            __UefiVersion = ConvertVersionToDecimal(__UefiVersion)
            self.SetUefiSpecificationVersion(str(__UefiVersion))
        if DefineObj.GetPiSpecificationVersion() is not None:
            __PiVersion = DefineObj.GetPiSpecificationVersion().GetValue()
            __PiVersion = ConvertVersionToDecimal(__PiVersion)

            self.SetPiSpecificationVersion(str(__PiVersion))
        SpecList = DefineObj.GetSpecification()
        NewSpecList = []
        for SpecItem in SpecList:
            NewSpecList.append((SpecItem[0], ConvertVersionToDecimal(SpecItem[1])))
        self.SetSpecList(NewSpecList)

        #
        # must exist items in INF define section
        # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING
        #
        if DefineObj.GetModuleType() is None:
            Logger.Error("InfParser", FORMAT_INVALID,
                         ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("MODULE_TYPE"), File=self.FullPath)
        else:
            self.SetModuleType(DefineObj.GetModuleType().GetValue())
            ModuleType = DefineObj.GetModuleType().GetValue()
            if ModuleType:
                #
                # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only
                # libraries are permitted to a have a MODULE_TYPE of "BASE".
                #
                if len(DefineObj.LibraryClass) == 0 and ModuleType == 'BASE':
                    Logger.Error("InfParser",
                                 FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_MODULETYPE_INVALID,
                                 File=self.FullPath,
                                 Line=DefineObj.ModuleType.CurrentLine.LineNo,
                                 ExtraData=DefineObj.ModuleType.CurrentLine.LineString)
                self.LibModuleTypeList.append(ModuleType)
        if DefineObj.GetBaseName() is None:
            Logger.Error("InfParser", FORMAT_INVALID,
                         ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("BASE_NAME"), File=self.FullPath)
        else:
            self.SetBaseName(DefineObj.GetBaseName().GetValue())
        if DefineObj.GetModuleUniFileName():
            self.UniFileClassObject = UniFileClassObject([PathClass(DefineObj.GetModuleUniFileName())])
        else:
            self.UniFileClassObject = None
        if DefineObj.GetInfVersion() is None:
            Logger.Error("InfParser", FORMAT_INVALID,
                         ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("INF_VERSION"), File=self.FullPath)
        else:
            self.SetVersion(DefineObj.GetInfVersion().GetValue())
        if DefineObj.GetFileGuid() is None:
            Logger.Error("InfParser", FORMAT_INVALID,
                         ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("FILE_GUID"), File=self.FullPath)
        else:
            self.SetGuid(DefineObj.GetFileGuid().GetValue())
        if DefineObj.GetVersionString() is None:
            #
            # VERSION_STRING is missing from the [Defines] section, tools must assume that the module's version is 0.
            #
            self.SetVersion('0')
        else:
            #
            # Get version of INF
            #
            if DefineObj.GetVersionString().GetValue() != "":
                #
                # EDK2 inf
                #
                VersionString = DefineObj.GetVersionString().GetValue()
                if len(VersionString) > 0:
                    VersionString = ConvertVersionToDecimal(VersionString)
                    self.SetVersion(VersionString)
            else:
                #
                # EDK1 inf
                #
                Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ExtraData=self.FullPath,
                             RaiseError=Logger.IS_RAISE_ERROR)
        #
        # if there is Shadow, Should judge the MODULE_TYPE in
        # SEC, PEI_CORE and PEIM
        #
        if DefineObj.GetShadow():
            ModuleTypeValue = DefineObj.GetModuleType().GetValue()
            if not (ModuleTypeValue == 'SEC' or ModuleTypeValue == 'PEI_CORE' or ModuleTypeValue == 'PEIM'):
                Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SHADOW_INVALID, File=self.FullPath)

        if DefineObj.GetPcdIsDriver() is not None:
            self.SetPcdIsDriver(DefineObj.GetPcdIsDriver().GetValue())
        #
        # LIBRARY_CLASS
        #
        self._GenModuleHeaderLibClass(DefineObj, ArchList)
        #
        # CUSTOM_MAKEFILE
        #
        self.CustomMakefile = DefineObj.GetCustomMakefile()
        #
        # Externs in Defines section
        # Only one define section, so just call once.
        #
        if not HasCalledFlag:
            self._GenModuleHeaderExterns(DefineObj)
            HasCalledFlag = True
        #
        # each module has only one module header
        #
        self.SetSupArchList(ArchList)
        #
        # Get Hob/BootMode/EventList information
        #
        self._GenSpecialComments()
        #
        # put all define statement into user-extension sections
        #
        DefinesDictNew = GenModuleHeaderUserExt(DefineObj, ArchString)
        if DefinesDictNew:
            UserExtension = CommonObject.UserExtensionObject()
            UserExtension.SetDefinesDict(DefinesDictNew)
            UserExtension.SetIdentifier('DefineModifiers')
            UserExtension.SetUserID('EDK2')
            self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension])
        #
        # Get all meta-file header information
        # the record is list of items formated:
        # [LineValue, Arch, StartLine, ID, Third]
        #
        InfHeaderObj = self.Parser.InfHeader
        #
        # Put header information into POM object
        #
        if self.UniFileClassObject:
            Lang = DT.TAB_LANGUAGE_EN_X
        else:
            Lang = DT.TAB_LANGUAGE_EN_US
        if InfHeaderObj.GetAbstract():
            self.SetAbstract((Lang, InfHeaderObj.GetAbstract()))
        if InfHeaderObj.GetDescription():
            self.SetDescription((Lang, InfHeaderObj.GetDescription()))
        if InfHeaderObj.GetCopyright():
            self.SetCopyright(('', InfHeaderObj.GetCopyright()))
        if InfHeaderObj.GetLicense():
            self.SetLicense(('', InfHeaderObj.GetLicense()))
        #
        # Put Binary header information into POM object
        #
        InfBinaryHeaderObj = self.Parser.InfBinaryHeader
        if InfBinaryHeaderObj.GetAbstract():
            self.SetBinaryHeaderAbstract((Lang, InfBinaryHeaderObj.GetAbstract()))
        if InfBinaryHeaderObj.GetDescription():
            self.SetBinaryHeaderDescription((Lang, InfBinaryHeaderObj.GetDescription()))
        if InfBinaryHeaderObj.GetCopyright():
            self.SetBinaryHeaderCopyright(('', InfBinaryHeaderObj.GetCopyright()))
        if InfBinaryHeaderObj.GetLicense():
            self.SetBinaryHeaderLicense(('', InfBinaryHeaderObj.GetLicense()))
Example #27
0
def GetLibInstanceInfo(String, WorkSpace, LineNo):

    FileGuidString = ""
    VerString = ""

    OrignalString = String
    String = String.strip()
    if not String:
        return None, None
    #
    # Remove "#" characters at the beginning
    #
    String = GetHelpStringByRemoveHashKey(String)
    String = String.strip()

    #
    # Validate file name exist.
    #
    FullFileName = os.path.normpath(
        os.path.realpath(os.path.join(WorkSpace, String)))
    if not (ValidFile(FullFileName)):
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_FILELIST_EXIST % (String),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OrignalString)

    #
    # Validate file exist/format.
    #
    if IsValidPath(String, WorkSpace):
        IsValidFileFlag = True
    else:
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                     (String),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OrignalString)
        return False
    if IsValidFileFlag:
        FileLinesList = []

        try:
            FInputfile = open(FullFileName, "rb", 0)
            try:
                FileLinesList = FInputfile.readlines()
            except BaseException:
                Logger.Error("InfParser",
                             ToolError.FILE_READ_FAILURE,
                             ST.ERR_FILE_OPEN_FAILURE,
                             File=FullFileName)
            finally:
                FInputfile.close()
        except BaseException:
            Logger.Error("InfParser",
                         ToolError.FILE_READ_FAILURE,
                         ST.ERR_FILE_OPEN_FAILURE,
                         File=FullFileName)

        ReFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$")
        ReVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$")

        FileLinesList = ProcessLineExtender(FileLinesList)

        for Line in FileLinesList:
            if ReFileGuidPattern.match(Line):
                FileGuidString = Line
            if ReVerStringPattern.match(Line):
                VerString = Line

        if FileGuidString:
            FileGuidString = GetSplitValueList(FileGuidString, '=', 1)[1]
        if VerString:
            VerString = GetSplitValueList(VerString, '=', 1)[1]

        return FileGuidString, VerString
Example #28
0
def SetValueDatumTypeMaxSizeToken(PcdItem,
                                  CurrentLineOfPcdItem,
                                  PcdItemObj,
                                  Arch,
                                  PackageInfo=None):
    #
    # Package information not been generated currently, we need to parser INF file to get information.
    #
    if not PackageInfo:
        PackageInfo = []
        InfFileName = CurrentLineOfPcdItem[2]
        PackageInfoList = GetPackageListInfo(InfFileName,
                                             GlobalData.gWORKSPACE, -1)
        for PackageInfoListItem in PackageInfoList:
            PackageInfoIns = InfPackageItem()
            PackageInfoIns.SetPackageName(PackageInfoListItem)
            PackageInfo.append(PackageInfoIns)

    PcdInfoInDecHasFound = False
    for PackageItem in PackageInfo:
        if PcdInfoInDecHasFound:
            break
        PackageName = PackageItem.PackageName
        #
        # Open DEC file to get information
        #
        FullFileName = os.path.normpath(
            os.path.realpath(os.path.join(GlobalData.gWORKSPACE, PackageName)))

        DecParser = None
        if FullFileName not in GlobalData.gPackageDict:
            DecParser = Dec(FullFileName)
            GlobalData.gPackageDict[FullFileName] = DecParser
        else:
            DecParser = GlobalData.gPackageDict[FullFileName]

        #
        # Find PCD information.
        #
        DecPcdsDict = DecParser.GetPcdSectionObject().ValueDict
        for Key in DecPcdsDict.keys():
            if (Key[0] == 'PCDSDYNAMICEX' and PcdItemObj.GetItemType() == 'PcdEx') and \
                (Key[1] == 'COMMON' or Key[1] == Arch):
                for PcdInDec in DecPcdsDict[Key]:
                    if PcdInDec.TokenCName == PcdItemObj.CName and \
                       PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName:
                        PcdItemObj.SetToken(PcdInDec.TokenValue)
                        PcdItemObj.SetDatumType(PcdInDec.DatumType)
                        PcdItemObj.SetSupportArchList([Arch])
                        PcdItemObj.SetDefaultValue(PcdInDec.DefaultValue)

            if (Key[0] == 'PCDSPATCHABLEINMODULE' and PcdItemObj.GetItemType() == 'PatchPcd') and \
           (Key[1] == 'COMMON' or Key[1] == Arch):
                for PcdInDec in DecPcdsDict[Key]:
                    if PcdInDec.TokenCName == PcdItemObj.CName and \
                       PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName:
                        PcdItemObj.SetToken(PcdInDec.TokenValue)
                        PcdItemObj.SetDatumType(PcdInDec.DatumType)
                        PcdItemObj.SetSupportArchList([Arch])

        if PcdItemObj.GetDatumType() == 'VOID*':
            if len(PcdItem) > 1:
                PcdItemObj.SetMaxDatumSize(
                    '%s' %
                    (len(GetSplitValueList(PcdItem[1], DT.TAB_COMMA_SPLIT))))

        DecGuidsDict = DecParser.GetGuidSectionObject().ValueDict
        for Key in DecGuidsDict.keys():
            if Key == 'COMMON' or Key == Arch:
                for GuidInDec in DecGuidsDict[Key]:
                    if GuidInDec.GuidCName == PcdItemObj.TokenSpaceGuidCName:
                        PcdItemObj.SetTokenSpaceGuidValue(GuidInDec.GuidString)

    if PcdItemObj.GetItemType().upper() == DT.TAB_INF_PATCH_PCD.upper():
        #
        # Validate Value.
        #
        # convert the value from a decimal 0 to a formatted hex value.
        if PcdItem[1] == "0":
            DatumType = PcdItemObj.GetDatumType()
            if DatumType == "UINT8":
                PcdItem[1] = "0x00"
            if DatumType == "UINT16":
                PcdItem[1] = "0x0000"
            if DatumType == "UINT32":
                PcdItem[1] = "0x00000000"
            if DatumType == "UINT64":
                PcdItem[1] = "0x0000000000000000"

        if ValidatePcdValueOnDatumType(PcdItem[1], PcdItemObj.GetDatumType()):
            PcdItemObj.SetDefaultValue(PcdItem[1])
        else:
            Logger.Error("InfParser",
                         ToolError.FORMAT_INVALID,
                         ST.ERR_ASBUILD_PCD_VALUE_INVALID %
                         ("\"" + PcdItem[1] + "\"",
                          "\"" + PcdItemObj.GetDatumType() + "\""),
                         File=CurrentLineOfPcdItem[2],
                         Line=CurrentLineOfPcdItem[1],
                         ExtraData=CurrentLineOfPcdItem[0])
        #
        # validate offset
        #
        if PcdItemObj.GetItemType().upper() == DT.TAB_INF_PATCH_PCD.upper():
            if not IsHexDigitUINT32(PcdItem[2]):
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_ASBUILD_PCD_OFFSET_FORMAT_INVALID %
                             ("\"" + PcdItem[2] + "\""),
                             File=CurrentLineOfPcdItem[2],
                             Line=CurrentLineOfPcdItem[1],
                             ExtraData=CurrentLineOfPcdItem[0])
            PcdItemObj.SetOffset(PcdItem[2])

    if PcdItemObj.GetToken() == '' or PcdItemObj.GetDatumType() == '':
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_ASBUILD_PCD_DECLARITION_MISS %
                     ("\"" + PcdItem[0] + "\""),
                     File=CurrentLineOfPcdItem[2],
                     Line=CurrentLineOfPcdItem[1],
                     ExtraData=CurrentLineOfPcdItem[0])

    return PcdItemObj
Example #29
0
def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):
    #
    # generate section
    #
    Content = ''
    NewSectionDict = {}
    for Obj in ObjectList:
        #
        # Generate comment
        #
        CommentStr = ''
        HelpTextList = Obj.GetHelpTextList()
        HelpStr = _GetHelpStr(HelpTextList)
        CommentStr = GenGenericCommentF(HelpStr)
        if SectionName == 'Hob':
            Type = Obj.GetHobType()
        elif SectionName == 'Event':
            Type = Obj.GetEventType()
        elif SectionName == 'BootMode':
            Type = Obj.GetSupportedBootModes()
        else:
            assert (SectionName)
        Usage = Obj.GetUsage()

        # If the content already in UserExtensionsContent then ignore
        if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:
            return ''

        Statement = ' ' + Type + ' ## ' + Usage
        if CommentStr in ['#\n', '#\n#\n']:
            CommentStr = '#\n#\n#\n'
        #
        # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'
        # else add '##\n' to meet the format defined in INF spec
        #
        if CommentStr.startswith('#\n'):
            CommentStr = '#' + CommentStr
        elif CommentStr:
            CommentStr = '##\n' + CommentStr
        if CommentStr and not CommentStr.endswith('\n#\n'):
            CommentStr = CommentStr + '#\n'
        NewStateMent = CommentStr + Statement
        SupArch = sorted(Obj.GetSupArchList())
        SortedArch = ' '.join(SupArch)
        if SortedArch in NewSectionDict:
            NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [
                NewStateMent
            ]
        else:
            NewSectionDict[SortedArch] = [NewStateMent]
    SectionContent = GenSection(SectionName, NewSectionDict)
    SectionContent = SectionContent.strip()
    if SectionContent:
        Content = '# ' + ('\n' + '# ').join(
            GetSplitValueList(SectionContent, '\n'))
        Content = Content.lstrip()
    #
    # add a return to differentiate it between other possible sections
    #
    if Content:
        Content += '\n'
    return Content
Example #30
0
    def ParseDecComment(self):
        IsFileHeader = False
        IsBinaryHeader = False
        FileHeaderLineIndex = -1
        BinaryHeaderLineIndex = -1
        TokenSpaceGuidCName = ''

        #
        # Parse PCD error comment section
        #
        while not self._RawData.IsEndOfFile():
            self._RawData.CurrentLine = self._RawData.GetNextLine()
            if self._RawData.CurrentLine.startswith(DT.TAB_COMMENT_SPLIT) and \
                DT.TAB_SECTION_START in self._RawData.CurrentLine and \
                DT.TAB_SECTION_END in self._RawData.CurrentLine:
                self._RawData.CurrentLine = self._RawData.CurrentLine.replace(DT.TAB_COMMENT_SPLIT, '').strip()

                if self._RawData.CurrentLine[0] == DT.TAB_SECTION_START and \
                    self._RawData.CurrentLine[-1] == DT.TAB_SECTION_END:
                    RawSection = self._RawData.CurrentLine[1:-1].strip()
                    if RawSection.upper().startswith(DT.TAB_PCD_ERROR.upper()+'.'):
                        TokenSpaceGuidCName = RawSection.split(DT.TAB_PCD_ERROR+'.')[1].strip()
                        continue

            if TokenSpaceGuidCName and self._RawData.CurrentLine.startswith(DT.TAB_COMMENT_SPLIT):
                self._RawData.CurrentLine = self._RawData.CurrentLine.replace(DT.TAB_COMMENT_SPLIT, '').strip()
                if self._RawData.CurrentLine != '':
                    if DT.TAB_VALUE_SPLIT not in self._RawData.CurrentLine:
                        self._LoggerError(ST.ERR_DECPARSE_PCDERRORMSG_MISS_VALUE_SPLIT)

                    PcdErrorNumber, PcdErrorMsg = GetSplitValueList(self._RawData.CurrentLine, DT.TAB_VALUE_SPLIT, 1)
                    PcdErrorNumber = ParsePcdErrorCode(PcdErrorNumber, self._RawData.Filename, self._RawData.LineIndex)
                    if not PcdErrorMsg.strip():
                        self._LoggerError(ST.ERR_DECPARSE_PCD_MISS_ERRORMSG)

                    self.PcdErrorCommentDict[(TokenSpaceGuidCName, PcdErrorNumber)] = PcdErrorMsg.strip()
            else:
                TokenSpaceGuidCName = ''

        self._RawData.LineIndex = 0
        self._RawData.CurrentLine = ''
        self._RawData.NextLine = ''

        while not self._RawData.IsEndOfFile():
            Line, Comment = CleanString(self._RawData.GetNextLine())

            #
            # Header must be pure comment
            #
            if Line != '':
                self._RawData.UndoNextLine()
                break

            if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) and Comment.find(DT.TAB_HEADER_COMMENT) > 0 \
                and not Comment[2:Comment.find(DT.TAB_HEADER_COMMENT)].strip():
                IsFileHeader = True
                IsBinaryHeader = False
                FileHeaderLineIndex = self._RawData.LineIndex

            #
            # Get license information before '@file'
            #
            if not IsFileHeader and not IsBinaryHeader and Comment and Comment.startswith(DT.TAB_COMMENT_SPLIT) and \
            DT.TAB_BINARY_HEADER_COMMENT not in Comment:
                self._HeadComment.append((Comment, self._RawData.LineIndex))

            if Comment and IsFileHeader and \
            not(Comment.startswith(DT.TAB_SPECIAL_COMMENT) \
            and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0):
                self._HeadComment.append((Comment, self._RawData.LineIndex))
            #
            # Double '#' indicates end of header comments
            #
            if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsFileHeader:
                IsFileHeader = False
                continue

            if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) \
            and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0:
                IsBinaryHeader = True
                IsFileHeader = False
                BinaryHeaderLineIndex = self._RawData.LineIndex

            if Comment and IsBinaryHeader:
                self.BinaryHeadComment.append((Comment, self._RawData.LineIndex))
            #
            # Double '#' indicates end of header comments
            #
            if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsBinaryHeader:
                IsBinaryHeader = False
                break

            if FileHeaderLineIndex > -1 and not IsFileHeader and not IsBinaryHeader:
                break

        if FileHeaderLineIndex > BinaryHeaderLineIndex and FileHeaderLineIndex > -1 and BinaryHeaderLineIndex > -1:
            self._LoggerError(ST.ERR_BINARY_HEADER_ORDER)

        if FileHeaderLineIndex == -1:
#            self._LoggerError(ST.ERR_NO_SOURCE_HEADER)
            Logger.Error(TOOL_NAME, FORMAT_INVALID,
                         ST.ERR_NO_SOURCE_HEADER,
                         File=self._RawData.Filename)
        return
Example #31
0
    def _ParseItem(self):
        Line = self._RawData.CurrentLine
        TokenList = Line.split(DT.TAB_VALUE_SPLIT)
        if len(TokenList) < 4:
            self._LoggerError(ST.ERR_DECPARSE_PCD_SPLIT)

        #
        # Token space guid C name
        #
        PcdName = GetSplitValueList(TokenList[0], DT.TAB_SPLIT)
        if len(PcdName) != 2 or PcdName[0] == '' or PcdName[1] == '':
            self._LoggerError(ST.ERR_DECPARSE_PCD_NAME)

        Guid = PcdName[0]
        if not IsValidToken(CVAR_PATTERN, Guid):
            self._LoggerError(ST.ERR_DECPARSE_PCD_CVAR_GUID)

        #
        # PCD C name
        #
        CName = PcdName[1]
        if not IsValidToken(CVAR_PATTERN, CName):
            self._LoggerError(ST.ERR_DECPARSE_PCD_CVAR_PCDCNAME)

        self._CheckReDefine(Guid + DT.TAB_SPLIT + CName)

        #
        # Default value, may be C array, string or number
        #
        Data = DT.TAB_VALUE_SPLIT.join(TokenList[1:-2]).strip()

        #
        # PCD data type
        #
        DataType = TokenList[-2].strip()
        Valid, Cause = IsValidPcdDatum(DataType, Data)
        if not Valid:
            self._LoggerError(Cause)
        PcdType = self._RawData.CurrentScope[0][0]
        if PcdType == DT.TAB_PCDS_FEATURE_FLAG_NULL.upper() and DataType != 'BOOLEAN':
            self._LoggerError(ST.ERR_DECPARSE_PCD_FEATUREFLAG)
        #
        # Token value is the last element in list.
        #
        Token = TokenList[-1].strip()
        if not IsValidToken(PCD_TOKEN_PATTERN, Token):
            self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN % Token)
        elif not Token.startswith('0x') and not Token.startswith('0X'):
            if int(Token) > 4294967295:
                self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token)
            Token = hex(int(Token))

        IntToken = int(Token, 0)
        if (Guid, IntToken) in self.TokenMap:
            if self.TokenMap[Guid, IntToken] != CName:
                self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_UNIQUE%(Token))
        else:
            self.TokenMap[Guid, IntToken] = CName

        Item = DecPcdItemObject(Guid, CName, Data, DataType, Token)
        self.ItemObject.AddItem(Item, self._RawData.CurrentScope)
        return Item
Example #32
0
    def _SectionHeaderParser(self):
        if self._RawData.CurrentLine[0] != DT.TAB_SECTION_START or self._RawData.CurrentLine[-1] != DT.TAB_SECTION_END:
            self._LoggerError(ST.ERR_DECPARSE_SECTION_IDENTIFY)

        RawSection = self._RawData.CurrentLine[1:-1].strip().upper()
        #
        # Check defines section which is only allowed to occur once and
        # no arch can be followed
        #
        if RawSection.startswith(DT.TAB_DEC_DEFINES.upper()):
            if RawSection != DT.TAB_DEC_DEFINES.upper():
                self._LoggerError(ST.ERR_DECPARSE_DEFINE_SECNAME)
        #
        # Check user extension section
        #
        if RawSection.startswith(DT.TAB_USER_EXTENSIONS.upper()):
            return self._UserExtentionSectionParser()
        self._RawData.CurrentScope = []
        SectionNames = []
        ArchList = set()
        for Item in GetSplitValueList(RawSection, DT.TAB_COMMA_SPLIT):
            if Item == '':
                self._LoggerError(ST.ERR_DECPARSE_SECTION_SUBEMPTY % self._RawData.CurrentLine)

            ItemList = GetSplitValueList(Item, DT.TAB_SPLIT)
            #
            # different types of PCD are permissible in one section
            #
            SectionName = ItemList[0]
            if SectionName not in self._SectionParser:
                self._LoggerError(ST.ERR_DECPARSE_SECTION_UNKNOW % SectionName)
            if SectionName not in SectionNames:
                SectionNames.append(SectionName)
            #
            # In DEC specification, all section headers have at most two part:
            # SectionName.Arch except UserExtention
            #
            if len(ItemList) > 2:
                self._LoggerError(ST.ERR_DECPARSE_SECTION_SUBTOOMANY % Item)

            if DT.TAB_PCDS_FEATURE_FLAG_NULL.upper() in SectionNames and len(SectionNames) > 1:
                self._LoggerError(ST.ERR_DECPARSE_SECTION_FEATUREFLAG % DT.TAB_PCDS_FEATURE_FLAG_NULL)
            #
            # S1 is always Arch
            #
            if len(ItemList) > 1:
                Str1 = ItemList[1]
                if not IsValidArch(Str1):
                    self._LoggerError(ST.ERR_DECPARSE_ARCH)
            else:
                Str1 = 'COMMON'
            ArchList.add(Str1)

            if [SectionName, Str1] not in self._RawData.CurrentScope:
                self._RawData.CurrentScope.append([SectionName, Str1])
        #
        # 'COMMON' must not be used with specific ARCHs at the same section
        #
        if 'COMMON' in ArchList and len(ArchList) > 1:
            self._LoggerError(ST.ERR_DECPARSE_SECTION_COMMON)
        if len(SectionNames) == 0:
            self._LoggerError(ST.ERR_DECPARSE_SECTION_SUBEMPTY % self._RawData.CurrentLine)
        if len(SectionNames) != 1:
            for Sec in SectionNames:
                if not Sec.startswith(DT.TAB_PCDS.upper()):
                    self._LoggerError(ST.ERR_DECPARSE_SECTION_NAME % str(SectionNames))