]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Parser/InfPackageSectionParser.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfPackageSectionParser.py
diff --git a/BaseTools/Source/Python/UPT/Parser/InfPackageSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfPackageSectionParser.py
new file mode 100644 (file)
index 0000000..67f1145
--- /dev/null
@@ -0,0 +1,140 @@
+## @file\r
+# This file contained the parser for [Packages] 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
+InfPackageSectionParser\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 Parser.InfParserMisc import InfParserSectionRoot\r
+\r
+class InfPackageSectionParser(InfParserSectionRoot):\r
+    ## InfPackageParser\r
+    #\r
+    #                       \r
+    def InfPackageParser(self, SectionString, InfSectionObject, FileName):\r
+        #\r
+        # Macro defined in this section \r
+        #\r
+        SectionMacros = {}\r
+        ValueList     = []\r
+        PackageList   = []\r
+        StillCommentFalg  = False\r
+        HeaderComments    = []\r
+        LineComment       = None                  \r
+        #\r
+        # Parse section content\r
+        #\r
+        for Line in SectionString:\r
+            PkgLineContent = Line[0]\r
+            PkgLineNo      = Line[1]  \r
+            \r
+            if PkgLineContent.strip() == '':\r
+                continue\r
+            \r
+            #\r
+            # Find Header Comments \r
+            #\r
+            if PkgLineContent.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
+                    continue\r
+                #\r
+                # First time encounter comment \r
+                #\r
+                else:\r
+                    #\r
+                    # Clear original data\r
+                    #\r
+                    HeaderComments = []\r
+                    HeaderComments.append(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 PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
+                TailComments = PkgLineContent[PkgLineContent.find(DT.TAB_COMMENT_SPLIT):]\r
+                PkgLineContent = PkgLineContent[:PkgLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
+                if LineComment == None:\r
+                    LineComment = InfLineCommentObject()\r
+                LineComment.SetTailComments(TailComments)                   \r
+            #\r
+            # Find Macro\r
+            #\r
+            Name, Value = MacroParser((PkgLineContent, PkgLineNo),\r
+                                      FileName,\r
+                                      DT.MODEL_META_DATA_PACKAGE,\r
+                                      self.FileLocalMacros)\r
+            if Name != None:\r
+                SectionMacros[Name] = Value\r
+                LineComment = None\r
+                HeaderComments = []                \r
+                continue\r
+\r
+            TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1)\r
+            ValueList[0:len(TokenList)] = TokenList\r
+            \r
+            #\r
+            # Replace with Local section Macro and [Defines] section Macro.\r
+            #            \r
+            ValueList = [InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo), \r
+                                        self.FileLocalMacros, SectionMacros, True)\r
+                                        for Value in ValueList]\r
+            \r
+            PackageList.append((ValueList, LineComment, \r
+                                (PkgLineContent, PkgLineNo, FileName)))\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
+        \r
+        if not InfSectionObject.SetPackages(PackageList, Arch = ArchList):\r
+            Logger.Error('InfParser', \r
+                         FORMAT_INVALID, \r
+                         ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\\r
+                         %("[Packages]"),\r
+                         File=FileName,\r
+                         Line=Item[3])         
\ No newline at end of file