blob: 9db9d829867b0574351847f06d84ab5c827d1d66 [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',
jbauch0f2e9392015-12-10 03:11:42 -080021 'webrtc/common_video',
jbauch70625e52015-12-09 14:18:14 -080022 'webrtc/examples',
terelius8f09f172015-12-15 00:51:54 -080023 'webrtc/modules/remote_bitrate_estimator',
mflodman88eeac42015-12-08 09:21:28 +010024 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 03:11:42 -080025 'webrtc/sound',
26 'webrtc/tools',
mflodmand1590b22015-12-09 07:07:59 -080027 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010028]
29
kjellanderfd595232015-12-04 02:44:09 -080030# List of directories of "supported" native APIs. That means changes to headers
31# will be done in a compatible way following this scheme:
32# 1. Non-breaking changes are made.
33# 2. The old APIs as marked as deprecated (with comments).
34# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
35# webrtc-users@google.com (internal list).
36# 4. (later) The deprecated APIs are removed.
37# Directories marked as DEPRECATED should not be used. They're only present in
38# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080039NATIVE_API_DIRS = (
40 'talk/app/webrtc',
41 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080042 'webrtc/base', # DEPRECATED.
43 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080044 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080045 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080046 'webrtc/modules/audio_device/include',
47 'webrtc/modules/audio_processing/include',
48 'webrtc/modules/bitrate_controller/include',
49 'webrtc/modules/include',
50 'webrtc/modules/remote_bitrate_estimator/include',
51 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080052 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080053 'webrtc/modules/utility/include',
54 'webrtc/modules/video_coding/codecs/h264/include',
55 'webrtc/modules/video_coding/codecs/i420/include',
56 'webrtc/modules/video_coding/codecs/vp8/include',
57 'webrtc/modules/video_coding/codecs/vp9/include',
58 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080059 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080060 'webrtc/voice_engine/include',
61)
62
63
64def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
65 """Ensures the list of native API header directories is up to date."""
66 non_existing_paths = []
67 native_api_full_paths = [
68 input_api.os_path.join(input_api.PresubmitLocalPath(),
69 *path.split('/')) for path in NATIVE_API_DIRS]
70 for path in native_api_full_paths:
71 if not os.path.isdir(path):
72 non_existing_paths.append(path)
73 if non_existing_paths:
74 return [output_api.PresubmitError(
75 'Directories to native API headers have changed which has made the '
76 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
77 'location of our native APIs.',
78 non_existing_paths)]
79 return []
80
81
82def _CheckNativeApiHeaderChanges(input_api, output_api):
83 """Checks to remind proper changing of native APIs."""
84 files = []
85 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
86 if f.LocalPath().endswith('.h'):
87 for path in NATIVE_API_DIRS:
88 if os.path.dirname(f.LocalPath()) == path:
89 files.append(f)
90
91 if files:
kjellanderffea13c2015-12-08 01:57:17 -080092 return [output_api.PresubmitNotifyResult(
kjellander53047c92015-12-02 23:56:14 -080093 'You seem to be changing native API header files. Please make sure '
94 'you:\n'
95 ' 1. Make compatible changes that don\'t break existing clients.\n'
96 ' 2. Mark the old APIs as deprecated.\n'
97 ' 3. Create a timeline and plan for when the deprecated method will '
98 'be removed (preferably 3 months or so).\n'
99 ' 4. Update/inform existing downstream code owners to stop using the '
100 'deprecated APIs: \n'
101 'send announcement to discuss-webrtc@googlegroups.com and '
102 'webrtc-users@google.com.\n'
103 ' 5. (after ~3 months) remove the deprecated API.\n'
104 'Related files:',
105 files)]
106 return []
107
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100108
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000109def _CheckNoIOStreamInHeaders(input_api, output_api):
110 """Checks to make sure no .h files include <iostream>."""
111 files = []
112 pattern = input_api.re.compile(r'^#include\s*<iostream>',
113 input_api.re.MULTILINE)
114 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
115 if not f.LocalPath().endswith('.h'):
116 continue
117 contents = input_api.ReadFile(f)
118 if pattern.search(contents):
119 files.append(f)
120
121 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200122 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000123 'Do not #include <iostream> in header files, since it inserts static ' +
124 'initialization into every file including the header. Instead, ' +
125 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200126 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000127 return []
128
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000129
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000130def _CheckNoFRIEND_TEST(input_api, output_api):
131 """Make sure that gtest's FRIEND_TEST() macro is not used, the
132 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
133 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
134 problems = []
135
136 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
137 for f in input_api.AffectedFiles(file_filter=file_filter):
138 for line_num, line in f.ChangedContents():
139 if 'FRIEND_TEST(' in line:
140 problems.append(' %s:%d' % (f.LocalPath(), line_num))
141
142 if not problems:
143 return []
144 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
145 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
146 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
147
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000148
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100149def _IsLintWhitelisted(whitelist_dirs, file_path):
150 """ Checks if a file is whitelisted for lint check."""
151 for path in whitelist_dirs:
152 if os.path.dirname(file_path).startswith(path):
153 return True
154 return False
155
156
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000157def _CheckApprovedFilesLintClean(input_api, output_api,
158 source_file_filter=None):
159 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000160 This check is based on _CheckChangeLintsClean in
161 depot_tools/presubmit_canned_checks.py but has less filters and only checks
162 added files."""
163 result = []
164
165 # Initialize cpplint.
166 import cpplint
167 # Access to a protected member _XX of a client class
168 # pylint: disable=W0212
169 cpplint._cpplint_state.ResetErrorCounts()
170
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100171 # Create a platform independent whitelist for the CPPLINT_DIRS.
172 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
173 for path in CPPLINT_DIRS]
174
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000175 # Use the strictest verbosity level for cpplint.py (level 1) which is the
176 # default when running cpplint.py from command line.
177 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000178 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000179 verbosity_level = 1
180 files = []
181 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200182 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100183 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000184 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000185
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000186 for file_name in files:
187 cpplint.ProcessFile(file_name, verbosity_level)
188
189 if cpplint._cpplint_state.error_count > 0:
190 if input_api.is_committing:
191 # TODO(kjellander): Change back to PresubmitError below when we're
192 # confident with the lint settings.
193 res_type = output_api.PresubmitPromptWarning
194 else:
195 res_type = output_api.PresubmitPromptWarning
196 result = [res_type('Changelist failed cpplint.py check.')]
197
198 return result
199
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000200def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
201 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
202 violating_files = []
203 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000204 gyp_exceptions = (
205 'base_tests.gyp',
206 'desktop_capture.gypi',
207 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000208 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000209 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000210 'sound.gyp',
211 'webrtc_test_common.gyp',
212 'webrtc_tests.gypi',
213 )
214 if f.LocalPath().endswith(gyp_exceptions):
215 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000216 contents = input_api.ReadFile(f)
217 if pattern.search(contents):
218 violating_files.append(f)
219 if violating_files:
220 return [output_api.PresubmitError(
221 'Depending on rtc_base is not allowed. Change your dependency to '
222 'rtc_base_approved and possibly sanitize and move the desired source '
223 'file(s) to rtc_base_approved.\nChanged GYP files:',
224 items=violating_files)]
225 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000226
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000227def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
228 # Disallow referencing source files with paths above the GYP file location.
229 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
230 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000231 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000232 violating_gyp_files = set()
233 violating_source_entries = []
234 for gyp_file in gyp_files:
235 contents = input_api.ReadFile(gyp_file)
236 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000237 # Find all source list entries starting with ../ in the source block
238 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000239 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000240 source_file = file_list_match.group(0)
241 if 'overrides/' not in source_file:
242 violating_source_entries.append(source_file)
243 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000244 if violating_gyp_files:
245 return [output_api.PresubmitError(
246 'Referencing source files above the directory of the GYP file is not '
247 'allowed. Please introduce new GYP targets and/or GYP files in the '
248 'proper location instead.\n'
249 'Invalid source entries:\n'
250 '%s\n'
251 'Violating GYP files:' % '\n'.join(violating_source_entries),
252 items=violating_gyp_files)]
253 return []
254
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000255def _CheckGypChanges(input_api, output_api):
256 source_file_filter = lambda x: input_api.FilterSourceFile(
257 x, white_list=(r'.+\.(gyp|gypi)$',))
258
259 gyp_files = []
260 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000261 if f.LocalPath().startswith('webrtc'):
262 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000263
264 result = []
265 if gyp_files:
266 result.append(output_api.PresubmitNotifyResult(
267 'As you\'re changing GYP files: please make sure corresponding '
268 'BUILD.gn files are also updated.\nChanged GYP files:',
269 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000270 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000271 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000272 return result
273
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000274def _CheckUnwantedDependencies(input_api, output_api):
275 """Runs checkdeps on #include statements added in this
276 change. Breaking - rules is an error, breaking ! rules is a
277 warning.
278 """
279 # Copied from Chromium's src/PRESUBMIT.py.
280
281 # We need to wait until we have an input_api object and use this
282 # roundabout construct to import checkdeps because this file is
283 # eval-ed and thus doesn't have __file__.
284 original_sys_path = sys.path
285 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000286 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
287 'buildtools', 'checkdeps')
288 if not os.path.exists(checkdeps_path):
289 return [output_api.PresubmitError(
290 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
291 'download Chromium and setup the symlinks?' % checkdeps_path)]
292 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000293 import checkdeps
294 from cpp_checker import CppChecker
295 from rules import Rule
296 finally:
297 # Restore sys.path to what it was before.
298 sys.path = original_sys_path
299
300 added_includes = []
301 for f in input_api.AffectedFiles():
302 if not CppChecker.IsCppFile(f.LocalPath()):
303 continue
304
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200305 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000306 added_includes.append([f.LocalPath(), changed_lines])
307
308 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
309
310 error_descriptions = []
311 warning_descriptions = []
312 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
313 added_includes):
314 description_with_path = '%s\n %s' % (path, rule_description)
315 if rule_type == Rule.DISALLOW:
316 error_descriptions.append(description_with_path)
317 else:
318 warning_descriptions.append(description_with_path)
319
320 results = []
321 if error_descriptions:
322 results.append(output_api.PresubmitError(
323 'You added one or more #includes that violate checkdeps rules.',
324 error_descriptions))
325 if warning_descriptions:
326 results.append(output_api.PresubmitPromptOrNotify(
327 'You added one or more #includes of files that are temporarily\n'
328 'allowed but being removed. Can you avoid introducing the\n'
329 '#include? See relevant DEPS file(s) for details and contacts.',
330 warning_descriptions))
331 return results
332
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000333
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200334def _RunPythonTests(input_api, output_api):
335 def join(*args):
336 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
337
338 test_directories = [
339 join('tools', 'autoroller', 'unittests'),
340 ]
341
342 tests = []
343 for directory in test_directories:
344 tests.extend(
345 input_api.canned_checks.GetUnitTestsInDirectory(
346 input_api,
347 output_api,
348 directory,
349 whitelist=[r'.+_test\.py$']))
350 return input_api.RunTests(tests, parallel=True)
351
352
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000353def _CommonChecks(input_api, output_api):
354 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000355 results = []
tkchin42f580e2015-11-26 23:18:23 -0800356 # Filter out files that are in objc or ios dirs from being cpplint-ed since
357 # they do not follow C++ lint rules.
358 black_list = input_api.DEFAULT_BLACK_LIST + (
359 r".*\bobjc[\\\/].*",
360 )
361 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
362 results.extend(_CheckApprovedFilesLintClean(
363 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000364 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
365 black_list=(r'^.*gviz_api\.py$',
366 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000367 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200368 r'^build[\\\/].*\.py$',
369 r'^buildtools[\\\/].*\.py$',
370 r'^chromium[\\\/].*\.py$',
371 r'^google_apis[\\\/].*\.py$',
372 r'^net.*[\\\/].*\.py$',
373 r'^out.*[\\\/].*\.py$',
374 r'^testing[\\\/].*\.py$',
375 r'^third_party[\\\/].*\.py$',
376 r'^tools[\\\/]find_depot_tools.py$',
377 r'^tools[\\\/]clang[\\\/].*\.py$',
378 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
379 r'^tools[\\\/]gn[\\\/].*\.py$',
380 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200381 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200382 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
383 r'^tools[\\\/]python[\\\/].*\.py$',
384 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
385 r'^tools[\\\/]refactoring[\\\/].*\.py$',
386 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
387 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000388 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200389 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
390 r'^tools[\\\/]valgrind[\\\/].*\.py$',
391 r'^tools[\\\/]win[\\\/].*\.py$',
392 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000393 disabled_warnings=['F0401', # Failed to import x
394 'E0611', # No package y in x
395 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200396 ],
397 pylintrc='pylintrc'))
398 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
399 # we need to have different license checks in talk/ and webrtc/ directories.
400 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200401
402 # Skip long-lines check for DEPS, GN and GYP files.
403 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
404 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000405 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200406 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000407 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
408 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000409 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
410 input_api, output_api))
411 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
412 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800413 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000414 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
415 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000416 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000417 results.extend(_CheckUnwantedDependencies(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200418 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000419 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000420
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000421
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000422def CheckChangeOnUpload(input_api, output_api):
423 results = []
424 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200425 results.extend(
426 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000427 return results
428
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000429
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000430def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000431 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000432 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800433 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000434 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000435 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
436 input_api, output_api))
437 results.extend(input_api.canned_checks.CheckChangeHasDescription(
438 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000439 results.extend(input_api.canned_checks.CheckChangeHasBugField(
440 input_api, output_api))
441 results.extend(input_api.canned_checks.CheckChangeHasTestField(
442 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000443 results.extend(input_api.canned_checks.CheckTreeIsOpen(
444 input_api, output_api,
445 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000446 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000447
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000448
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000449# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000450def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700451 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700452 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700453 # commit_queue.py below is a script in depot_tools directory, which has a
454 # 'builders' command to retrieve a list of CQ builders from the CQ config.
455 is_win = platform.system() == 'Windows'
456 masters = json.loads(subprocess.check_output(
457 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000458
kjellander986ee082015-06-16 04:32:13 -0700459 try_config = {}
460 for master in masters:
461 try_config.setdefault(master, {})
462 for builder in masters[master]:
463 if 'presubmit' in builder:
464 # Do not trigger presubmit builders, since they're likely to fail
465 # (e.g. OWNERS checks before finished code review), and we're running
466 # local presubmit anyway.
467 pass
468 else:
469 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000470
kjellander986ee082015-06-16 04:32:13 -0700471 return try_config