mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:59:16 +00:00
[python3] Migrate PRESUBMIT.py files
* 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 <bkonyi@google.com> Reviewed-by: William Hesse <whesse@google.com>
This commit is contained in:
parent
79be5898b4
commit
d2bd43f43e
39
PRESUBMIT.py
39
PRESUBMIT.py
|
@ -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.
|
||||
|
@ -10,11 +11,14 @@ for more details about the presubmit API built into gcl.
|
|||
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')
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'))
|
||||
|
||||
|
@ -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.
|
||||
|
@ -135,11 +138,12 @@ def _CheckDartFormat(input_api, output_api):
|
|||
'--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
|
||||
|
@ -158,8 +162,8 @@ def _CheckDartFormat(input_api, output_api):
|
|||
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 []
|
||||
|
@ -167,7 +171,6 @@ def _CheckDartFormat(input_api, output_api):
|
|||
|
||||
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'))
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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'
|
||||
|
@ -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.',
|
||||
|
|
|
@ -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.
|
||||
|
@ -11,6 +12,8 @@ import imp
|
|||
import os.path
|
||||
import subprocess
|
||||
|
||||
USE_PYTHON3 = True
|
||||
|
||||
|
||||
def runSmokeTest(input_api, output_api):
|
||||
hasChangedFiles = False
|
||||
|
|
|
@ -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.
|
||||
|
@ -11,6 +12,8 @@ import imp
|
|||
import os.path
|
||||
import subprocess
|
||||
|
||||
USE_PYTHON3 = True
|
||||
|
||||
|
||||
def runSmokeTest(input_api, output_api):
|
||||
hasChangedFiles = False
|
||||
|
|
|
@ -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.
|
||||
|
@ -11,6 +12,8 @@ import imp
|
|||
import os.path
|
||||
import subprocess
|
||||
|
||||
USE_PYTHON3 = True
|
||||
|
||||
|
||||
def runSmokeTest(input_api, output_api):
|
||||
hasChangedFiles = False
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/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.
|
||||
|
@ -5,8 +6,8 @@
|
|||
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
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
# Copyright (c) 2013, 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.
|
||||
"""
|
||||
Presubmit tests for dom tools.
|
||||
|
||||
This file is run by git_cl or gcl when an upload or submit happens with
|
||||
any files at this level or lower are in the change list.
|
||||
|
||||
See: http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def _AnySdkFiles(input_api):
|
||||
""" Returns true if any of the changed files are in the sdk, meaning we should
|
||||
check that docs.dart was run.
|
||||
"""
|
||||
for f in input_api.change.AffectedFiles():
|
||||
if f.LocalPath().find('sdk') > -1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
# TODO(amouravski): uncomment this check once docs.dart is faster.
|
||||
# if _AnySdkFiles(input_api):
|
||||
# results.extend(CheckDocs(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
def CheckChangeOnCommit(input_api, output_api):
|
||||
results = []
|
||||
if _AnySdkFiles(input_api):
|
||||
results.extend(CheckDocs(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
def CheckDocs(input_api, output_api):
|
||||
"""Ensure that documentation has been generated if it needs to be generated.
|
||||
|
||||
Prompts with a warning if documentation needs to be generated.
|
||||
"""
|
||||
results = []
|
||||
|
||||
cmd = [os.path.join(input_api.PresubmitLocalPath(), 'dom.py'), 'test_docs']
|
||||
|
||||
try:
|
||||
input_api.subprocess.check_output(
|
||||
cmd, stderr=input_api.subprocess.STDOUT)
|
||||
except (OSError, input_api.subprocess.CalledProcessError), e:
|
||||
results.append(
|
||||
output_api.PresubmitPromptWarning(
|
||||
('Docs test failed!%s\nYou should run `dom.py docs`' %
|
||||
(e if input_api.verbose else ''))))
|
||||
|
||||
return results
|
Loading…
Reference in a new issue