blob: be84a6b0a54d2f0fc08bcf1a46c924484c59e066 [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091# Copyright 2012 The Chromium Authors
maruel74e1ca72015-04-01 12:31:552# 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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details on the presubmit API built into depot_tools.
9"""
10
Garrett Beaty9d7590b12021-06-16 00:17:1811PRESUBMIT_VERSION = '2.0.0'
Josip Sokcevic2f4f9f62021-06-14 04:27:4612
Garrett Beatyac48e8c92021-12-14 01:28:4813_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 Shrimpton7f45a30532022-12-12 17:07:4117_FREEZE_START = 1671177600 # 2022/12/16 00:00 -0800
18_FREEZE_END = 1672646400 # 2023/01/02 00:00 -0800
Garrett Beatyac48e8c92021-12-14 01:28:4819
20
21def 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 Dawson70341932022-12-20 18:46:2530 # 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 Beatyac48e8c92021-12-14 01:28:4836 return [
Bruce Dawson70341932022-12-20 18:46:2537 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 Beatyac48e8c92021-12-14 01:28:4840 ]
41
42 return []
43
maruel74e1ca72015-04-01 12:31:5544
Garrett Beaty9d7590b12021-06-16 00:17:1845def CheckSourceSideSpecs(input_api, output_api):
46 return input_api.RunTests([
47 input_api.Command(name='check source side specs',
Garrett Beaty7e866fc2021-06-16 14:12:1048 cmd=[
49 input_api.python3_executable,
50 'generate_buildbot_json.py', '--check', '--verbose'
51 ],
Jamie Madillcf4f8c72021-05-20 19:24:2352 kwargs={},
53 message=output_api.PresubmitError),
Garrett Beaty9d7590b12021-06-16 00:17:1854 ])
55
56
57def CheckTests(input_api, output_api):
Ben Pastene66e03182023-05-08 17:01:4958 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 Beaty9d7590b12021-06-16 00:17:1866 glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*test.py')
Takuto Ikuta40def482023-06-02 02:23:4967 tests = input_api.canned_checks.GetUnitTests(input_api, output_api,
68 input_api.glob(glob))
Garrett Beaty9d7590b12021-06-16 00:17:1869 return input_api.RunTests(tests)
70
71
72def CheckManageJsonFiles(input_api, output_api):
73 return input_api.RunTests([
Jamie Madillcf4f8c72021-05-20 19:24:2374 input_api.Command(
Garrett Beaty9d7590b12021-06-16 00:17:1875 name='manage JSON files',
Jamie Madillcf4f8c72021-05-20 19:24:2376 cmd=[input_api.python3_executable, 'manage.py', '--check'],
77 kwargs={},
78 message=output_api.PresubmitError),
Garrett Beaty9d7590b12021-06-16 00:17:1879 ])
Garrett Beatyec1e3392023-04-12 19:01:1380
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.
92def 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 []