]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Parser/InfParser.py
Sync BaseTool trunk (version r2640) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfParser.py
index fb90c396f74c9746b72707f20b3e686d382f3a25..8a41eca0a71dc0b8ba31be343768aa05cf3e5e0e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file contained the parser for INF file\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -128,6 +128,10 @@ class InfParser(InfSectionParser):
         #\r
         HeaderCommentStart = False \r
         HeaderCommentEnd   = False\r
+        HeaderStarLineNo = -1\r
+        BinaryHeaderCommentStart = False \r
+        BinaryHeaderCommentEnd   = False\r
+        BinaryHeaderStarLineNo = -1\r
         \r
         #\r
         # While Section ends. parse whole section contents.\r
@@ -196,22 +200,16 @@ class InfParser(InfSectionParser):
             #\r
             if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \\r
                (Line.find(DT.TAB_HEADER_COMMENT) > -1) and \\r
-               not HeaderCommentStart:\r
-                if CurrentSection != DT.MODEL_UNKNOWN:\r
-                    Logger.Error("Parser", \r
-                                 PARSER_ERROR, \r
-                                 ST.ERR_INF_PARSER_HEADER_FILE, \r
-                                 File=Filename, \r
-                                 Line=LineNo, \r
-                                 RaiseError = Logger.IS_RAISE_ERROR)\r
-                else:\r
-                    CurrentSection = DT.MODEL_META_DATA_FILE_HEADER\r
-                    #\r
-                    # Append the first line to section lines.\r
-                    #\r
-                    SectionLines.append((Line, LineNo))\r
-                    HeaderCommentStart = True\r
-                    continue        \r
+               not HeaderCommentStart and not HeaderCommentEnd:\r
+\r
+                CurrentSection = DT.MODEL_META_DATA_FILE_HEADER\r
+                #\r
+                # Append the first line to section lines.\r
+                #\r
+                HeaderStarLineNo = LineNo\r
+                SectionLines.append((Line, LineNo))\r
+                HeaderCommentStart = True\r
+                continue        \r
             \r
             #\r
             # Collect Header content.\r
@@ -226,17 +224,72 @@ class InfParser(InfSectionParser):
             #\r
             if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \\r
                 and not HeaderCommentEnd:\r
-                SectionLines.append((Line, LineNo))\r
+                HeaderCommentEnd = True\r
+                BinaryHeaderCommentStart = False \r
+                BinaryHeaderCommentEnd   = False\r
                 HeaderCommentStart = False\r
+                if Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1:\r
+                    self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName) \r
+                    SectionLines = []\r
+                else:\r
+                    SectionLines.append((Line, LineNo))\r
                 #\r
                 # Call Header comment parser.\r
                 #\r
                 self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName)\r
                 SectionLines = []\r
+                continue\r
+\r
+            #\r
+            # check whether binary header comment section started\r
+            #\r
+            if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \\r
+                (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1) and \\r
+                not BinaryHeaderCommentStart:\r
+                SectionLines = []\r
+                CurrentSection = DT.MODEL_META_DATA_FILE_HEADER\r
+                #\r
+                # Append the first line to section lines.\r
+                #\r
+                BinaryHeaderStarLineNo = LineNo\r
+                SectionLines.append((Line, LineNo))\r
+                BinaryHeaderCommentStart = True\r
                 HeaderCommentEnd = True               \r
                 continue                   \r
  \r
             #\r
+            # check whether there are more than one binary header exist\r
+            #\r
+            if Line.startswith(DT.TAB_SPECIAL_COMMENT) and BinaryHeaderCommentStart and \\r
+                not BinaryHeaderCommentEnd and (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1):\r
+                Logger.Error('Parser',\r
+                             FORMAT_INVALID,\r
+                             ST.ERR_MULTIPLE_BINARYHEADER_EXIST,\r
+                             File=Filename)\r
+            \r
+            #\r
+            # Collect Binary Header content.\r
+            #\r
+            if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\\r
+                BinaryHeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\\r
+                BinaryHeaderCommentEnd and NextLine != '':\r
+                SectionLines.append((Line, LineNo))\r
+                continue\r
+            #\r
+            # Binary Header content end\r
+            #\r
+            if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith(DT.TAB_COMMENT_SPLIT)) and \\r
+                BinaryHeaderCommentStart and not BinaryHeaderCommentEnd:\r
+                SectionLines.append((Line, LineNo))\r
+                BinaryHeaderCommentStart = False\r
+                #\r
+                # Call Binary Header comment parser.\r
+                #\r
+                self.InfHeaderParser(SectionLines, self.InfBinaryHeader, self.FileName, True)\r
+                SectionLines = []\r
+                BinaryHeaderCommentEnd   = True               \r
+                continue                   \r
+            #\r
             # Find a new section tab\r
             # Or at the last line of INF file, \r
             # need to process the last section.\r
@@ -255,6 +308,10 @@ class InfParser(InfSectionParser):
             #\r
             if (Line.startswith(DT.TAB_SECTION_START) and \\r
                Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg:                  \r
+                \r
+                HeaderCommentEnd = True        \r
+                BinaryHeaderCommentEnd = True       \r
+                \r
                 if not LastSectionFalg:\r
                     #\r
                     # check to prevent '#' inside section header\r
@@ -333,18 +390,17 @@ class InfParser(InfSectionParser):
                 # Clear section lines\r
                 #\r
                 SectionLines = []                                             \r
-        #\r
-        # End of for\r
-        #\r
-        #\r
-        # Found the first section, No file header.\r
-        #\r
-        if DefineSectionParsedFlag and not HeaderCommentEnd:\r
+        \r
+        if HeaderStarLineNo == -1:\r
             Logger.Error("InfParser", \r
                          FORMAT_INVALID, \r
-                         ST.ERR_INF_PARSER_HEADER_MISSGING\r
+                         ST.ERR_NO_SOURCE_HEADER\r
                          File=self.FullPath)\r
-        \r
+        if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1  and HeaderStarLineNo > BinaryHeaderStarLineNo:\r
+            Logger.Error("InfParser", \r
+                        FORMAT_INVALID,\r
+                        ST.ERR_BINARY_HEADER_ORDER,\r
+                        File=self.FullPath)         \r
         #\r
         # EDKII INF should not have EDKI style comment\r
         #\r
@@ -627,4 +683,4 @@ def _ConvertSecNameToType(SectionName):
         SectionType = gINF_SECTION_DEF[SectionName.upper()]  \r
     \r
     return SectionType      \r
-        
\ No newline at end of file
+        \r