BaseTools: Resolve regex syntax warnings

Switches regex patterns to raw text to resolve python 3.12 syntax
warnings in regards to invalid escape sequences, as is suggested by the
re (regex) module in python.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
This commit is contained in:
Joey Vagedes via groups.io
2023-12-06 12:27:02 -08:00
committed by mergify[bot]
parent 89705ad6c6
commit 9f0061a03b
18 changed files with 60 additions and 60 deletions

View File

@ -17,7 +17,7 @@ from Common.BuildToolError import *
import sys import sys
import os import os
__description__ = """ __description__ = r"""
Convert an AML file to a .c file containing the AML bytecode stored in a C Convert an AML file to a .c file containing the AML bytecode stored in a C
array. By default, Tables\Dsdt.aml will generate Tables\Dsdt.c. array. By default, Tables\Dsdt.aml will generate Tables\Dsdt.c.
Tables\Dsdt.c will contain a C array named "dsdt_aml_code" that contains Tables\Dsdt.c will contain a C array named "dsdt_aml_code" that contains

View File

@ -306,7 +306,7 @@ class BuildRule:
_SubSectionList = [_InputFile, _OutputFile, _Command] _SubSectionList = [_InputFile, _OutputFile, _Command]
_PATH_SEP = "(+)" _PATH_SEP = "(+)"
_FileTypePattern = re.compile("^[_a-zA-Z][_\-0-9a-zA-Z]*$") _FileTypePattern = re.compile(r"^[_a-zA-Z][_\-0-9a-zA-Z]*$")
_BinaryFileRule = FileBuildRule(TAB_DEFAULT_BINARY_FILE, [], [os.path.join("$(OUTPUT_DIR)", "${s_name}")], _BinaryFileRule = FileBuildRule(TAB_DEFAULT_BINARY_FILE, [], [os.path.join("$(OUTPUT_DIR)", "${s_name}")],
["$(CP) ${src} ${dst}"], []) ["$(CP) ${src} ${dst}"], [])

View File

@ -126,7 +126,7 @@ class DependencyExpression:
# #
# open and close brace must be taken as individual tokens # open and close brace must be taken as individual tokens
# #
TokenPattern = re.compile("(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)") TokenPattern = re.compile(r"(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)")
## Constructor ## Constructor
# #

View File

@ -28,7 +28,7 @@ from Common.DataType import TAB_COMPILER_MSFT
gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE) gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)
## Regular expression for matching macro used in header file inclusion ## Regular expression for matching macro used in header file inclusion
gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE) gMacroPattern = re.compile(r"([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)
gIsFileMap = {} gIsFileMap = {}

View File

@ -18,7 +18,7 @@ import os
from Common.GlobalData import gIdentifierPattern from Common.GlobalData import gIdentifierPattern
from .UniClassObject import StripComments from .UniClassObject import StripComments
IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE) IMAGE_TOKEN = re.compile(r'IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
# #
# Value of different image information block types # Value of different image information block types

View File

@ -51,12 +51,12 @@ gInfSpecVersion = "0x00010017"
# #
# Match name = variable # Match name = variable
# #
gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)") gEfiVarStoreNamePattern = re.compile(r"\s*name\s*=\s*(\w+)")
# #
# The format of guid in efivarstore statement likes following and must be correct: # The format of guid in efivarstore statement likes following and must be correct:
# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}} # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
# #
gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})") gEfiVarStoreGuidPattern = re.compile(r"\s*guid\s*=\s*({.*?{.*?}\s*})")
# #
# Template string to generic AsBuilt INF # Template string to generic AsBuilt INF

View File

@ -54,7 +54,7 @@ NOT_REFERENCED = 'not referenced'
COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED
CHAR_ARRAY_DEFIN = 'unsigned char' CHAR_ARRAY_DEFIN = 'unsigned char'
COMMON_FILE_NAME = 'Strings' COMMON_FILE_NAME = 'Strings'
STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE) STRING_TOKEN = re.compile(r'STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
EFI_HII_ARRAY_SIZE_LENGTH = 4 EFI_HII_ARRAY_SIZE_LENGTH = 4
EFI_HII_PACKAGE_HEADER_LENGTH = 4 EFI_HII_PACKAGE_HEADER_LENGTH = 4

View File

@ -26,7 +26,7 @@ from Common.Misc import *
import json import json
## Regular expression for splitting Dependency Expression string into tokens ## Regular expression for splitting Dependency Expression string into tokens
gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)") gDepexTokenPattern = re.compile(r"(\(|\)|\w+| \S+\.inf)")
## Regular expression for match: PCD(xxxx.yyy) ## Regular expression for match: PCD(xxxx.yyy)
gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$") gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")

