Skip to content

Commit

Permalink
[python3] Migrate PRESUBMIT.py files
Browse files Browse the repository at this point in the history
* Force depot_tools to use python3 results (USE_PYTHON3=True).
* Fixes the dart format presubmit check.
* Remove broken DOM tools presubmit check.

TEST=Manually provoked errors and ran git cl presubmit -v -f.

Cq-Include-Trybots: luci.dart.try.shared:presubmit-try
Change-Id: I8ba46e2ae1640f1b2f82e18bc8024e0aa4838b2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210123
Reviewed-by: Ben Konyi <[email protected]>
Reviewed-by: William Hesse <[email protected]>
  • Loading branch information
athomas committed Aug 16, 2021
1 parent 79be589 commit d2bd43f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 81 deletions.
39 changes: 18 additions & 21 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Expand All @@ -10,11 +11,14 @@
import imp
import os
import os.path
from typing import Callable
import scm
import subprocess
import tempfile
import platform

USE_PYTHON3 = True


def is_cpp_file(path):
return path.endswith('.cc') or path.endswith('.h')

Expand Down Expand Up @@ -68,7 +72,7 @@ def _CheckFormat(input_api,
identification,
extension,
windows,
hasFormatErrors,
hasFormatErrors: Callable[[str, str], bool],
should_skip=lambda path: False):
local_root = input_api.change.RepositoryRoot()
upstream = input_api.change._upstream
Expand Down Expand Up @@ -105,7 +109,6 @@ def _CheckFormat(input_api,

def _CheckDartFormat(input_api, output_api):
local_root = input_api.change.RepositoryRoot()
upstream = input_api.change._upstream
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))

Expand All @@ -119,7 +122,7 @@ def _CheckDartFormat(input_api, output_api):
print('WARNING: dart not found: %s' % (dart))
return []

def HasFormatErrors(filename=None, contents=None):
def HasFormatErrors(filename: str = None, contents: str = None):
# Don't look for formatting errors in multitests. Since those are very
# sensitive to whitespace, many cannot be formatted with dartfmt without
# breaking them.
Expand All @@ -135,11 +138,12 @@ def HasFormatErrors(filename=None, contents=None):
'--set-exit-if-changed',
'--output=none',
'--summary=none',
filename,
]

process = subprocess.Popen(
args, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
if contents:
process = subprocess.run(args, input=contents, text=True)
else:
args.append(filename)
process = subprocess.run(args)

# Check for exit code 1 explicitly to distinguish it from a syntax error
# in the file (exit code 65). The repo contains many Dart files that are
Expand All @@ -158,16 +162,15 @@ def HasFormatErrors(filename=None, contents=None):
output_api.PresubmitError(
'File output does not match dartfmt.\n'
'Fix these issues with:\n'
'%s -w%s%s' % (prebuilt_dartfmt, lineSep,
lineSep.join(unformatted_files)))
'%s format %s%s' %
(dart, lineSep, lineSep.join(unformatted_files)))
]

return []


def _CheckStatusFiles(input_api, output_api):
local_root = input_api.change.RepositoryRoot()
upstream = input_api.change._upstream
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))

Expand All @@ -188,9 +191,7 @@ def _CheckStatusFiles(input_api, output_api):

def HasFormatErrors(filename=None, contents=None):
args = [dart, lint] + (['-t'] if contents else [filename])
process = subprocess.Popen(
args, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
process.communicate(input=contents)
process = subprocess.run(args, input=contents, text=True)
return process.returncode != 0

def should_skip(path):
Expand Down Expand Up @@ -230,12 +231,8 @@ def _CheckPackageConfigUpToDate(input_api, output_api):
dart = utils.CheckedInSdkExecutable()
generate = os.path.join(local_root, 'tools', 'generate_package_config.dart')
cmd = [dart, generate, '--check']
pipe = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=utils.IsWindows())
output = pipe.communicate()
if pipe.returncode != 0:
result = subprocess.run(cmd, shell=utils.IsWindows())
if result.returncode != 0:
return [
output_api.PresubmitError(
'File .dart_tool/package_config.json is out of date.\n'
Expand All @@ -255,7 +252,7 @@ def _CheckValidHostsInDEPS(input_api, output_api):
try:
input_api.subprocess.check_output(['gclient', 'verify'])
return []
except input_api.subprocess.CalledProcessError, error:
except input_api.subprocess.CalledProcessError as error:
return [
output_api.PresubmitError(
'DEPS file must have only dependencies from allowed hosts.',
Expand Down
3 changes: 3 additions & 0 deletions pkg/_fe_analyzer_shared/PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Expand All @@ -11,6 +12,8 @@
import os.path
import subprocess

USE_PYTHON3 = True


def runSmokeTest(input_api, output_api):
hasChangedFiles = False
Expand Down
3 changes: 3 additions & 0 deletions pkg/front_end/PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Expand All @@ -11,6 +12,8 @@
import os.path
import subprocess

USE_PYTHON3 = True


def runSmokeTest(input_api, output_api):
hasChangedFiles = False
Expand Down
3 changes: 3 additions & 0 deletions pkg/kernel/PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Expand All @@ -11,6 +12,8 @@
import os.path
import subprocess

USE_PYTHON3 = True


def runSmokeTest(input_api, output_api):
hasChangedFiles = False
Expand Down
3 changes: 2 additions & 1 deletion runtime/PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

import os
import cpplint
import re
import StringIO

USE_PYTHON3 = True

# memcpy does not handle overlapping memory regions. Even though this
# is well documented it seems to be used in error quite often. To avoid
Expand Down
59 changes: 0 additions & 59 deletions tools/dom/PRESUBMIT.py

This file was deleted.

0 comments on commit d2bd43f

Please sign in to comment.