From b871f2c17a56685306f1e8736df4b39a6ba89bbe Mon Sep 17 00:00:00 2001 From: Slice Date: Sun, 25 Feb 2024 22:31:31 +0300 Subject: [PATCH] adoptation to python312 Signed-off-by: Slice --- BaseTools/Source/Python/AmlToC/AmlToC.py | 2 +- .../Source/Python/AutoGen/BuildEngine.py | 2 +- BaseTools/Source/Python/AutoGen/GenDepex.py | 2 +- BaseTools/Source/Python/AutoGen/GenMake.py | 2 +- .../Source/Python/AutoGen/IdfClassObject.py | 2 +- .../Source/Python/AutoGen/ModuleAutoGen.py | 4 ++-- BaseTools/Source/Python/AutoGen/StrGather.py | 2 +- .../Source/Python/AutoGen/WorkspaceAutoGen.py | 2 +- BaseTools/Source/Python/Common/Expression.py | 12 +++++----- BaseTools/Source/Python/Common/GlobalData.py | 4 ++-- BaseTools/Source/Python/Common/Misc.py | 24 +++++++++---------- .../Python/Common/ToolDefClassObject.py | 6 ++--- BaseTools/Source/Python/GenFds/FdfParser.py | 10 ++++---- BaseTools/Source/Python/GenFds/GenFds.py | 2 +- .../GenPatchPcdTable/GenPatchPcdTable.py | 12 +++++----- BaseTools/Source/Python/Trim/Trim.py | 18 +++++++------- .../Source/Python/Workspace/DscBuildData.py | 6 ++--- .../Source/Python/Workspace/MetaFileParser.py | 2 +- Include/IndustryStandard/PeImage.h | 20 ++++++++++++++++ MdePkg/Include/IndustryStandard/PeImage.h | 19 +++++++++++++++ MdePkg/Include/IndustryStandard/PeImage2.h | 6 +++++ 21 files changed, 102 insertions(+), 57 deletions(-) diff --git a/BaseTools/Source/Python/AmlToC/AmlToC.py b/BaseTools/Source/Python/AmlToC/AmlToC.py index 346de7159..63931c972 100644 --- a/BaseTools/Source/Python/AmlToC/AmlToC.py +++ b/BaseTools/Source/Python/AmlToC/AmlToC.py @@ -17,7 +17,7 @@ from Common.BuildToolError import * import sys import os -__description__ = """ +__description__ = r""" 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. Tables\Dsdt.c will contain a C array named "dsdt_aml_code" that contains diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py index 722fead75..8876d0495 100644 --- a/BaseTools/Source/Python/AutoGen/BuildEngine.py +++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py @@ -306,7 +306,7 @@ class BuildRule: _SubSectionList = [_InputFile, _OutputFile, _Command] _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}")], ["$(CP) ${src} ${dst}"], []) diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source/Python/AutoGen/GenDepex.py index f2f2e9d65..b6db6645a 100644 --- a/BaseTools/Source/Python/AutoGen/GenDepex.py +++ b/BaseTools/Source/Python/AutoGen/GenDepex.py @@ -126,7 +126,7 @@ class DependencyExpression: # # open and close brace must be taken as individual tokens # - TokenPattern = re.compile("(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)") + TokenPattern = re.compile(r"(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)") ## Constructor # diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 219c8185d..90f4d2fa5 100755 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -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) ## 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 = {} diff --git a/BaseTools/Source/Python/AutoGen/IdfClassObject.py b/BaseTools/Source/Python/AutoGen/IdfClassObject.py index a6b8123c2..bb413c6a2 100644 --- a/BaseTools/Source/Python/AutoGen/IdfClassObject.py +++ b/BaseTools/Source/Python/AutoGen/IdfClassObject.py @@ -18,7 +18,7 @@ import os from Common.GlobalData import gIdentifierPattern 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 diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py index 368a31047..be408db2e 100755 --- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py @@ -51,12 +51,12 @@ gInfSpecVersion = "0x00010017" # # 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: # 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 diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py index eed30388b..9789f50ba 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -54,7 +54,7 @@ NOT_REFERENCED = 'not referenced' COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED CHAR_ARRAY_DEFIN = 'unsigned char' 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_PACKAGE_HEADER_LENGTH = 4 diff --git a/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py b/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py index f86c749c0..160e3a3cd 100644 --- a/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py @@ -26,7 +26,7 @@ from Common.Misc import * import json ## 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) gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$") diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 07ca039a9..bffa23548 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -242,10 +242,10 @@ class ValueExpression(BaseExpression): SymbolPattern = re.compile("(" - "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|" - "&&|\|\||!(?!=)|" - "(?<=\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"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|" + r"&&|\|\||!(?!=)|" + r"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|" + r"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)" ")") @staticmethod @@ -737,7 +737,7 @@ class ValueExpression(BaseExpression): self._Token = "'" + UStr + "'" return self._Token elif Expr.startswith('UINT'): - Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') + Re = re.compile(r'(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') try: RetValue = Re.search(Expr).group(1) except: @@ -975,7 +975,7 @@ class ValueExpressionEx(ValueExpression): TokenSpaceGuidName = '' if Item.startswith(TAB_GUID) and Item.endswith(')'): try: - TokenSpaceGuidName = re.search('GUID\((\w+)\)', Item).group(1) + TokenSpaceGuidName = re.search(r'GUID\((\w+)\)', Item).group(1) except: pass if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb: diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Source/Python/Common/GlobalData.py index a8fe755d9..9173880bf 100755 --- a/BaseTools/Source/Python/Common/GlobalData.py +++ b/BaseTools/Source/Python/Common/GlobalData.py @@ -32,10 +32,10 @@ gDefaultStores = [] gGuidDict = {} # 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 -gMacroRefPattern = re.compile("\$\(({})\)".format(_MacroNamePattern), re.UNICODE) +gMacroRefPattern = re.compile(r"\$\(({})\)".format(_MacroNamePattern), re.UNICODE) gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+") gMacroNamePattern = re.compile("^{}$".format(_MacroNamePattern)) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 4be795713..f87d9dbdb 100755 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -41,16 +41,16 @@ from CommonDataClass.Exceptions import BadExpression from Common.caching import cached_property 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 -gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE) +gPlaceholderPattern = re.compile(r"\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE) ## regular expressions for map file processing -startPatternGeneral = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class") -addressPatternGeneral = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base") -valuePatternGcc = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$') -pcdPatternGcc = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)') -secReGeneral = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE) +startPatternGeneral = re.compile(r"^Start[' ']+Length[' ']+Name[' ']+Class") +addressPatternGeneral = re.compile(r"^Address[' ']+Publics by Value[' ']+Rva\+Base") +valuePatternGcc = re.compile(r'^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$') +pcdPatternGcc = re.compile(r'^([\da-fA-Fx]+) +([\da-fA-Fx]+)') +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_]*$') @@ -82,7 +82,7 @@ def GetVariableOffset(mapfilepath, efifilepath, varnames): if len(lines) == 0: return None 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) if (firstline.startswith("Archive member included ") and firstline.endswith(" file (symbol)")): @@ -96,7 +96,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames): ret = [] for line in lines: 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:"): status = 1 continue @@ -104,7 +104,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames): for varname in varnames: if varname in line: # 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: ret.append((varname, m.group(1))) return ret @@ -170,7 +170,7 @@ def _parseGeneral(lines, efifilepath, varnames): status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table secs = [] # key = section name 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: line = line.strip() @@ -1926,4 +1926,4 @@ def CopyDict(ori_dict): # Remove the c/c++ comments: // and /* */ # def RemoveCComments(ctext): - return re.sub('//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S) + return re.sub(r'//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S) diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseTools/Source/Python/Common/ToolDefClassObject.py index 2b4b23849..afc20a3c1 100644 --- a/BaseTools/Source/Python/Common/ToolDefClassObject.py +++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py @@ -30,9 +30,9 @@ from .DataType import TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\ ## # Static variables used for pattern # -gMacroRefPattern = re.compile('(DEF\([^\(\)]+\))') -gEnvRefPattern = re.compile('(ENV\([^\(\)]+\))') -gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)") +gMacroRefPattern = re.compile(r'(DEF\([^\(\)]+\))') +gEnvRefPattern = re.compile(r'(ENV\([^\(\)]+\))') +gMacroDefPattern = re.compile(r"DEFINE\s+([^\s]+)") gDefaultToolsDefFile = "tools_def.txt" ## ToolDefClassObject diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 5c8263f9b..a8814ee32 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -64,11 +64,11 @@ ALIGNMENTS = {"Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "6 ALIGNMENT_NOAUTO = ALIGNMENTS - {"Auto"} CR_LB_SET = {T_CHAR_CR, TAB_LINE_BREAK} -RegionSizePattern = compile("\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*") -RegionSizeGuidPattern = compile("\s*(?P\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P\w+\.\w+[\.\w\[\]]*)\s*") -RegionOffsetPcdPattern = compile("\s*(?P\w+\.\w+[\.\w\[\]]*)\s*$") -ShortcutPcdPattern = compile("\s*\w+\s*=\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P\w+\.\w+)\s*") -BaseAddrValuePattern = compile('^0[xX][0-9a-fA-F]+') +RegionSizePattern = compile(r"\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*") +RegionSizeGuidPattern = compile(r"\s*(?P\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P\w+\.\w+[\.\w\[\]]*)\s*") +RegionOffsetPcdPattern = compile(r"\s*(?P\w+\.\w+[\.\w\[\]]*)\s*$") +ShortcutPcdPattern = compile(r"\s*\w+\s*=\s*(?P(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P\w+\.\w+)\s*") +BaseAddrValuePattern = compile(r'^0[xX][0-9a-fA-F]+') 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\)|\*)') AllIncludeFileList = [] diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index c34104500..a43dde37e 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -733,7 +733,7 @@ class GenFds(object): if not os.path.exists(FfsPath[0]): continue 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]) for File in FileList: Match = ReFileEnds.search(File) diff --git a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py index d962ab0ad..8750db998 100644 --- a/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py +++ b/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py @@ -31,7 +31,7 @@ __copyright__ = "Copyright (c) 2008 - 2018, Intel Corporation. All rights reserv #====================================== Internal Libraries ======================================== #============================================== 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): """ Parse map file to get binary patch pcd information @@ -49,7 +49,7 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath): if len(lines) == 0: return None 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) if (firstline.startswith("Archive member included ") and firstline.endswith(" file (symbol)")): @@ -59,12 +59,12 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath): return _parseGeneral(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 pcds = [] for line in lines: 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:"): status = 1 continue @@ -77,7 +77,7 @@ def _parseForXcodeAndClang9(lines, efifilepath): def _parseForGCC(lines, efifilepath): """ 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 imageBase = -1 sections = [] @@ -136,7 +136,7 @@ def _parseGeneral(lines, efifilepath): status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table secs = [] # key = section name bPcds = [] - symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)') + symPattern = re.compile(r'^[_]+gPcd_BinaryPatch_([\w]+)') for line in lines: line = line.strip() diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py index c479f7d2b..c1091163f 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -28,15 +28,15 @@ __version__ = "%prog Version " + __version_number__ __copyright__ = "Copyright (c) 2007-2018, Intel Corporation. All rights reserved." ## 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" -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" -gPragmaPattern = re.compile("^\s*#pragma\s+pack", re.MULTILINE) +gPragmaPattern = re.compile(r"^\s*#pragma\s+pack", re.MULTILINE) ## 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" -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: @@ -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 # ## 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 -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 -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 -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 gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE) ## Patterns used to convert EDK conventions to EDK2 ECP conventions diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index d1ee0ccae..1aff3bf3c 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -109,7 +109,7 @@ LIBS = -lCommon variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$') SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$') ## 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]+$') ## Regular expression for finding header file inclusions from AutoGen.GenMake import gIncludePattern @@ -2829,7 +2829,7 @@ class DscBuildData(PlatformBuildClassObject): # start generating makefile MakeApp = PcdMakefileHeader 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: 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)) + \ @@ -2939,7 +2939,7 @@ class DscBuildData(PlatformBuildClassObject): MakeApp += "$(OBJECTS) : %s\n" % include_file if sys.platform == "win32": 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) else: PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source/C/Common/PcdValueCommon.c")) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index a3b6edbd1..42bf2376a 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1893,7 +1893,7 @@ class DecParser(MetaFileParser): self._SectionType = [] ArchList = 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): if Item == '': EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, diff --git a/Include/IndustryStandard/PeImage.h b/Include/IndustryStandard/PeImage.h index 4efed8eeb..5736686e1 100644 --- a/Include/IndustryStandard/PeImage.h +++ b/Include/IndustryStandard/PeImage.h @@ -40,6 +40,12 @@ http://opensource.org/licenses/bsd-license.php. #define IMAGE_FILE_MACHINE_X64 0x8664 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x01c2 #define IMAGE_FILE_MACHINE_ARM64 0xAA64 +#define IMAGE_FILE_MACHINE_RISCV32 0x5032 +#define IMAGE_FILE_MACHINE_RISCV64 0x5064 +#define IMAGE_FILE_MACHINE_RISCV128 0x5128 +#define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232 +#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 + // // EXE file formats @@ -499,6 +505,20 @@ typedef struct { #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9 #define EFI_IMAGE_REL_BASED_DIR64 10 +/// +/// Relocation types of RISC-V processor. +/// +#define EFI_IMAGE_REL_BASED_RISCV_HI20 5 +#define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7 +#define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8 + +// +// Relocation types of LoongArch processor. +// +#define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8 +#define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8 + + /// /// Line number format. /// diff --git a/MdePkg/Include/IndustryStandard/PeImage.h b/MdePkg/Include/IndustryStandard/PeImage.h index 720bb084a..976aa82b2 100644 --- a/MdePkg/Include/IndustryStandard/PeImage.h +++ b/MdePkg/Include/IndustryStandard/PeImage.h @@ -34,6 +34,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define IMAGE_FILE_MACHINE_X64 0x8664 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x01c2 #define IMAGE_FILE_MACHINE_ARM64 0xAA64 +#define IMAGE_FILE_MACHINE_RISCV32 0x5032 +#define IMAGE_FILE_MACHINE_RISCV64 0x5064 +#define IMAGE_FILE_MACHINE_RISCV128 0x5128 +#define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232 +#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 + // // EXE file formats @@ -493,6 +499,19 @@ typedef struct { #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9 #define EFI_IMAGE_REL_BASED_DIR64 10 +/// +/// Relocation types of RISC-V processor. +/// +#define EFI_IMAGE_REL_BASED_RISCV_HI20 5 +#define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7 +#define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8 + +// +// Relocation types of LoongArch processor. +// +#define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8 +#define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8 + /// /// Line number format. /// diff --git a/MdePkg/Include/IndustryStandard/PeImage2.h b/MdePkg/Include/IndustryStandard/PeImage2.h index c17104722..2bf729be5 100644 --- a/MdePkg/Include/IndustryStandard/PeImage2.h +++ b/MdePkg/Include/IndustryStandard/PeImage2.h @@ -505,6 +505,12 @@ typedef struct { #define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7 #define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8 +// +// Relocation types of LoongArch processor. +// +#define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8 +#define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8 + /// /// Line number format. ///