blob: c717174d710ce4552f966a8bb80d0628feb9e03b [file] [log] [blame]
Lann Martin46361ee2019-03-14 15:30:47 -06001# Copyright 2019 The Chromium OS Authors. All rights reserved.
David Burgerc0effc22020-03-04 08:27:07 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Lann Martin46361ee2019-03-14 15:30:47 -06004
recipe-roller4202bc62020-09-17 17:38:22 -07005import git_cl
6
Lann Martin46361ee2019-03-14 15:30:47 -06007
8def CommonChecks(input_api, output_api):
Josip Sokcevic52f54362021-07-13 07:30:36 -07009 file_filter = lambda x: x.LocalPath() == 'infra/config/recipes.cfg'
10 results = input_api.canned_checks.CheckJsonParses(input_api, output_api,
11 file_filter=file_filter)
Lann Martin46361ee2019-03-14 15:30:47 -060012
13 # recipes.py test run
14 results += input_api.RunTests([
15 input_api.Command(
16 name='recipes test',
17 cmd=[input_api.python_executable, 'recipes.py', 'test', 'run'],
18 kwargs={},
19 message=output_api.PresubmitError,
20 )
21 ])
22
recipe-roller4202bc62020-09-17 17:38:22 -070023 # Python formatting issues are errors, but we need to ignore recipes.py, which
24 # we do not control.
25 bad_format = False
26 cmd = [
27 '-C',
28 input_api.change.RepositoryRoot(), 'cl', 'format', '--dry-run',
29 '--presubmit', '--python', '--no-clang-format', '--diff'
30 ]
31 code, out = git_cl.RunGitWithCode(cmd, suppress_stderr=True)
32 for line in out.splitlines():
33 if line.startswith('--- ') or line.startswith('+++ '):
34 if not ' recipes.py\t' in line:
35 bad_format = True
36 break
37
38 if bad_format:
39 results += input_api.canned_checks.CheckPatchFormatted(
40 input_api, output_api, check_python=True, check_clang_format=False,
41 result_factory=output_api.PresubmitError)
Andrew Lamb9b2d0862019-04-03 16:38:52 -060042
Lann Martin46361ee2019-03-14 15:30:47 -060043 return results
44
45
46CheckChangeOnUpload = CommonChecks
47CheckChangeOnCommit = CommonChecks