blob: 7557b6bece781447d8cb52363979375dd8e4ba93 [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',
danilchap377b5e62015-12-15 04:33:44 -080024 'webrtc/modules/rtp_rtcp',
mflodman88eeac42015-12-08 09:21:28 +010025 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 03:11:42 -080026 'webrtc/sound',
27 'webrtc/tools',
mflodmand1590b22015-12-09 07:07:59 -080028 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010029]
30
kjellanderfd595232015-12-04 02:44:09 -080031# List of directories of "supported" native APIs. That means changes to headers
32# will be done in a compatible way following this scheme:
33# 1. Non-breaking changes are made.
34# 2. The old APIs as marked as deprecated (with comments).
35# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
36# webrtc-users@google.com (internal list).
37# 4. (later) The deprecated APIs are removed.
38# Directories marked as DEPRECATED should not be used. They're only present in
39# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080040NATIVE_API_DIRS = (
41 'talk/app/webrtc',
42 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080043 'webrtc/base', # DEPRECATED.
44 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080045 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080046 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080047 'webrtc/modules/audio_device/include',
48 'webrtc/modules/audio_processing/include',
49 'webrtc/modules/bitrate_controller/include',
50 'webrtc/modules/include',
51 'webrtc/modules/remote_bitrate_estimator/include',
52 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080053 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080054 'webrtc/modules/utility/include',
55 'webrtc/modules/video_coding/codecs/h264/include',
56 'webrtc/modules/video_coding/codecs/i420/include',
57 'webrtc/modules/video_coding/codecs/vp8/include',
58 'webrtc/modules/video_coding/codecs/vp9/include',
59 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080060 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080061 'webrtc/voice_engine/include',
62)
63
64
65def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
66 """Ensures the list of native API header directories is up to date."""
67 non_existing_paths = []
68 native_api_full_paths = [
69 input_api.os_path.join(input_api.PresubmitLocalPath(),
70 *path.split('/')) for path in NATIVE_API_DIRS]
71 for path in native_api_full_paths:
72 if not os.path.isdir(path):
73 non_existing_paths.append(path)
74 if non_existing_paths:
75 return [output_api.PresubmitError(
76 'Directories to native API headers have changed which has made the '
77 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
78 'location of our native APIs.',
79 non_existing_paths)]
80 return []
81
82
83def _CheckNativeApiHeaderChanges(input_api, output_api):
84 """Checks to remind proper changing of native APIs."""
85 files = []
86 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
87 if f.LocalPath().endswith('.h'):
88 for path in NATIVE_API_DIRS:
89 if os.path.dirname(f.LocalPath()) == path:
90 files.append(f)
91
92 if files:
kjellanderffea13c2015-12-08 01:57:17 -080093 return [output_api.PresubmitNotifyResult(
kjellander53047c92015-12-02 23:56:14 -080094 'You seem to be changing native API header files. Please make sure '
95 'you:\n'
96 ' 1. Make compatible changes that don\'t break existing clients.\n'
97 ' 2. Mark the old APIs as deprecated.\n'
98 ' 3. Create a timeline and plan for when the deprecated method will '
99 'be removed (preferably 3 months or so).\n'
100 ' 4. Update/inform existing downstream code owners to stop using the '
101 'deprecated APIs: \n'
102 'send announcement to discuss-webrtc@googlegroups.com and '
103 'webrtc-users@google.com.\n'
104 ' 5. (after ~3 months) remove the deprecated API.\n'
105 'Related files:',
106 files)]
107 return []
108
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100109
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000110def _CheckNoIOStreamInHeaders(input_api, output_api):
111 """Checks to make sure no .h files include <iostream>."""
112 files = []
113 pattern = input_api.re.compile(r'^#include\s*<iostream>',
114 input_api.re.MULTILINE)
115 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
116 if not f.LocalPath().endswith('.h'):
117 continue
118 contents = input_api.ReadFile(f)
119 if pattern.search(contents):
120 files.append(f)
121
122 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200123 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000124 'Do not #include <iostream> in header files, since it inserts static ' +
125 'initialization into every file including the header. Instead, ' +
126 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200127 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000128 return []
129
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000130
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000131def _CheckNoFRIEND_TEST(input_api, output_api):
132 """Make sure that gtest's FRIEND_TEST() macro is not used, the
133 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
134 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
135 problems = []
136
137 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
138 for f in input_api.AffectedFiles(file_filter=file_filter):
139 for line_num, line in f.ChangedContents():
140 if 'FRIEND_TEST(' in line:
141 problems.append(' %s:%d' % (f.LocalPath(), line_num))
142
143 if not problems:
144 return []
145 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
146 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
147 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
148
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000149
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100150def _IsLintWhitelisted(whitelist_dirs, file_path):
151 """ Checks if a file is whitelisted for lint check."""
152 for path in whitelist_dirs:
153 if os.path.dirname(file_path).startswith(path):
154 return True
155 return False
156
157
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000158def _CheckApprovedFilesLintClean(input_api, output_api,
159 source_file_filter=None):
160 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000161 This check is based on _CheckChangeLintsClean in
162 depot_tools/presubmit_canned_checks.py but has less filters and only checks
163 added files."""
164 result = []
165
166 # Initialize cpplint.
167 import cpplint
168 # Access to a protected member _XX of a client class
169 # pylint: disable=W0212
170 cpplint._cpplint_state.ResetErrorCounts()
171
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100172 # Create a platform independent whitelist for the CPPLINT_DIRS.
173 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
174 for path in CPPLINT_DIRS]
175
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000176 # Use the strictest verbosity level for cpplint.py (level 1) which is the
177 # default when running cpplint.py from command line.
178 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000179 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000180 verbosity_level = 1
181 files = []
182 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200183 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100184 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000185 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000186
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000187 for file_name in files:
188 cpplint.ProcessFile(file_name, verbosity_level)
189
190 if cpplint._cpplint_state.error_count > 0:
191 if input_api.is_committing:
192 # TODO(kjellander): Change back to PresubmitError below when we're
193 # confident with the lint settings.
194 res_type = output_api.PresubmitPromptWarning
195 else:
196 res_type = output_api.PresubmitPromptWarning
197 result = [res_type('Changelist failed cpplint.py check.')]
198
199 return result
200
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000201def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
202 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
203 violating_files = []
204 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000205 gyp_exceptions = (
206 'base_tests.gyp',
207 'desktop_capture.gypi',
208 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000209 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000210 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000211 'sound.gyp',
212 'webrtc_test_common.gyp',
213 'webrtc_tests.gypi',
214 )
215 if f.LocalPath().endswith(gyp_exceptions):
216 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000217 contents = input_api.ReadFile(f)
218 if pattern.search(contents):
219 violating_files.append(f)
220 if violating_files:
221 return [output_api.PresubmitError(
222 'Depending on rtc_base is not allowed. Change your dependency to '
223 'rtc_base_approved and possibly sanitize and move the desired source '
224 'file(s) to rtc_base_approved.\nChanged GYP files:',
225 items=violating_files)]
226 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000227
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000228def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
229 # Disallow referencing source files with paths above the GYP file location.
230 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
231 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000232 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000233 violating_gyp_files = set()
234 violating_source_entries = []
235 for gyp_file in gyp_files:
236 contents = input_api.ReadFile(gyp_file)
237 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000238 # Find all source list entries starting with ../ in the source block
239 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000240 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000241 source_file = file_list_match.group(0)
242 if 'overrides/' not in source_file:
243 violating_source_entries.append(source_file)
244 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000245 if violating_gyp_files:
246 return [output_api.PresubmitError(
247 'Referencing source files above the directory of the GYP file is not '
248 'allowed. Please introduce new GYP targets and/or GYP files in the '
249 'proper location instead.\n'
250 'Invalid source entries:\n'
251 '%s\n'
252 'Violating GYP files:' % '\n'.join(violating_source_entries),
253 items=violating_gyp_files)]
254 return []
255
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000256def _CheckGypChanges(input_api, output_api):
257 source_file_filter = lambda x: input_api.FilterSourceFile(
258 x, white_list=(r'.+\.(gyp|gypi)$',))
259
260 gyp_files = []
261 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000262 if f.LocalPath().startswith('webrtc'):
263 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000264
265 result = []
266 if gyp_files:
267 result.append(output_api.PresubmitNotifyResult(
268 'As you\'re changing GYP files: please make sure corresponding '
269 'BUILD.gn files are also updated.\nChanged GYP files:',
270 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000271 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000272 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000273 return result
274
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000275def _CheckUnwantedDependencies(input_api, output_api):
276 """Runs checkdeps on #include statements added in this
277 change. Breaking - rules is an error, breaking ! rules is a
278 warning.
279 """
280 # Copied from Chromium's src/PRESUBMIT.py.
281
282 # We need to wait until we have an input_api object and use this
283 # roundabout construct to import checkdeps because this file is
284 # eval-ed and thus doesn't have __file__.
285 original_sys_path = sys.path
286 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000287 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
288 'buildtools', 'checkdeps')
289 if not os.path.exists(checkdeps_path):
290 return [output_api.PresubmitError(
291 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
292 'download Chromium and setup the symlinks?' % checkdeps_path)]
293 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000294 import checkdeps
295 from cpp_checker import CppChecker
296 from rules import Rule
297 finally:
298 # Restore sys.path to what it was before.
299 sys.path = original_sys_path
300
301 added_includes = []
302 for f in input_api.AffectedFiles():
303 if not CppChecker.IsCppFile(f.LocalPath()):
304 continue
305
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200306 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000307 added_includes.append([f.LocalPath(), changed_lines])
308
309 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
310
311 error_descriptions = []
312 warning_descriptions = []
313 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
314 added_includes):
315 description_with_path = '%s\n %s' % (path, rule_description)
316 if rule_type == Rule.DISALLOW:
317 error_descriptions.append(description_with_path)
318 else:
319 warning_descriptions.append(description_with_path)
320
321 results = []
322 if error_descriptions:
323 results.append(output_api.PresubmitError(
324 'You added one or more #includes that violate checkdeps rules.',
325 error_descriptions))
326 if warning_descriptions:
327 results.append(output_api.PresubmitPromptOrNotify(
328 'You added one or more #includes of files that are temporarily\n'
329 'allowed but being removed. Can you avoid introducing the\n'
330 '#include? See relevant DEPS file(s) for details and contacts.',
331 warning_descriptions))
332 return results
333
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000334
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200335def _RunPythonTests(input_api, output_api):
336 def join(*args):
337 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
338
339 test_directories = [
340 join('tools', 'autoroller', 'unittests'),
341 ]
342
343 tests = []
344 for directory in test_directories:
345 tests.extend(
346 input_api.canned_checks.GetUnitTestsInDirectory(
347 input_api,
348 output_api,
349 directory,
350 whitelist=[r'.+_test\.py$']))
351 return input_api.RunTests(tests, parallel=True)
352
353
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000354def _CommonChecks(input_api, output_api):
355 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000356 results = []
tkchin42f580e2015-11-26 23:18:23 -0800357 # Filter out files that are in objc or ios dirs from being cpplint-ed since
358 # they do not follow C++ lint rules.
359 black_list = input_api.DEFAULT_BLACK_LIST + (
360 r".*\bobjc[\\\/].*",
361 )
362 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
363 results.extend(_CheckApprovedFilesLintClean(
364 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000365 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
366 black_list=(r'^.*gviz_api\.py$',
367 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000368 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200369 r'^build[\\\/].*\.py$',
370 r'^buildtools[\\\/].*\.py$',
371 r'^chromium[\\\/].*\.py$',
372 r'^google_apis[\\\/].*\.py$',
373 r'^net.*[\\\/].*\.py$',
374 r'^out.*[\\\/].*\.py$',
375 r'^testing[\\\/].*\.py$',
376 r'^third_party[\\\/].*\.py$',
377 r'^tools[\\\/]find_depot_tools.py$',
378 r'^tools[\\\/]clang[\\\/].*\.py$',
379 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
380 r'^tools[\\\/]gn[\\\/].*\.py$',
381 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200382 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200383 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
384 r'^tools[\\\/]python[\\\/].*\.py$',
385 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
386 r'^tools[\\\/]refactoring[\\\/].*\.py$',
387 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
388 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000389 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200390 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
391 r'^tools[\\\/]valgrind[\\\/].*\.py$',
392 r'^tools[\\\/]win[\\\/].*\.py$',
393 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000394 disabled_warnings=['F0401', # Failed to import x
395 'E0611', # No package y in x
396 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200397 ],
398 pylintrc='pylintrc'))
399 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
400 # we need to have different license checks in talk/ and webrtc/ directories.
401 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200402
403 # Skip long-lines check for DEPS, GN and GYP files.
404 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
405 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000406 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200407 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000408 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
409 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000410 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
411 input_api, output_api))
412 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
413 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800414 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000415 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
416 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000417 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000418 results.extend(_CheckUnwantedDependencies(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200419 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000420 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000421
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000422
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000423def CheckChangeOnUpload(input_api, output_api):
424 results = []
425 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200426 results.extend(
427 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000428 return results
429
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000430
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000431def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000432 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000433 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800434 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000435 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000436 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
437 input_api, output_api))
438 results.extend(input_api.canned_checks.CheckChangeHasDescription(
439 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000440 results.extend(input_api.canned_checks.CheckChangeHasBugField(
441 input_api, output_api))
442 results.extend(input_api.canned_checks.CheckChangeHasTestField(
443 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000444 results.extend(input_api.canned_checks.CheckTreeIsOpen(
445 input_api, output_api,
446 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000447 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000448
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000449
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000450# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000451def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700452 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700453 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700454 # commit_queue.py below is a script in depot_tools directory, which has a
455 # 'builders' command to retrieve a list of CQ builders from the CQ config.
456 is_win = platform.system() == 'Windows'
457 masters = json.loads(subprocess.check_output(
458 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000459
kjellander986ee082015-06-16 04:32:13 -0700460 try_config = {}
461 for master in masters:
462 try_config.setdefault(master, {})
463 for builder in masters[master]:
464 if 'presubmit' in builder:
465 # Do not trigger presubmit builders, since they're likely to fail
466 # (e.g. OWNERS checks before finished code review), and we're running
467 # local presubmit anyway.
468 pass
469 else:
470 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000471
kjellander986ee082015-06-16 04:32:13 -0700472 return try_config