blob: 011e3afd2da647e775ffa9a09acaccdfab10c8ac [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',
jbauchf91e6d02016-01-24 23:05:21 -080023 'webrtc/modules/bitrate_controller',
jbauchd2a22962016-02-08 23:18:25 -080024 'webrtc/modules/pacing',
terelius8f09f172015-12-15 00:51:54 -080025 'webrtc/modules/remote_bitrate_estimator',
danilchap377b5e62015-12-15 04:33:44 -080026 'webrtc/modules/rtp_rtcp',
philipel5908c712015-12-21 08:23:20 -080027 'webrtc/modules/video_coding',
mflodman88eeac42015-12-08 09:21:28 +010028 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 03:11:42 -080029 'webrtc/sound',
30 'webrtc/tools',
mflodmand1590b22015-12-09 07:07:59 -080031 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010032]
33
jbauchc4e3ead2016-02-19 00:25:55 -080034# These filters will always be removed, even if the caller specifies a filter
35# set, as they are problematic or broken in some way.
36#
37# Justifications for each filter:
38# - build/c++11 : Rvalue ref checks are unreliable (false positives),
39# include file and feature blacklists are
40# google3-specific.
41BLACKLIST_LINT_FILTERS = [
42 '-build/c++11',
43]
44
kjellanderfd595232015-12-04 02:44:09 -080045# List of directories of "supported" native APIs. That means changes to headers
46# will be done in a compatible way following this scheme:
47# 1. Non-breaking changes are made.
48# 2. The old APIs as marked as deprecated (with comments).
49# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
50# webrtc-users@google.com (internal list).
51# 4. (later) The deprecated APIs are removed.
52# Directories marked as DEPRECATED should not be used. They're only present in
53# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080054NATIVE_API_DIRS = (
55 'talk/app/webrtc',
56 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080057 'webrtc/base', # DEPRECATED.
58 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080059 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080060 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080061 'webrtc/modules/audio_device/include',
62 'webrtc/modules/audio_processing/include',
63 'webrtc/modules/bitrate_controller/include',
64 'webrtc/modules/include',
65 'webrtc/modules/remote_bitrate_estimator/include',
66 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080067 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080068 'webrtc/modules/utility/include',
69 'webrtc/modules/video_coding/codecs/h264/include',
70 'webrtc/modules/video_coding/codecs/i420/include',
71 'webrtc/modules/video_coding/codecs/vp8/include',
72 'webrtc/modules/video_coding/codecs/vp9/include',
73 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080074 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080075 'webrtc/voice_engine/include',
76)
77
78
79def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
80 """Ensures the list of native API header directories is up to date."""
81 non_existing_paths = []
82 native_api_full_paths = [
83 input_api.os_path.join(input_api.PresubmitLocalPath(),
84 *path.split('/')) for path in NATIVE_API_DIRS]
85 for path in native_api_full_paths:
86 if not os.path.isdir(path):
87 non_existing_paths.append(path)
88 if non_existing_paths:
89 return [output_api.PresubmitError(
90 'Directories to native API headers have changed which has made the '
91 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
92 'location of our native APIs.',
93 non_existing_paths)]
94 return []
95
96
97def _CheckNativeApiHeaderChanges(input_api, output_api):
98 """Checks to remind proper changing of native APIs."""
99 files = []
100 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
101 if f.LocalPath().endswith('.h'):
102 for path in NATIVE_API_DIRS:
103 if os.path.dirname(f.LocalPath()) == path:
104 files.append(f)
105
106 if files:
kjellanderffea13c2015-12-08 01:57:17 -0800107 return [output_api.PresubmitNotifyResult(
kjellander53047c92015-12-02 23:56:14 -0800108 'You seem to be changing native API header files. Please make sure '
109 'you:\n'
110 ' 1. Make compatible changes that don\'t break existing clients.\n'
111 ' 2. Mark the old APIs as deprecated.\n'
112 ' 3. Create a timeline and plan for when the deprecated method will '
113 'be removed (preferably 3 months or so).\n'
114 ' 4. Update/inform existing downstream code owners to stop using the '
115 'deprecated APIs: \n'
116 'send announcement to discuss-webrtc@googlegroups.com and '
117 'webrtc-users@google.com.\n'
118 ' 5. (after ~3 months) remove the deprecated API.\n'
119 'Related files:',
120 files)]
121 return []
122
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100123
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000124def _CheckNoIOStreamInHeaders(input_api, output_api):
125 """Checks to make sure no .h files include <iostream>."""
126 files = []
127 pattern = input_api.re.compile(r'^#include\s*<iostream>',
128 input_api.re.MULTILINE)
129 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
130 if not f.LocalPath().endswith('.h'):
131 continue
132 contents = input_api.ReadFile(f)
133 if pattern.search(contents):
134 files.append(f)
135
136 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200137 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000138 'Do not #include <iostream> in header files, since it inserts static ' +
139 'initialization into every file including the header. Instead, ' +
140 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200141 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000142 return []
143
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000144
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000145def _CheckNoFRIEND_TEST(input_api, output_api):
146 """Make sure that gtest's FRIEND_TEST() macro is not used, the
147 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
148 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
149 problems = []
150
151 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
152 for f in input_api.AffectedFiles(file_filter=file_filter):
153 for line_num, line in f.ChangedContents():
154 if 'FRIEND_TEST(' in line:
155 problems.append(' %s:%d' % (f.LocalPath(), line_num))
156
157 if not problems:
158 return []
159 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
160 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
161 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
162
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000163
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100164def _IsLintWhitelisted(whitelist_dirs, file_path):
165 """ Checks if a file is whitelisted for lint check."""
166 for path in whitelist_dirs:
167 if os.path.dirname(file_path).startswith(path):
168 return True
169 return False
170
171
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000172def _CheckApprovedFilesLintClean(input_api, output_api,
173 source_file_filter=None):
174 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000175 This check is based on _CheckChangeLintsClean in
176 depot_tools/presubmit_canned_checks.py but has less filters and only checks
177 added files."""
178 result = []
179
180 # Initialize cpplint.
181 import cpplint
182 # Access to a protected member _XX of a client class
183 # pylint: disable=W0212
184 cpplint._cpplint_state.ResetErrorCounts()
185
jbauchc4e3ead2016-02-19 00:25:55 -0800186 lint_filters = cpplint._Filters()
187 lint_filters.extend(BLACKLIST_LINT_FILTERS)
188 cpplint._SetFilters(','.join(lint_filters))
189
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100190 # Create a platform independent whitelist for the CPPLINT_DIRS.
191 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
192 for path in CPPLINT_DIRS]
193
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000194 # Use the strictest verbosity level for cpplint.py (level 1) which is the
195 # default when running cpplint.py from command line.
196 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000197 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000198 verbosity_level = 1
199 files = []
200 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200201 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100202 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000203 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000204
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000205 for file_name in files:
206 cpplint.ProcessFile(file_name, verbosity_level)
207
208 if cpplint._cpplint_state.error_count > 0:
209 if input_api.is_committing:
210 # TODO(kjellander): Change back to PresubmitError below when we're
211 # confident with the lint settings.
212 res_type = output_api.PresubmitPromptWarning
213 else:
214 res_type = output_api.PresubmitPromptWarning
215 result = [res_type('Changelist failed cpplint.py check.')]
216
217 return result
218
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000219def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
220 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
221 violating_files = []
222 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000223 gyp_exceptions = (
224 'base_tests.gyp',
225 'desktop_capture.gypi',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000226 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000227 'sound.gyp',
228 'webrtc_test_common.gyp',
229 'webrtc_tests.gypi',
230 )
231 if f.LocalPath().endswith(gyp_exceptions):
232 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000233 contents = input_api.ReadFile(f)
234 if pattern.search(contents):
235 violating_files.append(f)
236 if violating_files:
237 return [output_api.PresubmitError(
238 'Depending on rtc_base is not allowed. Change your dependency to '
239 'rtc_base_approved and possibly sanitize and move the desired source '
240 'file(s) to rtc_base_approved.\nChanged GYP files:',
241 items=violating_files)]
242 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000243
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000244def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
245 # Disallow referencing source files with paths above the GYP file location.
246 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
247 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000248 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000249 violating_gyp_files = set()
250 violating_source_entries = []
251 for gyp_file in gyp_files:
kjellanderc61635c2016-02-02 02:30:07 -0800252 if 'supplement.gypi' in gyp_file.LocalPath():
253 # Exclude supplement.gypi from this check, as the LSan and TSan
254 # suppression files are located in a different location.
255 continue
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000256 contents = input_api.ReadFile(gyp_file)
257 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000258 # Find all source list entries starting with ../ in the source block
259 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000260 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000261 source_file = file_list_match.group(0)
262 if 'overrides/' not in source_file:
263 violating_source_entries.append(source_file)
264 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000265 if violating_gyp_files:
266 return [output_api.PresubmitError(
267 'Referencing source files above the directory of the GYP file is not '
268 'allowed. Please introduce new GYP targets and/or GYP files in the '
269 'proper location instead.\n'
270 'Invalid source entries:\n'
271 '%s\n'
272 'Violating GYP files:' % '\n'.join(violating_source_entries),
273 items=violating_gyp_files)]
274 return []
275
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000276def _CheckGypChanges(input_api, output_api):
277 source_file_filter = lambda x: input_api.FilterSourceFile(
278 x, white_list=(r'.+\.(gyp|gypi)$',))
279
280 gyp_files = []
281 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000282 if f.LocalPath().startswith('webrtc'):
283 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000284
285 result = []
286 if gyp_files:
287 result.append(output_api.PresubmitNotifyResult(
288 'As you\'re changing GYP files: please make sure corresponding '
289 'BUILD.gn files are also updated.\nChanged GYP files:',
290 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000291 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000292 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000293 return result
294
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000295def _CheckUnwantedDependencies(input_api, output_api):
296 """Runs checkdeps on #include statements added in this
297 change. Breaking - rules is an error, breaking ! rules is a
298 warning.
299 """
300 # Copied from Chromium's src/PRESUBMIT.py.
301
302 # We need to wait until we have an input_api object and use this
303 # roundabout construct to import checkdeps because this file is
304 # eval-ed and thus doesn't have __file__.
305 original_sys_path = sys.path
306 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000307 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
308 'buildtools', 'checkdeps')
309 if not os.path.exists(checkdeps_path):
310 return [output_api.PresubmitError(
311 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
312 'download Chromium and setup the symlinks?' % checkdeps_path)]
313 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000314 import checkdeps
315 from cpp_checker import CppChecker
316 from rules import Rule
317 finally:
318 # Restore sys.path to what it was before.
319 sys.path = original_sys_path
320
321 added_includes = []
322 for f in input_api.AffectedFiles():
323 if not CppChecker.IsCppFile(f.LocalPath()):
324 continue
325
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200326 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000327 added_includes.append([f.LocalPath(), changed_lines])
328
329 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
330
331 error_descriptions = []
332 warning_descriptions = []
333 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
334 added_includes):
335 description_with_path = '%s\n %s' % (path, rule_description)
336 if rule_type == Rule.DISALLOW:
337 error_descriptions.append(description_with_path)
338 else:
339 warning_descriptions.append(description_with_path)
340
341 results = []
342 if error_descriptions:
343 results.append(output_api.PresubmitError(
344 'You added one or more #includes that violate checkdeps rules.',
345 error_descriptions))
346 if warning_descriptions:
347 results.append(output_api.PresubmitPromptOrNotify(
348 'You added one or more #includes of files that are temporarily\n'
349 'allowed but being removed. Can you avoid introducing the\n'
350 '#include? See relevant DEPS file(s) for details and contacts.',
351 warning_descriptions))
352 return results
353
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000354
kjellander569cf942016-02-11 05:02:59 -0800355def _CheckJSONParseErrors(input_api, output_api):
356 """Check that JSON files do not contain syntax errors."""
357
358 def FilterFile(affected_file):
359 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
360
361 def GetJSONParseError(input_api, filename):
362 try:
363 contents = input_api.ReadFile(filename)
364 input_api.json.loads(contents)
365 except ValueError as e:
366 return e
367 return None
368
369 results = []
370 for affected_file in input_api.AffectedFiles(
371 file_filter=FilterFile, include_deletes=False):
372 parse_error = GetJSONParseError(input_api,
373 affected_file.AbsoluteLocalPath())
374 if parse_error:
375 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
376 (affected_file.LocalPath(), parse_error)))
377 return results
378
379
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200380def _RunPythonTests(input_api, output_api):
381 def join(*args):
382 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
383
384 test_directories = [
385 join('tools', 'autoroller', 'unittests'),
386 ]
387
388 tests = []
389 for directory in test_directories:
390 tests.extend(
391 input_api.canned_checks.GetUnitTestsInDirectory(
392 input_api,
393 output_api,
394 directory,
395 whitelist=[r'.+_test\.py$']))
396 return input_api.RunTests(tests, parallel=True)
397
398
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000399def _CommonChecks(input_api, output_api):
400 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000401 results = []
tkchin42f580e2015-11-26 23:18:23 -0800402 # Filter out files that are in objc or ios dirs from being cpplint-ed since
403 # they do not follow C++ lint rules.
404 black_list = input_api.DEFAULT_BLACK_LIST + (
405 r".*\bobjc[\\\/].*",
406 )
407 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
408 results.extend(_CheckApprovedFilesLintClean(
409 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000410 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
411 black_list=(r'^.*gviz_api\.py$',
412 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000413 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200414 r'^build[\\\/].*\.py$',
415 r'^buildtools[\\\/].*\.py$',
416 r'^chromium[\\\/].*\.py$',
417 r'^google_apis[\\\/].*\.py$',
418 r'^net.*[\\\/].*\.py$',
419 r'^out.*[\\\/].*\.py$',
420 r'^testing[\\\/].*\.py$',
421 r'^third_party[\\\/].*\.py$',
422 r'^tools[\\\/]find_depot_tools.py$',
423 r'^tools[\\\/]clang[\\\/].*\.py$',
424 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
425 r'^tools[\\\/]gn[\\\/].*\.py$',
426 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200427 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200428 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
429 r'^tools[\\\/]python[\\\/].*\.py$',
430 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
431 r'^tools[\\\/]refactoring[\\\/].*\.py$',
432 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
433 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000434 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200435 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
436 r'^tools[\\\/]valgrind[\\\/].*\.py$',
437 r'^tools[\\\/]win[\\\/].*\.py$',
438 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000439 disabled_warnings=['F0401', # Failed to import x
440 'E0611', # No package y in x
441 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200442 ],
443 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800444
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200445 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
446 # we need to have different license checks in talk/ and webrtc/ directories.
447 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200448
449 # Skip long-lines check for DEPS, GN and GYP files.
450 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
451 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000452 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200453 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000454 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
455 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000456 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
457 input_api, output_api))
458 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
459 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800460 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000461 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
462 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000463 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000464 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800465 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200466 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000467 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000468
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000469
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000470def CheckChangeOnUpload(input_api, output_api):
471 results = []
472 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200473 results.extend(
474 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000475 return results
476
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000477
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000478def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000479 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000480 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800481 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000482 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000483 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
484 input_api, output_api))
485 results.extend(input_api.canned_checks.CheckChangeHasDescription(
486 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000487 results.extend(input_api.canned_checks.CheckChangeHasBugField(
488 input_api, output_api))
489 results.extend(input_api.canned_checks.CheckChangeHasTestField(
490 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000491 results.extend(input_api.canned_checks.CheckTreeIsOpen(
492 input_api, output_api,
493 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000494 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000495
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000496
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000497# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000498def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700499 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700500 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700501 # commit_queue.py below is a script in depot_tools directory, which has a
502 # 'builders' command to retrieve a list of CQ builders from the CQ config.
503 is_win = platform.system() == 'Windows'
504 masters = json.loads(subprocess.check_output(
505 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000506
kjellander986ee082015-06-16 04:32:13 -0700507 try_config = {}
508 for master in masters:
509 try_config.setdefault(master, {})
510 for builder in masters[master]:
511 if 'presubmit' in builder:
512 # Do not trigger presubmit builders, since they're likely to fail
513 # (e.g. OWNERS checks before finished code review), and we're running
514 # local presubmit anyway.
515 pass
516 else:
517 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000518
kjellander986ee082015-06-16 04:32:13 -0700519 return try_config