blob: 46be5ff06f32cf30d5ba9c2bc0d0f92952d4f632 [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
ehmaldonado4fb97462017-01-30 05:27:22 -080012import subprocess
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +000013import sys
kjellander@webrtc.org85759802013-10-22 16:47:40 +000014
15
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010016# Directories that will be scanned by cpplint by the presubmit script.
17CPPLINT_DIRS = [
Fredrik Solenbergea073732015-12-01 11:26:34 +010018 'webrtc/audio',
19 'webrtc/call',
jbauch0f2e9392015-12-10 03:11:42 -080020 'webrtc/common_video',
jbauch70625e52015-12-09 14:18:14 -080021 'webrtc/examples',
aleloidf9e4d92016-08-08 10:26:09 -070022 'webrtc/modules/audio_mixer',
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.
kjellander53047c92015-12-02 23:56:14 -080055NATIVE_API_DIRS = (
kjellander53047c92015-12-02 23:56:14 -080056 'webrtc',
kjellanderdd705472016-06-09 11:17:27 -070057 'webrtc/api',
58 'webrtc/media',
kjellander53047c92015-12-02 23:56:14 -080059 'webrtc/modules/audio_device/include',
kjellanderdd705472016-06-09 11:17:27 -070060 'webrtc/pc',
61)
62# These directories should not be used but are maintained only to avoid breaking
63# some legacy downstream code.
64LEGACY_API_DIRS = (
kjellanderdd705472016-06-09 11:17:27 -070065 'webrtc/base',
66 'webrtc/common_audio/include',
67 'webrtc/modules/audio_coding/include',
68 'webrtc/modules/audio_conference_mixer/include',
kjellander53047c92015-12-02 23:56:14 -080069 'webrtc/modules/audio_processing/include',
70 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 13:30:42 +010071 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-02 23:56:14 -080072 'webrtc/modules/include',
73 'webrtc/modules/remote_bitrate_estimator/include',
74 'webrtc/modules/rtp_rtcp/include',
kjellanderdd705472016-06-09 11:17:27 -070075 'webrtc/modules/rtp_rtcp/source',
kjellander53047c92015-12-02 23:56:14 -080076 'webrtc/modules/utility/include',
77 'webrtc/modules/video_coding/codecs/h264/include',
78 'webrtc/modules/video_coding/codecs/i420/include',
79 'webrtc/modules/video_coding/codecs/vp8/include',
80 'webrtc/modules/video_coding/codecs/vp9/include',
81 'webrtc/modules/video_coding/include',
kjellanderdd705472016-06-09 11:17:27 -070082 'webrtc/system_wrappers/include',
kjellander53047c92015-12-02 23:56:14 -080083 'webrtc/voice_engine/include',
84)
kjellanderdd705472016-06-09 11:17:27 -070085API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
kjellander53047c92015-12-02 23:56:14 -080086
87
ehmaldonado4fb97462017-01-30 05:27:22 -080088def _RunCommand(command, cwd):
89 """Runs a command and returns the output from that command."""
90 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
91 cwd=cwd)
92 stdout = p.stdout.read()
93 stderr = p.stderr.read()
94 p.wait()
95 p.stdout.close()
96 p.stderr.close()
97 return p.returncode, stdout, stderr
98
99
kjellander53047c92015-12-02 23:56:14 -0800100def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
101 """Ensures the list of native API header directories is up to date."""
102 non_existing_paths = []
103 native_api_full_paths = [
104 input_api.os_path.join(input_api.PresubmitLocalPath(),
kjellanderdd705472016-06-09 11:17:27 -0700105 *path.split('/')) for path in API_DIRS]
kjellander53047c92015-12-02 23:56:14 -0800106 for path in native_api_full_paths:
107 if not os.path.isdir(path):
108 non_existing_paths.append(path)
109 if non_existing_paths:
110 return [output_api.PresubmitError(
111 'Directories to native API headers have changed which has made the '
112 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
113 'location of our native APIs.',
114 non_existing_paths)]
115 return []
116
kwibergeb133022016-04-07 07:41:48 -0700117api_change_msg = """
118You seem to be changing native API header files. Please make sure that you:
119 1. Make compatible changes that don't break existing clients.
120 2. Mark the old stuff as deprecated.
121 3. Create a timeline and plan for when the deprecated stuff will be
122 removed. (The amount of time we give users to change their code
123 should be informed by how much work it is for them. If they just
124 need to replace one name with another or something equally
125 simple, 1-2 weeks might be good; if they need to do serious work,
126 up to 3 months may be called for.)
127 4. Update/inform existing downstream code owners to stop using the
128 deprecated stuff. (Send announcements to
129 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
130 5. Remove the deprecated stuff, once the agreed-upon amount of time
131 has passed.
132Related files:
133"""
kjellander53047c92015-12-02 23:56:14 -0800134
135def _CheckNativeApiHeaderChanges(input_api, output_api):
136 """Checks to remind proper changing of native APIs."""
137 files = []
138 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
139 if f.LocalPath().endswith('.h'):
kjellanderdd705472016-06-09 11:17:27 -0700140 for path in API_DIRS:
kjellander53047c92015-12-02 23:56:14 -0800141 if os.path.dirname(f.LocalPath()) == path:
142 files.append(f)
143
144 if files:
kwibergeb133022016-04-07 07:41:48 -0700145 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-02 23:56:14 -0800146 return []
147
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100148
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000149def _CheckNoIOStreamInHeaders(input_api, output_api):
150 """Checks to make sure no .h files include <iostream>."""
151 files = []
152 pattern = input_api.re.compile(r'^#include\s*<iostream>',
153 input_api.re.MULTILINE)
154 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
155 if not f.LocalPath().endswith('.h'):
156 continue
157 contents = input_api.ReadFile(f)
158 if pattern.search(contents):
159 files.append(f)
160
161 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200162 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000163 'Do not #include <iostream> in header files, since it inserts static ' +
164 'initialization into every file including the header. Instead, ' +
165 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200166 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000167 return []
168
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000169
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000170def _CheckNoFRIEND_TEST(input_api, output_api):
171 """Make sure that gtest's FRIEND_TEST() macro is not used, the
172 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
173 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
174 problems = []
175
176 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
177 for f in input_api.AffectedFiles(file_filter=file_filter):
178 for line_num, line in f.ChangedContents():
179 if 'FRIEND_TEST(' in line:
180 problems.append(' %s:%d' % (f.LocalPath(), line_num))
181
182 if not problems:
183 return []
184 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
185 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
186 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
187
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000188
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100189def _IsLintWhitelisted(whitelist_dirs, file_path):
190 """ Checks if a file is whitelisted for lint check."""
191 for path in whitelist_dirs:
192 if os.path.dirname(file_path).startswith(path):
193 return True
194 return False
195
196
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000197def _CheckApprovedFilesLintClean(input_api, output_api,
198 source_file_filter=None):
199 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000200 This check is based on _CheckChangeLintsClean in
201 depot_tools/presubmit_canned_checks.py but has less filters and only checks
202 added files."""
203 result = []
204
205 # Initialize cpplint.
206 import cpplint
207 # Access to a protected member _XX of a client class
208 # pylint: disable=W0212
209 cpplint._cpplint_state.ResetErrorCounts()
210
jbauchc4e3ead2016-02-19 00:25:55 -0800211 lint_filters = cpplint._Filters()
212 lint_filters.extend(BLACKLIST_LINT_FILTERS)
213 cpplint._SetFilters(','.join(lint_filters))
214
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100215 # Create a platform independent whitelist for the CPPLINT_DIRS.
216 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
217 for path in CPPLINT_DIRS]
218
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000219 # Use the strictest verbosity level for cpplint.py (level 1) which is the
220 # default when running cpplint.py from command line.
221 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000222 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000223 verbosity_level = 1
224 files = []
225 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200226 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100227 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000228 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000229
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000230 for file_name in files:
231 cpplint.ProcessFile(file_name, verbosity_level)
232
233 if cpplint._cpplint_state.error_count > 0:
234 if input_api.is_committing:
235 # TODO(kjellander): Change back to PresubmitError below when we're
236 # confident with the lint settings.
237 res_type = output_api.PresubmitPromptWarning
238 else:
239 res_type = output_api.PresubmitPromptWarning
240 result = [res_type('Changelist failed cpplint.py check.')]
241
242 return result
243
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100244def _CheckNoSourcesAbove(input_api, gn_files, output_api):
ehmaldonado5b1ba082016-09-02 05:51:08 -0700245 # Disallow referencing source files with paths above the GN file location.
246 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
247 re.MULTILINE | re.DOTALL)
248 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"')
249 violating_gn_files = set()
250 violating_source_entries = []
251 for gn_file in gn_files:
252 contents = input_api.ReadFile(gn_file)
253 for source_block_match in source_pattern.finditer(contents):
254 # Find all source list entries starting with ../ in the source block
255 # (exclude overrides entries).
256 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
257 source_file = file_list_match.group(1)
258 if 'overrides/' not in source_file:
259 violating_source_entries.append(source_file)
260 violating_gn_files.add(gn_file)
261 if violating_gn_files:
262 return [output_api.PresubmitError(
263 'Referencing source files above the directory of the GN file is not '
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100264 'allowed. Please introduce new GN targets in the proper location '
265 'instead.\n'
ehmaldonado5b1ba082016-09-02 05:51:08 -0700266 'Invalid source entries:\n'
267 '%s\n'
268 'Violating GN files:' % '\n'.join(violating_source_entries),
269 items=violating_gn_files)]
270 return []
271
kjellander7439f972016-12-05 22:47:46 -0800272def _CheckNoMixingCAndCCSources(input_api, gn_files, output_api):
273 # Disallow mixing .c and .cc source files in the same target.
274 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
275 re.MULTILINE | re.DOTALL)
276 file_pattern = input_api.re.compile(r'"(.*)"')
277 violating_gn_files = dict()
278 for gn_file in gn_files:
279 contents = input_api.ReadFile(gn_file)
280 for source_block_match in source_pattern.finditer(contents):
281 c_files = []
282 cc_files = []
283 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
284 source_file = file_list_match.group(1)
285 if source_file.endswith('.c'):
286 c_files.append(source_file)
287 if source_file.endswith('.cc'):
288 cc_files.append(source_file)
289 if c_files and cc_files:
290 violating_gn_files[gn_file.LocalPath()] = sorted(c_files + cc_files)
291 if violating_gn_files:
292 return [output_api.PresubmitError(
293 'GN targets cannot mix .cc and .c source files. Please create a '
294 'separate target for each collection of sources.\n'
295 'Mixed sources: \n'
296 '%s\n'
297 'Violating GN files:' % json.dumps(violating_gn_files, indent=2),
298 items=violating_gn_files.keys())]
299 return []
300
ehmaldonado4fb97462017-01-30 05:27:22 -0800301def _CheckNoPackageBoundaryViolations(input_api, gn_files, output_api):
302 cwd = input_api.PresubmitLocalPath()
303 script_path = os.path.join('tools-webrtc', 'check_package_boundaries.py')
304 webrtc_path = os.path.join('webrtc')
305 command = [sys.executable, script_path, webrtc_path]
306 command += [gn_file.LocalPath() for gn_file in gn_files]
307 returncode, _, stderr = _RunCommand(command, cwd)
308 if returncode:
309 return [output_api.PresubmitError(
310 'There are package boundary violations in the following GN files:\n\n'
311 '%s' % stderr)]
312 return []
313
ehmaldonado5b1ba082016-09-02 05:51:08 -0700314def _CheckGnChanges(input_api, output_api):
315 source_file_filter = lambda x: input_api.FilterSourceFile(
316 x, white_list=(r'.+\.(gn|gni)$',))
317
318 gn_files = []
319 for f in input_api.AffectedSourceFiles(source_file_filter):
320 if f.LocalPath().startswith('webrtc'):
321 gn_files.append(f)
322
323 result = []
324 if gn_files:
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100325 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
kjellander7439f972016-12-05 22:47:46 -0800326 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api))
ehmaldonado4fb97462017-01-30 05:27:22 -0800327 result.extend(_CheckNoPackageBoundaryViolations(
328 input_api, gn_files, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700329 return result
330
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000331def _CheckUnwantedDependencies(input_api, output_api):
332 """Runs checkdeps on #include statements added in this
333 change. Breaking - rules is an error, breaking ! rules is a
334 warning.
335 """
336 # Copied from Chromium's src/PRESUBMIT.py.
337
338 # We need to wait until we have an input_api object and use this
339 # roundabout construct to import checkdeps because this file is
340 # eval-ed and thus doesn't have __file__.
341 original_sys_path = sys.path
342 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000343 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
344 'buildtools', 'checkdeps')
345 if not os.path.exists(checkdeps_path):
346 return [output_api.PresubmitError(
347 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
348 'download Chromium and setup the symlinks?' % checkdeps_path)]
349 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000350 import checkdeps
351 from cpp_checker import CppChecker
352 from rules import Rule
353 finally:
354 # Restore sys.path to what it was before.
355 sys.path = original_sys_path
356
357 added_includes = []
358 for f in input_api.AffectedFiles():
359 if not CppChecker.IsCppFile(f.LocalPath()):
360 continue
361
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200362 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000363 added_includes.append([f.LocalPath(), changed_lines])
364
365 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
366
367 error_descriptions = []
368 warning_descriptions = []
369 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
370 added_includes):
371 description_with_path = '%s\n %s' % (path, rule_description)
372 if rule_type == Rule.DISALLOW:
373 error_descriptions.append(description_with_path)
374 else:
375 warning_descriptions.append(description_with_path)
376
377 results = []
378 if error_descriptions:
379 results.append(output_api.PresubmitError(
380 'You added one or more #includes that violate checkdeps rules.',
381 error_descriptions))
382 if warning_descriptions:
383 results.append(output_api.PresubmitPromptOrNotify(
384 'You added one or more #includes of files that are temporarily\n'
385 'allowed but being removed. Can you avoid introducing the\n'
386 '#include? See relevant DEPS file(s) for details and contacts.',
387 warning_descriptions))
388 return results
389
kjellanderd1e26a92016-09-19 08:11:16 -0700390def _CheckChangeHasBugField(input_api, output_api):
391 """Requires that the changelist have a BUG= field.
392
393 This check is stricter than the one in depot_tools/presubmit_canned_checks.py
394 since it fails the presubmit if the BUG= field is missing or doesn't contain
395 a bug reference.
396 """
397 if input_api.change.BUG:
398 return []
399 else:
400 return [output_api.PresubmitError(
401 'The BUG=[bug number] field is mandatory. Please create a bug and '
402 'reference it using either of:\n'
403 ' * https://bugs.webrtc.org - reference it using BUG=webrtc:XXXX\n'
404 ' * https://crbug.com - reference it using BUG=chromium:XXXXXX')]
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000405
kjellander569cf942016-02-11 05:02:59 -0800406def _CheckJSONParseErrors(input_api, output_api):
407 """Check that JSON files do not contain syntax errors."""
408
409 def FilterFile(affected_file):
410 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
411
412 def GetJSONParseError(input_api, filename):
413 try:
414 contents = input_api.ReadFile(filename)
415 input_api.json.loads(contents)
416 except ValueError as e:
417 return e
418 return None
419
420 results = []
421 for affected_file in input_api.AffectedFiles(
422 file_filter=FilterFile, include_deletes=False):
423 parse_error = GetJSONParseError(input_api,
424 affected_file.AbsoluteLocalPath())
425 if parse_error:
426 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
427 (affected_file.LocalPath(), parse_error)))
428 return results
429
430
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200431def _RunPythonTests(input_api, output_api):
432 def join(*args):
433 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
434
435 test_directories = [
ehmaldonado4fb97462017-01-30 05:27:22 -0800436 join('webrtc', 'tools', 'py_event_log_analyzer')
437 ] + [
438 root for root, _, files in os.walk(join('tools-webrtc'))
439 if any(f.endswith('_test.py') for f in files)
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200440 ]
441
442 tests = []
443 for directory in test_directories:
444 tests.extend(
445 input_api.canned_checks.GetUnitTestsInDirectory(
446 input_api,
447 output_api,
448 directory,
449 whitelist=[r'.+_test\.py$']))
450 return input_api.RunTests(tests, parallel=True)
451
452
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000453def _CommonChecks(input_api, output_api):
454 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000455 results = []
tkchin42f580e2015-11-26 23:18:23 -0800456 # Filter out files that are in objc or ios dirs from being cpplint-ed since
457 # they do not follow C++ lint rules.
458 black_list = input_api.DEFAULT_BLACK_LIST + (
459 r".*\bobjc[\\\/].*",
Kári Tristan Helgason3fa35172016-09-09 08:55:05 +0000460 r".*objc\.[hcm]+$",
hjon65ae2d82016-08-02 23:55:44 -0700461 r"webrtc\/build\/ios\/SDK\/.*",
tkchin42f580e2015-11-26 23:18:23 -0800462 )
463 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
464 results.extend(_CheckApprovedFilesLintClean(
465 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000466 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
kjellander@webrtc.org177567c2016-12-22 10:40:28 +0100467 black_list=(r'^base[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200468 r'^build[\\\/].*\.py$',
469 r'^buildtools[\\\/].*\.py$',
Henrik Kjellander0779e8f2016-12-22 12:01:17 +0100470 r'^ios[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200471 r'^out.*[\\\/].*\.py$',
472 r'^testing[\\\/].*\.py$',
473 r'^third_party[\\\/].*\.py$',
kjellander@webrtc.org177567c2016-12-22 10:40:28 +0100474 r'^tools[\\\/].*\.py$',
kjellanderafd54942016-12-17 12:21:39 -0800475 # TODO(phoglund): should arguably be checked.
Henrik Kjellanderb2d55772016-12-18 22:14:50 +0100476 r'^tools-webrtc[\\\/]mb[\\\/].*\.py$',
kjellanderafd54942016-12-17 12:21:39 -0800477 r'^tools-webrtc[\\\/]valgrind[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200478 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000479 disabled_warnings=['F0401', # Failed to import x
480 'E0611', # No package y in x
481 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200482 ],
483 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800484
nisse3d21e232016-09-02 03:07:06 -0700485 # TODO(nisse): talk/ is no more, so make below checks simpler?
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200486 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
487 # we need to have different license checks in talk/ and webrtc/ directories.
488 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200489
tkchin3cd9a302016-06-08 12:40:28 -0700490 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
491 # ObjC subdirectories ObjC headers.
492 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100493 # Skip long-lines check for DEPS and GN files.
494 build_file_filter_list = (r'.+\.gn$', r'.+\.gni$', 'DEPS')
tkchin3cd9a302016-06-08 12:40:28 -0700495 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
496 black_list=build_file_filter_list + objc_filter_list)
497 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
498 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000499 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 12:40:28 -0700500 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
501 results.extend(input_api.canned_checks.CheckLongLines(
502 input_api, output_api, maxlen=100,
503 source_file_filter=hundred_char_sources))
504
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000505 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
506 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000507 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
508 input_api, output_api))
kjellandere5dc62a2016-12-14 00:16:21 -0800509 results.extend(input_api.canned_checks.CheckAuthorizedAuthor(
510 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000511 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
512 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800513 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000514 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
515 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700516 results.extend(_CheckGnChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000517 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800518 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200519 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000520 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000521
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000522
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000523def CheckChangeOnUpload(input_api, output_api):
524 results = []
525 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200526 results.extend(
527 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000528 return results
529
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000530
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000531def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000532 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000533 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800534 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000535 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000536 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
537 input_api, output_api))
538 results.extend(input_api.canned_checks.CheckChangeHasDescription(
539 input_api, output_api))
kjellanderd1e26a92016-09-19 08:11:16 -0700540 results.extend(_CheckChangeHasBugField(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000541 results.extend(input_api.canned_checks.CheckChangeHasTestField(
542 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000543 results.extend(input_api.canned_checks.CheckTreeIsOpen(
544 input_api, output_api,
545 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000546 return results