blob: 8492dc9fc888bed8f2c9edc473304f223baa71b9 [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',
Stefan Holmer80e12072016-02-23 13:30:42 +010024 'webrtc/modules/congestion_controller',
jbauchd2a22962016-02-08 23:18:25 -080025 'webrtc/modules/pacing',
terelius8f09f172015-12-15 00:51:54 -080026 'webrtc/modules/remote_bitrate_estimator',
danilchap377b5e62015-12-15 04:33:44 -080027 'webrtc/modules/rtp_rtcp',
philipel5908c712015-12-21 08:23:20 -080028 'webrtc/modules/video_coding',
mflodman88eeac42015-12-08 09:21:28 +010029 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 03:11:42 -080030 '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.
kjellandere5a87a52016-04-27 02:32:12 -070041# - whitespace/operators: Same as above (doesn't seem sufficient to eliminate
42# all move-related errors).
jbauchc4e3ead2016-02-19 00:25:55 -080043BLACKLIST_LINT_FILTERS = [
44 '-build/c++11',
kjellandere5a87a52016-04-27 02:32:12 -070045 '-whitespace/operators',
jbauchc4e3ead2016-02-19 00:25:55 -080046]
47
kjellanderfd595232015-12-04 02:44:09 -080048# List of directories of "supported" native APIs. That means changes to headers
49# will be done in a compatible way following this scheme:
50# 1. Non-breaking changes are made.
51# 2. The old APIs as marked as deprecated (with comments).
52# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
53# webrtc-users@google.com (internal list).
54# 4. (later) The deprecated APIs are removed.
55# Directories marked as DEPRECATED should not be used. They're only present in
56# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080057NATIVE_API_DIRS = (
58 'talk/app/webrtc',
59 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080060 'webrtc/base', # DEPRECATED.
61 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080062 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080063 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080064 'webrtc/modules/audio_device/include',
65 'webrtc/modules/audio_processing/include',
66 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 13:30:42 +010067 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-02 23:56:14 -080068 'webrtc/modules/include',
69 'webrtc/modules/remote_bitrate_estimator/include',
70 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080071 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080072 'webrtc/modules/utility/include',
73 'webrtc/modules/video_coding/codecs/h264/include',
74 'webrtc/modules/video_coding/codecs/i420/include',
75 'webrtc/modules/video_coding/codecs/vp8/include',
76 'webrtc/modules/video_coding/codecs/vp9/include',
77 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080078 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080079 'webrtc/voice_engine/include',
80)
81
82
83def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
84 """Ensures the list of native API header directories is up to date."""
85 non_existing_paths = []
86 native_api_full_paths = [
87 input_api.os_path.join(input_api.PresubmitLocalPath(),
88 *path.split('/')) for path in NATIVE_API_DIRS]
89 for path in native_api_full_paths:
90 if not os.path.isdir(path):
91 non_existing_paths.append(path)
92 if non_existing_paths:
93 return [output_api.PresubmitError(
94 'Directories to native API headers have changed which has made the '
95 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
96 'location of our native APIs.',
97 non_existing_paths)]
98 return []
99
kwibergeb133022016-04-07 07:41:48 -0700100api_change_msg = """
101You seem to be changing native API header files. Please make sure that you:
102 1. Make compatible changes that don't break existing clients.
103 2. Mark the old stuff as deprecated.
104 3. Create a timeline and plan for when the deprecated stuff will be
105 removed. (The amount of time we give users to change their code
106 should be informed by how much work it is for them. If they just
107 need to replace one name with another or something equally
108 simple, 1-2 weeks might be good; if they need to do serious work,
109 up to 3 months may be called for.)
110 4. Update/inform existing downstream code owners to stop using the
111 deprecated stuff. (Send announcements to
112 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
113 5. Remove the deprecated stuff, once the agreed-upon amount of time
114 has passed.
115Related files:
116"""
kjellander53047c92015-12-02 23:56:14 -0800117
118def _CheckNativeApiHeaderChanges(input_api, output_api):
119 """Checks to remind proper changing of native APIs."""
120 files = []
121 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
122 if f.LocalPath().endswith('.h'):
123 for path in NATIVE_API_DIRS:
124 if os.path.dirname(f.LocalPath()) == path:
125 files.append(f)
126
127 if files:
kwibergeb133022016-04-07 07:41:48 -0700128 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-02 23:56:14 -0800129 return []
130
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100131
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000132def _CheckNoIOStreamInHeaders(input_api, output_api):
133 """Checks to make sure no .h files include <iostream>."""
134 files = []
135 pattern = input_api.re.compile(r'^#include\s*<iostream>',
136 input_api.re.MULTILINE)
137 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
138 if not f.LocalPath().endswith('.h'):
139 continue
140 contents = input_api.ReadFile(f)
141 if pattern.search(contents):
142 files.append(f)
143
144 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200145 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000146 'Do not #include <iostream> in header files, since it inserts static ' +
147 'initialization into every file including the header. Instead, ' +
148 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200149 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000150 return []
151
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000152
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000153def _CheckNoFRIEND_TEST(input_api, output_api):
154 """Make sure that gtest's FRIEND_TEST() macro is not used, the
155 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
156 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
157 problems = []
158
159 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
160 for f in input_api.AffectedFiles(file_filter=file_filter):
161 for line_num, line in f.ChangedContents():
162 if 'FRIEND_TEST(' in line:
163 problems.append(' %s:%d' % (f.LocalPath(), line_num))
164
165 if not problems:
166 return []
167 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
168 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
169 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
170
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000171
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100172def _IsLintWhitelisted(whitelist_dirs, file_path):
173 """ Checks if a file is whitelisted for lint check."""
174 for path in whitelist_dirs:
175 if os.path.dirname(file_path).startswith(path):
176 return True
177 return False
178
179
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000180def _CheckApprovedFilesLintClean(input_api, output_api,
181 source_file_filter=None):
182 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000183 This check is based on _CheckChangeLintsClean in
184 depot_tools/presubmit_canned_checks.py but has less filters and only checks
185 added files."""
186 result = []
187
188 # Initialize cpplint.
189 import cpplint
190 # Access to a protected member _XX of a client class
191 # pylint: disable=W0212
192 cpplint._cpplint_state.ResetErrorCounts()
193
jbauchc4e3ead2016-02-19 00:25:55 -0800194 lint_filters = cpplint._Filters()
195 lint_filters.extend(BLACKLIST_LINT_FILTERS)
196 cpplint._SetFilters(','.join(lint_filters))
197
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100198 # Create a platform independent whitelist for the CPPLINT_DIRS.
199 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
200 for path in CPPLINT_DIRS]
201
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000202 # Use the strictest verbosity level for cpplint.py (level 1) which is the
203 # default when running cpplint.py from command line.
204 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000205 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000206 verbosity_level = 1
207 files = []
208 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200209 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100210 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000211 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000212
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000213 for file_name in files:
214 cpplint.ProcessFile(file_name, verbosity_level)
215
216 if cpplint._cpplint_state.error_count > 0:
217 if input_api.is_committing:
218 # TODO(kjellander): Change back to PresubmitError below when we're
219 # confident with the lint settings.
220 res_type = output_api.PresubmitPromptWarning
221 else:
222 res_type = output_api.PresubmitPromptWarning
223 result = [res_type('Changelist failed cpplint.py check.')]
224
225 return result
226
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000227def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
228 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
229 violating_files = []
230 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000231 gyp_exceptions = (
232 'base_tests.gyp',
233 'desktop_capture.gypi',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000234 'p2p.gyp',
tkchin9eeb6242016-04-27 01:54:20 -0700235 'sdk.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000236 'webrtc_test_common.gyp',
237 'webrtc_tests.gypi',
238 )
239 if f.LocalPath().endswith(gyp_exceptions):
240 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000241 contents = input_api.ReadFile(f)
242 if pattern.search(contents):
243 violating_files.append(f)
244 if violating_files:
245 return [output_api.PresubmitError(
246 'Depending on rtc_base is not allowed. Change your dependency to '
247 'rtc_base_approved and possibly sanitize and move the desired source '
248 'file(s) to rtc_base_approved.\nChanged GYP files:',
249 items=violating_files)]
250 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000251
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000252def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
253 # Disallow referencing source files with paths above the GYP file location.
254 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
255 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000256 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000257 violating_gyp_files = set()
258 violating_source_entries = []
259 for gyp_file in gyp_files:
kjellanderc61635c2016-02-02 02:30:07 -0800260 if 'supplement.gypi' in gyp_file.LocalPath():
261 # Exclude supplement.gypi from this check, as the LSan and TSan
262 # suppression files are located in a different location.
263 continue
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000264 contents = input_api.ReadFile(gyp_file)
265 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000266 # Find all source list entries starting with ../ in the source block
267 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000268 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000269 source_file = file_list_match.group(0)
270 if 'overrides/' not in source_file:
271 violating_source_entries.append(source_file)
272 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000273 if violating_gyp_files:
274 return [output_api.PresubmitError(
275 'Referencing source files above the directory of the GYP file is not '
276 'allowed. Please introduce new GYP targets and/or GYP files in the '
277 'proper location instead.\n'
278 'Invalid source entries:\n'
279 '%s\n'
280 'Violating GYP files:' % '\n'.join(violating_source_entries),
281 items=violating_gyp_files)]
282 return []
283
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000284def _CheckGypChanges(input_api, output_api):
285 source_file_filter = lambda x: input_api.FilterSourceFile(
286 x, white_list=(r'.+\.(gyp|gypi)$',))
287
288 gyp_files = []
289 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000290 if f.LocalPath().startswith('webrtc'):
291 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000292
293 result = []
294 if gyp_files:
295 result.append(output_api.PresubmitNotifyResult(
296 'As you\'re changing GYP files: please make sure corresponding '
297 'BUILD.gn files are also updated.\nChanged GYP files:',
298 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000299 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000300 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000301 return result
302
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000303def _CheckUnwantedDependencies(input_api, output_api):
304 """Runs checkdeps on #include statements added in this
305 change. Breaking - rules is an error, breaking ! rules is a
306 warning.
307 """
308 # Copied from Chromium's src/PRESUBMIT.py.
309
310 # We need to wait until we have an input_api object and use this
311 # roundabout construct to import checkdeps because this file is
312 # eval-ed and thus doesn't have __file__.
313 original_sys_path = sys.path
314 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000315 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
316 'buildtools', 'checkdeps')
317 if not os.path.exists(checkdeps_path):
318 return [output_api.PresubmitError(
319 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
320 'download Chromium and setup the symlinks?' % checkdeps_path)]
321 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000322 import checkdeps
323 from cpp_checker import CppChecker
324 from rules import Rule
325 finally:
326 # Restore sys.path to what it was before.
327 sys.path = original_sys_path
328
329 added_includes = []
330 for f in input_api.AffectedFiles():
331 if not CppChecker.IsCppFile(f.LocalPath()):
332 continue
333
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200334 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000335 added_includes.append([f.LocalPath(), changed_lines])
336
337 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
338
339 error_descriptions = []
340 warning_descriptions = []
341 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
342 added_includes):
343 description_with_path = '%s\n %s' % (path, rule_description)
344 if rule_type == Rule.DISALLOW:
345 error_descriptions.append(description_with_path)
346 else:
347 warning_descriptions.append(description_with_path)
348
349 results = []
350 if error_descriptions:
351 results.append(output_api.PresubmitError(
352 'You added one or more #includes that violate checkdeps rules.',
353 error_descriptions))
354 if warning_descriptions:
355 results.append(output_api.PresubmitPromptOrNotify(
356 'You added one or more #includes of files that are temporarily\n'
357 'allowed but being removed. Can you avoid introducing the\n'
358 '#include? See relevant DEPS file(s) for details and contacts.',
359 warning_descriptions))
360 return results
361
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000362
kjellander569cf942016-02-11 05:02:59 -0800363def _CheckJSONParseErrors(input_api, output_api):
364 """Check that JSON files do not contain syntax errors."""
365
366 def FilterFile(affected_file):
367 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
368
369 def GetJSONParseError(input_api, filename):
370 try:
371 contents = input_api.ReadFile(filename)
372 input_api.json.loads(contents)
373 except ValueError as e:
374 return e
375 return None
376
377 results = []
378 for affected_file in input_api.AffectedFiles(
379 file_filter=FilterFile, include_deletes=False):
380 parse_error = GetJSONParseError(input_api,
381 affected_file.AbsoluteLocalPath())
382 if parse_error:
383 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
384 (affected_file.LocalPath(), parse_error)))
385 return results
386
387
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200388def _RunPythonTests(input_api, output_api):
389 def join(*args):
390 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
391
392 test_directories = [
393 join('tools', 'autoroller', 'unittests'),
394 ]
395
396 tests = []
397 for directory in test_directories:
398 tests.extend(
399 input_api.canned_checks.GetUnitTestsInDirectory(
400 input_api,
401 output_api,
402 directory,
403 whitelist=[r'.+_test\.py$']))
404 return input_api.RunTests(tests, parallel=True)
405
406
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000407def _CommonChecks(input_api, output_api):
408 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000409 results = []
tkchin42f580e2015-11-26 23:18:23 -0800410 # Filter out files that are in objc or ios dirs from being cpplint-ed since
411 # they do not follow C++ lint rules.
412 black_list = input_api.DEFAULT_BLACK_LIST + (
413 r".*\bobjc[\\\/].*",
414 )
415 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
416 results.extend(_CheckApprovedFilesLintClean(
417 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000418 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
419 black_list=(r'^.*gviz_api\.py$',
420 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000421 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200422 r'^build[\\\/].*\.py$',
423 r'^buildtools[\\\/].*\.py$',
424 r'^chromium[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700425 r'^mojo.*[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200426 r'^out.*[\\\/].*\.py$',
427 r'^testing[\\\/].*\.py$',
428 r'^third_party[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200429 r'^tools[\\\/]clang[\\\/].*\.py$',
430 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700431 r'^tools[\\\/]generate_stubs[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200432 r'^tools[\\\/]gn[\\\/].*\.py$',
433 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200434 r'^tools[\\\/]isolate_driver.py$',
kjellanderd620f822016-04-04 06:07:08 -0700435 r'^tools[\\\/]mb[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200436 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
437 r'^tools[\\\/]python[\\\/].*\.py$',
438 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
439 r'^tools[\\\/]refactoring[\\\/].*\.py$',
440 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
441 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000442 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200443 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
444 r'^tools[\\\/]valgrind[\\\/].*\.py$',
445 r'^tools[\\\/]win[\\\/].*\.py$',
446 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000447 disabled_warnings=['F0401', # Failed to import x
448 'E0611', # No package y in x
449 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200450 ],
451 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800452
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200453 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
454 # we need to have different license checks in talk/ and webrtc/ directories.
455 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200456
tkchin3cd9a302016-06-08 12:40:28 -0700457 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
458 # ObjC subdirectories ObjC headers.
459 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellander63224672015-09-08 08:03:56 +0200460 # Skip long-lines check for DEPS, GN and GYP files.
tkchin3cd9a302016-06-08 12:40:28 -0700461 build_file_filter_list = (r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$',
462 'DEPS')
463 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
464 black_list=build_file_filter_list + objc_filter_list)
465 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
466 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000467 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 12:40:28 -0700468 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
469 results.extend(input_api.canned_checks.CheckLongLines(
470 input_api, output_api, maxlen=100,
471 source_file_filter=hundred_char_sources))
472
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000473 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
474 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000475 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
476 input_api, output_api))
477 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
478 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800479 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000480 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
481 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000482 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000483 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800484 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200485 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000486 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000487
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000488
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000489def CheckChangeOnUpload(input_api, output_api):
490 results = []
491 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200492 results.extend(
493 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000494 return results
495
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000496
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000497def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000498 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000499 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800500 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000501 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000502 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
503 input_api, output_api))
504 results.extend(input_api.canned_checks.CheckChangeHasDescription(
505 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000506 results.extend(input_api.canned_checks.CheckChangeHasBugField(
507 input_api, output_api))
508 results.extend(input_api.canned_checks.CheckChangeHasTestField(
509 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000510 results.extend(input_api.canned_checks.CheckTreeIsOpen(
511 input_api, output_api,
512 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000513 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000514
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000515
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000516# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000517def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700518 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700519 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700520 # commit_queue.py below is a script in depot_tools directory, which has a
521 # 'builders' command to retrieve a list of CQ builders from the CQ config.
522 is_win = platform.system() == 'Windows'
523 masters = json.loads(subprocess.check_output(
524 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000525
kjellander986ee082015-06-16 04:32:13 -0700526 try_config = {}
527 for master in masters:
528 try_config.setdefault(master, {})
529 for builder in masters[master]:
530 if 'presubmit' in builder:
531 # Do not trigger presubmit builders, since they're likely to fail
532 # (e.g. OWNERS checks before finished code review), and we're running
533 # local presubmit anyway.
534 pass
535 else:
536 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000537
kjellander986ee082015-06-16 04:32:13 -0700538 return try_config