blob: a973ffeb3a943fedaf7bff5388fea152d96386d8 [file] [log] [blame]
andrew@webrtc.org2442de12012-01-23 17:45:411# 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:348
kjellander@webrtc.orgaefe61a2014-12-08 13:00:309import os
kjellander@webrtc.org85759802013-10-22 16:47:4010import re
kjellander@webrtc.org3bd41562014-09-01 11:06:3711import sys
kjellander@webrtc.org85759802013-10-22 16:47:4012
13
kjellander@webrtc.org0fcaf992015-11-26 14:24:5214# Directories that will be scanned by cpplint by the presubmit script.
15CPPLINT_DIRS = [
Fredrik Solenbergea073732015-12-01 10:26:3416 'webrtc/audio',
17 'webrtc/call',
jbauch0f2e9392015-12-10 11:11:4218 'webrtc/common_video',
jbauch70625e52015-12-09 22:18:1419 'webrtc/examples',
aleloidf9e4d92016-08-08 17:26:0920 'webrtc/modules/audio_mixer',
jbauchf91e6d02016-01-25 07:05:2121 'webrtc/modules/bitrate_controller',
Stefan Holmer80e12072016-02-23 12:30:4222 'webrtc/modules/congestion_controller',
jbauchd2a22962016-02-09 07:18:2523 'webrtc/modules/pacing',
terelius8f09f172015-12-15 08:51:5424 'webrtc/modules/remote_bitrate_estimator',
danilchap377b5e62015-12-15 12:33:4425 'webrtc/modules/rtp_rtcp',
philipel5908c712015-12-21 16:23:2026 'webrtc/modules/video_coding',
mflodman88eeac42015-12-08 08:21:2827 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 11:11:4228 'webrtc/tools',
mflodmand1590b22015-12-09 15:07:5929 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 14:24:5230]
31
jbauchc4e3ead2016-02-19 08:25:5532# These filters will always be removed, even if the caller specifies a filter
33# set, as they are problematic or broken in some way.
34#
35# Justifications for each filter:
36# - build/c++11 : Rvalue ref checks are unreliable (false positives),
37# include file and feature blacklists are
38# google3-specific.
kjellandere5a87a52016-04-27 09:32:1239# - whitespace/operators: Same as above (doesn't seem sufficient to eliminate
40# all move-related errors).
jbauchc4e3ead2016-02-19 08:25:5541BLACKLIST_LINT_FILTERS = [
42 '-build/c++11',
kjellandere5a87a52016-04-27 09:32:1243 '-whitespace/operators',
jbauchc4e3ead2016-02-19 08:25:5544]
45
kjellanderfd595232015-12-04 10:44:0946# List of directories of "supported" native APIs. That means changes to headers
47# will be done in a compatible way following this scheme:
48# 1. Non-breaking changes are made.
49# 2. The old APIs as marked as deprecated (with comments).
50# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
51# webrtc-users@google.com (internal list).
52# 4. (later) The deprecated APIs are removed.
kjellander53047c92015-12-03 07:56:1453NATIVE_API_DIRS = (
kjellander53047c92015-12-03 07:56:1454 'webrtc',
kjellanderdd705472016-06-09 18:17:2755 'webrtc/api',
56 'webrtc/media',
kjellander53047c92015-12-03 07:56:1457 'webrtc/modules/audio_device/include',
kjellanderdd705472016-06-09 18:17:2758 'webrtc/pc',
59)
60# These directories should not be used but are maintained only to avoid breaking
61# some legacy downstream code.
62LEGACY_API_DIRS = (
kjellanderdd705472016-06-09 18:17:2763 'webrtc/base',
64 'webrtc/common_audio/include',
65 'webrtc/modules/audio_coding/include',
66 'webrtc/modules/audio_conference_mixer/include',
kjellander53047c92015-12-03 07:56:1467 'webrtc/modules/audio_processing/include',
68 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 12:30:4269 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-03 07:56:1470 'webrtc/modules/include',
71 'webrtc/modules/remote_bitrate_estimator/include',
72 'webrtc/modules/rtp_rtcp/include',
kjellanderdd705472016-06-09 18:17:2773 'webrtc/modules/rtp_rtcp/source',
kjellander53047c92015-12-03 07:56:1474 'webrtc/modules/utility/include',
75 'webrtc/modules/video_coding/codecs/h264/include',
76 'webrtc/modules/video_coding/codecs/i420/include',
77 'webrtc/modules/video_coding/codecs/vp8/include',
78 'webrtc/modules/video_coding/codecs/vp9/include',
79 'webrtc/modules/video_coding/include',
kjellanderdd705472016-06-09 18:17:2780 'webrtc/system_wrappers/include',
kjellander53047c92015-12-03 07:56:1481 'webrtc/voice_engine/include',
82)
kjellanderdd705472016-06-09 18:17:2783API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
kjellander53047c92015-12-03 07:56:1484
85
86def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
87 """Ensures the list of native API header directories is up to date."""
88 non_existing_paths = []
89 native_api_full_paths = [
90 input_api.os_path.join(input_api.PresubmitLocalPath(),
kjellanderdd705472016-06-09 18:17:2791 *path.split('/')) for path in API_DIRS]
kjellander53047c92015-12-03 07:56:1492 for path in native_api_full_paths:
93 if not os.path.isdir(path):
94 non_existing_paths.append(path)
95 if non_existing_paths:
96 return [output_api.PresubmitError(
97 'Directories to native API headers have changed which has made the '
98 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
99 'location of our native APIs.',
100 non_existing_paths)]
101 return []
102
kwibergeb133022016-04-07 14:41:48103api_change_msg = """
104You seem to be changing native API header files. Please make sure that you:
105 1. Make compatible changes that don't break existing clients.
106 2. Mark the old stuff as deprecated.
107 3. Create a timeline and plan for when the deprecated stuff will be
108 removed. (The amount of time we give users to change their code
109 should be informed by how much work it is for them. If they just
110 need to replace one name with another or something equally
111 simple, 1-2 weeks might be good; if they need to do serious work,
112 up to 3 months may be called for.)
113 4. Update/inform existing downstream code owners to stop using the
114 deprecated stuff. (Send announcements to
115 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
116 5. Remove the deprecated stuff, once the agreed-upon amount of time
117 has passed.
118Related files:
119"""
kjellander53047c92015-12-03 07:56:14120
121def _CheckNativeApiHeaderChanges(input_api, output_api):
122 """Checks to remind proper changing of native APIs."""
123 files = []
124 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
125 if f.LocalPath().endswith('.h'):
kjellanderdd705472016-06-09 18:17:27126 for path in API_DIRS:
kjellander53047c92015-12-03 07:56:14127 if os.path.dirname(f.LocalPath()) == path:
128 files.append(f)
129
130 if files:
kwibergeb133022016-04-07 14:41:48131 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-03 07:56:14132 return []
133
kjellander@webrtc.org0fcaf992015-11-26 14:24:52134
kjellander@webrtc.org51198f12012-02-21 17:53:46135def _CheckNoIOStreamInHeaders(input_api, output_api):
136 """Checks to make sure no .h files include <iostream>."""
137 files = []
138 pattern = input_api.re.compile(r'^#include\s*<iostream>',
139 input_api.re.MULTILINE)
140 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
141 if not f.LocalPath().endswith('.h'):
142 continue
143 contents = input_api.ReadFile(f)
144 if pattern.search(contents):
145 files.append(f)
146
147 if len(files):
Henrik Kjellander57e5fd22015-05-25 10:55:39148 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46149 'Do not #include <iostream> in header files, since it inserts static ' +
150 'initialization into every file including the header. Instead, ' +
151 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 10:55:39152 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46153 return []
154
kjellander@webrtc.orge4158642014-08-06 09:11:18155
kjellander@webrtc.org51198f12012-02-21 17:53:46156def _CheckNoFRIEND_TEST(input_api, output_api):
157 """Make sure that gtest's FRIEND_TEST() macro is not used, the
158 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
159 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
160 problems = []
161
162 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
163 for f in input_api.AffectedFiles(file_filter=file_filter):
164 for line_num, line in f.ChangedContents():
165 if 'FRIEND_TEST(' in line:
166 problems.append(' %s:%d' % (f.LocalPath(), line_num))
167
168 if not problems:
169 return []
170 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
171 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
172 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
173
kjellander@webrtc.orge4158642014-08-06 09:11:18174
kjellander@webrtc.org0fcaf992015-11-26 14:24:52175def _IsLintWhitelisted(whitelist_dirs, file_path):
176 """ Checks if a file is whitelisted for lint check."""
177 for path in whitelist_dirs:
178 if os.path.dirname(file_path).startswith(path):
179 return True
180 return False
181
182
mflodman@webrtc.org2a452092012-07-01 05:55:23183def _CheckApprovedFilesLintClean(input_api, output_api,
184 source_file_filter=None):
185 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46186 This check is based on _CheckChangeLintsClean in
187 depot_tools/presubmit_canned_checks.py but has less filters and only checks
188 added files."""
189 result = []
190
191 # Initialize cpplint.
192 import cpplint
193 # Access to a protected member _XX of a client class
194 # pylint: disable=W0212
195 cpplint._cpplint_state.ResetErrorCounts()
196
jbauchc4e3ead2016-02-19 08:25:55197 lint_filters = cpplint._Filters()
198 lint_filters.extend(BLACKLIST_LINT_FILTERS)
199 cpplint._SetFilters(','.join(lint_filters))
200
kjellander@webrtc.org0fcaf992015-11-26 14:24:52201 # Create a platform independent whitelist for the CPPLINT_DIRS.
202 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
203 for path in CPPLINT_DIRS]
204
kjellander@webrtc.org51198f12012-02-21 17:53:46205 # Use the strictest verbosity level for cpplint.py (level 1) which is the
206 # default when running cpplint.py from command line.
207 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23208 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46209 verbosity_level = 1
210 files = []
211 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 10:55:39212 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 14:24:52213 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46214 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23215
kjellander@webrtc.org51198f12012-02-21 17:53:46216 for file_name in files:
217 cpplint.ProcessFile(file_name, verbosity_level)
218
219 if cpplint._cpplint_state.error_count > 0:
220 if input_api.is_committing:
221 # TODO(kjellander): Change back to PresubmitError below when we're
222 # confident with the lint settings.
223 res_type = output_api.PresubmitPromptWarning
224 else:
225 res_type = output_api.PresubmitPromptWarning
226 result = [res_type('Changelist failed cpplint.py check.')]
227
228 return result
229
Henrik Kjellanderb4af3d62016-11-16 19:11:29230def _CheckNoRtcBaseDeps(input_api, gn_files, output_api):
ehmaldonado5b1ba082016-09-02 12:51:08231 pattern = input_api.re.compile(r'base:rtc_base\s*"')
232 violating_files = []
233 for f in gn_files:
234 gn_exceptions = (
maxmorinec623742016-09-15 12:11:55235 os.path.join('audio_device', 'BUILD.gn'),
ehmaldonado5b1ba082016-09-02 12:51:08236 os.path.join('base_tests', 'BUILD.gn'),
237 os.path.join('desktop_capture', 'BUILD.gn'),
238 os.path.join('p2p', 'BUILD.gn'),
239 os.path.join('sdk', 'BUILD.gn'),
240 os.path.join('webrtc_test_common', 'BUILD.gn'),
241 os.path.join('webrtc_tests', 'BUILD.gn'),
242
243 # TODO(ehmaldonado): Clean up references to rtc_base in these files.
244 # See https://bugs.chromium.org/p/webrtc/issues/detail?id=3806
245 os.path.join('webrtc', 'BUILD.gn'),
246 os.path.join('xmllite', 'BUILD.gn'),
247 os.path.join('xmpp', 'BUILD.gn'),
248 os.path.join('modules', 'BUILD.gn'),
249 os.path.join('audio_device', 'BUILD.gn'),
250 os.path.join('pc', 'BUILD.gn'),
251 )
252 if f.LocalPath().endswith(gn_exceptions):
253 continue
254 contents = input_api.ReadFile(f)
255 if pattern.search(contents):
256 violating_files.append(f)
257 if violating_files:
258 return [output_api.PresubmitError(
259 'Depending on rtc_base is not allowed. Change your dependency to '
260 'rtc_base_approved and possibly sanitize and move the desired source '
261 'file(s) to rtc_base_approved.\nChanged GN files:',
262 items=violating_files)]
263 return []
264
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24265
Henrik Kjellanderb4af3d62016-11-16 19:11:29266def _CheckNoSourcesAbove(input_api, gn_files, output_api):
ehmaldonado5b1ba082016-09-02 12:51:08267 # Disallow referencing source files with paths above the GN file location.
268 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
269 re.MULTILINE | re.DOTALL)
270 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"')
271 violating_gn_files = set()
272 violating_source_entries = []
273 for gn_file in gn_files:
274 contents = input_api.ReadFile(gn_file)
275 for source_block_match in source_pattern.finditer(contents):
276 # Find all source list entries starting with ../ in the source block
277 # (exclude overrides entries).
278 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
279 source_file = file_list_match.group(1)
280 if 'overrides/' not in source_file:
281 violating_source_entries.append(source_file)
282 violating_gn_files.add(gn_file)
283 if violating_gn_files:
284 return [output_api.PresubmitError(
285 'Referencing source files above the directory of the GN file is not '
Henrik Kjellanderb4af3d62016-11-16 19:11:29286 'allowed. Please introduce new GN targets in the proper location '
287 'instead.\n'
ehmaldonado5b1ba082016-09-02 12:51:08288 'Invalid source entries:\n'
289 '%s\n'
290 'Violating GN files:' % '\n'.join(violating_source_entries),
291 items=violating_gn_files)]
292 return []
293
ehmaldonado5b1ba082016-09-02 12:51:08294def _CheckGnChanges(input_api, output_api):
295 source_file_filter = lambda x: input_api.FilterSourceFile(
296 x, white_list=(r'.+\.(gn|gni)$',))
297
298 gn_files = []
299 for f in input_api.AffectedSourceFiles(source_file_filter):
300 if f.LocalPath().startswith('webrtc'):
301 gn_files.append(f)
302
303 result = []
304 if gn_files:
Henrik Kjellanderb4af3d62016-11-16 19:11:29305 result.extend(_CheckNoRtcBaseDeps(input_api, gn_files, output_api))
306 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
ehmaldonado5b1ba082016-09-02 12:51:08307 return result
308
kjellander@webrtc.org3bd41562014-09-01 11:06:37309def _CheckUnwantedDependencies(input_api, output_api):
310 """Runs checkdeps on #include statements added in this
311 change. Breaking - rules is an error, breaking ! rules is a
312 warning.
313 """
314 # Copied from Chromium's src/PRESUBMIT.py.
315
316 # We need to wait until we have an input_api object and use this
317 # roundabout construct to import checkdeps because this file is
318 # eval-ed and thus doesn't have __file__.
319 original_sys_path = sys.path
320 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30321 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
322 'buildtools', 'checkdeps')
323 if not os.path.exists(checkdeps_path):
324 return [output_api.PresubmitError(
325 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
326 'download Chromium and setup the symlinks?' % checkdeps_path)]
327 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37328 import checkdeps
329 from cpp_checker import CppChecker
330 from rules import Rule
331 finally:
332 # Restore sys.path to what it was before.
333 sys.path = original_sys_path
334
335 added_includes = []
336 for f in input_api.AffectedFiles():
337 if not CppChecker.IsCppFile(f.LocalPath()):
338 continue
339
Henrik Kjellander57e5fd22015-05-25 10:55:39340 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37341 added_includes.append([f.LocalPath(), changed_lines])
342
343 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
344
345 error_descriptions = []
346 warning_descriptions = []
347 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
348 added_includes):
349 description_with_path = '%s\n %s' % (path, rule_description)
350 if rule_type == Rule.DISALLOW:
351 error_descriptions.append(description_with_path)
352 else:
353 warning_descriptions.append(description_with_path)
354
355 results = []
356 if error_descriptions:
357 results.append(output_api.PresubmitError(
358 'You added one or more #includes that violate checkdeps rules.',
359 error_descriptions))
360 if warning_descriptions:
361 results.append(output_api.PresubmitPromptOrNotify(
362 'You added one or more #includes of files that are temporarily\n'
363 'allowed but being removed. Can you avoid introducing the\n'
364 '#include? See relevant DEPS file(s) for details and contacts.',
365 warning_descriptions))
366 return results
367
kjellanderd1e26a92016-09-19 15:11:16368def _CheckChangeHasBugField(input_api, output_api):
369 """Requires that the changelist have a BUG= field.
370
371 This check is stricter than the one in depot_tools/presubmit_canned_checks.py
372 since it fails the presubmit if the BUG= field is missing or doesn't contain
373 a bug reference.
374 """
375 if input_api.change.BUG:
376 return []
377 else:
378 return [output_api.PresubmitError(
379 'The BUG=[bug number] field is mandatory. Please create a bug and '
380 'reference it using either of:\n'
381 ' * https://bugs.webrtc.org - reference it using BUG=webrtc:XXXX\n'
382 ' * https://crbug.com - reference it using BUG=chromium:XXXXXX')]
kjellander@webrtc.orge4158642014-08-06 09:11:18383
kjellander569cf942016-02-11 13:02:59384def _CheckJSONParseErrors(input_api, output_api):
385 """Check that JSON files do not contain syntax errors."""
386
387 def FilterFile(affected_file):
388 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
389
390 def GetJSONParseError(input_api, filename):
391 try:
392 contents = input_api.ReadFile(filename)
393 input_api.json.loads(contents)
394 except ValueError as e:
395 return e
396 return None
397
398 results = []
399 for affected_file in input_api.AffectedFiles(
400 file_filter=FilterFile, include_deletes=False):
401 parse_error = GetJSONParseError(input_api,
402 affected_file.AbsoluteLocalPath())
403 if parse_error:
404 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
405 (affected_file.LocalPath(), parse_error)))
406 return results
407
408
Henrik Kjellander8d3ad822015-05-26 17:52:05409def _RunPythonTests(input_api, output_api):
410 def join(*args):
411 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
412
413 test_directories = [
414 join('tools', 'autoroller', 'unittests'),
aleloi7ebbf902016-06-20 14:39:15415 join('webrtc', 'tools', 'py_event_log_analyzer'),
Henrik Kjellander8d3ad822015-05-26 17:52:05416 ]
417
418 tests = []
419 for directory in test_directories:
420 tests.extend(
421 input_api.canned_checks.GetUnitTestsInDirectory(
422 input_api,
423 output_api,
424 directory,
425 whitelist=[r'.+_test\.py$']))
426 return input_api.RunTests(tests, parallel=True)
427
428
andrew@webrtc.org53df1362012-01-26 21:24:23429def _CommonChecks(input_api, output_api):
430 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34431 results = []
tkchin42f580e2015-11-27 07:18:23432 # Filter out files that are in objc or ios dirs from being cpplint-ed since
433 # they do not follow C++ lint rules.
434 black_list = input_api.DEFAULT_BLACK_LIST + (
435 r".*\bobjc[\\\/].*",
Kári Tristan Helgason3fa35172016-09-09 08:55:05436 r".*objc\.[hcm]+$",
hjon65ae2d82016-08-03 06:55:44437 r"webrtc\/build\/ios\/SDK\/.*",
tkchin42f580e2015-11-27 07:18:23438 )
439 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
440 results.extend(_CheckApprovedFilesLintClean(
441 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43442 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
443 black_list=(r'^.*gviz_api\.py$',
444 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30445 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 11:10:04446 r'^build[\\\/].*\.py$',
447 r'^buildtools[\\\/].*\.py$',
448 r'^chromium[\\\/].*\.py$',
kjellanderd620f822016-04-04 13:07:08449 r'^mojo.*[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 11:10:04450 r'^out.*[\\\/].*\.py$',
451 r'^testing[\\\/].*\.py$',
452 r'^third_party[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 11:10:04453 r'^tools[\\\/]clang[\\\/].*\.py$',
454 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
kjellanderd620f822016-04-04 13:07:08455 r'^tools[\\\/]generate_stubs[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 11:10:04456 r'^tools[\\\/]gn[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 20:19:11457 r'^tools[\\\/]isolate_driver.py$',
kjellanderd620f822016-04-04 13:07:08458 r'^tools[\\\/]mb[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 11:10:04459 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
460 r'^tools[\\\/]python[\\\/].*\.py$',
461 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
462 r'^tools[\\\/]refactoring[\\\/].*\.py$',
463 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
464 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43465 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 11:10:04466 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
467 r'^tools[\\\/]valgrind[\\\/].*\.py$',
468 r'^tools[\\\/]win[\\\/].*\.py$',
469 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43470 disabled_warnings=['F0401', # Failed to import x
471 'E0611', # No package y in x
472 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 10:55:39473 ],
474 pylintrc='pylintrc'))
kjellander569cf942016-02-11 13:02:59475
nisse3d21e232016-09-02 10:07:06476 # TODO(nisse): talk/ is no more, so make below checks simpler?
Henrik Kjellander57e5fd22015-05-25 10:55:39477 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
478 # we need to have different license checks in talk/ and webrtc/ directories.
479 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 06:03:56480
tkchin3cd9a302016-06-08 19:40:28481 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
482 # ObjC subdirectories ObjC headers.
483 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellanderb4af3d62016-11-16 19:11:29484 # Skip long-lines check for DEPS and GN files.
485 build_file_filter_list = (r'.+\.gn$', r'.+\.gni$', 'DEPS')
tkchin3cd9a302016-06-08 19:40:28486 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
487 black_list=build_file_filter_list + objc_filter_list)
488 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
489 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41490 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 19:40:28491 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
492 results.extend(input_api.canned_checks.CheckLongLines(
493 input_api, output_api, maxlen=100,
494 source_file_filter=hundred_char_sources))
495
andrew@webrtc.org2442de12012-01-23 17:45:41496 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
497 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23498 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
499 input_api, output_api))
500 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
501 input_api, output_api))
kjellander53047c92015-12-03 07:56:14502 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46503 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
504 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
ehmaldonado5b1ba082016-09-02 12:51:08505 results.extend(_CheckGnChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37506 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 13:02:59507 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 17:52:05508 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23509 return results
andrew@webrtc.org2442de12012-01-23 17:45:41510
kjellander@webrtc.orge4158642014-08-06 09:11:18511
andrew@webrtc.org53df1362012-01-26 21:24:23512def CheckChangeOnUpload(input_api, output_api):
513 results = []
514 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 10:55:39515 results.extend(
516 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34517 return results
518
kjellander@webrtc.orge4158642014-08-06 09:11:18519
andrew@webrtc.org2442de12012-01-23 17:45:41520def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24521 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23522 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-03 07:56:14523 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24524 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23525 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
526 input_api, output_api))
527 results.extend(input_api.canned_checks.CheckChangeHasDescription(
528 input_api, output_api))
kjellanderd1e26a92016-09-19 15:11:16529 results.extend(_CheckChangeHasBugField(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46530 results.extend(input_api.canned_checks.CheckChangeHasTestField(
531 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43532 results.extend(input_api.canned_checks.CheckTreeIsOpen(
533 input_api, output_api,
534 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24535 return results