1 # Copyright 2015 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 _IGNORE_FREEZE_FOOTER = 'Ignore-Freeze'
9 # The time module's handling of timezones is abysmal, so the boundaries are
10 # precomputed in UNIX time
11 _FREEZE_START = 1671177600 # 2022/12/16 00:00 -0800
12 _FREEZE_END = 1672646400 # 2023/01/02 00:00 -0800
15 def CheckFreeze(input_api, output_api):
16 if _FREEZE_START <= input_api.time.time() < _FREEZE_END:
17 footers = input_api.change.GitFootersFromDescription()
18 if _IGNORE_FREEZE_FOOTER not in footers:
21 ts = input_api.time.localtime(t)
22 return input_api.time.strftime('%Y/%m/%d %H:%M %z', ts)
24 # Don't report errors when on the presubmit --all bot or when testing
25 # with presubmit --files.
26 if input_api.no_diffs:
27 report_type = output_api.PresubmitPromptWarning
29 report_type = output_api.PresubmitError
31 report_type('There is a prod freeze in effect from {} until {},'
32 ' files in //tools/mb cannot be modified'.format(
33 convert(_FREEZE_START), convert(_FREEZE_END)))
39 def CheckTests(input_api, output_api):
40 glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*_test.py')
41 tests = input_api.canned_checks.GetUnitTests(input_api, output_api,
43 return input_api.RunTests(tests)
46 def _CommonChecks(input_api, output_api):
49 # Run Pylint over the files in the directory.
51 input_api.canned_checks.GetPylint(
55 # pylint complains about Checkfreeze not being defined, its probably
56 # finding a different PRESUBMIT.py. Note that this warning only
57 # appears if the number of Pylint jobs is greater than one.
58 files_to_skip=['PRESUBMIT_test.py'],
59 # Disabling this warning because this pattern involving ToSrcRelPath
60 # seems intrinsic to how mb_unittest.py is implemented.
62 'attribute-defined-outside-init',
65 # Run the MB unittests.
67 input_api.canned_checks.GetUnitTestsInDirectory(input_api, output_api,
69 [r'^.+_unittest\.py$']))
71 # Validate the format of the mb_config.pyl file.
72 cmd = [input_api.python3_executable, 'mb.py', 'validate']
73 kwargs = {'cwd': input_api.PresubmitLocalPath()}
75 input_api.Command(name='mb_validate',
78 message=output_api.PresubmitError))
81 results.extend(input_api.RunTests(tests))
82 results.extend(CheckFreeze(input_api, output_api))
83 results.extend(CheckTests(input_api, output_api))
88 def CheckChangeOnUpload(input_api, output_api):
89 return _CommonChecks(input_api, output_api)
92 def CheckChangeOnCommit(input_api, output_api):
93 return _CommonChecks(input_api, output_api)