View File

@ -41,8 +41,8 @@ ERR_EMPTY_EXPR = 'Empty expression is not allowed.'
ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).' ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'
__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') __ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
_ReLabel = re.compile('LABEL\((\w+)\)') _ReLabel = re.compile(r'LABEL\((\w+)\)')
_ReOffset = re.compile('OFFSET_OF\((\w+)\)') _ReOffset = re.compile(r'OFFSET_OF\((\w+)\)')
PcdPattern = re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$') PcdPattern = re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
## SplitString ## SplitString
@ -242,10 +242,10 @@ class ValueExpression(BaseExpression):
SymbolPattern = re.compile("(" SymbolPattern = re.compile("("
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|" r"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
"&&|\|\||!(?!=)|" r"&&|\|\||!(?!=)|"
"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|" r"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)" r"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
")") ")")
@staticmethod @staticmethod
@ -737,7 +737,7 @@ class ValueExpression(BaseExpression):
self._Token = "'" + UStr + "'" self._Token = "'" + UStr + "'"
return self._Token return self._Token
elif Expr.startswith('UINT'): elif Expr.startswith('UINT'):
Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') Re = re.compile(r'(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
try: try:
RetValue = Re.search(Expr).group(1) RetValue = Re.search(Expr).group(1)
except: except:
@ -975,7 +975,7 @@ class ValueExpressionEx(ValueExpression):
TokenSpaceGuidName = '' TokenSpaceGuidName = ''
if Item.startswith(TAB_GUID) and Item.endswith(')'): if Item.startswith(TAB_GUID) and Item.endswith(')'):
try: try:
TokenSpaceGuidName = re.search('GUID\((\w+)\)', Item).group(1) TokenSpaceGuidName = re.search(r'GUID\((\w+)\)', Item).group(1)
except: except:
pass pass
if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb: if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb:

View File

@ -33,10 +33,10 @@ gDefaultStores = []
gGuidDict = {} gGuidDict = {}
# definition for a MACRO name. used to create regular expressions below. # definition for a MACRO name. used to create regular expressions below.
_MacroNamePattern = "[A-Z][A-Z0-9_]*" _MacroNamePattern = r"[A-Z][A-Z0-9_]*"
## Regular expression for matching macro used in DSC/DEC/INF file inclusion ## Regular expression for matching macro used in DSC/DEC/INF file inclusion
gMacroRefPattern = re.compile("\$\(({})\)".format(_MacroNamePattern), re.UNICODE) gMacroRefPattern = re.compile(r"\$\(({})\)".format(_MacroNamePattern), re.UNICODE)
gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+") gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+")
gMacroNamePattern = re.compile("^{}$".format(_MacroNamePattern)) gMacroNamePattern = re.compile("^{}$".format(_MacroNamePattern))

View File

