예제 #1
0
def GetPcdOfInf(Item, Type, File, LineNo):
    Format = '<TokenSpaceGuidCName>.<PcdCName>[|<Value>]'
    TokenGuid, TokenName, Value, InfType = '', '', '', ''

    if Type == DataType.TAB_PCDS_FIXED_AT_BUILD:
        InfType = DataType.TAB_INF_FIXED_PCD
    elif Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE:
        InfType = DataType.TAB_INF_PATCH_PCD
    elif Type == DataType.TAB_PCDS_FEATURE_FLAG:
        InfType = DataType.TAB_INF_FEATURE_PCD
    elif Type == DataType.TAB_PCDS_DYNAMIC_EX:
        InfType = DataType.TAB_INF_PCD_EX
    elif Type == DataType.TAB_PCDS_DYNAMIC:
        InfType = DataType.TAB_INF_PCD
    List = GetSplitValueList(Item, DataType.TAB_VALUE_SPLIT, 1)
    TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)
    if len(TokenInfo) != 2:
        RaiseParserError(Item, InfType, File, Format, LineNo)
    else:
        TokenGuid = TokenInfo[0]
        TokenName = TokenInfo[1]

    if len(List) > 1:
        Value = List[1]
    else:
        Value = None
    return (TokenGuid, TokenName, Value, InfType)
