From 2bc3256ca6d439ebf5d85d5e74e5f3e68df14130 Mon Sep 17 00:00:00 2001 From: "Gao, Liming" Date: Fri, 10 Jan 2014 05:25:50 +0000 Subject: Sync BaseTool trunk (version r2640) into EDKII BaseTools. Signed-off-by: Gao, Liming Reviewed-by: Liu, Jiang A git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15089 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/UPT/Parser/InfParser.py | 112 ++++++++++++++++++------ 1 file changed, 84 insertions(+), 28 deletions(-) (limited to 'BaseTools/Source/Python/UPT/Parser/InfParser.py') diff --git a/BaseTools/Source/Python/UPT/Parser/InfParser.py b/BaseTools/Source/Python/UPT/Parser/InfParser.py index fb90c396f7..8a41eca0a7 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfParser.py @@ -1,7 +1,7 @@ ## @file # This file contained the parser for INF file # -# Copyright (c) 2011, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.
# # This program and the accompanying materials are licensed and made available # under the terms and conditions of the BSD License which accompanies this @@ -128,6 +128,10 @@ class InfParser(InfSectionParser): # HeaderCommentStart = False HeaderCommentEnd = False + HeaderStarLineNo = -1 + BinaryHeaderCommentStart = False + BinaryHeaderCommentEnd = False + BinaryHeaderStarLineNo = -1 # # While Section ends. parse whole section contents. @@ -196,22 +200,16 @@ class InfParser(InfSectionParser): # if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \ (Line.find(DT.TAB_HEADER_COMMENT) > -1) and \ - not HeaderCommentStart: - if CurrentSection != DT.MODEL_UNKNOWN: - Logger.Error("Parser", - PARSER_ERROR, - ST.ERR_INF_PARSER_HEADER_FILE, - File=Filename, - Line=LineNo, - RaiseError = Logger.IS_RAISE_ERROR) - else: - CurrentSection = DT.MODEL_META_DATA_FILE_HEADER - # - # Append the first line to section lines. - # - SectionLines.append((Line, LineNo)) - HeaderCommentStart = True - continue + 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. @@ -226,17 +224,72 @@ class InfParser(InfSectionParser): # if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \ and not HeaderCommentEnd: - SectionLines.append((Line, LineNo)) + 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. @@ -255,6 +308,10 @@ class InfParser(InfSectionParser): # 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 @@ -333,18 +390,17 @@ class InfParser(InfSectionParser): # Clear section lines # SectionLines = [] - # - # End of for - # - # - # Found the first section, No file header. - # - if DefineSectionParsedFlag and not HeaderCommentEnd: + + if HeaderStarLineNo == -1: Logger.Error("InfParser", FORMAT_INVALID, - ST.ERR_INF_PARSER_HEADER_MISSGING, + 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 # @@ -627,4 +683,4 @@ def _ConvertSecNameToType(SectionName): SectionType = gINF_SECTION_DEF[SectionName.upper()] return SectionType - \ No newline at end of file + -- cgit v1.2.3