blob: 6e5fb591cf18272483b194c27e678a8e7f839e0a [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 = [
oprypin803dc292017-02-01 01:55:59 -080018 'webrtc/api',
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',
aleloidf9e4d92016-08-08 10:26:09 -070023 'webrtc/modules/audio_mixer',
jbauchf91e6d02016-01-24 23:05:21 -080024 'webrtc/modules/bitrate_controller',
Stefan Holmer80e12072016-02-23 13:30:42 +010025 'webrtc/modules/congestion_controller',
jbauchd2a22962016-02-08 23:18:25 -080026 'webrtc/modules/pacing',
terelius8f09f172015-12-15 00:51:54 -080027 'webrtc/modules/remote_bitrate_estimator',
danilchap377b5e62015-12-15 04:33:44 -080028 'webrtc/modules/rtp_rtcp',
philipel5908c712015-12-21 08:23:20 -080029 'webrtc/modules/video_coding',
mflodman88eeac42015-12-08 09:21:28 +010030 'webrtc/modules/video_processing',
jbauch0f2e9392015-12-10 03:11:42 -080031 'webrtc/tools',
mflodmand1590b22015-12-09 07:07:59 -080032 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010033]
34
jbauchc4e3ead2016-02-19 00:25:55 -080035# These filters will always be removed, even if the caller specifies a filter
36# set, as they are problematic or broken in some way.
37#
38# Justifications for each filter:
39# - build/c++11 : Rvalue ref checks are unreliable (false positives),
40# include file and feature blacklists are
41# google3-specific.
kjellandere5a87a52016-04-27 02:32:12 -070042# - whitespace/operators: Same as above (doesn't seem sufficient to eliminate
43# all move-related errors).
jbauchc4e3ead2016-02-19 00:25:55 -080044BLACKLIST_LINT_FILTERS = [
45 '-build/c++11',
kjellandere5a87a52016-04-27 02:32:12 -070046 '-whitespace/operators',
jbauchc4e3ead2016-02-19 00:25:55 -080047]
48
kjellanderfd595232015-12-04 02:44:09 -080049# List of directories of "supported" native APIs. That means changes to headers
50# will be done in a compatible way following this scheme:
51# 1. Non-breaking changes are made.
52# 2. The old APIs as marked as deprecated (with comments).
53# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
54# webrtc-users@google.com (internal list).
55# 4. (later) The deprecated APIs are removed.
kjellander53047c92015-12-02 23:56:14 -080056NATIVE_API_DIRS = (
kjellander53047c92015-12-02 23:56:14 -080057 'webrtc',
kjellanderdd705472016-06-09 11:17:27 -070058 'webrtc/api',
59 'webrtc/media',
kjellander53047c92015-12-02 23:56:14 -080060 'webrtc/modules/audio_device/include',
kjellanderdd705472016-06-09 11:17:27 -070061 'webrtc/pc',
62)
63# These directories should not be used but are maintained only to avoid breaking
64# some legacy downstream code.
65LEGACY_API_DIRS = (
kjellanderdd705472016-06-09 11:17:27 -070066 'webrtc/base',
67 'webrtc/common_audio/include',
68 'webrtc/modules/audio_coding/include',
69 'webrtc/modules/audio_conference_mixer/include',
kjellander53047c92015-12-02 23:56:14 -080070 'webrtc/modules/audio_processing/include',
71 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 13:30:42 +010072 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-02 23:56:14 -080073 'webrtc/modules/include',
74 'webrtc/modules/remote_bitrate_estimator/include',
75 'webrtc/modules/rtp_rtcp/include',
kjellanderdd705472016-06-09 11:17:27 -070076 'webrtc/modules/rtp_rtcp/source',
kjellander53047c92015-12-02 23:56:14 -080077 'webrtc/modules/utility/include',
78 'webrtc/modules/video_coding/codecs/h264/include',
79 'webrtc/modules/video_coding/codecs/i420/include',
80 'webrtc/modules/video_coding/codecs/vp8/include',
81 'webrtc/modules/video_coding/codecs/vp9/include',
82 'webrtc/modules/video_coding/include',
kjellanderdd705472016-06-09 11:17:27 -070083 'webrtc/system_wrappers/include',
kjellander53047c92015-12-02 23:56:14 -080084 'webrtc/voice_engine/include',
85)
kjellanderdd705472016-06-09 11:17:27 -070086API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
kjellander53047c92015-12-02 23:56:14 -080087
88
ehmaldonado4fb97462017-01-30 05:27:22 -080089def _RunCommand(command, cwd):
90 """Runs a command and returns the output from that command."""
91 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
92 cwd=cwd)
93 stdout = p.stdout.read()
94 stderr = p.stderr.read()
95 p.wait()
96 p.stdout.close()
97 p.stderr.close()
98 return p.returncode, stdout, stderr
99
100
kjellander53047c92015-12-02 23:56:14 -0800101def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
102 """Ensures the list of native API header directories is up to date."""
103 non_existing_paths = []
104 native_api_full_paths = [
105 input_api.os_path.join(input_api.PresubmitLocalPath(),
kjellanderdd705472016-06-09 11:17:27 -0700106 *path.split('/')) for path in API_DIRS]
kjellander53047c92015-12-02 23:56:14 -0800107 for path in native_api_full_paths:
108 if not os.path.isdir(path):
109 non_existing_paths.append(path)
110 if non_existing_paths:
111 return [output_api.PresubmitError(
112 'Directories to native API headers have changed which has made the '
113 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
114 'location of our native APIs.',
115 non_existing_paths)]
116 return []
117
kwibergeb133022016-04-07 07:41:48 -0700118api_change_msg = """
119You seem to be changing native API header files. Please make sure that you:
120 1. Make compatible changes that don't break existing clients.
121 2. Mark the old stuff as deprecated.
122 3. Create a timeline and plan for when the deprecated stuff will be
123 removed. (The amount of time we give users to change their code
124 should be informed by how much work it is for them. If they just
125 need to replace one name with another or something equally
126 simple, 1-2 weeks might be good; if they need to do serious work,
127 up to 3 months may be called for.)
128 4. Update/inform existing downstream code owners to stop using the
129 deprecated stuff. (Send announcements to
130 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
131 5. Remove the deprecated stuff, once the agreed-upon amount of time
132 has passed.
133Related files:
134"""
kjellander53047c92015-12-02 23:56:14 -0800135
136def _CheckNativeApiHeaderChanges(input_api, output_api):
137 """Checks to remind proper changing of native APIs."""
138 files = []
139 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
140 if f.LocalPath().endswith('.h'):
kjellanderdd705472016-06-09 11:17:27 -0700141 for path in API_DIRS:
kjellander53047c92015-12-02 23:56:14 -0800142 if os.path.dirname(f.LocalPath()) == path:
143 files.append(f)
144
145 if files:
kwibergeb133022016-04-07 07:41:48 -0700146 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-02 23:56:14 -0800147 return []
148
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100149
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000150def _CheckNoIOStreamInHeaders(input_api, output_api):
151 """Checks to make sure no .h files include <iostream>."""
152 files = []
153 pattern = input_api.re.compile(r'^#include\s*<iostream>',
154 input_api.re.MULTILINE)
155 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
156 if not f.LocalPath().endswith('.h'):
157 continue
158 contents = input_api.ReadFile(f)
159 if pattern.search(contents):
160 files.append(f)
161
162 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200163 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000164 'Do not #include <iostream> in header files, since it inserts static ' +
165 'initialization into every file including the header. Instead, ' +
166 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200167 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000168 return []
169
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000170
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000171def _CheckNoFRIEND_TEST(input_api, output_api):
172 """Make sure that gtest's FRIEND_TEST() macro is not used, the
173 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
174 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
175 problems = []
176
177 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
178 for f in input_api.AffectedFiles(file_filter=file_filter):
179 for line_num, line in f.ChangedContents():
180 if 'FRIEND_TEST(' in line:
181 problems.append(' %s:%d' % (f.LocalPath(), line_num))
182
183 if not problems:
184 return []
185 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
186 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
187 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
188
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000189
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100190def _IsLintWhitelisted(whitelist_dirs, file_path):
191 """ Checks if a file is whitelisted for lint check."""
192 for path in whitelist_dirs:
193 if os.path.dirname(file_path).startswith(path):
194 return True
195 return False
196
197
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000198def _CheckApprovedFilesLintClean(input_api, output_api,
199 source_file_filter=None):
200 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000201 This check is based on _CheckChangeLintsClean in
202 depot_tools/presubmit_canned_checks.py but has less filters and only checks
203 added files."""
204 result = []
205
206 # Initialize cpplint.
207 import cpplint
208 # Access to a protected member _XX of a client class
209 # pylint: disable=W0212
210 cpplint._cpplint_state.ResetErrorCounts()
211
jbauchc4e3ead2016-02-19 00:25:55 -0800212 lint_filters = cpplint._Filters()
213 lint_filters.extend(BLACKLIST_LINT_FILTERS)
214 cpplint._SetFilters(','.join(lint_filters))
215
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100216 # Create a platform independent whitelist for the CPPLINT_DIRS.
217 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
218 for path in CPPLINT_DIRS]
219
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000220 # Use the strictest verbosity level for cpplint.py (level 1) which is the
221 # default when running cpplint.py from command line.
222 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000223 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000224 verbosity_level = 1
225 files = []
226 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200227 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100228 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000229 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000230
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000231 for file_name in files:
232 cpplint.ProcessFile(file_name, verbosity_level)
233
234 if cpplint._cpplint_state.error_count > 0:
235 if input_api.is_committing:
236 # TODO(kjellander): Change back to PresubmitError below when we're
237 # confident with the lint settings.
238 res_type = output_api.PresubmitPromptWarning
239 else:
240 res_type = output_api.PresubmitPromptWarning
241 result = [res_type('Changelist failed cpplint.py check.')]
242
243 return result
244
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100245def _CheckNoSourcesAbove(input_api, gn_files, output_api):
ehmaldonado5b1ba082016-09-02 05:51:08 -0700246 # Disallow referencing source files with paths above the GN file location.
247 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
248 re.MULTILINE | re.DOTALL)
249 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"')
250 violating_gn_files = set()
251 violating_source_entries = []
252 for gn_file in gn_files:
253 contents = input_api.ReadFile(gn_file)
254 for source_block_match in source_pattern.finditer(contents):
255 # Find all source list entries starting with ../ in the source block
256 # (exclude overrides entries).
257 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
258 source_file = file_list_match.group(1)
259 if 'overrides/' not in source_file:
260 violating_source_entries.append(source_file)
261 violating_gn_files.add(gn_file)
262 if violating_gn_files:
263 return [output_api.PresubmitError(
264 'Referencing source files above the directory of the GN file is not '
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100265 'allowed. Please introduce new GN targets in the proper location '
266 'instead.\n'
ehmaldonado5b1ba082016-09-02 05:51:08 -0700267 'Invalid source entries:\n'
268 '%s\n'
269 'Violating GN files:' % '\n'.join(violating_source_entries),
270 items=violating_gn_files)]
271 return []
272
kjellander7439f972016-12-05 22:47:46 -0800273def _CheckNoMixingCAndCCSources(input_api, gn_files, output_api):
274 # Disallow mixing .c and .cc source files in the same target.
275 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
276 re.MULTILINE | re.DOTALL)
277 file_pattern = input_api.re.compile(r'"(.*)"')
278 violating_gn_files = dict()
279 for gn_file in gn_files:
280 contents = input_api.ReadFile(gn_file)
281 for source_block_match in source_pattern.finditer(contents):
282 c_files = []
283 cc_files = []
284 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
285 source_file = file_list_match.group(1)
286 if source_file.endswith('.c'):
287 c_files.append(source_file)
288 if source_file.endswith('.cc'):
289 cc_files.append(source_file)
290 if c_files and cc_files:
291 violating_gn_files[gn_file.LocalPath()] = sorted(c_files + cc_files)
292 if violating_gn_files:
293 return [output_api.PresubmitError(
294 'GN targets cannot mix .cc and .c source files. Please create a '
295 'separate target for each collection of sources.\n'
296 'Mixed sources: \n'
297 '%s\n'
298 'Violating GN files:' % json.dumps(violating_gn_files, indent=2),
299 items=violating_gn_files.keys())]
300 return []
301
ehmaldonado4fb97462017-01-30 05:27:22 -0800302def _CheckNoPackageBoundaryViolations(input_api, gn_files, output_api):
303 cwd = input_api.PresubmitLocalPath()
304 script_path = os.path.join('tools-webrtc', 'check_package_boundaries.py')
305 webrtc_path = os.path.join('webrtc')
306 command = [sys.executable, script_path, webrtc_path]
307 command += [gn_file.LocalPath() for gn_file in gn_files]
308 returncode, _, stderr = _RunCommand(command, cwd)
309 if returncode:
310 return [output_api.PresubmitError(
311 'There are package boundary violations in the following GN files:\n\n'
312 '%s' % stderr)]
313 return []
314
ehmaldonado5b1ba082016-09-02 05:51:08 -0700315def _CheckGnChanges(input_api, output_api):
316 source_file_filter = lambda x: input_api.FilterSourceFile(
317 x, white_list=(r'.+\.(gn|gni)$',))
318
319 gn_files = []
320 for f in input_api.AffectedSourceFiles(source_file_filter):
321 if f.LocalPath().startswith('webrtc'):
322 gn_files.append(f)
323
324 result = []
325 if gn_files:
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100326 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
kjellander7439f972016-12-05 22:47:46 -0800327 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api))
ehmaldonado4fb97462017-01-30 05:27:22 -0800328 result.extend(_CheckNoPackageBoundaryViolations(
329 input_api, gn_files, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700330 return result
331
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000332def _CheckUnwantedDependencies(input_api, output_api):
333 """Runs checkdeps on #include statements added in this
334 change. Breaking - rules is an error, breaking ! rules is a
335 warning.
336 """
337 # Copied from Chromium's src/PRESUBMIT.py.
338
339 # We need to wait until we have an input_api object and use this
340 # roundabout construct to import checkdeps because this file is
341 # eval-ed and thus doesn't have __file__.
342 original_sys_path = sys.path
343 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000344 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
345 'buildtools', 'checkdeps')
346 if not os.path.exists(checkdeps_path):
347 return [output_api.PresubmitError(
348 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
349 'download Chromium and setup the symlinks?' % checkdeps_path)]
350 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000351 import checkdeps
352 from cpp_checker import CppChecker
353 from rules import Rule
354 finally:
355 # Restore sys.path to what it was before.
356 sys.path = original_sys_path
357
358 added_includes = []
359 for f in input_api.AffectedFiles():
360 if not CppChecker.IsCppFile(f.LocalPath()):
361 continue
362
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200363 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000364 added_includes.append([f.LocalPath(), changed_lines])
365
366 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
367
368 error_descriptions = []
369 warning_descriptions = []
370 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
371 added_includes):
372 description_with_path = '%s\n %s' % (path, rule_description)
373 if rule_type == Rule.DISALLOW:
374 error_descriptions.append(description_with_path)
375 else:
376 warning_descriptions.append(description_with_path)
377
378 results = []
379 if error_descriptions:
380 results.append(output_api.PresubmitError(
381 'You added one or more #includes that violate checkdeps rules.',
382 error_descriptions))
383 if warning_descriptions:
384 results.append(output_api.PresubmitPromptOrNotify(
385 'You added one or more #includes of files that are temporarily\n'
386 'allowed but being removed. Can you avoid introducing the\n'
387 '#include? See relevant DEPS file(s) for details and contacts.',
388 warning_descriptions))
389 return results
390
kjellanderd1e26a92016-09-19 08:11:16 -0700391def _CheckChangeHasBugField(input_api, output_api):
392 """Requires that the changelist have a BUG= field.
393
394 This check is stricter than the one in depot_tools/presubmit_canned_checks.py
395 since it fails the presubmit if the BUG= field is missing or doesn't contain
396 a bug reference.
397 """
398 if input_api.change.BUG:
399 return []
400 else:
401 return [output_api.PresubmitError(
402 'The BUG=[bug number] field is mandatory. Please create a bug and '
403 'reference it using either of:\n'
404 ' * https://bugs.webrtc.org - reference it using BUG=webrtc:XXXX\n'
405 ' * https://crbug.com - reference it using BUG=chromium:XXXXXX')]
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000406
kjellander569cf942016-02-11 05:02:59 -0800407def _CheckJSONParseErrors(input_api, output_api):
408 """Check that JSON files do not contain syntax errors."""
409
410 def FilterFile(affected_file):
411 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
412
413 def GetJSONParseError(input_api, filename):
414 try:
415 contents = input_api.ReadFile(filename)
416 input_api.json.loads(contents)
417 except ValueError as e:
418 return e
419 return None
420
421 results = []
422 for affected_file in input_api.AffectedFiles(
423 file_filter=FilterFile, include_deletes=False):
424 parse_error = GetJSONParseError(input_api,
425 affected_file.AbsoluteLocalPath())
426 if parse_error:
427 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
428 (affected_file.LocalPath(), parse_error)))
429 return results
430
431
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200432def _RunPythonTests(input_api, output_api):
433 def join(*args):
434 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
435
436 test_directories = [
ehmaldonado4fb97462017-01-30 05:27:22 -0800437 join('webrtc', 'tools', 'py_event_log_analyzer')
438 ] + [
439 root for root, _, files in os.walk(join('tools-webrtc'))
440 if any(f.endswith('_test.py') for f in files)
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200441 ]
442
443 tests = []
444 for directory in test_directories:
445 tests.extend(
446 input_api.canned_checks.GetUnitTestsInDirectory(
447 input_api,
448 output_api,
449 directory,
450 whitelist=[r'.+_test\.py$']))
451 return input_api.RunTests(tests, parallel=True)
452
453
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000454def _CommonChecks(input_api, output_api):
455 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000456 results = []
tkchin42f580e2015-11-26 23:18:23 -0800457 # Filter out files that are in objc or ios dirs from being cpplint-ed since
458 # they do not follow C++ lint rules.
459 black_list = input_api.DEFAULT_BLACK_LIST + (
460 r".*\bobjc[\\\/].*",
Kári Tristan Helgason3fa35172016-09-09 08:55:05 +0000461 r".*objc\.[hcm]+$",
hjon65ae2d82016-08-02 23:55:44 -0700462 r"webrtc\/build\/ios\/SDK\/.*",
tkchin42f580e2015-11-26 23:18:23 -0800463 )
464 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
465 results.extend(_CheckApprovedFilesLintClean(
466 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000467 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
kjellander@webrtc.org177567c2016-12-22 10:40:28 +0100468 black_list=(r'^base[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200469 r'^build[\\\/].*\.py$',
470 r'^buildtools[\\\/].*\.py$',
Henrik Kjellander0779e8f2016-12-22 12:01:17 +0100471 r'^ios[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200472 r'^out.*[\\\/].*\.py$',
473 r'^testing[\\\/].*\.py$',
474 r'^third_party[\\\/].*\.py$',
kjellander@webrtc.org177567c2016-12-22 10:40:28 +0100475 r'^tools[\\\/].*\.py$',
kjellanderafd54942016-12-17 12:21:39 -0800476 # TODO(phoglund): should arguably be checked.
Henrik Kjellanderb2d55772016-12-18 22:14:50 +0100477 r'^tools-webrtc[\\\/]mb[\\\/].*\.py$',
kjellanderafd54942016-12-17 12:21:39 -0800478 r'^tools-webrtc[\\\/]valgrind[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200479 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000480 disabled_warnings=['F0401', # Failed to import x
481 'E0611', # No package y in x
482 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200483 ],
484 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800485
nisse3d21e232016-09-02 03:07:06 -0700486 # TODO(nisse): talk/ is no more, so make below checks simpler?
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200487 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
488 # we need to have different license checks in talk/ and webrtc/ directories.
489 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200490
tkchin3cd9a302016-06-08 12:40:28 -0700491 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
492 # ObjC subdirectories ObjC headers.
493 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellanderb4af3d62016-11-16 20:11:29 +0100494 # Skip long-lines check for DEPS and GN files.
495 build_file_filter_list = (r'.+\.gn$', r'.+\.gni$', 'DEPS')
tkchin3cd9a302016-06-08 12:40:28 -0700496 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
497 black_list=build_file_filter_list + objc_filter_list)
498 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
499 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000500 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 12:40:28 -0700501 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
502 results.extend(input_api.canned_checks.CheckLongLines(
503 input_api, output_api, maxlen=100,
504 source_file_filter=hundred_char_sources))
505
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000506 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
507 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000508 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
509 input_api, output_api))
kjellandere5dc62a2016-12-14 00:16:21 -0800510 results.extend(input_api.canned_checks.CheckAuthorizedAuthor(
511 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000512 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
513 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800514 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000515 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
516 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
ehmaldonado5b1ba082016-09-02 05:51:08 -0700517 results.extend(_CheckGnChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000518 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800519 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200520 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000521 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000522
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000523
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000524def CheckChangeOnUpload(input_api, output_api):
525 results = []
526 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200527 results.extend(
528 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000529 return results
530
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000531
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000532def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000533 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000534 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800535 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000536 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000537 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
538 input_api, output_api))
539 results.extend(input_api.canned_checks.CheckChangeHasDescription(
540 input_api, output_api))
kjellanderd1e26a92016-09-19 08:11:16 -0700541 results.extend(_CheckChangeHasBugField(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000542 results.extend(input_api.canned_checks.CheckChangeHasTestField(
543 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000544 results.extend(input_api.canned_checks.CheckTreeIsOpen(
545 input_api, output_api,
546 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000547 return results