예제 #2
0
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
예제 #3
0
    def testNormalCase2(self):
        TestCommentLines = \
        '''## hello world
        # second line
        # @ValidList 1, 2, 3
        # 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')
        ExpectedList = GetSplitValueList('1 2 3', TAB_SPACE_SPLIT)
        ActualList = [item for item in \
            GetSplitValueList(PcdErr.GetValidValue(), TAB_SPACE_SPLIT) if item]
        self.assertEqual(ExpectedList, ActualList)
        self.failIf(PcdErr.GetExpression())
        self.failIf(PcdErr.GetValidValueRange())
예제 #4
0
    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
예제 #5
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()

    FileLinesList = GetFileLineContent(String, WorkSpace, LineNo,
                                       OrignalString)

    ReFindFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$")
    ReFindVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$")

    FileLinesList = ProcessLineExtender(FileLinesList)

    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]

    return FileGuidString, VerString
예제 #6
0
def GenSection(SectionName, SectionDict, SplitArch=True):
    Content = ''
    for SectionAttrs in SectionDict:
        StatementList = SectionDict[SectionAttrs]
        if SectionAttrs and SectionName != 'Defines' and SectionAttrs.strip(
        ).upper() != DataType.TAB_ARCH_COMMON:
            if SplitArch:
                ArchList = GetSplitValueList(SectionAttrs,
                                             DataType.TAB_SPACE_SPLIT)
            else:
                if SectionName != 'UserExtensions':
                    ArchList = GetSplitValueList(SectionAttrs,
                                                 DataType.TAB_COMMENT_SPLIT)
                else:
                    ArchList = [SectionAttrs]
            for Index in xrange(0, len(ArchList)):
                ArchList[Index] = ConvertArchForInstall(ArchList[Index])
            Section = '[' + SectionName + '.' + (', ' + SectionName +
                                                 '.').join(ArchList) + ']'
        else:
            Section = '[' + SectionName + ']'
        Content += '\n\n' + Section + '\n'
        if StatementList != None:
            for Statement in StatementList:
                Content += Statement + '\n'

    return Content
예제 #7
0
def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName):

    FileGuidString = ""
    VerString = ""

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

    #
    # To deal with library instance specified by GUID and version
    #
    RegFormatGuidPattern = re.compile("\s*([0-9a-fA-F]){8}-"
                                      "([0-9a-fA-F]){4}-"
                                      "([0-9a-fA-F]){4}-"
                                      "([0-9a-fA-F]){4}-"
                                      "([0-9a-fA-F]){12}\s*")
    VersionPattern = re.compile('[\t\s]*\d+(\.\d+)?[\t\s]*')
    GuidMatchedObj = RegFormatGuidPattern.search(String)

    if String.upper().startswith(
            'GUID') and GuidMatchedObj and 'Version' in String:
        VersionStr = String[String.upper().find('VERSION') + 8:]
        VersionMatchedObj = VersionPattern.search(VersionStr)
        if VersionMatchedObj:
            Guid = GuidMatchedObj.group().strip()
            Version = VersionMatchedObj.group().strip()
            return GetGuidVerFormLibInstance(Guid, Version, WorkSpace,
                                             CurrentInfFileName)

    #
    # To deal with library instance specified by file name
    #
    FileLinesList = GetFileLineContent(String, WorkSpace, LineNo,
                                       OrignalString)

    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]

    return FileGuidString, VerString
예제 #8
0
 def FromXml(self, Item, Key):
     if Key:
         pass
     self.Usage = XmlAttribute(Item, 'Usage')
     self.SupArchList = \
     [Arch for Arch in GetSplitValueList(XmlAttribute(Item, 'SupArchList'), DataType.TAB_SPACE_SPLIT) if Arch]
     self.SupModList = \
     [Mod for Mod in GetSplitValueList(XmlAttribute(Item, 'SupModList'), DataType.TAB_SPACE_SPLIT) if Mod]
     self.FeatureFlag = ConvertNOTEQToNE(XmlAttribute(Item, 'FeatureFlag'))
예제 #9
0
    def _CheckSectionHeaders(self, Line, LineNo):
        if len(self.SectionHeaderContent) == 0:
            Logger.Error("InfParser",
                         FORMAT_INVALID,
                         ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,
                         File=self.FullPath,
                         Line=LineNo,
                         ExtraData=Line)
        else:
            for SectionItem in self.SectionHeaderContent:
                ArchList = []
                #
                # Not cover Depex/UserExtension section header
                # check.
                #
                if SectionItem[0].strip().upper() == DT.TAB_INF_FIXED_PCD.upper() or \
                    SectionItem[0].strip().upper() == DT.TAB_INF_PATCH_PCD.upper() or \
                    SectionItem[0].strip().upper() == DT.TAB_INF_PCD_EX.upper() or \
                    SectionItem[0].strip().upper() == DT.TAB_INF_PCD.upper() or \
                    SectionItem[0].strip().upper() == DT.TAB_INF_FEATURE_PCD.upper():
                    ArchList = GetSplitValueList(SectionItem[1].strip(), ' ')
                else:
                    ArchList = [SectionItem[1].strip()]

                for Arch in ArchList:
                    if (not IsValidArch(Arch)) and \
                        (SectionItem[0].strip().upper() != DT.TAB_DEPEX.upper()) and \
                        (SectionItem[0].strip().upper() != DT.TAB_USER_EXTENSIONS.upper()) and \
                        (SectionItem[0].strip().upper() != DT.TAB_COMMON_DEFINES.upper()):
                        Logger.Error("InfParser",
                                     FORMAT_INVALID,
                                     ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                                     (SectionItem[1]),
                                     File=self.FullPath,
                                     Line=LineNo,
                                     ExtraData=Line)
                #
                # Check if the ModuleType is valid
                #
                ChkModSectionList = ['LIBRARYCLASSES']
                if (self.SectionHeaderContent[0][0].upper()
                        in ChkModSectionList):
                    if SectionItem[2].strip().upper():
                        MoudleTypeList = GetSplitValueList(
                            SectionItem[2].strip().upper())
                        if (not IsValidInfMoudleTypeList(MoudleTypeList)):
                            Logger.Error(
                                "InfParser",
                                FORMAT_INVALID,
                                ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                                (SectionItem[2]),
                                File=self.FullPath,
                                Line=LineNo,
                                ExtraData=Line)
예제 #10
0
def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo=-1):
    TokenGuid, TokenName, List1, List2 = '', '', '', ''
    List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT)
    if len(List) < 3 or len(List) > 4:
        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, \
                         '<PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>\
                         [|<MaximumDatumSize>]'                                               , LineNo)
    else:
        List1, List2 = List[1], List[2]
    if CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo):
        (TokenGuid, TokenName) = GetSplitValueList(List[0], DataType.TAB_SPLIT)

    return (TokenName, TokenGuid, List1, List2, Type)
예제 #11
0
def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo=-1):
    TokenGuid, TokenName, Value = '', '', ''
    List = GetSplitValueList(Item)
    if len(List) != 2:
        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, \
                         '<PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE', \
                         LineNo)
    else:
        Value = List[1]
    if CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo):
        (TokenGuid, TokenName) = GetSplitValueList(List[0], DataType.TAB_SPLIT)

    return (TokenName, TokenGuid, Value, Type)
예제 #12
0
def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo=-1):
    TokenGuid, TokenName, Value, DatumTyp, MaxDatumSize = '', '', '', '', ''
    List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)
    if len(List) < 4 or len(List) > 8:
        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, \
                         '<PcdTokenSpaceGuidCName>.<TokenCName>|<Value>\
                         [|<DatumTyp>[|<MaxDatumSize>]]'                                                        , LineNo)
    else:
        Value = List[1]
        DatumTyp = List[2]
        MaxDatumSize = List[3]
    if CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo):
        (TokenGuid, TokenName) = GetSplitValueList(List[0], DataType.TAB_SPLIT)

    return (TokenName, TokenGuid, Value, DatumTyp, MaxDatumSize, Type)
예제 #13
0
    def _MacroParser(self, String):
        TokenList = GetSplitValueList(String, ' ', 1)
        if len(TokenList) < 2 or TokenList[1] == '':
            self._LoggerError(ST.ERR_DECPARSE_MACRO_PAIR)

        TokenList = GetSplitValueList(TokenList[1], DT.TAB_EQUAL_SPLIT, 1)
        if TokenList[0] == '':
            self._LoggerError(ST.ERR_DECPARSE_MACRO_NAME)
        elif not IsValidToken(MACRO_PATTERN, TokenList[0]):
            self._LoggerError(ST.ERR_DECPARSE_MACRO_NAME_UPPER % TokenList[0])
        
        if len(TokenList) == 1:
            self._LocalMacro[TokenList[0]] = ''
        else:
            self._LocalMacro[TokenList[0]] = self._ReplaceMacro(TokenList[1])
예제 #14
0
def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
    Content = ''
    for SectionAttrs in SectionDict:
        StatementList = SectionDict[SectionAttrs]
        if SectionAttrs and SectionName != 'Defines' and SectionAttrs.strip(
        ).upper() != DataType.TAB_ARCH_COMMON:
            if SplitArch:
                ArchList = GetSplitValueList(SectionAttrs,
                                             DataType.TAB_SPACE_SPLIT)
            else:
                if SectionName != 'UserExtensions':
                    ArchList = GetSplitValueList(SectionAttrs,
                                                 DataType.TAB_COMMENT_SPLIT)
                else:
                    ArchList = [SectionAttrs]
            for Index in xrange(0, len(ArchList)):
                ArchList[Index] = ConvertArchForInstall(ArchList[Index])
            Section = '[' + SectionName + '.' + (', ' + SectionName +
                                                 '.').join(ArchList) + ']'
        else:
            Section = '[' + SectionName + ']'
        Content += '\n' + Section + '\n'
        if StatementList != None:
            for Statement in StatementList:
                LineList = Statement.split('\n')
                NewStatement = ""
                for Line in LineList:
                    # ignore blank comment
                    if not Line.replace(
                            "#", '').strip() and SectionName not in (
                                'Defines', 'Hob', 'Event', 'BootMode'):
                        continue
                    # add two space before non-comments line except the comments in Defines section
                    if Line.strip().startswith(
                            '#') and SectionName == 'Defines':
                        NewStatement += "%s\n" % Line
                        continue
                    NewStatement += "  %s\n" % Line
                if NeedBlankLine:
                    Content += NewStatement + '\n'
                else:
                    Content += NewStatement

        if NeedBlankLine:
            Content = Content[:-1]
    if not Content.replace('\\n', '').strip():
        return ''
    return Content
예제 #15
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, "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 '', ''
예제 #16
0
    def SetDestructor(self, Destructor, Comments):
        #
        # It can be a list and only 1 set to TRUE
        #
        ValueList = []

        TokenList = GetSplitValueList(Destructor, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList

        InfDefineDestructorItemObj = InfDefineDestructorItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineDestructorItemObj.SetCName(ValueList[0])
        if len(ValueList) >= 2:
            ModList = GetSplitValueList(ValueList[1].strip(), ' ')
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            for ModItem in ModList:
                if ModItem not in DT.MODULE_LIST:
                    ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID %
                               (ModItem),
                               LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetSupModList(ModList)
        if len(ValueList) == 3:
            if ValueList[2].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[2]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[2].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetFeatureFlagExp(ValueList[2])

        if len(ValueList) > 3:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Destructor),
                       LineInfo=self.CurrentLine)

        InfDefineDestructorItemObj.Comments = Comments
        self.Destructor.append(InfDefineDestructorItemObj)
예제 #17
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 = Obj.GetSupArchList()
        SupArch.sort()
        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
예제 #18
0
def GenTailCommentLines(TailCommentLines, LeadingSpaceNum=0):
    EndOfLine = "\n"
    TailCommentLines = TailCommentLines.rstrip(EndOfLine)
    CommentStr = "  ## " + (EndOfLine + LeadingSpaceNum * TAB_SPACE_SPLIT + \
                            "  ## ").join(GetSplitValueList(TailCommentLines, \
                                                            EndOfLine))
    return CommentStr
예제 #19
0
    def testErrorCase2(self):
        TestCommentLines = \
        '''
        ## @file
        # Abstract
        #
        this is invalid line
        # Description
        #
        # Copyright (c) 2007 - 2010, 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")
