blob: 2b2c5aa2188c72748c976f601c978bd700cbdf4b [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(
7 ['git', 'diff', '--exit-code'],
8 stdout=input_api.subprocess.PIPE,
9 stderr=input_api.subprocess.PIPE)
10 return ret != 0
11
David Burger9206f8f2019-06-20 15:27:22 -060012def CheckGenerated(input_api, output_api):
13 results = []
14 input_api.subprocess.call(
Allen Li4f211142020-02-21 17:31:10 -080015 ['./generate.sh'],
David Burger9206f8f2019-06-20 15:27:22 -060016 stdout=input_api.subprocess.PIPE,
17 stderr=input_api.subprocess.PIPE)
Allen Licb2fb8a2020-03-24 15:50:41 -070018 if _HasLocalChanges(input_api):
David Burger9206f8f2019-06-20 15:27:22 -060019 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
24def CheckChangeOnUpload(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080025 results = []
26 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080027 return results
David Burger9206f8f2019-06-20 15:27:22 -060028
29def CheckChangeOnCommit(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080030 results = []
31 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080032 return results