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 | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame^] | 15 | ['./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 | |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame^] | 24 | def CheckExamples(input_api, output_api): |
| 25 | results = [] |
| 26 | ret = input_api.subprocess.call( |
| 27 | ['./check_examples.sh'], |
| 28 | stdout=input_api.subprocess.PIPE, |
| 29 | stderr=input_api.subprocess.PIPE) |
| 30 | if ret: |
| 31 | results.append(output_api.PresubmitError( |
| 32 | 'go test failed. Please run check_examples.sh for details.')) |
| 33 | return results |
| 34 | |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 35 | def CheckChangeOnUpload(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame^] | 36 | results = [] |
| 37 | results.extend(CheckGenerated(input_api, output_api)) |
| 38 | results.extend(CheckExamples(input_api, output_api)) |
| 39 | return results |
David Burger | 9206f8f | 2019-06-20 15:27:22 -0600 | [diff] [blame] | 40 | |
| 41 | def CheckChangeOnCommit(input_api, output_api): |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame^] | 42 | results = [] |
| 43 | results.extend(CheckGenerated(input_api, output_api)) |
| 44 | results.extend(CheckExamples(input_api, output_api)) |
| 45 | return results |