예제 #20
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
예제 #21
0
def GenTailCommentLines(TailCommentLines, LeadingSpaceNum=0):
    TailCommentLines = TailCommentLines.rstrip(END_OF_LINE)
    CommentStr = TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + \
    (END_OF_LINE + LeadingSpaceNum * TAB_SPACE_SPLIT + TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + \
     TAB_SPACE_SPLIT).join(GetSplitValueList(TailCommentLines, END_OF_LINE))

    return CommentStr
예제 #22
0
def IsValidBuildOptionName(BuildOptionName):
    if not BuildOptionName:
        return False
    
    ToolOptionList = GetSplitValueList(BuildOptionName, '_', 4)
    
    if len(ToolOptionList) != 5:
        return False
    
    ReIsValidBuildOption1 = re.compile(r"^\s*(\*)|([A-Z][a-zA-Z0-9]*)$")
    ReIsValidBuildOption2 = re.compile(r"^\s*(\*)|([a-zA-Z][a-zA-Z0-9]*)$")
    
    if ReIsValidBuildOption1.match(ToolOptionList[0]) == None:
        return False
    
    if ReIsValidBuildOption1.match(ToolOptionList[1]) == None:
        return False
    
    if ReIsValidBuildOption2.match(ToolOptionList[2]) == None:
        return False
    
    if ToolOptionList[3] == "*" and ToolOptionList[4] not in ['FAMILY', 'DLL', 'DPATH']:
        return False
           
    return True
