Jon Murphy | 6c59154 | 2022-07-15 07:08:49 -0700 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors. All rights reserved. |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Josip Sokcevic | dbda693 | 2021-07-09 07:17:09 -0700 | [diff] [blame] | 5 | USE_PYTHON3 = True |
| 6 | |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 7 | def _HasLocalChanges(input_api): |
| 8 | ret = input_api.subprocess.call( |
Sean McAllister | 91734cf | 2021-05-20 15:52:47 -0600 | [diff] [blame] | 9 | ['git', 'diff', '--exit-code']) |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 10 | return ret != 0 |
| 11 | |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 12 | def CheckGenerated(input_api, output_api): |
Josip Sokcevic | dbda693 | 2021-07-09 07:17:09 -0700 | [diff] [blame] | 13 | file_filter = lambda x: x.LocalPath() == 'infra/config/recipes.cfg' |
| 14 | results = input_api.canned_checks.CheckJsonParses(input_api, output_api, |
| 15 | file_filter=file_filter) |
| 16 | |
Sean McAllister | 975e7e8 | 2021-06-15 14:00:21 -0600 | [diff] [blame] | 17 | if input_api.subprocess.call(['./generate.sh']): |
| 18 | results.append(output_api.PresubmitError('Error calling generate.sh')) |
| 19 | |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 20 | if _HasLocalChanges(input_api): |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 21 | msg = ('Running generate.sh produced a diff. Please ' |
| 22 | 'run the script, amend your changes, and try again.') |
| 23 | results.append(output_api.PresubmitError(msg)) |
| 24 | return results |
| 25 | |
| 26 | def CheckChangeOnUpload(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 27 | results = [] |
| 28 | results.extend(CheckGenerated(input_api, output_api)) |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 29 | return results |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 30 | |
| 31 | def CheckChangeOnCommit(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 32 | results = [] |
| 33 | results.extend(CheckGenerated(input_api, output_api)) |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 34 | return results |