]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Parser/DecParser.py
BaseTools: Adjust the spaces around commas and colons
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / DecParser.py
index 25407f9a2d505b975bd8b99e51af92c41b258dd2..7ac0dfa1ed944ef50b9a69b55d61bd2e9fbc3d2c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse DEC file. It will consumed by DecParser\r
 #\r
-# Copyright (c) 2011 - 2014, 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
@@ -29,6 +29,7 @@ from Library.ParserValidate import IsValidIdString
 from Library.ParserValidate import IsValidUserId\r
 from Library.ParserValidate import IsValidArch\r
 from Library.ParserValidate import IsValidWord\r
+from Library.ParserValidate import IsValidDecVersionVal\r
 from Parser.DecParserMisc import TOOL_NAME\r
 from Parser.DecParserMisc import CleanString\r
 from Parser.DecParserMisc import IsValidPcdDatum\r
@@ -56,10 +57,10 @@ from Object.Parser.DecObject import DecPcdObject
 from Object.Parser.DecObject import DecPcdItemObject\r
 from Library.Misc import GuidStructureStringToGuidString\r
 from Library.Misc import CheckGuidRegFormat\r
-from Library.String import ReplaceMacro\r
-from Library.String import GetSplitValueList\r
-from Library.String import gMACRO_PATTERN\r
-from Library.String import ConvertSpecialChar\r
+from Library.StringUtils import ReplaceMacro\r
+from Library.StringUtils import GetSplitValueList\r
+from Library.StringUtils import gMACRO_PATTERN\r
+from Library.StringUtils import ConvertSpecialChar\r
 from Library.CommentParsing import ParsePcdErrorCode\r
 \r
 ##\r
@@ -269,7 +270,21 @@ class _DecBase:
                     self._LoggerError(ST.ERR_DECPARSE_BACKSLASH_EMPTY)\r
                 CatLine += Line\r
          \r
-        self._RawData.CurrentLine = self._ReplaceMacro(CatLine)\r
+        #\r
+        # All MACRO values defined by the DEFINE statements in any section\r
+        # (except [Userextensions] sections for Intel) of the INF or DEC file\r
+        # must be expanded before processing of the file.\r
+        #\r
+        __IsReplaceMacro = True\r
+        Header = self._RawData.CurrentScope[0] if self._RawData.CurrentScope else None\r
+        if Header and len(Header) > 2:\r
+            if Header[0].upper() == 'USEREXTENSIONS' and not (Header[1] == 'TianoCore' and Header[2] == '"ExtraFiles"'):\r
+                __IsReplaceMacro = False\r
+        if __IsReplaceMacro:\r
+            self._RawData.CurrentLine = self._ReplaceMacro(CatLine)\r
+        else:\r
+            self._RawData.CurrentLine = CatLine\r
+\r
         return CatLine, CommentList\r
     \r
     ## Parse\r
@@ -452,7 +467,8 @@ class _DecDefine(_DecBase):
         if self.ItemObject.GetPackageSpecification():\r
             self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_DEC_SPECIFICATION)\r
         if not IsValidToken('0[xX][0-9a-fA-F]{8}', Token):\r
-            self._LoggerError(ST.ERR_DECPARSE_DEFINE_SPEC)\r
+            if not IsValidDecVersionVal(Token):\r
+                self._LoggerError(ST.ERR_DECPARSE_DEFINE_SPEC)\r
         self.ItemObject.SetPackageSpecification(Token)\r
     \r
     def _SetPackageName(self, Token):\r
@@ -740,7 +756,26 @@ class Dec(_DecBase, _DecComments):
         except BaseException:\r
             Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,\r
                          ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)\r
-        RawData = FileContent(DecFile, Content)\r
+\r
+        #\r
+        # Pre-parser for Private section\r
+        #\r
+        self._Private = ''\r
+        __IsFoundPrivate = False\r
+        NewContent = []\r
+        for Line in Content:\r
+            Line = Line.strip()\r
+            if Line.startswith(DT.TAB_SECTION_START) and Line.endswith(DT.TAB_PRIVATE + DT.TAB_SECTION_END):\r
+                __IsFoundPrivate = True\r
+            if Line.startswith(DT.TAB_SECTION_START) and Line.endswith(DT.TAB_SECTION_END)\\r
+               and not Line.endswith(DT.TAB_PRIVATE + DT.TAB_SECTION_END):\r
+                __IsFoundPrivate = False\r
+            if __IsFoundPrivate:\r
+                self._Private += Line + '\r'\r
+            if not __IsFoundPrivate:\r
+                NewContent.append(Line + '\r')\r
+\r
+        RawData = FileContent(DecFile, NewContent)\r
         \r
         _DecComments.__init__(self)\r
         _DecBase.__init__(self, RawData)\r
@@ -1058,3 +1093,5 @@ class Dec(_DecBase, _DecComments):
         return self._Define.GetDataObject().GetPackageVersion()\r
     def GetPackageUniFile(self):\r
         return self._Define.GetDataObject().GetPackageUniFile()\r
+    def GetPrivateSections(self):\r
+        return self._Private\r