blob: 00d650181c7c3a21f880173ee030a1bbd5e66eb7 [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 = []
12 input_api.subprocess.call(
Sean McAllister91734cf2021-05-20 15:52:47 -060013 ['./generate.sh'])
Allen Licb2fb8a2020-03-24 15:50:41 -070014 if _HasLocalChanges(input_api):
David Burger9206f8f2019-06-20 15:27:22 -060015 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
20def CheckChangeOnUpload(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080021 results = []
22 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080023 return results
David Burger9206f8f2019-06-20 15:27:22 -060024
25def CheckChangeOnCommit(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080026 results = []
27 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080028 return results