@ -41,16 +41,16 @@ from CommonDataClass.Exceptions import BadExpression
from Common.caching import cached_property from Common.caching import cached_property
import struct import struct
ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]") ArrayIndex = re.compile(r"\[\s*[0-9a-fA-FxX]*\s*\]")
## Regular expression used to find out place holders in string template ## Regular expression used to find out place holders in string template
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE) gPlaceholderPattern = re.compile(r"\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
## regular expressions for map file processing ## regular expressions for map file processing
startPatternGeneral = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class") startPatternGeneral = re.compile(r"^Start[' ']+Length[' ']+Name[' ']+Class")
addressPatternGeneral = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base") addressPatternGeneral = re.compile(r"^Address[' ']+Publics by Value[' ']+Rva\+Base")
valuePatternGcc = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$') valuePatternGcc = re.compile(r'^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
pcdPatternGcc = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)') pcdPatternGcc = re.compile(r'^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
secReGeneral = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE) secReGeneral = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$') StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
@ -82,7 +82,7 @@ def GetVariableOffset(mapfilepath, efifilepath, varnames):
if len(lines) == 0: return None if len(lines) == 0: return None
firstline = lines[0].strip() firstline = lines[0].strip()
if re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline): if re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
return _parseForXcodeAndClang9(lines, efifilepath, varnames) return _parseForXcodeAndClang9(lines, efifilepath, varnames)
if (firstline.startswith("Archive member included ") and if (firstline.startswith("Archive member included ") and
firstline.endswith(" file (symbol)")): firstline.endswith(" file (symbol)")):
@ -96,7 +96,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames):
ret = [] ret = []
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if status == 0 and (re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \ if status == 0 and (re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
or line == "# Symbols:"): or line == "# Symbols:"):
status = 1 status = 1
continue continue
@ -104,7 +104,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames):
for varname in varnames: for varname in varnames:
if varname in line: if varname in line:
# cannot pregenerate this RegEx since it uses varname from varnames. # cannot pregenerate this RegEx since it uses varname from varnames.
m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line) m = re.match(r'^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
if m is not None: if m is not None:
ret.append((varname, m.group(1))) ret.append((varname, m.group(1)))
return ret return ret
@ -170,7 +170,7 @@ def _parseGeneral(lines, efifilepath, varnames):
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
secs = [] # key = section name secs = [] # key = section name
varoffset = [] varoffset = []
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE) symRe = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE)
for line in lines: for line in lines:
line = line.strip() line = line.strip()
@ -1926,4 +1926,4 @@ def CopyDict(ori_dict):
# Remove the c/c++ comments: // and /* */ # Remove the c/c++ comments: // and /* */
# #
def RemoveCComments(ctext): def RemoveCComments(ctext):
return re.sub('//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S) return re.sub(r'//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S)

View File

@ -30,9 +30,9 @@ from .DataType import TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\
## ##
# Static variables used for pattern # Static variables used for pattern
# #
gMacroRefPattern = re.compile('(DEF\([^\(\)]+\))') gMacroRefPattern = re.compile(r'(DEF\([^\(\)]+\))')
gEnvRefPattern = re.compile('(ENV\([^\(\)]+\))') gEnvRefPattern = re.compile(r'(ENV\([^\(\)]+\))')
gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)") gMacroDefPattern = re.compile(r"DEFINE\s+([^\s]+)")
gDefaultToolsDefFile = "tools_def.txt" gDefaultToolsDefFile = "tools_def.txt"
## ToolDefClassObject ## ToolDefClassObject

View File