예제 #23
0
    def SetUnloadImages(self, UnloadImages, Comments):
        #
        # It can be a list
        #
        ValueList = []
        TokenList = GetSplitValueList(UnloadImages, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList
        InfDefineUnloadImageItemObj = InfDefineUnloadImageItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.SetCName(ValueList[0])
        if len(ValueList) == 2:
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[1].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineUnloadImageItemObj.SetFeatureFlagExp(ValueList[1])

        if len(ValueList) > 2:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (UnloadImages),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.Comments = Comments
        self.UnloadImages.append(InfDefineUnloadImageItemObj)
예제 #24
0
def SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj):
    #
    # Only PCD Name specified 
    # <PcdName> ::= <TokenSpaceGuidCName> "." <TokenCName>
    #
    PcdId = GetSplitValueList(PcdItem[0], DT.TAB_SPLIT)
    if len(PcdId) != 2:
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_INF_PARSER_PCD_NAME_FORMAT_ERROR,
                     File=CurrentLineOfPcdItem[2],
                     Line=CurrentLineOfPcdItem[1],
                     ExtraData=CurrentLineOfPcdItem[0])
    else:
        #
        # Validate PcdTokenSpaceGuidCName
        #
        if not IsValidCVariableName(PcdId[0]):
            Logger.Error("InfParser",
                         ToolError.FORMAT_INVALID,
                         ST.ERR_INF_PARSER_PCD_CVAR_GUID,
                         File=CurrentLineOfPcdItem[2],
                         Line=CurrentLineOfPcdItem[1],
                         ExtraData=PcdId[0])
        if not IsValidCVariableName(PcdId[1]):
            Logger.Error("InfParser",
                         ToolError.FORMAT_INVALID,
                         ST.ERR_INF_PARSER_PCD_CVAR_PCDCNAME,
                         File=CurrentLineOfPcdItem[2],
                         Line=CurrentLineOfPcdItem[1],
                         ExtraData=PcdId[1])
        PcdItemObj.SetTokenSpaceGuidCName(PcdId[0])
        PcdItemObj.SetCName(PcdId[1])

    return PcdItemObj
