Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index f850b03948c9b2e1a03a9960ef8f54a3bc2d9cb2..6fc5cb32180c445614acb7aa5d704cab6b1bd907 100644 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -8,7 +8,10 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| for more details about the presubmit API built into gcl. |
| """ |
| -def CheckChangeOnCommit(input_api, output_api): |
| +import imp |
| +import os |
| + |
| +def _CheckBuildStatus(input_api, output_api): |
| results = [] |
| status_check = input_api.canned_checks.CheckTreeIsOpen( |
| input_api, |
| @@ -16,3 +19,27 @@ def CheckChangeOnCommit(input_api, output_api): |
| json_url='http://dart-status.appspot.com/current?format=json') |
| results.extend(status_check) |
| return results |
| + |
| +def _CheckDartFormat(input_api, output_api): |
| + utils = imp.load_source('utils', |
| + os.path.join(input_api.change.RepositoryRoot(), 'tools', 'utils.py')) |
| + |
| + results = [] |
| + 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
|
| + |
| + for git_file in input_api.AffectedTextFiles(): |
| + filename = git_file.AbsoluteLocalPath() |
| + if filename.endswith('.dart'): |
| + cmd = '%s --set-exit-if-changed -n %s ' % (prebuilt_dartfmt, filename) |
| + 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
|
| + results += [output_api.PresubmitError( |
| + 'Must run dartfmt on %s' % filename)] |
| + |
| + return results |
| + |
| +def CheckChangeOnCommit(input_api, output_api): |
| + return (_CheckBuildStatus(input_api, output_api) + |
| + _CheckDartFormat(input_api, output_api)) |
| + |
| +def CheckChangeOnUpload(input_api, output_api): |
| + return _CheckDartFormat(input_api, output_api) |