Commit da51af28 authored by Tamer Tas's avatar Tamer Tas Committed by V8 LUCI CQ

[infra] migrate the main PRESUBMIT script to py3

R=​machenbach@chromium.org,alexschulze@chromium.org

Bug: chromium:1298869
Change-Id: Icaba8b1eaf3e9171b39039681e48d54b6a7e479e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3472074
Commit-Queue: Tamer Tas <tmrts@chromium.org>
Auto-Submit: Tamer Tas <tmrts@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79172}
parent a5137930
...@@ -36,6 +36,9 @@ import os ...@@ -36,6 +36,9 @@ import os
import re import re
import sys import sys
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
_EXCLUDED_PATHS = ( _EXCLUDED_PATHS = (
r"^test[\\\/].*", r"^test[\\\/].*",
...@@ -223,7 +226,7 @@ def _CheckUnwantedDependencies(input_api, output_api): ...@@ -223,7 +226,7 @@ def _CheckUnwantedDependencies(input_api, output_api):
warning_descriptions = [] warning_descriptions = []
for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
added_includes): added_includes):
description_with_path = '%s\n %s' % (path, rule_description) description_with_path = '{}\n {}'.format(path, rule_description)
if rule_type == Rule.DISALLOW: if rule_type == Rule.DISALLOW:
error_descriptions.append(description_with_path) error_descriptions.append(description_with_path)
else: else:
...@@ -285,8 +288,8 @@ def _CheckHeadersHaveIncludeGuards(input_api, output_api): ...@@ -285,8 +288,8 @@ def _CheckHeadersHaveIncludeGuards(input_api, output_api):
break break
if not file_omitted and not all(found_patterns): if not file_omitted and not all(found_patterns):
problems.append( problems.append('{}: Missing include guard \'{}\''.format(
'%s: Missing include guard \'%s\'' % (local_path, guard_macro)) local_path, guard_macro))
if problems: if problems:
return [output_api.PresubmitError( return [output_api.PresubmitError(
...@@ -320,8 +323,8 @@ def _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api): ...@@ -320,8 +323,8 @@ def _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api):
local_path = f.LocalPath() local_path = f.LocalPath()
for line_number, line in f.ChangedContents(): for line_number, line in f.ChangedContents():
if (include_directive_pattern.search(line)): if (include_directive_pattern.search(line)):
problems.append( problems.append('{}:{}\n {}'.format(local_path, line_number,
'%s:%d\n %s' % (local_path, line_number, line.strip())) line.strip()))
if problems: if problems:
return [output_api.PresubmitError(include_error, problems)] return [output_api.PresubmitError(include_error, problems)]
...@@ -341,11 +344,13 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): ...@@ -341,11 +344,13 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
file_inclusion_pattern = r'.+\.cc' file_inclusion_pattern = r'.+\.cc'
base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?' base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?'
inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) inclusion_pattern = input_api.re.compile(
comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) r'({})\s*\('.format(base_function_pattern))
comment_pattern = input_api.re.compile(
r'//.*({})'.format(base_function_pattern))
exclusion_pattern = input_api.re.compile( exclusion_pattern = input_api.re.compile(
r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( r'::[A-Za-z0-9_]+({})|({})[^;]+'.format(base_function_pattern,
base_function_pattern, base_function_pattern)) base_function_pattern) + '\{')
def FilterFile(affected_file): def FilterFile(affected_file):
files_to_skip = (_EXCLUDED_PATHS + files_to_skip = (_EXCLUDED_PATHS +
...@@ -363,8 +368,8 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): ...@@ -363,8 +368,8 @@ def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
if (inclusion_pattern.search(line) and if (inclusion_pattern.search(line) and
not comment_pattern.search(line) and not comment_pattern.search(line) and
not exclusion_pattern.search(line)): not exclusion_pattern.search(line)):
problems.append( problems.append('{}:{}\n {}'.format(local_path, line_number,
'%s:%d\n %s' % (local_path, line_number, line.strip())) line.strip()))
if problems: if problems:
return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
...@@ -423,7 +428,7 @@ def _SkipTreeCheck(input_api, output_api): ...@@ -423,7 +428,7 @@ def _SkipTreeCheck(input_api, output_api):
def _CheckCommitMessageBugEntry(input_api, output_api): def _CheckCommitMessageBugEntry(input_api, output_api):
"""Check that bug entries are well-formed in commit message.""" """Check that bug entries are well-formed in commit message."""
bogus_bug_msg = ( bogus_bug_msg = (
'Bogus BUG entry: %s. Please specify the issue tracker prefix and the ' 'Bogus BUG entry: {}. Please specify the issue tracker prefix and the '
'issue number, separated by a colon, e.g. v8:123 or chromium:12345.') 'issue number, separated by a colon, e.g. v8:123 or chromium:12345.')
results = [] results = []
for bug in (input_api.change.BUG or '').split(','): for bug in (input_api.change.BUG or '').split(','):
...@@ -437,12 +442,13 @@ def _CheckCommitMessageBugEntry(input_api, output_api): ...@@ -437,12 +442,13 @@ def _CheckCommitMessageBugEntry(input_api, output_api):
prefix_guess = 'chromium' prefix_guess = 'chromium'
else: else:
prefix_guess = 'v8' prefix_guess = 'v8'
results.append('BUG entry requires issue tracker prefix, e.g. %s:%s' % results.append(
(prefix_guess, bug)) 'BUG entry requires issue tracker prefix, e.g. {}:{}'.format(
prefix_guess, bug))
except ValueError: except ValueError:
results.append(bogus_bug_msg % bug) results.append(bogus_bug_msg.format(bug))
elif not re.match(r'\w+:\d+', bug): elif not re.match(r'\w+:\d+', bug):
results.append(bogus_bug_msg % bug) results.append(bogus_bug_msg.format(bug))
return [output_api.PresubmitError(r) for r in results] return [output_api.PresubmitError(r) for r in results]
...@@ -459,8 +465,8 @@ def _CheckJSONFiles(input_api, output_api): ...@@ -459,8 +465,8 @@ def _CheckJSONFiles(input_api, output_api):
try: try:
json.load(j) json.load(j)
except Exception as e: except Exception as e:
results.append( results.append('JSON validation failed for {}. Error:\n{}'.format(
'JSON validation failed for %s. Error:\n%s' % (f.LocalPath(), e)) f.LocalPath(), e))
return [output_api.PresubmitError(r) for r in results] return [output_api.PresubmitError(r) for r in results]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment