blob: fe9d0104a908878dc7dbcab59bf0e7e7405a269d [file] [log] [blame]
andrew@webrtc.org2442de12012-01-23 17:45:41 +00001# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
niklase@google.comda159d62011-05-30 11:51:34 +00008
kjellander986ee082015-06-16 04:32:13 -07009import json
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +000010import os
kjellander986ee082015-06-16 04:32:13 -070011import platform
kjellander@webrtc.org85759802013-10-22 16:47:40 +000012import re
kjellander986ee082015-06-16 04:32:13 -070013import subprocess
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +000014import sys
kjellander@webrtc.org85759802013-10-22 16:47:40 +000015
16
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010017# Directories that will be scanned by cpplint by the presubmit script.
18CPPLINT_DIRS = [
Fredrik Solenbergea073732015-12-01 11:26:34 +010019 'webrtc/audio',
20 'webrtc/call',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010021 'webrtc/video_engine',
22]
23
kjellander53047c92015-12-02 23:56:14 -080024NATIVE_API_DIRS = (
25 'talk/app/webrtc',
26 'webrtc',
27 'webrtc/common_audio/include', # DEPRECATED (will go away).
28 'webrtc/modules/audio_coding/include',
29 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED (will go away).
30 'webrtc/modules/audio_device/include',
31 'webrtc/modules/audio_processing/include',
32 'webrtc/modules/bitrate_controller/include',
33 'webrtc/modules/include',
34 'webrtc/modules/remote_bitrate_estimator/include',
35 'webrtc/modules/rtp_rtcp/include',
36 'webrtc/modules/rtp_rtcp/source', # DEPRECATED (will go away).
37 'webrtc/modules/utility/include',
38 'webrtc/modules/video_coding/codecs/h264/include',
39 'webrtc/modules/video_coding/codecs/i420/include',
40 'webrtc/modules/video_coding/codecs/vp8/include',
41 'webrtc/modules/video_coding/codecs/vp9/include',
42 'webrtc/modules/video_coding/include',
43 'webrtc/system_wrappers/include', # DEPRECATED (will go away).
44 'webrtc/voice_engine/include',
45)
46
47
48def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
49 """Ensures the list of native API header directories is up to date."""
50 non_existing_paths = []
51 native_api_full_paths = [
52 input_api.os_path.join(input_api.PresubmitLocalPath(),
53 *path.split('/')) for path in NATIVE_API_DIRS]
54 for path in native_api_full_paths:
55 if not os.path.isdir(path):
56 non_existing_paths.append(path)
57 if non_existing_paths:
58 return [output_api.PresubmitError(
59 'Directories to native API headers have changed which has made the '
60 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
61 'location of our native APIs.',
62 non_existing_paths)]
63 return []
64
65
66def _CheckNativeApiHeaderChanges(input_api, output_api):
67 """Checks to remind proper changing of native APIs."""
68 files = []
69 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
70 if f.LocalPath().endswith('.h'):
71 for path in NATIVE_API_DIRS:
72 if os.path.dirname(f.LocalPath()) == path:
73 files.append(f)
74
75 if files:
76 return [output_api.PresubmitPromptWarning(
77 'You seem to be changing native API header files. Please make sure '
78 'you:\n'
79 ' 1. Make compatible changes that don\'t break existing clients.\n'
80 ' 2. Mark the old APIs as deprecated.\n'
81 ' 3. Create a timeline and plan for when the deprecated method will '
82 'be removed (preferably 3 months or so).\n'
83 ' 4. Update/inform existing downstream code owners to stop using the '
84 'deprecated APIs: \n'
85 'send announcement to discuss-webrtc@googlegroups.com and '
86 'webrtc-users@google.com.\n'
87 ' 5. (after ~3 months) remove the deprecated API.\n'
88 'Related files:',
89 files)]
90 return []
91
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010092
kjellander@webrtc.org51198f12012-02-21 17:53:46 +000093def _CheckNoIOStreamInHeaders(input_api, output_api):
94 """Checks to make sure no .h files include <iostream>."""
95 files = []
96 pattern = input_api.re.compile(r'^#include\s*<iostream>',
97 input_api.re.MULTILINE)
98 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
99 if not f.LocalPath().endswith('.h'):
100 continue
101 contents = input_api.ReadFile(f)
102 if pattern.search(contents):
103 files.append(f)
104
105 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200106 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000107 'Do not #include <iostream> in header files, since it inserts static ' +
108 'initialization into every file including the header. Instead, ' +
109 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200110 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000111 return []
112
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000113
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000114def _CheckNoFRIEND_TEST(input_api, output_api):
115 """Make sure that gtest's FRIEND_TEST() macro is not used, the
116 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
117 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
118 problems = []
119
120 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
121 for f in input_api.AffectedFiles(file_filter=file_filter):
122 for line_num, line in f.ChangedContents():
123 if 'FRIEND_TEST(' in line:
124 problems.append(' %s:%d' % (f.LocalPath(), line_num))
125
126 if not problems:
127 return []
128 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
129 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
130 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
131
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000132
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100133def _IsLintWhitelisted(whitelist_dirs, file_path):
134 """ Checks if a file is whitelisted for lint check."""
135 for path in whitelist_dirs:
136 if os.path.dirname(file_path).startswith(path):
137 return True
138 return False
139
140
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000141def _CheckApprovedFilesLintClean(input_api, output_api,
142 source_file_filter=None):
143 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000144 This check is based on _CheckChangeLintsClean in
145 depot_tools/presubmit_canned_checks.py but has less filters and only checks
146 added files."""
147 result = []
148
149 # Initialize cpplint.
150 import cpplint
151 # Access to a protected member _XX of a client class
152 # pylint: disable=W0212
153 cpplint._cpplint_state.ResetErrorCounts()
154
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100155 # Create a platform independent whitelist for the CPPLINT_DIRS.
156 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
157 for path in CPPLINT_DIRS]
158
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000159 # Use the strictest verbosity level for cpplint.py (level 1) which is the
160 # default when running cpplint.py from command line.
161 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000162 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000163 verbosity_level = 1
164 files = []
165 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200166 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100167 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000168 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000169
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000170 for file_name in files:
171 cpplint.ProcessFile(file_name, verbosity_level)
172
173 if cpplint._cpplint_state.error_count > 0:
174 if input_api.is_committing:
175 # TODO(kjellander): Change back to PresubmitError below when we're
176 # confident with the lint settings.
177 res_type = output_api.PresubmitPromptWarning
178 else:
179 res_type = output_api.PresubmitPromptWarning
180 result = [res_type('Changelist failed cpplint.py check.')]
181
182 return result
183
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000184def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
185 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
186 violating_files = []
187 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000188 gyp_exceptions = (
189 'base_tests.gyp',
190 'desktop_capture.gypi',
191 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000192 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000193 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000194 'sound.gyp',
195 'webrtc_test_common.gyp',
196 'webrtc_tests.gypi',
197 )
198 if f.LocalPath().endswith(gyp_exceptions):
199 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000200 contents = input_api.ReadFile(f)
201 if pattern.search(contents):
202 violating_files.append(f)
203 if violating_files:
204 return [output_api.PresubmitError(
205 'Depending on rtc_base is not allowed. Change your dependency to '
206 'rtc_base_approved and possibly sanitize and move the desired source '
207 'file(s) to rtc_base_approved.\nChanged GYP files:',
208 items=violating_files)]
209 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000210
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000211def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
212 # Disallow referencing source files with paths above the GYP file location.
213 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
214 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000215 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000216 violating_gyp_files = set()
217 violating_source_entries = []
218 for gyp_file in gyp_files:
219 contents = input_api.ReadFile(gyp_file)
220 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000221 # Find all source list entries starting with ../ in the source block
222 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000223 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000224 source_file = file_list_match.group(0)
225 if 'overrides/' not in source_file:
226 violating_source_entries.append(source_file)
227 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000228 if violating_gyp_files:
229 return [output_api.PresubmitError(
230 'Referencing source files above the directory of the GYP file is not '
231 'allowed. Please introduce new GYP targets and/or GYP files in the '
232 'proper location instead.\n'
233 'Invalid source entries:\n'
234 '%s\n'
235 'Violating GYP files:' % '\n'.join(violating_source_entries),
236 items=violating_gyp_files)]
237 return []
238
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000239def _CheckGypChanges(input_api, output_api):
240 source_file_filter = lambda x: input_api.FilterSourceFile(
241 x, white_list=(r'.+\.(gyp|gypi)$',))
242
243 gyp_files = []
244 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000245 if f.LocalPath().startswith('webrtc'):
246 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000247
248 result = []
249 if gyp_files:
250 result.append(output_api.PresubmitNotifyResult(
251 'As you\'re changing GYP files: please make sure corresponding '
252 'BUILD.gn files are also updated.\nChanged GYP files:',
253 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000254 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000255 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000256 return result
257
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000258def _CheckUnwantedDependencies(input_api, output_api):
259 """Runs checkdeps on #include statements added in this
260 change. Breaking - rules is an error, breaking ! rules is a
261 warning.
262 """
263 # Copied from Chromium's src/PRESUBMIT.py.
264
265 # We need to wait until we have an input_api object and use this
266 # roundabout construct to import checkdeps because this file is
267 # eval-ed and thus doesn't have __file__.
268 original_sys_path = sys.path
269 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000270 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
271 'buildtools', 'checkdeps')
272 if not os.path.exists(checkdeps_path):
273 return [output_api.PresubmitError(
274 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
275 'download Chromium and setup the symlinks?' % checkdeps_path)]
276 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000277 import checkdeps
278 from cpp_checker import CppChecker
279 from rules import Rule
280 finally:
281 # Restore sys.path to what it was before.
282 sys.path = original_sys_path
283
284 added_includes = []
285 for f in input_api.AffectedFiles():
286 if not CppChecker.IsCppFile(f.LocalPath()):
287 continue
288
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200289 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000290 added_includes.append([f.LocalPath(), changed_lines])
291
292 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
293
294 error_descriptions = []
295 warning_descriptions = []
296 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
297 added_includes):
298 description_with_path = '%s\n %s' % (path, rule_description)
299 if rule_type == Rule.DISALLOW:
300 error_descriptions.append(description_with_path)
301 else:
302 warning_descriptions.append(description_with_path)
303
304 results = []
305 if error_descriptions:
306 results.append(output_api.PresubmitError(
307 'You added one or more #includes that violate checkdeps rules.',
308 error_descriptions))
309 if warning_descriptions:
310 results.append(output_api.PresubmitPromptOrNotify(
311 'You added one or more #includes of files that are temporarily\n'
312 'allowed but being removed. Can you avoid introducing the\n'
313 '#include? See relevant DEPS file(s) for details and contacts.',
314 warning_descriptions))
315 return results
316
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000317
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200318def _RunPythonTests(input_api, output_api):
319 def join(*args):
320 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
321
322 test_directories = [
323 join('tools', 'autoroller', 'unittests'),
324 ]
325
326 tests = []
327 for directory in test_directories:
328 tests.extend(
329 input_api.canned_checks.GetUnitTestsInDirectory(
330 input_api,
331 output_api,
332 directory,
333 whitelist=[r'.+_test\.py$']))
334 return input_api.RunTests(tests, parallel=True)
335
336
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000337def _CommonChecks(input_api, output_api):
338 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000339 results = []
tkchin42f580e2015-11-26 23:18:23 -0800340 # Filter out files that are in objc or ios dirs from being cpplint-ed since
341 # they do not follow C++ lint rules.
342 black_list = input_api.DEFAULT_BLACK_LIST + (
343 r".*\bobjc[\\\/].*",
344 )
345 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
346 results.extend(_CheckApprovedFilesLintClean(
347 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000348 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
349 black_list=(r'^.*gviz_api\.py$',
350 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000351 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200352 r'^build[\\\/].*\.py$',
353 r'^buildtools[\\\/].*\.py$',
354 r'^chromium[\\\/].*\.py$',
355 r'^google_apis[\\\/].*\.py$',
356 r'^net.*[\\\/].*\.py$',
357 r'^out.*[\\\/].*\.py$',
358 r'^testing[\\\/].*\.py$',
359 r'^third_party[\\\/].*\.py$',
360 r'^tools[\\\/]find_depot_tools.py$',
361 r'^tools[\\\/]clang[\\\/].*\.py$',
362 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
363 r'^tools[\\\/]gn[\\\/].*\.py$',
364 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200365 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200366 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
367 r'^tools[\\\/]python[\\\/].*\.py$',
368 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
369 r'^tools[\\\/]refactoring[\\\/].*\.py$',
370 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
371 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000372 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200373 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
374 r'^tools[\\\/]valgrind[\\\/].*\.py$',
375 r'^tools[\\\/]win[\\\/].*\.py$',
376 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000377 disabled_warnings=['F0401', # Failed to import x
378 'E0611', # No package y in x
379 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200380 ],
381 pylintrc='pylintrc'))
382 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
383 # we need to have different license checks in talk/ and webrtc/ directories.
384 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200385
386 # Skip long-lines check for DEPS, GN and GYP files.
387 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
388 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000389 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200390 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000391 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
392 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000393 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
394 input_api, output_api))
395 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
396 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800397 results.extend(_CheckApprovedFilesLintClean(input_api, output_api))
398 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000399 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
400 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000401 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000402 results.extend(_CheckUnwantedDependencies(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200403 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000404 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000405
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000406
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000407def CheckChangeOnUpload(input_api, output_api):
408 results = []
409 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200410 results.extend(
411 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000412 return results
413
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000414
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000415def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000416 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000417 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800418 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000419 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000420 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
421 input_api, output_api))
422 results.extend(input_api.canned_checks.CheckChangeHasDescription(
423 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000424 results.extend(input_api.canned_checks.CheckChangeHasBugField(
425 input_api, output_api))
426 results.extend(input_api.canned_checks.CheckChangeHasTestField(
427 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000428 results.extend(input_api.canned_checks.CheckTreeIsOpen(
429 input_api, output_api,
430 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000431 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000432
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000433
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000434# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000435def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700436 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700437 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700438 # commit_queue.py below is a script in depot_tools directory, which has a
439 # 'builders' command to retrieve a list of CQ builders from the CQ config.
440 is_win = platform.system() == 'Windows'
441 masters = json.loads(subprocess.check_output(
442 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000443
kjellander986ee082015-06-16 04:32:13 -0700444 try_config = {}
445 for master in masters:
446 try_config.setdefault(master, {})
447 for builder in masters[master]:
448 if 'presubmit' in builder:
449 # Do not trigger presubmit builders, since they're likely to fail
450 # (e.g. OWNERS checks before finished code review), and we're running
451 # local presubmit anyway.
452 pass
453 else:
454 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000455
kjellander986ee082015-06-16 04:32:13 -0700456 return try_config