]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfSectionParser.py
index 879f924c45760073fd9f586ff7fee056becc5a8b..1f254058d1332685891585017ae8289dc030bd3f 100644 (file)
@@ -1,11 +1,11 @@
 ## @file\r
-# This file contained the parser for sections in INF file \r
+# This file contained the parser for sections in INF file\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2018, 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
+# 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
@@ -21,7 +21,7 @@ InfSectionParser
 from copy import deepcopy\r
 import re\r
 \r
-from Library.String import GetSplitValueList\r
+from Library.StringUtils import GetSplitValueList\r
 from Library.CommentParsing import ParseHeaderCommentSection\r
 from Library.CommentParsing import ParseComment\r
 \r
@@ -95,7 +95,7 @@ def GetSpecialStr2(ItemList, FileName, LineNo, SectionString):
             if ItemList[3] != '':\r
                 Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_SOURCE_SECTION_SECTIONNAME_INVALID \\r
                              % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString)\r
-        \r
+\r
         if not ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper():\r
             Str2 = ItemList[2] + ' | ' + ItemList[3]\r
         else:\r
@@ -108,7 +108,7 @@ def GetSpecialStr2(ItemList, FileName, LineNo, SectionString):
     return Str2\r
 \r
 ## ProcessUseExtHeader\r
-# \r
+#\r
 #\r
 def ProcessUseExtHeader(ItemList):\r
     NewItemList = []\r
@@ -138,12 +138,12 @@ def ProcessUseExtHeader(ItemList):
                 NewItemList.append(Item)\r
             else:\r
                 AppendContent = AppendContent + "." + Item\r
-    \r
+\r
     if len(NewItemList) > 4:\r
         return False, []\r
-    \r
+\r
     return True, NewItemList\r
-  \r
+\r
 ## GetArch\r
 #\r
 # GetArch\r
@@ -239,11 +239,12 @@ class InfSectionParser(InfDefinSectionParser,
         self.InfSmmDepexSection = InfDepexObject()\r
         self.InfBinariesSection = InfBinariesObject()\r
         self.InfHeader = InfHeaderObject()\r
+        self.InfBinaryHeader = InfHeaderObject()\r
         self.InfSpecialCommentSection = InfSpecialCommentObject()\r
 \r
         #\r
         # A List for store define section content.\r
-        #    \r
+        #\r
         self._PcdNameList = []\r
         self._SectionName = ''\r
         self._SectionType = 0\r
@@ -252,9 +253,17 @@ class InfSectionParser(InfDefinSectionParser,
 \r
     #\r
     # File Header content parser\r
-    #    \r
-    def InfHeaderParser(self, Content, InfHeaderObject2, FileName):\r
-        (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName)\r
+    #\r
+    def InfHeaderParser(self, Content, InfHeaderObject2, FileName, IsBinaryHeader = False):\r
+        if IsBinaryHeader:\r
+            (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName, True)\r
+            if not Abstract or not Description or not Copyright or not License:\r
+                Logger.Error('Parser',\r
+                             FORMAT_INVALID,\r
+                             ST.ERR_INVALID_BINARYHEADER_FORMAT,\r
+                             File=FileName)\r
+        else:\r
+            (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName)\r
         #\r
         # Not process file name now, for later usage.\r
         #\r
@@ -263,7 +272,7 @@ class InfSectionParser(InfDefinSectionParser,
 \r
         #\r
         # Insert Abstract, Description, CopyRight, License into header object\r
-        #                                \r
+        #\r
         InfHeaderObject2.SetAbstract(Abstract)\r
         InfHeaderObject2.SetDescription(Description)\r
         InfHeaderObject2.SetCopyright(Copyright)\r
@@ -278,7 +287,7 @@ class InfSectionParser(InfDefinSectionParser,
     #\r
     #       [section_name.arch<.platform|module_type>]\r
     #\r
-    # @param String    A string contained the content need to be parsed. \r
+    # @param String    A string contained the content need to be parsed.\r
     #\r
     def SectionHeaderParser(self, SectionString, FileName, LineNo):\r
         _Scope = []\r
@@ -304,7 +313,7 @@ class InfSectionParser(InfDefinSectionParser,
             #\r
             # different section should not mix in one section\r
             # Allow different PCD type sections mixed together\r
-            # \r
+            #\r
             if _SectionName.upper() not in _PcdNameList:\r
                 if _SectionName != '' and _SectionName.upper() != ItemList[0].upper():\r
                     Logger.Error('Parser',\r
@@ -341,7 +350,7 @@ class InfSectionParser(InfDefinSectionParser,
 \r
             #\r
             # For [Defines] section, do special check.\r
-            # \r
+            #\r
             if ItemList[0].upper() == DT.TAB_COMMON_DEFINES.upper():\r
                 if len(ItemList) != 1:\r
                     Logger.Error('Parser',\r
@@ -351,26 +360,26 @@ class InfSectionParser(InfDefinSectionParser,
 \r
             #\r
             # For [UserExtension] section, do special check.\r
-            # \r
+            #\r
             if ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper():\r
-            \r
+\r
                 RetValue = ProcessUseExtHeader(ItemList)\r
-                \r
+\r
                 if not RetValue[0]:\r
                     Logger.Error('Parser',\r
                                  FORMAT_INVALID,\r
                                  ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString),\r
                                  File=FileName, Line=LineNo, ExtraData=SectionString)\r
                 else:\r
-                    ItemList = RetValue[1]              \r
-                \r
+                    ItemList = RetValue[1]\r
+\r
                 if len(ItemList) == 3:\r
                     ItemList.append('COMMON')\r
-                \r
+\r
                 Str1 = ItemList[1]\r
 \r
             #\r
-            # For Library classes, need to check module type.       \r
+            # For Library classes, need to check module type.\r
             #\r
             if ItemList[0].upper() == DT.TAB_LIBRARY_CLASSES.upper() and len(ItemList) == 3:\r
                 if ItemList[2] != '':\r
@@ -415,10 +424,10 @@ class InfSectionParser(InfDefinSectionParser,
 \r
     ## GenSpecialSectionList\r
     #\r
-    #  @param SpecialSectionList: a list of list, of which item's format \r
+    #  @param SpecialSectionList: a list of list, of which item's format\r
     #                             (Comment, LineNum)\r
     #  @param ContainerFile:      Input value for filename of Inf file\r
-    # \r
+    #\r
     def InfSpecialCommentParser (self, SpecialSectionList, InfSectionObject, ContainerFile, SectionType):\r
         ReFindSpecialCommentRe = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL)\r
         ReFindHobArchRe = re.compile(r"""[Hh][Oo][Bb]\.([^,]*)""", re.DOTALL)\r