blob: 17e95d6176428cb49cf8045df8e663db7b0f0743 [file] [log] [blame]
Jon Murphy6c591542022-07-15 07:08:49 -07001# Copyright 2019 The ChromiumOS Authors. All rights reserved.
David Burger9206f8f2019-06-20 15:27:22 -06002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Josip Sokcevicdbda6932021-07-09 07:17:09 -07005USE_PYTHON3 = True
6
Allen Licb2fb8a2020-03-24 15:50:41 -07007def _HasLocalChanges(input_api):
8 ret = input_api.subprocess.call(
Sean McAllister91734cf2021-05-20 15:52:47 -06009 ['git', 'diff', '--exit-code'])
Allen Licb2fb8a2020-03-24 15:50:41 -070010 return ret != 0
11
David Burger9206f8f2019-06-20 15:27:22 -060012def CheckGenerated(input_api, output_api):
Josip Sokcevicdbda6932021-07-09 07:17:09 -070013 file_filter = lambda x: x.LocalPath() == 'infra/config/recipes.cfg'
14 results = input_api.canned_checks.CheckJsonParses(input_api, output_api,
15 file_filter=file_filter)
16
Sean McAllister975e7e82021-06-15 14:00:21 -060017 if input_api.subprocess.call(['./generate.sh']):
18 results.append(output_api.PresubmitError('Error calling generate.sh'))
19
Allen Licb2fb8a2020-03-24 15:50:41 -070020 if _HasLocalChanges(input_api):
David Burger9206f8f2019-06-20 15:27:22 -060021 msg = ('Running generate.sh produced a diff. Please '
22 'run the script, amend your changes, and try again.')
23 results.append(output_api.PresubmitError(msg))
24 return results
25
26def CheckChangeOnUpload(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
David Burger9206f8f2019-06-20 15:27:22 -060030
31def CheckChangeOnCommit(input_api, output_api):
Allen Li4f211142020-02-21 17:31:10 -080032 results = []
33 results.extend(CheckGenerated(input_api, output_api))
Allen Li4f211142020-02-21 17:31:10 -080034 return results