blob: d33b72ba99eccae5ab2cedc6d1d13882a857e91c [file] [log] [blame]
David Burger9206f8f2019-06-20 15:27:22 -06001# 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 Licb2fb8a2020-03-24 15:50:41 -07005def _HasLocalChanges(input_api):
6 ret = input_api.subprocess.call(
Sean McAllister91734cf2021-05-20 15:52:47 -06007 ['git', 'diff', '--exit-code'])
Allen Licb2fb8a2020-03-24 15:50:41 -07008 return ret != 0
9
David Burger9206f8f2019-06-20 15:27:22 -060010def CheckGenerated(input_api, output_api):
11 results = []
Sean McAllister975e7e82021-06-15 14:00:21 -060012 if input_api.subprocess.call(['./generate.sh']):
13 results.append(output_api.PresubmitError('Error calling generate.sh'))
14
Allen Licb2fb8a2020-03-24 15:50:41 -070015 if _HasLocalChanges(input_api):
David Burger9206f8f2019-06-20 15:27:22 -060016 msg = ('Running generate.sh produced a diff. Please '
17 'run the script, amend your changes, and try again.')
18 results.append(output_api.PresubmitError(msg))
19 return results
20
21def CheckChangeOnUpload(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080022 results = []
23 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080024 return results
David Burger9206f8f2019-06-20 15:27:22 -060025
26def CheckChangeOnCommit(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080027 results = []
28 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080029 return results