## @file\r
-# This file contained the miscellaneous functions for INF parser \r
+# This file contained the miscellaneous functions for INF parser\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
-# 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
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
'''\r
from Library import DataType as DT\r
\r
\r
-from Library.String import gMACRO_PATTERN\r
-from Library.String import ReplaceMacro\r
+from Library.StringUtils import gMACRO_PATTERN\r
+from Library.StringUtils import ReplaceMacro\r
from Object.Parser.InfMisc import ErrorInInf\r
from Logger.StringTable import ERR_MARCO_DEFINITION_MISS_ERROR\r
\r
#\r
# EDK1 section\r
# TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE\r
- # \r
+ #\r
}\r
\r
## InfExpandMacro\r
#\r
-# Expand MACRO definition with MACROs defined in [Defines] section and specific section. \r
+# Expand MACRO definition with MACROs defined in [Defines] section and specific section.\r
# The MACROs defined in specific section has high priority and will be expanded firstly.\r
#\r
# @param LineInfo Contain information of FileName, LineContent, LineNo\r
# @param GlobalMacros MACROs defined in INF [Defines] section\r
# @param SectionMacros MACROs defined in INF specific section\r
-# @param Flag If the flag set to True, need to skip macros in a quoted string \r
+# @param Flag If the flag set to True, need to skip macros in a quoted string\r
#\r
def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Flag=False):\r
- if GlobalMacros == None:\r
+ if GlobalMacros is None:\r
GlobalMacros = {}\r
- if SectionMacros == None:\r
+ if SectionMacros is None:\r
SectionMacros = {}\r
- \r
+\r
FileName = LineInfo[0]\r
LineContent = LineInfo[1]\r
LineNo = LineInfo[2]\r
- \r
+\r
# Don't expand macros in comments\r
if LineContent.strip().startswith("#"):\r
return Content\r
\r
NewLineInfo = (FileName, LineNo, LineContent)\r
- \r
+\r
#\r
# First, replace MARCOs with value defined in specific section\r
#\r
- Content = ReplaceMacro (Content, \r
+ Content = ReplaceMacro (Content,\r
SectionMacros,\r
False,\r
(LineContent, LineNo),\r
#\r
# Then replace MARCOs with value defined in [Defines] section\r
#\r
- Content = ReplaceMacro (Content, \r
+ Content = ReplaceMacro (Content,\r
GlobalMacros,\r
False,\r
(LineContent, LineNo),\r
FileName,\r
Flag)\r
- \r
+\r
MacroUsed = gMACRO_PATTERN.findall(Content)\r
#\r
# no macro found in String, stop replacing\r
#\r
ErrorInInf (ERR_MARCO_DEFINITION_MISS_ERROR,\r
LineInfo=NewLineInfo)\r
- \r
+\r
return Content\r
- \r
+\r
\r
## IsBinaryInf\r
#\r
def IsBinaryInf(FileLineList):\r
if not FileLineList:\r
return False\r
- \r
+\r
ReIsSourcesSection = re.compile("^\s*\[Sources.*\]\s.*$", re.IGNORECASE)\r
ReIsBinarySection = re.compile("^\s*\[Binaries.*\]\s.*$", re.IGNORECASE)\r
BinarySectionFoundFlag = False\r
- \r
+\r
for Line in FileLineList:\r
if ReIsSourcesSection.match(Line):\r
return False\r
if ReIsBinarySection.match(Line):\r
BinarySectionFoundFlag = True\r
- \r
+\r
if BinarySectionFoundFlag:\r
return True\r
- \r
+\r
return False\r
- \r
- \r
+\r
+\r
## IsLibInstanceInfo\r
-# \r
+#\r
# Judge whether the string contain the information of ## @LIB_INSTANCES.\r
#\r
# @param String\r
return True\r
else:\r
return False\r
- \r
- \r
+\r
+\r
## IsAsBuildOptionInfo\r
-# \r
+#\r
# Judge whether the string contain the information of ## @ASBUILD.\r
#\r
# @param String\r
if ReIsAsBuildInstance.match(String):\r
return True\r
else:\r
- return False \r
- \r
+ return False\r
+\r
\r
class InfParserSectionRoot(object):\r
def __init__(self):\r
# Macros defined in [Define] section are file scope global\r
#\r
self.FileLocalMacros = {}\r
- \r
+\r
#\r
- # Current Section Header content. \r
+ # Current Section Header content.\r
#\r
self.SectionHeaderContent = []\r
\r
#\r
- # Last time Section Header content. \r
+ # Last time Section Header content.\r
#\r
- self.LastSectionHeaderContent = [] \r
- \r
+ self.LastSectionHeaderContent = []\r
+\r
self.FullPath = ''\r
- \r
+\r
self.InfDefSection = None\r
self.InfBuildOptionSection = None\r
self.InfLibraryClassSection = None\r
self.InfSmmDepexSection = None\r
self.InfBinariesSection = None\r
self.InfHeader = None\r
- self.InfSpecialCommentSection = None \r
+ self.InfSpecialCommentSection = None\r