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 | _IGNORE_FREEZE_FOOTER = 'Ignore-Freeze' |
| 14 | |
| 15 | # The time module's handling of timezones is abysmal, so the boundaries are |
| 16 | # precomputed in UNIX time |
Struan Shrimpton | 7f45a3053 | 2022-12-12 17:07:41 | [diff] [blame] | 17 | _FREEZE_START = 1671177600 # 2022/12/16 00:00 -0800 |
| 18 | _FREEZE_END = 1672646400 # 2023/01/02 00:00 -0800 |
Garrett Beaty | ac48e8c9 | 2021-12-14 01:28:48 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def CheckFreeze(input_api, output_api): |
| 22 | if _FREEZE_START <= input_api.time.time() < _FREEZE_END: |
| 23 | footers = input_api.change.GitFootersFromDescription() |
| 24 | if _IGNORE_FREEZE_FOOTER not in footers: |
| 25 | |
| 26 | def convert(t): |
| 27 | ts = input_api.time.localtime(t) |
| 28 | return input_api.time.strftime('%Y/%m/%d %H:%M %z', ts) |
| 29 | |
Bruce Dawson | 7034193 | 2022-12-20 18:46:25 | [diff] [blame] | 30 | # Don't report errors when on the presubmit --all bot or when testing |
| 31 | # with presubmit --files. |
| 32 | if input_api.no_diffs: |
| 33 | report_type = output_api.PresubmitPromptWarning |
| 34 | else: |
| 35 | report_type = output_api.PresubmitError |
Garrett Beaty | ac48e8c9 | 2021-12-14 01:28:48 | [diff] [blame] | 36 | return [ |
Bruce Dawson | 7034193 | 2022-12-20 18:46:25 | [diff] [blame] | 37 | report_type('There is a prod freeze in effect from {} until {},' |
| 38 | ' files in //testing/buildbot cannot be modified'.format( |
| 39 | convert(_FREEZE_START), convert(_FREEZE_END))) |
Garrett Beaty | ac48e8c9 | 2021-12-14 01:28:48 | [diff] [blame] | 40 | ] |
| 41 | |
| 42 | return [] |
| 43 | |
maruel | 74e1ca7 | 2015-04-01 12:31:55 | [diff] [blame] | 44 | |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 45 | def CheckSourceSideSpecs(input_api, output_api): |
| 46 | return input_api.RunTests([ |
| 47 | input_api.Command(name='check source side specs', |
Garrett Beaty | 7e866fc | 2021-06-16 14:12:10 | [diff] [blame] | 48 | cmd=[ |
| 49 | input_api.python3_executable, |
| 50 | 'generate_buildbot_json.py', '--check', '--verbose' |
| 51 | ], |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 52 | kwargs={}, |
| 53 | message=output_api.PresubmitError), |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 54 | ]) |
| 55 | |
| 56 | |
| 57 | def CheckTests(input_api, output_api): |
Ben Pastene | 66e0318 | 2023-05-08 17:01:49 | [diff] [blame] | 58 | for f in input_api.AffectedFiles(): |
| 59 | # If the only files changed here match //testing/buildbot/*.(pyl|json), |
| 60 | # then we can assume the unit tests are unaffected. |
| 61 | if (len(f.LocalPath().split(input_api.os_path.sep)) != 3 |
| 62 | or not f.LocalPath().endswith(('.json', '.pyl'))): |
| 63 | break |
| 64 | else: |
| 65 | return [] |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 66 | glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*test.py') |
Takuto Ikuta | 40def48 | 2023-06-02 02:23:49 | [diff] [blame^] | 67 | tests = input_api.canned_checks.GetUnitTests(input_api, output_api, |
| 68 | input_api.glob(glob)) |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 69 | return input_api.RunTests(tests) |
| 70 | |
| 71 | |
| 72 | def CheckManageJsonFiles(input_api, output_api): |
| 73 | return input_api.RunTests([ |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 74 | input_api.Command( |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 75 | name='manage JSON files', |
Jamie Madill | cf4f8c7 | 2021-05-20 19:24:23 | [diff] [blame] | 76 | cmd=[input_api.python3_executable, 'manage.py', '--check'], |
| 77 | kwargs={}, |
| 78 | message=output_api.PresubmitError), |
Garrett Beaty | 9d7590b1 | 2021-06-16 00:17:18 | [diff] [blame] | 79 | ]) |
Garrett Beaty | ec1e339 | 2023-04-12 19:01:13 | [diff] [blame] | 80 | |
| 81 | |
| 82 | # TODO(gbeaty) pinpoint runs builds against revisions that aren't tip-of-tree, |
| 83 | # so recipe side config can't be updated to refer to |
| 84 | # //infra/config/generated/testing/gn_isolate_map.pyl until all of the revisions |
| 85 | # that pinpoint will run against have that file. To workaround this, we'll copy |
| 86 | # the generated file to //testing/buildbot/gn_isiolate_map.pyl. Once pinpoint is |
| 87 | # only building revisions that contain |
| 88 | # //infra/config/generated/testing/gn_isolate_map.pyl, the recipe configs can be |
| 89 | # updated and we can remove this presubmit check, |
| 90 | # //testing/buildbot/gn_isiolate_map.pyl and |
| 91 | # //infra/config/scripts/sync-isolate-map.py. |
| 92 | def CheckGnIsolateMapPylSynced(input_api, output_api): |
| 93 | if ('testing/buildbot/gn_isolate_map.pyl' in input_api.change.LocalPaths() |
| 94 | and 'infra/config/generated/testing/gn_isolate_map.pyl' |
| 95 | not in input_api.change.LocalPaths()): |
| 96 | return [ |
| 97 | output_api.PresubmitError( |
| 98 | '//testing/buildbot/gn_isolate_map.pyl should not be edited' |
| 99 | ' manually, instead modify //infra/config/targets/targets.star,' |
| 100 | ' run //infra/config/main.star and run' |
| 101 | ' //infra/config/scripts/sync-isolate-map.py') |
| 102 | ] |
| 103 | return [] |