Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Top-level presubmit script for Dart. | 5 """Top-level presubmit script for Dart. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 def CheckChangeOnCommit(input_api, output_api): | 11 import imp |
| 12 import os | |
| 13 | |
| 14 def _CheckBuildStatus(input_api, output_api): | |
| 12 results = [] | 15 results = [] |
| 13 status_check = input_api.canned_checks.CheckTreeIsOpen( | 16 status_check = input_api.canned_checks.CheckTreeIsOpen( |
| 14 input_api, | 17 input_api, |
| 15 output_api, | 18 output_api, |
| 16 json_url='http://dart-status.appspot.com/current?format=json') | 19 json_url='http://dart-status.appspot.com/current?format=json') |
| 17 results.extend(status_check) | 20 results.extend(status_check) |
| 18 return results | 21 return results |
| 22 | |
| 23 def _CheckDartFormat(input_api, output_api): | |
| 24 utils = imp.load_source('utils', | |
| 25 os.path.join(input_api.change.RepositoryRoot(), 'tools', 'utils.py')) | |
| 26 | |
| 27 results = [] | |
| 28 prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt') | |
|
zra
2017/03/20 19:26:06
The presubmit check should degrade gracefully if t
Jacob
2017/03/20 19:59:07
Done. I now print a warning if the file doesn't ex
| |
| 29 | |
| 30 for git_file in input_api.AffectedTextFiles(): | |
| 31 filename = git_file.AbsoluteLocalPath() | |
| 32 if filename.endswith('.dart'): | |
| 33 cmd = '%s --set-exit-if-changed -n %s ' % (prebuilt_dartfmt, filename) | |
| 34 if os.system(cmd): | |
|
zra
2017/03/20 19:26:06
Could you rather use the presubmit API to run comm
Jacob
2017/03/20 19:59:07
Done. Thanks for pointing out the existing presubm
| |
| 35 results += [output_api.PresubmitError( | |
| 36 'Must run dartfmt on %s' % filename)] | |
| 37 | |
| 38 return results | |
| 39 | |
| 40 def CheckChangeOnCommit(input_api, output_api): | |
| 41 return (_CheckBuildStatus(input_api, output_api) + | |
| 42 _CheckDartFormat(input_api, output_api)) | |
| 43 | |
| 44 def CheckChangeOnUpload(input_api, output_api): | |
| 45 return _CheckDartFormat(input_api, output_api) | |
| OLD | NEW |