Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 1 | # Copyright 2012 The Chromium Authors |
maruel | 74e1ca7 | 2015-04-01 12:31:55 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Enforces json format. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details on the presubmit API built into depot_tools. |
| 9 | """ |
| 10 | |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 11 | PRESUBMIT_VERSION = '2.0.0' |
Josip Sokcevic | 2f4f9f6 | 2021-06-14 04:27:46 | [diff] [blame] | 12 | |
Garrett Beaty | ac48e8c9 | 2021-12-14 01:28:48 | [diff] [blame] | 13 | |
| 14 | def CheckFreeze(input_api, output_api): |
Garrett Beaty | ee19843 | 2024-01-25 00:08:41 | [diff] [blame] | 15 | return input_api.canned_checks.CheckInfraFreeze( |
| 16 | input_api, output_api, files_to_exclude=['.+/filters/.+']) |
Garrett Beaty | ac48e8c9 | 2021-12-14 01:28:48 | [diff] [blame] | 17 | |
maruel | 74e1ca7 | 2015-04-01 12:31:55 | [diff] [blame] | 18 | |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 19 | def CheckSourceSideSpecs(input_api, output_api): |
| 20 | return input_api.RunTests([ |
| 21 | input_api.Command(name='check source side specs', |
Garrett Beaty | 7e866fc | 2021-06-16 14:12:10 | [diff] [blame] | 22 | cmd=[ |
| 23 | input_api.python3_executable, |
| 24 | 'generate_buildbot_json.py', '--check', '--verbose' |
| 25 | ], |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 26 | kwargs={}, |
| 27 | message=output_api.PresubmitError), |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 28 | ]) |
| 29 | |
| 30 | |
| 31 | def CheckTests(input_api, output_api): |
Ben Pastene | 66e0318 | 2023-05-08 17:01:49 | [diff] [blame] | 32 | for f in input_api.AffectedFiles(): |
| 33 | # If the only files changed here match //testing/buildbot/*.(pyl|json), |
| 34 | # then we can assume the unit tests are unaffected. |
| 35 | if (len(f.LocalPath().split(input_api.os_path.sep)) != 3 |
| 36 | or not f.LocalPath().endswith(('.json', '.pyl'))): |
| 37 | break |
| 38 | else: |
| 39 | return [] |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 40 | glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*test.py') |
Takuto Ikuta | 40def48 | 2023-06-02 02:23:49 | [diff] [blame] | 41 | tests = input_api.canned_checks.GetUnitTests(input_api, output_api, |
| 42 | input_api.glob(glob)) |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 43 | return input_api.RunTests(tests) |
| 44 | |
| 45 | |
Garrett Beaty | babf03eb | 2023-06-23 16:04:34 | [diff] [blame] | 46 | def CheckJsonFiles(input_api, output_api): |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 47 | return input_api.RunTests([ |
Garrett Beaty | babf03eb | 2023-06-23 16:04:34 | [diff] [blame] | 48 | input_api.Command(name='check JSON files', |
Garrett Beaty | 6735f43 | 2023-06-23 16:24:30 | [diff] [blame] | 49 | cmd=[input_api.python3_executable, 'check.py'], |
Garrett Beaty | babf03eb | 2023-06-23 16:04:34 | [diff] [blame] | 50 | kwargs={}, |
| 51 | message=output_api.PresubmitError), |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 52 | ]) |
Garrett Beaty | ec1e339 | 2023-04-12 19:01:13 | [diff] [blame] | 53 | |
| 54 | |
Garrett Beaty | 96802d0 | 2023-07-07 14:18:05 | [diff] [blame] | 55 | def CheckPylFilesSynced(input_api, output_api): |
| 56 | return input_api.RunTests([ |
| 57 | input_api.Command( |
| 58 | name='check-pyl-files-synced', |
| 59 | cmd=[ |
| 60 | input_api.python3_executable, |
| 61 | '../../infra/config/scripts/sync-pyl-files.py', |
| 62 | '--check', |
| 63 | ], |
| 64 | kwargs={}, |
| 65 | message=output_api.PresubmitError, |
| 66 | ), |
| 67 | ]) |