Пример #1
0
 def __init__(self):
     self.Binaries = Sdict()
     #
     # Macro defined in this section should be only used in this section.
     #
     self.Macros = {}
     InfSectionCommonDef.__init__(self)
Пример #2
0
 def __init__(self):
     self.Binaries = Sdict()
     #
     # Macro defined in this section should be only used in this section.
     #
     self.Macros = {}
     InfSectionCommonDef.__init__(self)
Пример #3
0
    def ParseInfFile(self, Filename):

        Filename = NormPath(Filename)
        (Path, Name) = os.path.split(Filename)
        self.FullPath = Filename
        self.RelaPath = Path
        self.FileName = Name
        GlobalData.gINF_MODULE_DIR = Path
        GlobalData.gINF_MODULE_NAME = self.FullPath
        GlobalData.gIS_BINARY_INF = False
        #
        # Initialize common data
        #
        LineNo = 0
        CurrentSection = DT.MODEL_UNKNOWN
        SectionLines = []

        #
        # Flags
        #
        HeaderCommentStart = False
        HeaderCommentEnd = False
        HeaderStarLineNo = -1
        BinaryHeaderCommentStart = False
        BinaryHeaderCommentEnd = False
        BinaryHeaderStarLineNo = -1

        #
        # While Section ends. parse whole section contents.
        #
        NewSectionStartFlag = False
        FirstSectionStartFlag = False

        #
        # Parse file content
        #
        CommentBlock = []

        #
        # Variables for Event/Hob/BootMode
        #
        self.EventList = []
        self.HobList = []
        self.BootModeList = []
        SectionType = ''

        FileLinesList = OpenInfFile(Filename)

        #
        # One INF file can only has one [Defines] section.
        #
        DefineSectionParsedFlag = False

        #
        # Convert special characters in lines to space character.
        #
        FileLinesList = ConvertSpecialChar(FileLinesList)

        #
        # Process Line Extender
        #
        FileLinesList = ProcessLineExtender(FileLinesList)

        #
        # Process EdkI INF style comment if found
        #
        OrigLines = [Line for Line in FileLinesList]
        FileLinesList, EdkCommentStartPos = ProcessEdkComment(FileLinesList)

        #
        # Judge whether the INF file is Binary INF or not
        #
        if IsBinaryInf(FileLinesList):
            GlobalData.gIS_BINARY_INF = True

        InfSectionCommonDefObj = None

        for Line in FileLinesList:
            LineNo = LineNo + 1
            Line = Line.strip()
            if (LineNo < len(FileLinesList) - 1):
                NextLine = FileLinesList[LineNo].strip()

            #
            # blank line
            #
            if (Line == '' or not Line) and LineNo == len(FileLinesList):
                LastSectionFalg = True

            #
            # check whether file header comment section started
            #
            if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \
               (Line.find(DT.TAB_HEADER_COMMENT) > -1) and \
               not HeaderCommentStart and not HeaderCommentEnd:

                CurrentSection = DT.MODEL_META_DATA_FILE_HEADER
                #
                # Append the first line to section lines.
                #
                HeaderStarLineNo = LineNo
                SectionLines.append((Line, LineNo))
                HeaderCommentStart = True
                continue

            #
            # Collect Header content.
            #
            if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\
                HeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\
                HeaderCommentEnd and NextLine != '':
                SectionLines.append((Line, LineNo))
                continue
            #
            # Header content end
            #
            if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \
                and not HeaderCommentEnd:
                HeaderCommentEnd = True
                BinaryHeaderCommentStart = False
                BinaryHeaderCommentEnd = False
                HeaderCommentStart = False
                if Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1:
                    self.InfHeaderParser(SectionLines, self.InfHeader,
                                         self.FileName)
                    SectionLines = []
                else:
                    SectionLines.append((Line, LineNo))
                    #
                    # Call Header comment parser.
                    #
                    self.InfHeaderParser(SectionLines, self.InfHeader,
                                         self.FileName)
                    SectionLines = []
                    continue

            #
            # check whether binary header comment section started
            #
            if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \
                (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1) and \
                not BinaryHeaderCommentStart:
                SectionLines = []
                CurrentSection = DT.MODEL_META_DATA_FILE_HEADER
                #
                # Append the first line to section lines.
                #
                BinaryHeaderStarLineNo = LineNo
                SectionLines.append((Line, LineNo))
                BinaryHeaderCommentStart = True
                HeaderCommentEnd = True
                continue

            #
            # check whether there are more than one binary header exist
            #
            if Line.startswith(DT.TAB_SPECIAL_COMMENT) and BinaryHeaderCommentStart and \
                not BinaryHeaderCommentEnd and (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1):
                Logger.Error('Parser',
                             FORMAT_INVALID,
                             ST.ERR_MULTIPLE_BINARYHEADER_EXIST,
                             File=Filename)

            #
            # Collect Binary Header content.
            #
            if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\
                BinaryHeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\
                BinaryHeaderCommentEnd and NextLine != '':
                SectionLines.append((Line, LineNo))
                continue
            #
            # Binary Header content end
            #
            if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith(DT.TAB_COMMENT_SPLIT)) and \
                BinaryHeaderCommentStart and not BinaryHeaderCommentEnd:
                SectionLines.append((Line, LineNo))
                BinaryHeaderCommentStart = False
                #
                # Call Binary Header comment parser.
                #
                self.InfHeaderParser(SectionLines, self.InfBinaryHeader,
                                     self.FileName, True)
                SectionLines = []
                BinaryHeaderCommentEnd = True
                continue
            #
            # Find a new section tab
            # Or at the last line of INF file,
            # need to process the last section.
            #
            LastSectionFalg = False
            if LineNo == len(FileLinesList):
                LastSectionFalg = True

            if Line.startswith(DT.TAB_COMMENT_SPLIT) and not Line.startswith(
                    DT.TAB_SPECIAL_COMMENT):
                SectionLines.append((Line, LineNo))
                if not LastSectionFalg:
                    continue

            #
            # Encountered a section. start with '[' and end with ']'
            #
            if (Line.startswith(DT.TAB_SECTION_START) and \
               Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg:

                HeaderCommentEnd = True
                BinaryHeaderCommentEnd = True

                if not LastSectionFalg:
                    #
                    # check to prevent '#' inside section header
                    #
                    HeaderContent = Line[1:Line.find(DT.TAB_SECTION_END)]
                    if HeaderContent.find(DT.TAB_COMMENT_SPLIT) != -1:
                        Logger.Error(
                            "InfParser",
                            FORMAT_INVALID,
                            ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,
                            File=self.FullPath,
                            Line=LineNo,
                            ExtraData=Line)

                    #
                    # Keep last time section header content for section parser
                    # usage.
                    #
                    self.LastSectionHeaderContent = deepcopy(
                        self.SectionHeaderContent)

                    #
                    # TailComments in section define.
                    #
                    TailComments = ''
                    CommentIndex = Line.find(DT.TAB_COMMENT_SPLIT)
                    if CommentIndex > -1:
                        TailComments = Line[CommentIndex:]
                        Line = Line[:CommentIndex]

                    InfSectionCommonDefObj = InfSectionCommonDef()
                    if TailComments != '':
                        InfSectionCommonDefObj.SetTailComments(TailComments)
                    if CommentBlock != '':
                        InfSectionCommonDefObj.SetHeaderComments(CommentBlock)
                        CommentBlock = []
                    #
                    # Call section parser before section header parer to avoid encounter EDKI INF file
                    #
                    if CurrentSection == DT.MODEL_META_DATA_DEFINE:
                        DefineSectionParsedFlag = self._CallSectionParsers(
                            CurrentSection, DefineSectionParsedFlag,
                            SectionLines, InfSectionCommonDefObj, LineNo)
                    #
                    # Compare the new section name with current
                    #
                    self.SectionHeaderParser(Line, self.FileName, LineNo)

                    self._CheckSectionHeaders(Line, LineNo)

                    SectionType = _ConvertSecNameToType(
                        self.SectionHeaderContent[0][0])

                if not FirstSectionStartFlag:
                    CurrentSection = SectionType
                    FirstSectionStartFlag = True
                else:
                    NewSectionStartFlag = True
            else:
                SectionLines.append((Line, LineNo))
                continue

            if LastSectionFalg:
                SectionLines, CurrentSection = self._ProcessLastSection(
                    SectionLines, Line, LineNo, CurrentSection)

            #
            # End of section content collect.
            # Parser the section content collected previously.
            #
            if NewSectionStartFlag or LastSectionFalg:
                if CurrentSection != DT.MODEL_META_DATA_DEFINE or \
                    (LastSectionFalg and CurrentSection == DT.MODEL_META_DATA_DEFINE):
                    DefineSectionParsedFlag = self._CallSectionParsers(
                        CurrentSection, DefineSectionParsedFlag, SectionLines,
                        InfSectionCommonDefObj, LineNo)

                CurrentSection = SectionType
                #
                # Clear section lines
                #
                SectionLines = []

        if HeaderStarLineNo == -1:
            Logger.Error("InfParser",
                         FORMAT_INVALID,
                         ST.ERR_NO_SOURCE_HEADER,
                         File=self.FullPath)
        if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1 and HeaderStarLineNo > BinaryHeaderStarLineNo:
            Logger.Error("InfParser",
                         FORMAT_INVALID,
                         ST.ERR_BINARY_HEADER_ORDER,
                         File=self.FullPath)
        #
        # EDKII INF should not have EDKI style comment
        #
        if EdkCommentStartPos != -1:
            Logger.Error("InfParser",
                         FORMAT_INVALID,
                         ST.ERR_INF_PARSER_EDKI_COMMENT_IN_EDKII,
                         File=self.FullPath,
                         Line=EdkCommentStartPos + 1,
                         ExtraData=OrigLines[EdkCommentStartPos])

        #
        # extract [Event] [Hob] [BootMode] sections
        #
        self._ExtractEventHobBootMod(FileLinesList)
Пример #4
0
 def __init__(self):
     self.SpecialComments = Sdict()
     InfSectionCommonDef.__init__(self)
Пример #5
0
 def __init__(self):
     self.Defines = Sdict()
     InfSectionCommonDef.__init__(self)
 def __init__(self):
     self.Defines = Sdict()
     InfSectionCommonDef.__init__(self)
 def __init__(self):
     self.Depex = []
     self.AllContent = ''
     self.SectionContent = ''
     InfSectionCommonDef.__init__(self)
Пример #8
0
 def __init__(self):
     self.BuildOptions = []
     InfSectionCommonDef.__init__(self)
Пример #9
0
 def __init__(self):
     self.SpecialComments = Sdict()
     InfSectionCommonDef.__init__(self)
Пример #10
0
 def __init__(self):
     self.Sources = Sdict()
     InfSectionCommonDef.__init__(self)
Пример #11
0
 def __init__(self):
     self.Depex = []
     self.AllContent = ''
     self.SectionContent = ''
     InfSectionCommonDef.__init__(self)
Пример #12
0
 def __init__(self):
     self.Sources = Sdict()
     InfSectionCommonDef.__init__(self)