diff --git a/PRESUBMIT.py b/PRESUBMIT.py index ec4e5d2f5144..6662d2e636ca 100644 --- a/PRESUBMIT.py +++ b/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 @@ 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 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 @@ -158,8 +162,8 @@ 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 [] @@ -167,7 +171,6 @@ def HasFormatErrors(filename=None, contents=None): 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.', diff --git a/pkg/_fe_analyzer_shared/PRESUBMIT.py b/pkg/_fe_analyzer_shared/PRESUBMIT.py index 1a4331de4217..70592807da55 100644 --- a/pkg/_fe_analyzer_shared/PRESUBMIT.py +++ b/pkg/_fe_analyzer_shared/PRESUBMIT.py @@ -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 os.path import subprocess +USE_PYTHON3 = True + def runSmokeTest(input_api, output_api): hasChangedFiles = False diff --git a/pkg/front_end/PRESUBMIT.py b/pkg/front_end/PRESUBMIT.py index 8f25cd26adc6..0a0490477b19 100644 --- a/pkg/front_end/PRESUBMIT.py +++ b/pkg/front_end/PRESUBMIT.py @@ -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 os.path import subprocess +USE_PYTHON3 = True + def runSmokeTest(input_api, output_api): hasChangedFiles = False diff --git a/pkg/kernel/PRESUBMIT.py b/pkg/kernel/PRESUBMIT.py index ee42fc840bfd..8630f2084e58 100644 --- a/pkg/kernel/PRESUBMIT.py +++ b/pkg/kernel/PRESUBMIT.py @@ -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 os.path import subprocess +USE_PYTHON3 = True + def runSmokeTest(input_api, output_api): hasChangedFiles = False diff --git a/runtime/PRESUBMIT.py b/runtime/PRESUBMIT.py index 210b9518651c..2077f5a9881d 100644 --- a/runtime/PRESUBMIT.py +++ b/runtime/PRESUBMIT.py @@ -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 diff --git a/tools/dom/PRESUBMIT.py b/tools/dom/PRESUBMIT.py deleted file mode 100644 index f6a643958380..000000000000 --- a/tools/dom/PRESUBMIT.py +++ /dev/null @@ -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