8b66930364
Previously, in the `CheckSorted` presubmit check, if
`verify_sorted_test.dart` returned a nonzero exit code but none of its
output lines contained the string `Unsorted file`, then a presubmit
failure would be generated containing an empty string, resulting in
confusing output like this:
Running presubmit upload checks ...
18.4s to run CheckChangeOnUpload from /home/paulberry/dart1/sdk/pkg/_fe_analyzer_shared/PRESUBMIT.py.
** Presubmit ERRORS: 1 **
Presubmit checks took 21.4s to calculate.
There were presubmit errors.
This might happen, for example, if `verify_sorted_test.dart` contained
a compile-time error or threw an unhandled exception.
With this change, the message is `CheckSorted: could not parse output
of verify_sorted_test.dart`, followed by the full stdout and stderr
from the attempt.
This should make this sort of failure a lot easier to debug.
Note: I've made this same fix before to
`pkg/_fe_analyzer_shared/PRESUBMIT.py` (see
https://dart-review.googlesource.com/c/sdk/+/485601). I didn't realize
at the time that the code was duplicated.
Note: This should make it easier to debug
https://github.com/dart-lang/sdk/issues/63464.
Change-Id: I4892dcff7ad6969ca40564c1fd7e62e36a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506605
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2026, 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.
|
|
"""Analysis server specific presubmit script.
|
|
|
|
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
|
for more details about the presubmit API built into gcl.
|
|
"""
|
|
|
|
import importlib.util
|
|
import importlib.machinery
|
|
import os.path
|
|
import subprocess
|
|
|
|
USE_PYTHON3 = True
|
|
PRESUBMIT_VERSION = '2.0.0'
|
|
|
|
|
|
def load_source(modname, filename):
|
|
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
|
spec = importlib.util.spec_from_file_location(modname,
|
|
filename,
|
|
loader=loader)
|
|
module = importlib.util.module_from_spec(spec)
|
|
# The module is always executed and not cached in sys.modules.
|
|
# Uncomment the following line to cache the module.
|
|
# sys.modules[module.__name__] = module
|
|
loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def CheckSorted(input_api, output_api):
|
|
local_root = input_api.change.RepositoryRoot()
|
|
utils = load_source('utils', os.path.join(local_root, 'tools', 'utils.py'))
|
|
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
|
|
windows = utils.GuessOS() == 'win32'
|
|
if windows:
|
|
dart += '.exe'
|
|
sourceArgs = [
|
|
arg for git_file in input_api.AffectedTestableFiles()
|
|
for arg in ('-s', git_file.AbsoluteLocalPath())
|
|
]
|
|
result = subprocess.run([
|
|
dart,
|
|
'run',
|
|
os.path.join(local_root, 'pkg', 'analysis_server', 'test',
|
|
'verify_sorted_test.dart'),
|
|
] + sourceArgs,
|
|
capture_output=True)
|
|
if result.returncode != 0:
|
|
unsorted_file_details = [
|
|
line for line in result.stdout.decode('utf-8').splitlines()
|
|
if 'Unsorted file' in line
|
|
]
|
|
if len(unsorted_file_details) == 0:
|
|
return [
|
|
output_api.PresubmitError('\n'.join([
|
|
'CheckSorted: could not parse output of verify_sorted_test.dart',
|
|
'Stdout:',
|
|
result.stdout.decode('utf-8'),
|
|
'',
|
|
'Stderr:',
|
|
result.stderr.decode('utf-8')
|
|
]))
|
|
]
|
|
return [
|
|
output_api.PresubmitError('\n'.join(unsorted_file_details))
|
|
]
|
|
return []
|