blob: 70f576a81a4de6498eb54c20020219b6cf8ca385 [file] [log] [blame]
verwaest@chromium.org33e09c82012-10-10 17:07:22 +00001# Copyright 2012 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6# * Redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer.
8# * Redistributions in binary form must reproduce the above
9# copyright notice, this list of conditions and the following
10# disclaimer in the documentation and/or other materials provided
11# with the distribution.
12# * Neither the name of Google Inc. nor the names of its
13# contributors may be used to endorse or promote products derived
14# from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28"""Top-level presubmit script for V8.
29
30See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
31for more details about the presubmit API built into gcl.
32"""
33
machenbach@chromium.org196eb602014-06-04 00:06:13 +000034import sys
35
36
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000037def _V8PresubmitChecks(input_api, output_api):
38 """Runs the V8 presubmit checks."""
39 import sys
40 sys.path.append(input_api.os_path.join(
41 input_api.PresubmitLocalPath(), 'tools'))
42 from presubmit import CppLintProcessor
43 from presubmit import SourceProcessor
44
45 results = []
46 if not CppLintProcessor().Run(input_api.PresubmitLocalPath()):
47 results.append(output_api.PresubmitError("C++ lint check failed"))
48 if not SourceProcessor().Run(input_api.PresubmitLocalPath()):
49 results.append(output_api.PresubmitError(
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000050 "Copyright header, trailing whitespaces and two empty lines " \
51 "between declarations check failed"))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000052 return results
53
54
machenbach@chromium.org196eb602014-06-04 00:06:13 +000055def _CheckUnwantedDependencies(input_api, output_api):
56 """Runs checkdeps on #include statements added in this
57 change. Breaking - rules is an error, breaking ! rules is a
58 warning.
59 """
60 # We need to wait until we have an input_api object and use this
61 # roundabout construct to import checkdeps because this file is
62 # eval-ed and thus doesn't have __file__.
63 original_sys_path = sys.path
64 try:
65 sys.path = sys.path + [input_api.os_path.join(
66 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
67 import checkdeps
68 from cpp_checker import CppChecker
69 from rules import Rule
70 finally:
71 # Restore sys.path to what it was before.
72 sys.path = original_sys_path
73
74 added_includes = []
75 for f in input_api.AffectedFiles():
76 if not CppChecker.IsCppFile(f.LocalPath()):
77 continue
78
79 changed_lines = [line for line_num, line in f.ChangedContents()]
80 added_includes.append([f.LocalPath(), changed_lines])
81
82 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
83
84 error_descriptions = []
85 warning_descriptions = []
86 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
87 added_includes):
88 description_with_path = '%s\n %s' % (path, rule_description)
89 if rule_type == Rule.DISALLOW:
90 error_descriptions.append(description_with_path)
91 else:
92 warning_descriptions.append(description_with_path)
93
94 results = []
95 if error_descriptions:
96 results.append(output_api.PresubmitError(
97 'You added one or more #includes that violate checkdeps rules.',
98 error_descriptions))
99 if warning_descriptions:
100 results.append(output_api.PresubmitPromptOrNotify(
101 'You added one or more #includes of files that are temporarily\n'
102 'allowed but being removed. Can you avoid introducing the\n'
103 '#include? See relevant DEPS file(s) for details and contacts.',
104 warning_descriptions))
105 return results
106
107
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000108def _CommonChecks(input_api, output_api):
109 """Checks common to both upload and commit."""
110 results = []
111 results.extend(input_api.canned_checks.CheckOwners(
112 input_api, output_api, source_file_filter=None))
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000113 results.extend(_V8PresubmitChecks(input_api, output_api))
machenbach@chromium.org196eb602014-06-04 00:06:13 +0000114 results.extend(_CheckUnwantedDependencies(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000115 return results
116
117
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000118def _SkipTreeCheck(input_api, output_api):
119 """Check the env var whether we want to skip tree check.
120 Only skip if src/version.cc has been updated."""
121 src_version = 'src/version.cc'
machenbach@chromium.org4ddd2f12014-01-14 08:13:44 +0000122 FilterFile = lambda file: file.LocalPath() == src_version
123 if not input_api.AffectedSourceFiles(
124 lambda file: file.LocalPath() == src_version):
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000125 return False
126 return input_api.environ.get('PRESUBMIT_TREE_CHECK') == 'skip'
127
128
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000129def _CheckChangeLogFlag(input_api, output_api):
130 """Checks usage of LOG= flag in the commit message."""
131 results = []
132 if input_api.change.BUG and not 'LOG' in input_api.change.tags:
133 results.append(output_api.PresubmitError(
134 'An issue reference (BUG=) requires a change log flag (LOG=). '
135 'Use LOG=Y for including this commit message in the change log. '
136 'Use LOG=N or leave blank otherwise.'))
137 return results
138
139
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000140def CheckChangeOnUpload(input_api, output_api):
141 results = []
142 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000143 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000144 return results
145
146
147def CheckChangeOnCommit(input_api, output_api):
148 results = []
149 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000150 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000151 results.extend(input_api.canned_checks.CheckChangeHasDescription(
152 input_api, output_api))
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000153 if not _SkipTreeCheck(input_api, output_api):
154 results.extend(input_api.canned_checks.CheckTreeIsOpen(
155 input_api, output_api,
156 json_url='http://v8-status.appspot.com/current?format=json'))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000157 return results
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000158
159
160def GetPreferredTryMasters(project, change):
161 return {
162 'tryserver.v8': {
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000163 'v8_linux_rel': set(['defaulttests']),
machenbach@chromium.orged1a6312014-04-02 00:05:15 +0000164 'v8_linux_dbg': set(['defaulttests']),
165 'v8_linux_nosnap_rel': set(['defaulttests']),
166 'v8_linux_nosnap_dbg': set(['defaulttests']),
167 'v8_linux64_rel': set(['defaulttests']),
168 'v8_linux_arm_dbg': set(['defaulttests']),
169 'v8_linux_arm64_rel': set(['defaulttests']),
machenbach@chromium.orgaa107b22014-05-15 00:04:44 +0000170 'v8_linux_layout_dbg': set(['defaulttests']),
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000171 'v8_mac_rel': set(['defaulttests']),
172 'v8_win_rel': set(['defaulttests']),
173 },
174 }