@ -65,11 +65,11 @@ ALIGNMENTS = {"Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "6
ALIGNMENT_NOAUTO = ALIGNMENTS - {"Auto"} ALIGNMENT_NOAUTO = ALIGNMENTS - {"Auto"}
CR_LB_SET = {T_CHAR_CR, TAB_LINE_BREAK} CR_LB_SET = {T_CHAR_CR, TAB_LINE_BREAK}
RegionSizePattern = compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*") RegionSizePattern = compile(r"\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")
RegionSizeGuidPattern = compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*") RegionSizeGuidPattern = compile(r"\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*")
RegionOffsetPcdPattern = compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$") RegionOffsetPcdPattern = compile(r"\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$")
ShortcutPcdPattern = compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*") ShortcutPcdPattern = compile(r"\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")
BaseAddrValuePattern = compile('^0[xX][0-9a-fA-F]+') BaseAddrValuePattern = compile(r'^0[xX][0-9a-fA-F]+')
FileExtensionPattern = compile(r'([a-zA-Z][a-zA-Z0-9]*)') FileExtensionPattern = compile(r'([a-zA-Z][a-zA-Z0-9]*)')
TokenFindPattern = compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') TokenFindPattern = compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
AllIncludeFileList = [] AllIncludeFileList = []

View File

@ -733,7 +733,7 @@ class GenFds(object):
if not os.path.exists(FfsPath[0]): if not os.path.exists(FfsPath[0]):
continue continue
MatchDict = {} MatchDict = {}
ReFileEnds = compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$') ReFileEnds = compile(r'\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')
FileList = os.listdir(FfsPath[0]) FileList = os.listdir(FfsPath[0])
for File in FileList: for File in FileList:
Match = ReFileEnds.search(File) Match = ReFileEnds.search(File)

View File

@ -31,7 +31,7 @@ __copyright__ = "Copyright (c) 2008 - 2018, Intel Corporation. All rights reserv
#====================================== Internal Libraries ======================================== #====================================== Internal Libraries ========================================
#============================================== Code =============================================== #============================================== Code ===============================================
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE) symRe = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)
def parsePcdInfoFromMapFile(mapfilepath, efifilepath): def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
""" Parse map file to get binary patch pcd information """ Parse map file to get binary patch pcd information
@ -49,7 +49,7 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
if len(lines) == 0: return None if len(lines) == 0: return None
firstline = lines[0].strip() firstline = lines[0].strip()
if re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline): if re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
return _parseForXcodeAndClang9(lines, efifilepath) return _parseForXcodeAndClang9(lines, efifilepath)
if (firstline.startswith("Archive member included ") and if (firstline.startswith("Archive member included ") and
firstline.endswith(" file (symbol)")): firstline.endswith(" file (symbol)")):
@ -59,12 +59,12 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
return _parseGeneral(lines, efifilepath) return _parseGeneral(lines, efifilepath)
def _parseForXcodeAndClang9(lines, efifilepath): def _parseForXcodeAndClang9(lines, efifilepath):
valuePattern = re.compile('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))') valuePattern = re.compile(r'^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))')
status = 0 status = 0
pcds = [] pcds = []
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if status == 0 and (re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \ if status == 0 and (re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
or line == "# Symbols:"): or line == "# Symbols:"):
status = 1 status = 1
continue continue
@ -77,7 +77,7 @@ def _parseForXcodeAndClang9(lines, efifilepath):
def _parseForGCC(lines, efifilepath): def _parseForGCC(lines, efifilepath):
""" Parse map file generated by GCC linker """ """ Parse map file generated by GCC linker """
dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$') dataPattern = re.compile(r'^.data._gPcd_BinaryPatch_([\w_\d]+)$')
status = 0 status = 0
imageBase = -1 imageBase = -1
sections = [] sections = []
@ -136,7 +136,7 @@ def _parseGeneral(lines, efifilepath):
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
secs = [] # key = section name secs = [] # key = section name
bPcds = [] bPcds = []
symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)') symPattern = re.compile(r'^[_]+gPcd_BinaryPatch_([\w]+)')
for line in lines: for line in lines:
line = line.strip() line = line.strip()

View File

@ -28,15 +28,15 @@ __version__ = "%prog Version " + __version_number__
__copyright__ = "Copyright (c) 2007-2018, Intel Corporation. All rights reserved." __copyright__ = "Copyright (c) 2007-2018, Intel Corporation. All rights reserved."
## Regular expression for matching Line Control directive like "#line xxx" ## Regular expression for matching Line Control directive like "#line xxx"
gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"') gLineControlDirective = re.compile(r'^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')
## Regular expression for matching "typedef struct" ## Regular expression for matching "typedef struct"
gTypedefPattern = re.compile("^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE) gTypedefPattern = re.compile(r"^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE)
## Regular expression for matching "#pragma pack" ## Regular expression for matching "#pragma pack"
gPragmaPattern = re.compile("^\s*#pragma\s+pack", re.MULTILINE) gPragmaPattern = re.compile(r"^\s*#pragma\s+pack", re.MULTILINE)
## Regular expression for matching "typedef" ## Regular expression for matching "typedef"
gTypedef_SinglePattern = re.compile("^\s*typedef", re.MULTILINE) gTypedef_SinglePattern = re.compile(r"^\s*typedef", re.MULTILINE)
## Regular expression for matching "typedef struct, typedef union, struct, union" ## Regular expression for matching "typedef struct, typedef union, struct, union"
gTypedef_MulPattern = re.compile("^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE) gTypedef_MulPattern = re.compile(r"^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE)
# #
# The following number pattern match will only match if following criteria is met: # The following number pattern match will only match if following criteria is met:
@ -44,14 +44,14 @@ gTypedef_MulPattern = re.compile("^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]
# as the pattern is greedily match, so it is ok for the gDecNumberPattern or gHexNumberPattern to grab the maximum match # as the pattern is greedily match, so it is ok for the gDecNumberPattern or gHexNumberPattern to grab the maximum match
# #
## Regular expression for matching HEX number ## Regular expression for matching HEX number
gHexNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])(0[xX])([0-9a-fA-F]+)(U(?=$|[^a-zA-Z0-9_]))?") gHexNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])(0[xX])([0-9a-fA-F]+)(U(?=$|[^a-zA-Z0-9_]))?")
## Regular expression for matching decimal number with 'U' postfix ## Regular expression for matching decimal number with 'U' postfix
gDecNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])([0-9]+)U(?=$|[^a-zA-Z0-9_])") gDecNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])([0-9]+)U(?=$|[^a-zA-Z0-9_])")
## Regular expression for matching constant with 'ULL' 'LL' postfix ## Regular expression for matching constant with 'ULL' 'LL' postfix
gLongNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?LL(?=$|[^a-zA-Z0-9_])") gLongNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?LL(?=$|[^a-zA-Z0-9_])")
## Regular expression for matching "Include ()" in asl file ## Regular expression for matching "Include ()" in asl file
gAslIncludePattern = re.compile("^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE) gAslIncludePattern = re.compile(r"^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE)
## Regular expression for matching C style #include "XXX.asl" in asl file ## Regular expression for matching C style #include "XXX.asl" in asl file
gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE) gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE)
## Patterns used to convert EDK conventions to EDK2 ECP conventions ## Patterns used to convert EDK conventions to EDK2 ECP conventions

