blob: 46d16013ae27835481e93aa6d3bb78941fa060eb [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
kjellander7439f972016-12-05 22:47:46 -08009import json
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +000010import os
kjellander@webrtc.org85759802013-10-22 16:47:40 +000011import re
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +000012import sys
kjellander@webrtc.org85759802013-10-22 16:47:40 +000013
14
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010015# Directories that will be scanned by cpplint by the presubmit script.
16CPPLINT_DIRS = [
Fredrik Solenbergea073732015-12-01 11:26:34 +010017 'webrtc/audio',
18 'webrtc/call',
jbauch0f2e9392015-12-10 03:11:42 -080019 'webrtc/common_video',
jbauch70625e52015-12-09 14:18:14 -080020 'webrtc/examples',
aleloidf9e4d92016-08-08 10:26:09 -070021 'webrtc/modules/audio_mixer',
jbauchf91e6d02016-01-24 23:05:21 -080022 'webrtc/modules/bitrate_controller',
Stefan Holmer80e12072016-02-23 13:30:42 +010023 'webrtc/modules/congestion_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/tools',
mflodmand1590b22015-12-09 07:07:59 -080030 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010031]
32
jbauchc4e3ead2016-02-19 00:25:55 -080033# These filters will always be removed, even if the caller specifies a filter
34# set, as they are problematic or broken in some way.
35#
36# Justifications for each filter:
37# - build/c++11 : Rvalue ref checks are unreliable (false positives),
38# include file and feature blacklists are
39# google3-specific.
kjellandere5a87a52016-04-27 02:32:12 -070040# - whitespace/operators: Same as above (doesn't seem sufficient to eliminate
41# all move-related errors).
jbauchc4e3ead2016-02-19 00:25:55 -080042BLACKLIST_LINT_FILTERS = [
43 '-build/c++11',
kjellandere5a87a52016-04-27 02:32:12 -070044 '-whitespace/operators',
jbauchc4e3ead2016-02-19 00:25:55 -080045]
46
kjellanderfd595232015-12-04 02:44:09 -080047# List of directories of "supported" native APIs. That means changes to headers
48# will be done in a compatible way following this scheme:
49# 1. Non-breaking changes are made.
50# 2. The old APIs as marked as deprecated (with comments).
51# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
52# webrtc-users@google.com (internal list).
53# 4. (later) The deprecated APIs are removed.
kjellander53047c92015-12-02 23:56:14 -080054NATIVE_API_DIRS = (
kjellander53047c92015-12-02 23:56:14 -080055 'webrtc',
kjellanderdd705472016-06-09 11:17:27 -070056 'webrtc/api',
57 'webrtc/media',
kjellander53047c92015-12-02 23:56:14 -080058 'webrtc/modules/audio_device/include',
kjellanderdd705472016-06-09 11:17:27 -070059 'webrtc/pc',
60)
61# These directories should not be used but are maintained only to avoid breaking
62# some legacy downstream code.
63LEGACY_API_DIRS = (
kjellanderdd705472016-06-09 11:17:27 -070064 'webrtc/base',
65 'webrtc/common_audio/include',
66 'webrtc/modules/audio_coding/include',
67 'webrtc/modules/audio_conference_mixer/include',
kjellander53047c92015-12-02 23:56:14 -080068 'webrtc/modules/audio_processing/include',
69 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 13:30:42 +010070 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-02 23:56:14 -080071 'webrtc/modules/include',
72 'webrtc/modules/remote_bitrate_estimator/include',
73 'webrtc/modules/rtp_rtcp/include',
kjellanderdd705472016-06-09 11:17:27 -070074 'webrtc/modules/rtp_rtcp/source',
kjellander53047c92015-12-02 23:56:14 -080075 'webrtc/modules/utility/include',
76 'webrtc/modules/video_coding/codecs/h264/include',
77 'webrtc/modules/video_coding/codecs/i420/include',
78 'webrtc/modules/video_coding/codecs/vp8/include',
79 'webrtc/modules/video_coding/codecs/vp9/include',
80 'webrtc/modules/video_coding/include',
kjellanderdd705472016-06-09 11:17:27 -070081 'webrtc/system_wrappers/include',
kjellander53047c92015-12-02 23:56:14 -080082 'webrtc/voice_engine/include',
83)
kjellanderdd705472016-06-09 11:17:27 -070084API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
kjellander53047c92015-12-02 23:56:14 -080085
86
87def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
88 """Ensures the list of native API header directories is up to date."""
89 non_existing_paths = []
90 native_api_full_paths = [
91 input_api.os_path.join(input_api.PresubmitLocalPath(),
kjellanderdd705472016-06-09 11:17:27 -070092 *path.split('/')) for path in API_DIRS]
kjellander53047c92015-12-02 23:56:14 -080093 for path in native_api_full_paths:
94 if not os.path.isdir(path):
95 non_existing_paths.append(path)
96 if non_existing_paths:
97 return [output_api.PresubmitError(
98 'Directories to native API headers have changed which has made the '
99 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
100 'location of our native APIs.',
101 non_existing_paths)]
102 return []
103
kwibergeb133022016-04-07 07:41:48 -0700104api_change_msg = """
105You seem to be changing native API header files. Please make sure that you:
106 1. Make compatible changes that don't break existing clients.
107 2. Mark the old stuff as deprecated.
108 3. Create a timeline and plan for when the deprecated stuff will be
109 removed. (The amount of time we give users to change their code
110 should be informed by how much work it is for them. If they just
111 need to replace one name with another or something equally
112 simple, 1-2 weeks might be good; if they need to do serious work,
113 up to 3 months may be called for.)
114 4. Update/inform existing downstream code owners to stop using the
115 deprecated stuff. (Send announcements to
116 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
117 5. Remove the deprecated stuff, once the agreed-upon amount of time
118 has passed.
119Related files:
120"""
kjellander53047c92015-12-02 23:56:14 -0800121
122def _CheckNativeApiHeaderChanges(input_api, output_api):
123 """Checks to remind proper changing of native APIs."""
124 files = []
125 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
126 if f.LocalPath().endswith('.h'):
kjellanderdd705472016-06-09 11:17:27 -0700127 for path in API_DIRS:
kjellander53047c92015-12-02 23:56:14 -0800128 if os.path.dirname(f.LocalPath()) == path:
129 files.append(f)
130
131 if files:
kwibergeb133022016-04-07 07:41:48 -0700132 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-02 23:56:14 -0800133 return []
134
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100135
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000136def _CheckNoIOStreamInHeaders(input_api, output_api):
137 """Checks to make sure no .h files include <iostream>."""
138 files = []
139 pattern = input_api.re.compile(r'^#include\s*<iostream>',
140 input_api.re.MULTILINE)
141 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
142 if not f.LocalPath().endswith('.h'):
143 continue
144 contents = input_api.ReadFile(f)
145 if pattern.search(contents):
146 files.append(f)
147
148 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200149 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000150 'Do not #include <iostream> in header files, since it inserts static ' +
151 'initialization into every file including the header. Instead, ' +
152 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200153 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000154 return []
155
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000156
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000157def _CheckNoFRIEND_TEST(input_api, output_api):
158 """Make sure that gtest's FRIEND_TEST() macro is not used, the
159 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
160 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
161 problems = []
162
163 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
164 for f in input_api.AffectedFiles(file_filter=file_filter):
165 for line_num, line in f.ChangedContents():
166 if 'FRIEND_TEST(' in line:
167 problems.append(' %s:%d' % (f.LocalPath(), line_num))
168
169 if not problems:
170 return []
171 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
172 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
173 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
174
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000175
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100176def _IsLintWhitelisted(whitelist_dirs, file_path):
177 """ Checks if a file is whitelisted for lint check."""
178 for path in whitelist_dirs:
179 if os.path.dirname(file_path).startswith(path):
180 return True
181 return False
182
183
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000184def _CheckApprovedFilesLintClean(input_api, output_api,
185 source_file_filter=None):
186 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000187 This check is based on _CheckChangeLintsClean in
188 depot_tools/presubmit_canned_checks.py but has less filters and only checks
189 added files."""
190 result = []
191
192 # Initialize cpplint.
193 import cpplint
194 # Access to a protected member _XX of a client class
195 # pylint: disable=W0212
196 cpplint._cpplint_state.ResetErrorCounts()
197
jbauchc4e3ead2016-02-19 00:25:55 -0800198 lint_filters = cpplint._Filters()
199 lint_filters.extend(BLACKLIST_LINT_FILTERS)
200 cpplint._SetFilters(','.join(lint_filters))
201
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100202 # Create a platform independent whitelist for the CPPLINT_DIRS.
203 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
204 for path in CPPLINT_DIRS]
205
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000206 # Use the strictest verbosity level for cpplint.py (level 1) which is the
207 # default when running cpplint.py from command line.
208 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000209 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000210 verbosity_level = 1
211 files = []
212 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200213 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100214 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000215 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000216
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000217 for file_name in files:
218 cpplint.ProcessFile(file_name, verbosity_level)
219
220 if cpplint._cpplint_state.error_count > 0:
221 if input_api.is_committing:
222 # TODO(kjellander): Change back to PresubmitError below when we're
223 # confident with the lint settings.
224 res_type = output_api.PresubmitPromptWarning
225 else:
226 res_type = output_api.PresubmitPromptWarning
227 result = [res_type('Changelist failed cpplint.py check.')]
228
229 return result
230
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100231def _CheckNoSourcesAbove(input_api, gn_files, output_api):
ehmaldonado5b1ba082016-09-02 05:51:08 -0700232 # Disallow referencing source files with paths above the GN file location.
233 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
234 re.MULTILINE | re.DOTALL)
235 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"')
236 violating_gn_files = set()
237 violating_source_entries = []
238 for gn_file in gn_files:
239 contents = input_api.ReadFile(gn_file)
240 for source_block_match in source_pattern.finditer(contents):
241 # Find all source list entries starting with ../ in the source block
242 # (exclude overrides entries).
243 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
244 source_file = file_list_match.group(1)
245 if 'overrides/' not in source_file:
246 violating_source_entries.append(source_file)
247 violating_gn_files.add(gn_file)
248 if violating_gn_files:
249 return [output_api.PresubmitError(
250 'Referencing source files above the directory of the GN file is not '
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100251 'allowed. Please introduce new GN targets in the proper location '
252 'instead.\n'
ehmaldonado5b1ba082016-09-02 05:51:08 -0700253 'Invalid source entries:\n'
254 '%s\n'
255 'Violating GN files:' % '\n'.join(violating_source_entries),
256 items=violating_gn_files)]
257 return []
258
kjellander7439f972016-12-05 22:47:46 -0800259def _CheckNoMixingCAndCCSources(input_api, gn_files, output_api):
260 # Disallow mixing .c and .cc source files in the same target.
261 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
262 re.MULTILINE | re.DOTALL)
263 file_pattern = input_api.re.compile(r'"(.*)"')
264 violating_gn_files = dict()
265 for gn_file in gn_files:
266 contents = input_api.ReadFile(gn_file)
267 for source_block_match in source_pattern.finditer(contents):
268 c_files = []
269 cc_files = []
270 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
271 source_file = file_list_match.group(1)
272 if source_file.endswith('.c'):
273 c_files.append(source_file)
274 if source_file.endswith('.cc'):
275 cc_files.append(source_file)
276 if c_files and cc_files:
277 violating_gn_files[gn_file.LocalPath()] = sorted(c_files + cc_files)
278 if violating_gn_files:
279 return [output_api.PresubmitError(
280 'GN targets cannot mix .cc and .c source files. Please create a '
281 'separate target for each collection of sources.\n'
282 'Mixed sources: \n'
283 '%s\n'
284 'Violating GN files:' % json.dumps(violating_gn_files, indent=2),
285 items=violating_gn_files.keys())]
286 return []
287
ehmaldonado5b1ba082016-09-02 05:51:08 -0700288def _CheckGnChanges(input_api, output_api):
289 source_file_filter = lambda x: input_api.FilterSourceFile(
290 x, white_list=(r'.+\.(gn|gni)$',))
291
292 gn_files = []
293 for f in input_api.AffectedSourceFiles(source_file_filter):
294 if f.LocalPath().startswith('webrtc'):
295 gn_files.append(f)
296
297 result = []
298 if gn_files:
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100299 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
kjellander7439f972016-12-05 22:47:46 -0800300 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700301 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
kjellanderd1e26a92016-09-19 08:11:16 -0700362def _CheckChangeHasBugField(input_api, output_api):
363 """Requires that the changelist have a BUG= field.
364
365 This check is stricter than the one in depot_tools/presubmit_canned_checks.py
366 since it fails the presubmit if the BUG= field is missing or doesn't contain
367 a bug reference.
368 """
369 if input_api.change.BUG:
370 return []
371 else:
372 return [output_api.PresubmitError(
373 'The BUG=[bug number] field is mandatory. Please create a bug and '
374 'reference it using either of:\n'
375 ' * https://bugs.webrtc.org - reference it using BUG=webrtc:XXXX\n'
376 ' * https://crbug.com - reference it using BUG=chromium:XXXXXX')]
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000377
kjellander569cf942016-02-11 05:02:59 -0800378def _CheckJSONParseErrors(input_api, output_api):
379 """Check that JSON files do not contain syntax errors."""
380
381 def FilterFile(affected_file):
382 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
383
384 def GetJSONParseError(input_api, filename):
385 try:
386 contents = input_api.ReadFile(filename)
387 input_api.json.loads(contents)
388 except ValueError as e:
389 return e
390 return None
391
392 results = []
393 for affected_file in input_api.AffectedFiles(
394 file_filter=FilterFile, include_deletes=False):
395 parse_error = GetJSONParseError(input_api,
396 affected_file.AbsoluteLocalPath())
397 if parse_error:
398 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
399 (affected_file.LocalPath(), parse_error)))
400 return results
401
402
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200403def _RunPythonTests(input_api, output_api):
404 def join(*args):
405 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
406
407 test_directories = [
Henrik Kjellander24db1792016-12-15 10:20:10 +0100408 join('tools-webrtc', 'autoroller', 'unittests'),
aleloi7ebbf902016-06-20 07:39:15 -0700409 join('webrtc', 'tools', 'py_event_log_analyzer'),
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200410 ]
411
412 tests = []
413 for directory in test_directories:
414 tests.extend(
415 input_api.canned_checks.GetUnitTestsInDirectory(
416 input_api,
417 output_api,
418 directory,
419 whitelist=[r'.+_test\.py$']))
420 return input_api.RunTests(tests, parallel=True)
421
422
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000423def _CommonChecks(input_api, output_api):
424 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000425 results = []
tkchin42f580e2015-11-26 23:18:23 -0800426 # Filter out files that are in objc or ios dirs from being cpplint-ed since
427 # they do not follow C++ lint rules.
428 black_list = input_api.DEFAULT_BLACK_LIST + (
429 r".*\bobjc[\\\/].*",
Kári Tristan Helgason3fa35172016-09-09 08:55:05 +0000430 r".*objc\.[hcm]+$",
hjon65ae2d82016-08-02 23:55:44 -0700431 r"webrtc\/build\/ios\/SDK\/.*",
tkchin42f580e2015-11-26 23:18:23 -0800432 )
433 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
434 results.extend(_CheckApprovedFilesLintClean(
435 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000436 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
437 black_list=(r'^.*gviz_api\.py$',
438 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000439 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200440 r'^build[\\\/].*\.py$',
441 r'^buildtools[\\\/].*\.py$',
442 r'^chromium[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700443 r'^mojo.*[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200444 r'^out.*[\\\/].*\.py$',
445 r'^testing[\\\/].*\.py$',
446 r'^third_party[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200447 r'^tools[\\\/]clang[\\\/].*\.py$',
448 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700449 r'^tools[\\\/]generate_stubs[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200450 r'^tools[\\\/]gn[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200451 r'^tools[\\\/]isolate_driver.py$',
kjellanderd620f822016-04-04 06:07:08 -0700452 r'^tools[\\\/]mb[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200453 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
454 r'^tools[\\\/]python[\\\/].*\.py$',
455 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
456 r'^tools[\\\/]refactoring[\\\/].*\.py$',
457 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
458 r'^tools[\\\/]vim[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200459 r'^tools[\\\/]valgrind[\\\/].*\.py$',
460 r'^tools[\\\/]win[\\\/].*\.py$',
kjellanderafd54942016-12-17 12:21:39 -0800461 # TODO(phoglund): should arguably be checked.
462 r'^tools-webrtc[\\\/]valgrind[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200463 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000464 disabled_warnings=['F0401', # Failed to import x
465 'E0611', # No package y in x
466 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200467 ],
468 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800469
nisse3d21e232016-09-02 03:07:06 -0700470 # TODO(nisse): talk/ is no more, so make below checks simpler?
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200471 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
472 # we need to have different license checks in talk/ and webrtc/ directories.
473 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200474
tkchin3cd9a302016-06-08 12:40:28 -0700475 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
476 # ObjC subdirectories ObjC headers.
477 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100478 # Skip long-lines check for DEPS and GN files.
479 build_file_filter_list = (r'.+\.gn$', r'.+\.gni$', 'DEPS')
tkchin3cd9a302016-06-08 12:40:28 -0700480 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
481 black_list=build_file_filter_list + objc_filter_list)
482 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
483 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000484 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 12:40:28 -0700485 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
486 results.extend(input_api.canned_checks.CheckLongLines(
487 input_api, output_api, maxlen=100,
488 source_file_filter=hundred_char_sources))
489
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000490 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
491 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000492 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
493 input_api, output_api))
kjellandere5dc62a2016-12-14 00:16:21 -0800494 results.extend(input_api.canned_checks.CheckAuthorizedAuthor(
495 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000496 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
497 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800498 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000499 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
500 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700501 results.extend(_CheckGnChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000502 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800503 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200504 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000505 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000506
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000507
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000508def CheckChangeOnUpload(input_api, output_api):
509 results = []
510 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200511 results.extend(
512 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000513 return results
514
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000515
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000516def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000517 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000518 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800519 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000520 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000521 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
522 input_api, output_api))
523 results.extend(input_api.canned_checks.CheckChangeHasDescription(
524 input_api, output_api))
kjellanderd1e26a92016-09-19 08:11:16 -0700525 results.extend(_CheckChangeHasBugField(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000526 results.extend(input_api.canned_checks.CheckChangeHasTestField(
527 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000528 results.extend(input_api.canned_checks.CheckTreeIsOpen(
529 input_api, output_api,
530 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000531 return results