[tools] Fix invalid escape sequence warnings in Python scripts

Running tools/run_perf.py or the presubmit with Python 3.12 prints
"SyntaxWarning: invalid escape sequence" for regexes written as plain
string literals, the same problem crrev.com/c/7580173 fixed in
test/benchmarks/csuite/benchmark.py. Compiling every tracked .py file
with warnings enabled still reports 29 such escapes in 14 files, and
Python has announced that they will eventually become a SyntaxError.

This turns them into raw strings. In sancov_formatter.py the literals
also contained \' so they become double-quoted raw strings, and in
mb_test.py the Windows path only gets its remaining backslashes doubled.

Nothing should change at runtime. I compared the AST of each file
before and after: all string values are identical except four patterns
in v8_presubmit.py where "\n" becomes r"\n", and those compile to the
same regex bytecode. After the change no tracked .py file emits a
SyntaxWarning.

AI tools used

Change-Id: If33347a100847ac0d7506206bf909662b0258524
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8400127
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#109806}
This commit is contained in:
leoca authored and v8-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-09-14 03:21:32 -07:00
1 parent 1d3ed7e2a3
commit baec853a93
14 files changed
+28 -28

No files matched your search

+1 -1
View File
@@ -436,7 +436,7 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
r'//.*({})'.format(base_function_pattern))
exclusion_pattern = input_api.re.compile(
r'::[A-Za-z0-9_]+({})|({})[^;]+'.format(base_function_pattern,
base_function_pattern) + '\{')
base_function_pattern) + r'\{')
def FilterFile(affected_file):
files_to_skip = (_EXCLUDED_PATHS +
+3 -3
View File
@@ -15,10 +15,10 @@ import sys
from blinkpy.common.system.log_utils import configure_logging
from blinkpy.w3c.common import read_credentials
TEST_FILE_REFERENCE_IN_STATUS_FILE = re.compile("^\s*'(.*)':.*,$")
TEST_FILE_REFERENCE_IN_STATUS_FILE = re.compile(r"^\s*'(.*)':.*,$")
TEST262_FAILURE_LINE = re.compile("=== test262/(.*) ===")
TEST262_PATTERN = re.compile('^test/(.*)\.[^\s]*$')
TEST262_RENAME_PATTERN = re.compile('^R[^\s]*\s*([^\s]*)\s*([^\s]*)$')
TEST262_PATTERN = re.compile(r'^test/(.*)\.[^\s]*$')
TEST262_RENAME_PATTERN = re.compile(r'^R[^\s]*\s*([^\s]*)\s*([^\s]*)$')
TEST262_REPO_URL = 'https://chromium.googlesource.com/external/github.com/tc39/test262'
V8_TEST262_ROLLS_META_BUG = 'v8:7834'
+2 -2
View File
@@ -282,9 +282,9 @@ def jomb(debugger, param, *args):
@lldbCommand
def bta(debugger, *args):
"""Print stack trace with assertion scopes"""
func_name_re = re.compile("([^(<]+)(?:\(.+\))?")
func_name_re = re.compile(r"([^(<]+)(?:\(.+\))?")
assert_re = re.compile(
"^v8::internal::Per\w+AssertType::(\w+)_ASSERT, (false|true)>")
r"^v8::internal::Per\w+AssertType::(\w+)_ASSERT, (false|true)>")
thread = current_thread(debugger)
for frame in thread:
functionSignature = frame.GetDisplayFunctionName()
+1 -1
View File
@@ -32,7 +32,7 @@ except NameError:
ARGPARSE = argparse.ArgumentParser(
description=("A script that computes LoC for a build dir"),
epilog="""Examples:
epilog=r"""Examples:
Count with default settings for build in out/Default:
locs.py --build-dir out/Default
Count only a custom group of files settings for build in out/Default:
+1 -1
View File
@@ -547,7 +547,7 @@ class UnitTest(unittest.TestCase):
" 'type': 'raw',"
" 'args': [],"
"}}\n"),
'c:\\fake_src\out\Default\cc_perftests.exe.runtime_deps':
'c:\\fake_src\\out\\Default\\cc_perftests.exe.runtime_deps':
("cc_perftests\n"),
}
mbw = self.fake_mbw(files=files, win32=True)
+5 -5
View File
@@ -624,16 +624,16 @@ class Step(GitRecipesMixin):
output = ""
for line in FileToText(version_file).splitlines():
if line.startswith("#define V8_MAJOR_VERSION"):
line = re.sub("\d+$", self[prefix + "major"], line)
line = re.sub(r"\d+$", self[prefix + "major"], line)
elif line.startswith("#define V8_MINOR_VERSION"):
line = re.sub("\d+$", self[prefix + "minor"], line)
line = re.sub(r"\d+$", self[prefix + "minor"], line)
elif line.startswith("#define V8_BUILD_NUMBER"):
line = re.sub("\d+$", self[prefix + "build"], line)
line = re.sub(r"\d+$", self[prefix + "build"], line)
elif line.startswith("#define V8_PATCH_LEVEL"):
line = re.sub("\d+$", self[prefix + "patch"], line)
line = re.sub(r"\d+$", self[prefix + "patch"], line)
elif (self[prefix + "candidate"] and
line.startswith("#define V8_IS_CANDIDATE_VERSION")):
line = re.sub("\d+$", self[prefix + "candidate"], line)
line = re.sub(r"\d+$", self[prefix + "candidate"], line)
output += "%s\n" % line
TextToFile(output, version_file)
+1 -1
View File
@@ -118,7 +118,7 @@ class EnableMergeWatchlist(Step):
def RunStep(self):
old_watchlist_content = FileToText(os.path.join(self.default_cwd,
WATCHLISTS_FILE))
new_watchlist_content = re.sub("(# 'v8-merges@googlegroups\.com',)",
new_watchlist_content = re.sub(r"(# 'v8-merges@googlegroups\.com',)",
"'v8-merges@googlegroups.com',",
old_watchlist_content)
TextToFile(new_watchlist_content, os.path.join(self.default_cwd,
+1 -1
View File
@@ -88,7 +88,7 @@ def get_first_canary(branches):
return canaries[0].split('/')[-1]
def get_first_v8_version(branches):
version_re = re.compile("remotes/origin/[0-9]+\.[0-9]+\.[0-9]+")
version_re = re.compile(r"remotes/origin/[0-9]+\.[0-9]+\.[0-9]+")
versions = [branch for branch in branches if version_re.match(branch)]
if len(versions) == 0:
return "--"
+1 -1
View File
@@ -18,7 +18,7 @@ import sys
CLANG_TIDY_WARNING = re.compile(r'(\/.*?)\ .*\[(.*)\]$')
CLANG_TIDY_CMDLINE_OUT = re.compile(r'^clang-tidy.*\ .*|^\./\.\*')
FILE_REGEXS = ['../src/*', '../test/*']
HEADER_REGEX = ['\.\.\/src\/.*|\.\.\/include\/.*|\.\.\/test\/.*']
HEADER_REGEX = [r'\.\.\/src\/.*|\.\.\/include\/.*|\.\.\/test\/.*']
THREADS = multiprocessing.cpu_count()
+1 -1
View File
@@ -5,7 +5,7 @@
from __future__ import annotations
"""
r"""
Performance runner for d8.
Call e.g. with tools/run-perf.py --arch x64 some_suite.json
+3 -3
View File
@@ -168,9 +168,9 @@ def get_instrumented_lines(executable):
# We don't call the sancov tool to get more speed.
process = subprocess.Popen(
'objdump -d %s | '
'grep \'^\s\+[0-9a-f]\+:.*\scall\(q\|\)\s\+[0-9a-f]\+ '
'<__sanitizer_cov\(_with_check\|\|_trace_pc_guard\)\(@plt\|\)>\' | '
'grep \'^\s\+[0-9a-f]\+\' -o | '
r"grep '^\s\+[0-9a-f]\+:.*\scall\(q\|\)\s\+[0-9a-f]\+ "
r"<__sanitizer_cov\(_with_check\|\|_trace_pc_guard\)\(@plt\|\)>' | "
r"grep '^\s\+[0-9a-f]\+' -o | "
'%s | '
'%s --obj %s -functions=none' %
(executable, SANITIZE_PCS, SYMBOLIZER, executable),
+1 -1
View File
@@ -38,7 +38,7 @@ class ExceptionOutProc(base.OutProc):
# somefile:somelinenumber: someerror[: sometext]
# somefile might include an optional drive letter on windows e.g. "e:".
match = re.search(
'^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', string, re.MULTILINE)
r'^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', string, re.MULTILINE)
if match:
return match.group(1).strip()
else:
+1 -1
View File
@@ -33,7 +33,7 @@ def main():
if not os.path.isfile(OUTPUT):
sys.exit("Output file {} does not exist; run this script in a v8 checkout."
.format(OUTPUT))
regexp = re.compile('^#define (\w+)')
regexp = re.compile(r'^#define (\w+)')
seen = set()
with open(INPUT, 'r') as infile, open(OUTPUT, 'w') as outfile:
outfile.write(HEADER)
+6 -6
View File
@@ -74,11 +74,11 @@ LINT_RULES = """
""".split()
LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]')
FLAGS_LINE = re.compile("//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n")
FLAGS_LINE = re.compile(r"//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n")
ASSERT_OPTIMIZED_PATTERN = re.compile("assertOptimized")
FLAGS_ENABLE_MAGLEV = re.compile("//\s*Flags:.*--maglev[^-].*\n")
FLAGS_ENABLE_TURBOLEV = re.compile("//\s*Flags:.*--turbolev[^-].*\n")
FLAGS_ENABLE_TURBOFAN = re.compile("//\s*Flags:.*--turbofan[^-].*\n")
FLAGS_ENABLE_MAGLEV = re.compile(r"//\s*Flags:.*--maglev[^-].*\n")
FLAGS_ENABLE_TURBOLEV = re.compile(r"//\s*Flags:.*--turbolev[^-].*\n")
FLAGS_ENABLE_TURBOFAN = re.compile(r"//\s*Flags:.*--turbofan[^-].*\n")
ASSERT_UNOPTIMIZED_PATTERN = re.compile("assertUnoptimized")
TOOLS_PATH = dirname(abspath(__file__))
@@ -541,7 +541,7 @@ class SourceProcessor(SourceFileProcessor):
print ("Runtime functions list is suspiciously short. "
"Consider updating the presubmit script.")
sys.exit(1)
str = '(\%\s+(' + '|'.join(runtime_functions) + '))[\s\(]'
str = r'(\%\s+(' + '|'.join(runtime_functions) + r'))[\s\(]'
return re.compile(str)
# Overwriting the one in the parent class.
@@ -789,7 +789,7 @@ class GCMoleProcessor(SourceFileProcessor):
tools/gcmole/gcmole.py::build_file_list()
"""
gcmole_re = re.compile('### gcmole(.*)')
arch_re = re.compile('\((.+)\) ###')
arch_re = re.compile(r'\((.+)\) ###')
def IsRelevant(self, name):
return True