View File

@ -90,7 +90,7 @@ PcdMakefileHeader = '''
WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 ' WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
LinuxCFLAGS = 'CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable ' LinuxCFLAGS = 'CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
PcdMakefileEnd = ''' PcdMakefileEnd = r'''
!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app !INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
''' '''
@ -110,7 +110,7 @@ LIBS = -lCommon
variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$') variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$')
SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$') SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
## regular expressions for finding decimal and hex numbers ## regular expressions for finding decimal and hex numbers
Pattern = re.compile('^[1-9]\d*|0$') Pattern = re.compile(r'^[1-9]\d*|0$')
HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
## Regular expression for finding header file inclusions ## Regular expression for finding header file inclusions
from AutoGen.GenMake import gIncludePattern from AutoGen.GenMake import gIncludePattern
@ -2840,7 +2840,7 @@ class DscBuildData(PlatformBuildClassObject):
# start generating makefile # start generating makefile
MakeApp = PcdMakefileHeader MakeApp = PcdMakefileHeader
if sys.platform == "win32": if sys.platform == "win32":
MakeApp = MakeApp + 'APPFILE = %s\%s.exe\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = ' MakeApp = MakeApp + r'APPFILE = %s\%s.exe\n' % (self.OutputPath, PcdValueInitName) + r'APPNAME = %s\n' % (PcdValueInitName) + r'OBJECTS = %s\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = '
else: else:
MakeApp = MakeApp + PcdGccMakefile MakeApp = MakeApp + PcdGccMakefile
MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \ MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
@ -2950,7 +2950,7 @@ class DscBuildData(PlatformBuildClassObject):
MakeApp += "$(OBJECTS) : %s\n" % include_file MakeApp += "$(OBJECTS) : %s\n" % include_file
if sys.platform == "win32": if sys.platform == "win32":
PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c")) PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
MakeApp = MakeApp + '%s\PcdValueCommon.c : %s\n' % (self.OutputPath, PcdValueCommonPath) MakeApp = MakeApp + r'%s\PcdValueCommon.c : %s\n' % (self.OutputPath, PcdValueCommonPath)
MakeApp = MakeApp + '\tcopy /y %s $@\n' % (PcdValueCommonPath) MakeApp = MakeApp + '\tcopy /y %s $@\n' % (PcdValueCommonPath)
else: else:
PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c")) PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c"))

View File

@ -1897,7 +1897,7 @@ class DecParser(MetaFileParser):
self._SectionType = [] self._SectionType = []
ArchList = set() ArchList = set()
PrivateList = set() PrivateList = set()
Line = re.sub(',[\s]*', TAB_COMMA_SPLIT, self._CurrentLine) Line = re.sub(r',[\s]*', TAB_COMMA_SPLIT, self._CurrentLine)
for Item in Line[1:-1].split(TAB_COMMA_SPLIT): for Item in Line[1:-1].split(TAB_COMMA_SPLIT):
if Item == '': if Item == '':
EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR,