blob: 2c0da0f8764f53b46d158f70262e6abc20dffbf3 [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]
22
kjellanderfd595232015-12-04 02:44:09 -080023# List of directories of "supported" native APIs. That means changes to headers
24# will be done in a compatible way following this scheme:
25# 1. Non-breaking changes are made.
26# 2. The old APIs as marked as deprecated (with comments).
27# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
28# webrtc-users@google.com (internal list).
29# 4. (later) The deprecated APIs are removed.
30# Directories marked as DEPRECATED should not be used. They're only present in
31# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080032NATIVE_API_DIRS = (
33 'talk/app/webrtc',
34 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080035 'webrtc/base', # DEPRECATED.
36 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080037 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080038 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080039 'webrtc/modules/audio_device/include',
40 'webrtc/modules/audio_processing/include',
41 'webrtc/modules/bitrate_controller/include',
42 'webrtc/modules/include',
43 'webrtc/modules/remote_bitrate_estimator/include',
44 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080045 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080046 'webrtc/modules/utility/include',
47 'webrtc/modules/video_coding/codecs/h264/include',
48 'webrtc/modules/video_coding/codecs/i420/include',
49 'webrtc/modules/video_coding/codecs/vp8/include',
50 'webrtc/modules/video_coding/codecs/vp9/include',
51 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080052 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080053 'webrtc/voice_engine/include',
54)
55
56
57def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
58 """Ensures the list of native API header directories is up to date."""
59 non_existing_paths = []
60 native_api_full_paths = [
61 input_api.os_path.join(input_api.PresubmitLocalPath(),
62 *path.split('/')) for path in NATIVE_API_DIRS]
63 for path in native_api_full_paths:
64 if not os.path.isdir(path):
65 non_existing_paths.append(path)
66 if non_existing_paths:
67 return [output_api.PresubmitError(
68 'Directories to native API headers have changed which has made the '
69 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
70 'location of our native APIs.',
71 non_existing_paths)]
72 return []
73
74
75def _CheckNativeApiHeaderChanges(input_api, output_api):
76 """Checks to remind proper changing of native APIs."""
77 files = []
78 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
79 if f.LocalPath().endswith('.h'):
80 for path in NATIVE_API_DIRS:
81 if os.path.dirname(f.LocalPath()) == path:
82 files.append(f)
83
84 if files:
85 return [output_api.PresubmitPromptWarning(
86 'You seem to be changing native API header files. Please make sure '
87 'you:\n'
88 ' 1. Make compatible changes that don\'t break existing clients.\n'
89 ' 2. Mark the old APIs as deprecated.\n'
90 ' 3. Create a timeline and plan for when the deprecated method will '
91 'be removed (preferably 3 months or so).\n'
92 ' 4. Update/inform existing downstream code owners to stop using the '
93 'deprecated APIs: \n'
94 'send announcement to discuss-webrtc@googlegroups.com and '
95 'webrtc-users@google.com.\n'
96 ' 5. (after ~3 months) remove the deprecated API.\n'
97 'Related files:',
98 files)]
99 return []
100
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100101
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000102def _CheckNoIOStreamInHeaders(input_api, output_api):
103 """Checks to make sure no .h files include <iostream>."""
104 files = []
105 pattern = input_api.re.compile(r'^#include\s*<iostream>',
106 input_api.re.MULTILINE)
107 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
108 if not f.LocalPath().endswith('.h'):
109 continue
110 contents = input_api.ReadFile(f)
111 if pattern.search(contents):
112 files.append(f)
113
114 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200115 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000116 'Do not #include <iostream> in header files, since it inserts static ' +
117 'initialization into every file including the header. Instead, ' +
118 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200119 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000120 return []
121
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000122
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000123def _CheckNoFRIEND_TEST(input_api, output_api):
124 """Make sure that gtest's FRIEND_TEST() macro is not used, the
125 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
126 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
127 problems = []
128
129 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
130 for f in input_api.AffectedFiles(file_filter=file_filter):
131 for line_num, line in f.ChangedContents():
132 if 'FRIEND_TEST(' in line:
133 problems.append(' %s:%d' % (f.LocalPath(), line_num))
134
135 if not problems:
136 return []
137 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
138 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
139 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
140
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000141
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100142def _IsLintWhitelisted(whitelist_dirs, file_path):
143 """ Checks if a file is whitelisted for lint check."""
144 for path in whitelist_dirs:
145 if os.path.dirname(file_path).startswith(path):
146 return True
147 return False
148
149
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000150def _CheckApprovedFilesLintClean(input_api, output_api,
151 source_file_filter=None):
152 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000153 This check is based on _CheckChangeLintsClean in
154 depot_tools/presubmit_canned_checks.py but has less filters and only checks
155 added files."""
156 result = []
157
158 # Initialize cpplint.
159 import cpplint
160 # Access to a protected member _XX of a client class
161 # pylint: disable=W0212
162 cpplint._cpplint_state.ResetErrorCounts()
163
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100164 # Create a platform independent whitelist for the CPPLINT_DIRS.
165 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
166 for path in CPPLINT_DIRS]
167
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000168 # Use the strictest verbosity level for cpplint.py (level 1) which is the
169 # default when running cpplint.py from command line.
170 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000171 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000172 verbosity_level = 1
173 files = []
174 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200175 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100176 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000177 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000178
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000179 for file_name in files:
180 cpplint.ProcessFile(file_name, verbosity_level)
181
182 if cpplint._cpplint_state.error_count > 0:
183 if input_api.is_committing:
184 # TODO(kjellander): Change back to PresubmitError below when we're
185 # confident with the lint settings.
186 res_type = output_api.PresubmitPromptWarning
187 else:
188 res_type = output_api.PresubmitPromptWarning
189 result = [res_type('Changelist failed cpplint.py check.')]
190
191 return result
192
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000193def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
194 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
195 violating_files = []
196 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000197 gyp_exceptions = (
198 'base_tests.gyp',
199 'desktop_capture.gypi',
200 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000201 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000202 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000203 'sound.gyp',
204 'webrtc_test_common.gyp',
205 'webrtc_tests.gypi',
206 )
207 if f.LocalPath().endswith(gyp_exceptions):
208 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000209 contents = input_api.ReadFile(f)
210 if pattern.search(contents):
211 violating_files.append(f)
212 if violating_files:
213 return [output_api.PresubmitError(
214 'Depending on rtc_base is not allowed. Change your dependency to '
215 'rtc_base_approved and possibly sanitize and move the desired source '
216 'file(s) to rtc_base_approved.\nChanged GYP files:',
217 items=violating_files)]
218 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000219
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000220def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
221 # Disallow referencing source files with paths above the GYP file location.
222 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
223 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000224 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000225 violating_gyp_files = set()
226 violating_source_entries = []
227 for gyp_file in gyp_files:
228 contents = input_api.ReadFile(gyp_file)
229 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000230 # Find all source list entries starting with ../ in the source block
231 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000232 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000233 source_file = file_list_match.group(0)
234 if 'overrides/' not in source_file:
235 violating_source_entries.append(source_file)
236 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000237 if violating_gyp_files:
238 return [output_api.PresubmitError(
239 'Referencing source files above the directory of the GYP file is not '
240 'allowed. Please introduce new GYP targets and/or GYP files in the '
241 'proper location instead.\n'
242 'Invalid source entries:\n'
243 '%s\n'
244 'Violating GYP files:' % '\n'.join(violating_source_entries),
245 items=violating_gyp_files)]
246 return []
247
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000248def _CheckGypChanges(input_api, output_api):
249 source_file_filter = lambda x: input_api.FilterSourceFile(
250 x, white_list=(r'.+\.(gyp|gypi)$',))
251
252 gyp_files = []
253 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000254 if f.LocalPath().startswith('webrtc'):
255 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000256
257 result = []
258 if gyp_files:
259 result.append(output_api.PresubmitNotifyResult(
260 'As you\'re changing GYP files: please make sure corresponding '
261 'BUILD.gn files are also updated.\nChanged GYP files:',
262 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000263 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000264 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000265 return result
266
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000267def _CheckUnwantedDependencies(input_api, output_api):
268 """Runs checkdeps on #include statements added in this
269 change. Breaking - rules is an error, breaking ! rules is a
270 warning.
271 """
272 # Copied from Chromium's src/PRESUBMIT.py.
273
274 # We need to wait until we have an input_api object and use this
275 # roundabout construct to import checkdeps because this file is
276 # eval-ed and thus doesn't have __file__.
277 original_sys_path = sys.path
278 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000279 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
280 'buildtools', 'checkdeps')
281 if not os.path.exists(checkdeps_path):
282 return [output_api.PresubmitError(
283 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
284 'download Chromium and setup the symlinks?' % checkdeps_path)]
285 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000286 import checkdeps
287 from cpp_checker import CppChecker
288 from rules import Rule
289 finally:
290 # Restore sys.path to what it was before.
291 sys.path = original_sys_path
292
293 added_includes = []
294 for f in input_api.AffectedFiles():
295 if not CppChecker.IsCppFile(f.LocalPath()):
296 continue
297
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200298 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000299 added_includes.append([f.LocalPath(), changed_lines])
300
301 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
302
303 error_descriptions = []
304 warning_descriptions = []
305 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
306 added_includes):
307 description_with_path = '%s\n %s' % (path, rule_description)
308 if rule_type == Rule.DISALLOW:
309 error_descriptions.append(description_with_path)
310 else:
311 warning_descriptions.append(description_with_path)
312
313 results = []
314 if error_descriptions:
315 results.append(output_api.PresubmitError(
316 'You added one or more #includes that violate checkdeps rules.',
317 error_descriptions))
318 if warning_descriptions:
319 results.append(output_api.PresubmitPromptOrNotify(
320 'You added one or more #includes of files that are temporarily\n'
321 'allowed but being removed. Can you avoid introducing the\n'
322 '#include? See relevant DEPS file(s) for details and contacts.',
323 warning_descriptions))
324 return results
325
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000326
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200327def _RunPythonTests(input_api, output_api):
328 def join(*args):
329 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
330
331 test_directories = [
332 join('tools', 'autoroller', 'unittests'),
333 ]
334
335 tests = []
336 for directory in test_directories:
337 tests.extend(
338 input_api.canned_checks.GetUnitTestsInDirectory(
339 input_api,
340 output_api,
341 directory,
342 whitelist=[r'.+_test\.py$']))
343 return input_api.RunTests(tests, parallel=True)
344
345
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000346def _CommonChecks(input_api, output_api):
347 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000348 results = []
tkchin42f580e2015-11-26 23:18:23 -0800349 # Filter out files that are in objc or ios dirs from being cpplint-ed since
350 # they do not follow C++ lint rules.
351 black_list = input_api.DEFAULT_BLACK_LIST + (
352 r".*\bobjc[\\\/].*",
353 )
354 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
355 results.extend(_CheckApprovedFilesLintClean(
356 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000357 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
358 black_list=(r'^.*gviz_api\.py$',
359 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000360 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200361 r'^build[\\\/].*\.py$',
362 r'^buildtools[\\\/].*\.py$',
363 r'^chromium[\\\/].*\.py$',
364 r'^google_apis[\\\/].*\.py$',
365 r'^net.*[\\\/].*\.py$',
366 r'^out.*[\\\/].*\.py$',
367 r'^testing[\\\/].*\.py$',
368 r'^third_party[\\\/].*\.py$',
369 r'^tools[\\\/]find_depot_tools.py$',
370 r'^tools[\\\/]clang[\\\/].*\.py$',
371 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
372 r'^tools[\\\/]gn[\\\/].*\.py$',
373 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200374 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200375 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
376 r'^tools[\\\/]python[\\\/].*\.py$',
377 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
378 r'^tools[\\\/]refactoring[\\\/].*\.py$',
379 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
380 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000381 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200382 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
383 r'^tools[\\\/]valgrind[\\\/].*\.py$',
384 r'^tools[\\\/]win[\\\/].*\.py$',
385 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000386 disabled_warnings=['F0401', # Failed to import x
387 'E0611', # No package y in x
388 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200389 ],
390 pylintrc='pylintrc'))
391 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
392 # we need to have different license checks in talk/ and webrtc/ directories.
393 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200394
395 # Skip long-lines check for DEPS, GN and GYP files.
396 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
397 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000398 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200399 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000400 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
401 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000402 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
403 input_api, output_api))
404 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
405 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800406 results.extend(_CheckApprovedFilesLintClean(input_api, output_api))
407 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000408 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
409 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000410 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000411 results.extend(_CheckUnwantedDependencies(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200412 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000413 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000414
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000415
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000416def CheckChangeOnUpload(input_api, output_api):
417 results = []
418 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200419 results.extend(
420 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000421 return results
422
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000423
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000424def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000425 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000426 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800427 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000428 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000429 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
430 input_api, output_api))
431 results.extend(input_api.canned_checks.CheckChangeHasDescription(
432 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000433 results.extend(input_api.canned_checks.CheckChangeHasBugField(
434 input_api, output_api))
435 results.extend(input_api.canned_checks.CheckChangeHasTestField(
436 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000437 results.extend(input_api.canned_checks.CheckTreeIsOpen(
438 input_api, output_api,
439 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000440 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000441
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000442
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000443# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000444def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700445 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700446 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700447 # commit_queue.py below is a script in depot_tools directory, which has a
448 # 'builders' command to retrieve a list of CQ builders from the CQ config.
449 is_win = platform.system() == 'Windows'
450 masters = json.loads(subprocess.check_output(
451 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000452
kjellander986ee082015-06-16 04:32:13 -0700453 try_config = {}
454 for master in masters:
455 try_config.setdefault(master, {})
456 for builder in masters[master]:
457 if 'presubmit' in builder:
458 # Do not trigger presubmit builders, since they're likely to fail
459 # (e.g. OWNERS checks before finished code review), and we're running
460 # local presubmit anyway.
461 pass
462 else:
463 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000464
kjellander986ee082015-06-16 04:32:13 -0700465 return try_config