]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfBinarySectionParser.py
diff --git a/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
new file mode 100644 (file)
index 0000000..36142cf
--- /dev/null
@@ -0,0 +1,217 @@
+## @file\r
+# This file contained the parser for [Binaries] sections in INF file \r
+#\r
+# Copyright (c) 2011, 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
+# distribution. The full text of the license may be found at \r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+'''\r
+InfBinarySectionParser\r
+'''\r
+##\r
+# Import Modules\r
+#\r
+\r
+import Logger.Log as Logger\r
+from Logger import StringTable as ST\r
+from Logger.ToolError import FORMAT_INVALID\r
+from Parser.InfParserMisc import InfExpandMacro\r
+from Library import DataType as DT\r
+from Library.Parsing import MacroParser\r
+from Library.Misc import GetSplitValueList\r
+from Object.Parser.InfCommonObject import InfLineCommentObject\r
+from Object.Parser.InfCommonObject import CurrentLine\r
+from Parser.InfParserMisc import InfParserSectionRoot\r
+\r
+class InfBinarySectionParser(InfParserSectionRoot):\r
+    ## InfBinaryParser\r
+    #\r
+    #\r
+    def InfBinaryParser(self, SectionString, InfSectionObject, FileName):\r
+        #\r
+        # Macro defined in this section \r
+        #\r
+        SectionMacros = {}\r
+        ValueList     = []\r
+        #\r
+        # For UI (UI, SEC_UI, UNI_UI) binaries\r
+        # One and only one UI section can be included\r
+        #\r
+        UiBinaryList  = []\r
+        #\r
+        # For Version (VER, SEC_VER, UNI_VER).\r
+        # One and only one VER section on be included\r
+        #\r
+        VerBinaryList = []\r
+        #\r
+        # For other common type binaries\r
+        #\r
+        ComBinaryList = []\r
+\r
+        StillCommentFalg  = False\r
+        HeaderComments    = []\r
+        LineComment       = None           \r
+        \r
+        AllSectionContent = ''\r
+        #\r
+        # Parse section content\r
+        #\r
+        for Line in SectionString:\r
+            BinLineContent = Line[0]\r
+            BinLineNo      = Line[1]\r
+            \r
+            if BinLineContent.strip() == '':\r
+                continue\r
+            \r
+            CurrentLineObj = CurrentLine()\r
+            CurrentLineObj.FileName = FileName\r
+            CurrentLineObj.LineString = BinLineContent\r
+            CurrentLineObj.LineNo = BinLineNo\r
+            #\r
+            # Found Header Comments \r
+            #\r
+            if BinLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
+                #\r
+                # Last line is comments, and this line go on.\r
+                #\r
+                if StillCommentFalg:\r
+                    HeaderComments.append(Line)\r
+                    AllSectionContent += BinLineContent + DT.END_OF_LINE\r
+                    continue\r
+                #\r
+                # First time encounter comment \r
+                #\r
+                else:\r
+                    #\r
+                    # Clear original data\r
+                    #\r
+                    HeaderComments = []\r
+                    HeaderComments.append(Line)\r
+                    AllSectionContent += BinLineContent + DT.END_OF_LINE\r
+                    StillCommentFalg = True\r
+                    continue\r
+            else:\r
+                StillCommentFalg = False\r
+                          \r
+            if len(HeaderComments) >= 1:\r
+                LineComment = InfLineCommentObject()\r
+                LineCommentContent = ''\r
+                for Item in HeaderComments:\r
+                    LineCommentContent += Item[0] + DT.END_OF_LINE\r
+                LineComment.SetHeaderComments(LineCommentContent)\r
+            \r
+            #\r
+            # Find Tail comment.\r
+            #\r
+            if BinLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
+                TailComments = BinLineContent[BinLineContent.find(DT.TAB_COMMENT_SPLIT):]\r
+                BinLineContent = BinLineContent[:BinLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
+                if LineComment == None:\r
+                    LineComment = InfLineCommentObject()\r
+                LineComment.SetTailComments(TailComments)            \r
+            \r
+            #\r
+            # Find Macro\r
+            #\r
+            MacroDef = MacroParser((BinLineContent, BinLineNo),\r
+                                      FileName,\r
+                                      DT.MODEL_EFI_BINARY_FILE,\r
+                                      self.FileLocalMacros)\r
+            if MacroDef[0] != None:\r
+                SectionMacros[MacroDef[0]] = MacroDef[1]\r
+                LineComment = None\r
+                HeaderComments = []                   \r
+                continue\r
+            \r
+            #\r
+            # Replace with Local section Macro and [Defines] section Macro.\r
+            #            \r
+            LineContent = InfExpandMacro(BinLineContent, \r
+                                         (FileName, BinLineContent, BinLineNo), \r
+                                         self.FileLocalMacros, \r
+                                         SectionMacros, True)\r
+            \r
+            AllSectionContent += LineContent + DT.END_OF_LINE           \r
+            TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
+            ValueList[0:len(TokenList)] = TokenList\r
+        \r
+            #              \r
+            # Should equal to UI/SEC_UI/UNI_UI\r
+            #\r
+            ValueList[0] = ValueList[0].strip()\r
+            if ValueList[0] == DT.BINARY_FILE_TYPE_UNI_UI or \\r
+               ValueList[0] == DT.BINARY_FILE_TYPE_SEC_UI or \\r
+               ValueList[0] == DT.BINARY_FILE_TYPE_UI:\r
+                if len(ValueList) == 2:\r
+                    TokenList = GetSplitValueList(ValueList[1], \r
+                                                  DT.TAB_VALUE_SPLIT, \r
+                                                  2)\r
+                    NewValueList = []\r
+                    NewValueList.append(ValueList[0])\r
+                    for Item in TokenList:\r
+                        NewValueList.append(Item)\r
+                    UiBinaryList.append((NewValueList, \r
+                                         LineComment, \r
+                                         CurrentLineObj)) \r
+            #              \r
+            # Should equal to VER/SEC_VER/UNI_VER\r
+            #\r
+            elif ValueList[0] == DT.BINARY_FILE_TYPE_UNI_VER or \\r
+               ValueList[0] == DT.BINARY_FILE_TYPE_SEC_VER or \\r
+               ValueList[0] == DT.BINARY_FILE_TYPE_VER:\r
+                if len(ValueList) == 2:\r
+                    TokenList = GetSplitValueList(ValueList[1], \r
+                                                  DT.TAB_VALUE_SPLIT, \r
+                                                  2)\r
+                    NewValueList = []\r
+                    NewValueList.append(ValueList[0])\r
+                    for Item in TokenList:\r
+                        NewValueList.append(Item)                             \r
+                    VerBinaryList.append((NewValueList, \r
+                                          LineComment, \r
+                                          CurrentLineObj))\r
+            else:\r
+                if len(ValueList) == 2:\r
+                    TokenList = GetSplitValueList(ValueList[1], \r
+                                                  DT.TAB_VALUE_SPLIT, \r
+                                                  4)\r
+                    NewValueList = []\r
+                    NewValueList.append(ValueList[0])\r
+                    for Item in TokenList:\r
+                        NewValueList.append(Item)                             \r
+                    ComBinaryList.append((NewValueList, \r
+                                          LineComment, \r
+                                          CurrentLineObj))\r
+            \r
+            ValueList = []\r
+            LineComment = None\r
+            TailComments = ''\r
+            HeaderComments = []           \r
+            continue\r
+\r
+        #\r
+        # Current section archs\r
+        #    \r
+        ArchList = []\r
+        for Item in self.LastSectionHeaderContent:\r
+            if Item[1] not in ArchList:\r
+                ArchList.append(Item[1])      \r
+                InfSectionObject.SetSupArchList(Item[1])\r
+                \r
+        InfSectionObject.SetAllContent(AllSectionContent)        \r
+        if not InfSectionObject.SetBinary(UiBinaryList, \r
+                                          VerBinaryList, \r
+                                          ComBinaryList, \r
+                                          ArchList):\r
+            Logger.Error('InfParser', \r
+                         FORMAT_INVALID,\r
+                         ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Binaries]"),\r
+                         File=FileName,\r
+                         Line=Item[3])     \r
+    
\ No newline at end of file