blob: 9d0fbdf16dfde8cb81227814939b995b128c4fb6 [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
machenbach@chromium.org2c81ceb2014-09-11 00:05:22 +000044 from presubmit import CheckRuntimeVsNativesNameClashes
machenbach@chromium.org9d72b8d2014-08-07 08:39:21 +000045 from presubmit import CheckExternalReferenceRegistration
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000046
47 results = []
48 if not CppLintProcessor().Run(input_api.PresubmitLocalPath()):
49 results.append(output_api.PresubmitError("C++ lint check failed"))
50 if not SourceProcessor().Run(input_api.PresubmitLocalPath()):
51 results.append(output_api.PresubmitError(
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000052 "Copyright header, trailing whitespaces and two empty lines " \
53 "between declarations check failed"))
machenbach@chromium.org2c81ceb2014-09-11 00:05:22 +000054 if not CheckRuntimeVsNativesNameClashes(input_api.PresubmitLocalPath()):
machenbach@chromium.org08e75692014-06-25 00:05:37 +000055 results.append(output_api.PresubmitError(
machenbach@chromium.org2c81ceb2014-09-11 00:05:22 +000056 "Runtime/natives name clash check failed"))
machenbach@chromium.org9d72b8d2014-08-07 08:39:21 +000057 if not CheckExternalReferenceRegistration(input_api.PresubmitLocalPath()):
58 results.append(output_api.PresubmitError(
59 "External references registration check failed"))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000060 return results
61
62
machenbach@chromium.org196eb602014-06-04 00:06:13 +000063def _CheckUnwantedDependencies(input_api, output_api):
64 """Runs checkdeps on #include statements added in this
65 change. Breaking - rules is an error, breaking ! rules is a
66 warning.
67 """
68 # We need to wait until we have an input_api object and use this
69 # roundabout construct to import checkdeps because this file is
70 # eval-ed and thus doesn't have __file__.
71 original_sys_path = sys.path
72 try:
73 sys.path = sys.path + [input_api.os_path.join(
74 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
75 import checkdeps
76 from cpp_checker import CppChecker
77 from rules import Rule
78 finally:
79 # Restore sys.path to what it was before.
80 sys.path = original_sys_path
81
82 added_includes = []
83 for f in input_api.AffectedFiles():
84 if not CppChecker.IsCppFile(f.LocalPath()):
85 continue
86
87 changed_lines = [line for line_num, line in f.ChangedContents()]
88 added_includes.append([f.LocalPath(), changed_lines])
89
90 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
91
92 error_descriptions = []
93 warning_descriptions = []
94 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
95 added_includes):
96 description_with_path = '%s\n %s' % (path, rule_description)
97 if rule_type == Rule.DISALLOW:
98 error_descriptions.append(description_with_path)
99 else:
100 warning_descriptions.append(description_with_path)
101
102 results = []
103 if error_descriptions:
104 results.append(output_api.PresubmitError(
105 'You added one or more #includes that violate checkdeps rules.',
106 error_descriptions))
107 if warning_descriptions:
108 results.append(output_api.PresubmitPromptOrNotify(
109 'You added one or more #includes of files that are temporarily\n'
110 'allowed but being removed. Can you avoid introducing the\n'
111 '#include? See relevant DEPS file(s) for details and contacts.',
112 warning_descriptions))
113 return results
114
115
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000116def _CommonChecks(input_api, output_api):
117 """Checks common to both upload and commit."""
118 results = []
119 results.extend(input_api.canned_checks.CheckOwners(
120 input_api, output_api, source_file_filter=None))
machenbach@chromium.orgd0bddc62014-07-07 00:05:07 +0000121 results.extend(input_api.canned_checks.CheckPatchFormatted(
122 input_api, output_api))
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000123 results.extend(_V8PresubmitChecks(input_api, output_api))
machenbach@chromium.org196eb602014-06-04 00:06:13 +0000124 results.extend(_CheckUnwantedDependencies(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000125 return results
126
127
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000128def _SkipTreeCheck(input_api, output_api):
129 """Check the env var whether we want to skip tree check.
130 Only skip if src/version.cc has been updated."""
131 src_version = 'src/version.cc'
machenbach@chromium.org4ddd2f12014-01-14 08:13:44 +0000132 FilterFile = lambda file: file.LocalPath() == src_version
133 if not input_api.AffectedSourceFiles(
134 lambda file: file.LocalPath() == src_version):
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000135 return False
136 return input_api.environ.get('PRESUBMIT_TREE_CHECK') == 'skip'
137
138
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000139def _CheckChangeLogFlag(input_api, output_api):
140 """Checks usage of LOG= flag in the commit message."""
141 results = []
142 if input_api.change.BUG and not 'LOG' in input_api.change.tags:
143 results.append(output_api.PresubmitError(
144 'An issue reference (BUG=) requires a change log flag (LOG=). '
145 'Use LOG=Y for including this commit message in the change log. '
146 'Use LOG=N or leave blank otherwise.'))
147 return results
148
149
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000150def CheckChangeOnUpload(input_api, output_api):
151 results = []
152 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000153 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000154 return results
155
156
157def CheckChangeOnCommit(input_api, output_api):
158 results = []
159 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000160 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000161 results.extend(input_api.canned_checks.CheckChangeHasDescription(
162 input_api, output_api))
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000163 if not _SkipTreeCheck(input_api, output_api):
164 results.extend(input_api.canned_checks.CheckTreeIsOpen(
165 input_api, output_api,
166 json_url='http://v8-status.appspot.com/current?format=json'))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000167 return results
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000168
169
170def GetPreferredTryMasters(project, change):
171 return {
172 'tryserver.v8': {
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000173 'v8_linux_rel': set(['defaulttests']),
machenbach@chromium.orged1a6312014-04-02 00:05:15 +0000174 'v8_linux_dbg': set(['defaulttests']),
175 'v8_linux_nosnap_rel': set(['defaulttests']),
176 'v8_linux_nosnap_dbg': set(['defaulttests']),
177 'v8_linux64_rel': set(['defaulttests']),
178 'v8_linux_arm_dbg': set(['defaulttests']),
179 'v8_linux_arm64_rel': set(['defaulttests']),
machenbach@chromium.orgaa107b22014-05-15 00:04:44 +0000180 'v8_linux_layout_dbg': set(['defaulttests']),
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000181 'v8_mac_rel': set(['defaulttests']),
182 'v8_win_rel': set(['defaulttests']),
machenbach@chromium.org70d29e12014-07-11 07:33:43 +0000183 'v8_win64_rel': set(['defaulttests']),
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000184 },
185 }