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( |
| 7 | ['git', 'diff', '--exit-code'], |
| 8 | stdout=input_api.subprocess.PIPE, |
| 9 | stderr=input_api.subprocess.PIPE) |
| 10 | return ret != 0 |
| 11 | |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 12 | def CheckGenerated(input_api, output_api): |
| 13 | results = [] |
| 14 | input_api.subprocess.call( |
Allen Li | 9854522 | 2020-03-11 14:34:14 -0700 | [diff] [blame] | 15 | ['bash', './generate.sh'], |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 16 | stdout=input_api.subprocess.PIPE, |
| 17 | stderr=input_api.subprocess.PIPE) |
Allen Li | cb2fb8a | 2020-03-24 15:50:41 -0700 | [diff] [blame^] | 18 | if _HasLocalChanges(input_api): |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 19 | msg = ('Running generate.sh produced a diff. Please ' |
| 20 | 'run the script, amend your changes, and try again.') |
| 21 | results.append(output_api.PresubmitError(msg)) |
| 22 | return results |
| 23 | |
| 24 | def CheckChangeOnUpload(input_api, output_api): |
| 25 | return CheckGenerated(input_api, output_api) |
| 26 | |
| 27 | def CheckChangeOnCommit(input_api, output_api): |
| 28 | return CheckGenerated(input_api, output_api) |