Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / tools / mb / PRESUBMIT.py
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.
4
5
6
7 _IGNORE_FREEZE_FOOTER = 'Ignore-Freeze'
8
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
13
14
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:
19
20       def convert(t):
21         ts = input_api.time.localtime(t)
22         return input_api.time.strftime('%Y/%m/%d %H:%M %z', ts)
23
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
28       else:
29         report_type = output_api.PresubmitError
30       return [
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)))
34       ]
35
36   return []
37
38
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,
42                                                input_api.glob(glob))
43   return input_api.RunTests(tests)
44
45
46 def _CommonChecks(input_api, output_api):
47   tests = []
48
49   # Run Pylint over the files in the directory.
50   tests.extend(
51       input_api.canned_checks.GetPylint(
52           input_api,
53           output_api,
54           version='2.7',
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.
61           disabled_warnings=[
62               'attribute-defined-outside-init',
63           ]))
64
65   # Run the MB unittests.
66   tests.extend(
67       input_api.canned_checks.GetUnitTestsInDirectory(input_api, output_api,
68                                                       '.',
69                                                       [r'^.+_unittest\.py$']))
70
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()}
74   tests.append(
75       input_api.Command(name='mb_validate',
76                         cmd=cmd,
77                         kwargs=kwargs,
78                         message=output_api.PresubmitError))
79
80   results = []
81   results.extend(input_api.RunTests(tests))
82   results.extend(CheckFreeze(input_api, output_api))
83   results.extend(CheckTests(input_api, output_api))
84
85   return results
86
87
88 def CheckChangeOnUpload(input_api, output_api):
89   return _CommonChecks(input_api, output_api)
90
91
92 def CheckChangeOnCommit(input_api, output_api):
93   return _CommonChecks(input_api, output_api)