예제 #25
0
 def _ParseItem(self):
     Line = self._RawData.CurrentLine
     TokenList = GetSplitValueList(Line, DT.TAB_VALUE_SPLIT)
     if len(TokenList) != 2:
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_SPLIT) 
     if TokenList[0] == '' or TokenList[1] == '':
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_EMPTY)
     if not IsValidToken('[A-Z][0-9A-Za-z]*', TokenList[0]):
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_LIB)
     
     self._CheckReDefine(TokenList[0])
     
     Value = TokenList[1]
     #
     # Must end with .h
     #
     if not Value.endswith('.h'):
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_PATH_EXT)
     
     #
     # Path must be existed
     #
     if not IsValidPath(Value, self._RawData.PackagePath):
         self._LoggerError(ST.ERR_DECPARSE_INCLUDE % Value)
     
     Item = DecLibraryclassItemObject(TokenList[0], StripRoot(self._RawData.PackagePath, Value),
                                      self._RawData.PackagePath)
     self.ItemObject.AddItem(Item, self._RawData.CurrentScope)
     return Item
예제 #26
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) == 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) == None:
        Logger.Error('Parser',
                     FORMAT_INVALID,
                     ST.ERR_MACROVALUE_INVALID % (Value),
                     ExtraData=LineContent,
                     File=FileName,
                     Line=LineNo)

    return Name, Value
예제 #27
0
 def SetSpecification(self, Specification, Comments):
     #
     # Valid the value of Specification
     #
     __ValueList = []
     TokenList = GetSplitValueList(Specification, DT.TAB_EQUAL_SPLIT, 1)
     __ValueList[0:len(TokenList)] = TokenList
     if len(__ValueList) != 2:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME + ' Or ' +
                    ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,
                    LineInfo=self.CurrentLine)
     Name = __ValueList[0].strip()
     Version = __ValueList[1].strip()
     if IsValidIdentifier(Name):
         if IsValidDecVersion(Version):
             self.Specification.append((Name, Version, Comments))
             return True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Version),
                        LineInfo=self.CurrentLine)
             return False
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Name),
                    LineInfo=self.CurrentLine)
         return False
     return True
예제 #28
0
def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo=-1):
    TokenGuid, TokenName, List1, List2, List3, List4, List5 = \
    '', '', '', '', '', '', ''
    List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)
    if len(List) < 6 or len(List) > 8:
        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, \
                         '<PcdTokenSpaceGuidCName>.<TokenCName>|<String>|\
                         <VariableGuidCName>|<VariableOffset>[|<DefaultValue>\
                         [|<MaximumDatumSize>]]'                                                , LineNo)
    else:
        List1, List2, List3, List4, List5 = \
        List[1], List[2], List[3], List[4], List[5]
    if CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo):
        (TokenGuid, TokenName) = GetSplitValueList(List[0], DataType.TAB_SPLIT)

    return (TokenName, TokenGuid, List1, List2, List3, List4, List5, Type)
예제 #29
0
def ParserPcdInfoInDec(String):
    ValueList = GetSplitValueList(String, DT.TAB_VALUE_SPLIT, 3)

    #
    # DatumType, Token
    #
    return ValueList[2], ValueList[3]
예제 #30
0
def GenGenericComment(CommentLines):
    if not CommentLines:
        return ''
    CommentLines = CommentLines.rstrip(END_OF_LINE)
    CommentStr = TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + (END_OF_LINE + TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT).join\
    (GetSplitValueList(CommentLines, END_OF_LINE)) + END_OF_LINE
    return CommentStr