blob: 430692f9cafd01354a0afe1da821030ab65ba0d7 [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.org08e75692014-06-25 00:05:37 +000044 from presubmit import CheckGeneratedRuntimeTests
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000045
46 results = []
47 if not CppLintProcessor().Run(input_api.PresubmitLocalPath()):
48 results.append(output_api.PresubmitError("C++ lint check failed"))
49 if not SourceProcessor().Run(input_api.PresubmitLocalPath()):
50 results.append(output_api.PresubmitError(
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +000051 "Copyright header, trailing whitespaces and two empty lines " \
52 "between declarations check failed"))
machenbach@chromium.org08e75692014-06-25 00:05:37 +000053 if not CheckGeneratedRuntimeTests(input_api.PresubmitLocalPath()):
54 results.append(output_api.PresubmitError(
55 "Generated runtime tests check failed"))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000056 return results
57
58
machenbach@chromium.org196eb602014-06-04 00:06:13 +000059def _CheckUnwantedDependencies(input_api, output_api):
60 """Runs checkdeps on #include statements added in this
61 change. Breaking - rules is an error, breaking ! rules is a
62 warning.
63 """
64 # We need to wait until we have an input_api object and use this
65 # roundabout construct to import checkdeps because this file is
66 # eval-ed and thus doesn't have __file__.
67 original_sys_path = sys.path
68 try:
69 sys.path = sys.path + [input_api.os_path.join(
70 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
71 import checkdeps
72 from cpp_checker import CppChecker
73 from rules import Rule
74 finally:
75 # Restore sys.path to what it was before.
76 sys.path = original_sys_path
77
78 added_includes = []
79 for f in input_api.AffectedFiles():
80 if not CppChecker.IsCppFile(f.LocalPath()):
81 continue
82
83 changed_lines = [line for line_num, line in f.ChangedContents()]
84 added_includes.append([f.LocalPath(), changed_lines])
85
86 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
87
88 error_descriptions = []
89 warning_descriptions = []
90 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
91 added_includes):
92 description_with_path = '%s\n %s' % (path, rule_description)
93 if rule_type == Rule.DISALLOW:
94 error_descriptions.append(description_with_path)
95 else:
96 warning_descriptions.append(description_with_path)
97
98 results = []
99 if error_descriptions:
100 results.append(output_api.PresubmitError(
101 'You added one or more #includes that violate checkdeps rules.',
102 error_descriptions))
103 if warning_descriptions:
104 results.append(output_api.PresubmitPromptOrNotify(
105 'You added one or more #includes of files that are temporarily\n'
106 'allowed but being removed. Can you avoid introducing the\n'
107 '#include? See relevant DEPS file(s) for details and contacts.',
108 warning_descriptions))
109 return results
110
111
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000112def _CommonChecks(input_api, output_api):
113 """Checks common to both upload and commit."""
114 results = []
115 results.extend(input_api.canned_checks.CheckOwners(
116 input_api, output_api, source_file_filter=None))
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000117 results.extend(_V8PresubmitChecks(input_api, output_api))
machenbach@chromium.org196eb602014-06-04 00:06:13 +0000118 results.extend(_CheckUnwantedDependencies(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000119 return results
120
121
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000122def _SkipTreeCheck(input_api, output_api):
123 """Check the env var whether we want to skip tree check.
124 Only skip if src/version.cc has been updated."""
125 src_version = 'src/version.cc'
machenbach@chromium.org4ddd2f12014-01-14 08:13:44 +0000126 FilterFile = lambda file: file.LocalPath() == src_version
127 if not input_api.AffectedSourceFiles(
128 lambda file: file.LocalPath() == src_version):
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000129 return False
130 return input_api.environ.get('PRESUBMIT_TREE_CHECK') == 'skip'
131
132
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000133def _CheckChangeLogFlag(input_api, output_api):
134 """Checks usage of LOG= flag in the commit message."""
135 results = []
136 if input_api.change.BUG and not 'LOG' in input_api.change.tags:
137 results.append(output_api.PresubmitError(
138 'An issue reference (BUG=) requires a change log flag (LOG=). '
139 'Use LOG=Y for including this commit message in the change log. '
140 'Use LOG=N or leave blank otherwise.'))
141 return results
142
143
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000144def CheckChangeOnUpload(input_api, output_api):
145 results = []
146 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000147 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000148 return results
149
150
151def CheckChangeOnCommit(input_api, output_api):
152 results = []
153 results.extend(_CommonChecks(input_api, output_api))
machenbach@chromium.orgb5be0a92013-11-15 10:32:41 +0000154 results.extend(_CheckChangeLogFlag(input_api, output_api))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000155 results.extend(input_api.canned_checks.CheckChangeHasDescription(
156 input_api, output_api))
machenbach@chromium.org3d079fe2013-09-25 08:19:55 +0000157 if not _SkipTreeCheck(input_api, output_api):
158 results.extend(input_api.canned_checks.CheckTreeIsOpen(
159 input_api, output_api,
160 json_url='http://v8-status.appspot.com/current?format=json'))
verwaest@chromium.org33e09c82012-10-10 17:07:22 +0000161 return results
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000162
163
164def GetPreferredTryMasters(project, change):
165 return {
166 'tryserver.v8': {
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000167 'v8_linux_rel': set(['defaulttests']),
machenbach@chromium.orged1a6312014-04-02 00:05:15 +0000168 'v8_linux_dbg': set(['defaulttests']),
169 'v8_linux_nosnap_rel': set(['defaulttests']),
170 'v8_linux_nosnap_dbg': set(['defaulttests']),
171 'v8_linux64_rel': set(['defaulttests']),
172 'v8_linux_arm_dbg': set(['defaulttests']),
173 'v8_linux_arm64_rel': set(['defaulttests']),
machenbach@chromium.orgaa107b22014-05-15 00:04:44 +0000174 'v8_linux_layout_dbg': set(['defaulttests']),
titzer@chromium.orgf5a24542014-03-04 09:06:17 +0000175 'v8_mac_rel': set(['defaulttests']),
176 'v8_win_rel': set(['defaulttests']),
177 },
178 }