David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 5 | def _HasLocalChanges(input_api): |
| 6 | ret = input_api.subprocess.call( |
Sean McAllister | 91734cf | 2021-05-20 15:52:47 -0600 | [diff] [blame^] | 7 | ['git', 'diff', '--exit-code']) |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 8 | return ret != 0 |
| 9 | |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 10 | def CheckGenerated(input_api, output_api): |
| 11 | results = [] |
| 12 | input_api.subprocess.call( |
Sean McAllister | 91734cf | 2021-05-20 15:52:47 -0600 | [diff] [blame^] | 13 | ['./generate.sh']) |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame] | 14 | if _HasLocalChanges(input_api): |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 15 | msg = ('Running generate.sh produced a diff. Please ' |
| 16 | 'run the script, amend your changes, and try again.') |
| 17 | results.append(output_api.PresubmitError(msg)) |
| 18 | return results |
| 19 | |
| 20 | def CheckChangeOnUpload(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 21 | results = [] |
| 22 | results.extend(CheckGenerated(input_api, output_api)) |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 23 | return results |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 24 | |
| 25 | def CheckChangeOnCommit(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 26 | results = [] |
| 27 | results.extend(CheckGenerated(input_api, output_api)) |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 28 | return results |