blob: 00bcc3e545910a89f381d575d74d94e877bff554 [file] [log] [blame]
andrew@webrtc.org2442de12012-01-23 17:45:41 +00001# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
niklase@google.comda159d62011-05-30 11:51:34 +00008
kjellander986ee082015-06-16 04:32:13 -07009import json
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +000010import os
kjellander986ee082015-06-16 04:32:13 -070011import platform
kjellander@webrtc.org85759802013-10-22 16:47:40 +000012import re
kjellander986ee082015-06-16 04:32:13 -070013import subprocess
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +000014import sys
kjellander@webrtc.org85759802013-10-22 16:47:40 +000015
16
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010017# Directories that will be scanned by cpplint by the presubmit script.
18CPPLINT_DIRS = [
Fredrik Solenbergea073732015-12-01 11:26:34 +010019 'webrtc/audio',
20 'webrtc/call',
jbauch0f2e9392015-12-10 03:11:42 -080021 'webrtc/common_video',
jbauch70625e52015-12-09 14:18:14 -080022 'webrtc/examples',
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 = (
66 'talk/app/webrtc',
67 'webrtc/base',
68 'webrtc/common_audio/include',
69 'webrtc/modules/audio_coding/include',
70 'webrtc/modules/audio_conference_mixer/include',
kjellander53047c92015-12-02 23:56:14 -080071 'webrtc/modules/audio_processing/include',
72 'webrtc/modules/bitrate_controller/include',
Stefan Holmer80e12072016-02-23 13:30:42 +010073 'webrtc/modules/congestion_controller/include',
kjellander53047c92015-12-02 23:56:14 -080074 'webrtc/modules/include',
75 'webrtc/modules/remote_bitrate_estimator/include',
76 'webrtc/modules/rtp_rtcp/include',
kjellanderdd705472016-06-09 11:17:27 -070077 'webrtc/modules/rtp_rtcp/source',
kjellander53047c92015-12-02 23:56:14 -080078 'webrtc/modules/utility/include',
79 'webrtc/modules/video_coding/codecs/h264/include',
80 'webrtc/modules/video_coding/codecs/i420/include',
81 'webrtc/modules/video_coding/codecs/vp8/include',
82 'webrtc/modules/video_coding/codecs/vp9/include',
83 'webrtc/modules/video_coding/include',
kjellanderdd705472016-06-09 11:17:27 -070084 'webrtc/system_wrappers/include',
kjellander53047c92015-12-02 23:56:14 -080085 'webrtc/voice_engine/include',
86)
kjellanderdd705472016-06-09 11:17:27 -070087API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
kjellander53047c92015-12-02 23:56:14 -080088
89
90def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
91 """Ensures the list of native API header directories is up to date."""
92 non_existing_paths = []
93 native_api_full_paths = [
94 input_api.os_path.join(input_api.PresubmitLocalPath(),
kjellanderdd705472016-06-09 11:17:27 -070095 *path.split('/')) for path in API_DIRS]
kjellander53047c92015-12-02 23:56:14 -080096 for path in native_api_full_paths:
97 if not os.path.isdir(path):
98 non_existing_paths.append(path)
99 if non_existing_paths:
100 return [output_api.PresubmitError(
101 'Directories to native API headers have changed which has made the '
102 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
103 'location of our native APIs.',
104 non_existing_paths)]
105 return []
106
kwibergeb133022016-04-07 07:41:48 -0700107api_change_msg = """
108You seem to be changing native API header files. Please make sure that you:
109 1. Make compatible changes that don't break existing clients.
110 2. Mark the old stuff as deprecated.
111 3. Create a timeline and plan for when the deprecated stuff will be
112 removed. (The amount of time we give users to change their code
113 should be informed by how much work it is for them. If they just
114 need to replace one name with another or something equally
115 simple, 1-2 weeks might be good; if they need to do serious work,
116 up to 3 months may be called for.)
117 4. Update/inform existing downstream code owners to stop using the
118 deprecated stuff. (Send announcements to
119 discuss-webrtc@googlegroups.com and webrtc-users@google.com.)
120 5. Remove the deprecated stuff, once the agreed-upon amount of time
121 has passed.
122Related files:
123"""
kjellander53047c92015-12-02 23:56:14 -0800124
125def _CheckNativeApiHeaderChanges(input_api, output_api):
126 """Checks to remind proper changing of native APIs."""
127 files = []
128 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
129 if f.LocalPath().endswith('.h'):
kjellanderdd705472016-06-09 11:17:27 -0700130 for path in API_DIRS:
kjellander53047c92015-12-02 23:56:14 -0800131 if os.path.dirname(f.LocalPath()) == path:
132 files.append(f)
133
134 if files:
kwibergeb133022016-04-07 07:41:48 -0700135 return [output_api.PresubmitNotifyResult(api_change_msg, files)]
kjellander53047c92015-12-02 23:56:14 -0800136 return []
137
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100138
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000139def _CheckNoIOStreamInHeaders(input_api, output_api):
140 """Checks to make sure no .h files include <iostream>."""
141 files = []
142 pattern = input_api.re.compile(r'^#include\s*<iostream>',
143 input_api.re.MULTILINE)
144 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
145 if not f.LocalPath().endswith('.h'):
146 continue
147 contents = input_api.ReadFile(f)
148 if pattern.search(contents):
149 files.append(f)
150
151 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200152 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000153 'Do not #include <iostream> in header files, since it inserts static ' +
154 'initialization into every file including the header. Instead, ' +
155 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200156 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000157 return []
158
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000159
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000160def _CheckNoFRIEND_TEST(input_api, output_api):
161 """Make sure that gtest's FRIEND_TEST() macro is not used, the
162 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
163 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
164 problems = []
165
166 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
167 for f in input_api.AffectedFiles(file_filter=file_filter):
168 for line_num, line in f.ChangedContents():
169 if 'FRIEND_TEST(' in line:
170 problems.append(' %s:%d' % (f.LocalPath(), line_num))
171
172 if not problems:
173 return []
174 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
175 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
176 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
177
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000178
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100179def _IsLintWhitelisted(whitelist_dirs, file_path):
180 """ Checks if a file is whitelisted for lint check."""
181 for path in whitelist_dirs:
182 if os.path.dirname(file_path).startswith(path):
183 return True
184 return False
185
186
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000187def _CheckApprovedFilesLintClean(input_api, output_api,
188 source_file_filter=None):
189 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000190 This check is based on _CheckChangeLintsClean in
191 depot_tools/presubmit_canned_checks.py but has less filters and only checks
192 added files."""
193 result = []
194
195 # Initialize cpplint.
196 import cpplint
197 # Access to a protected member _XX of a client class
198 # pylint: disable=W0212
199 cpplint._cpplint_state.ResetErrorCounts()
200
jbauchc4e3ead2016-02-19 00:25:55 -0800201 lint_filters = cpplint._Filters()
202 lint_filters.extend(BLACKLIST_LINT_FILTERS)
203 cpplint._SetFilters(','.join(lint_filters))
204
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100205 # Create a platform independent whitelist for the CPPLINT_DIRS.
206 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
207 for path in CPPLINT_DIRS]
208
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000209 # Use the strictest verbosity level for cpplint.py (level 1) which is the
210 # default when running cpplint.py from command line.
211 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000212 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000213 verbosity_level = 1
214 files = []
215 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200216 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100217 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000218 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000219
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000220 for file_name in files:
221 cpplint.ProcessFile(file_name, verbosity_level)
222
223 if cpplint._cpplint_state.error_count > 0:
224 if input_api.is_committing:
225 # TODO(kjellander): Change back to PresubmitError below when we're
226 # confident with the lint settings.
227 res_type = output_api.PresubmitPromptWarning
228 else:
229 res_type = output_api.PresubmitPromptWarning
230 result = [res_type('Changelist failed cpplint.py check.')]
231
232 return result
233
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000234def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
235 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
236 violating_files = []
237 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000238 gyp_exceptions = (
239 'base_tests.gyp',
240 'desktop_capture.gypi',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000241 'p2p.gyp',
tkchin9eeb6242016-04-27 01:54:20 -0700242 'sdk.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000243 'webrtc_test_common.gyp',
244 'webrtc_tests.gypi',
245 )
246 if f.LocalPath().endswith(gyp_exceptions):
247 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000248 contents = input_api.ReadFile(f)
249 if pattern.search(contents):
250 violating_files.append(f)
251 if violating_files:
252 return [output_api.PresubmitError(
253 'Depending on rtc_base is not allowed. Change your dependency to '
254 'rtc_base_approved and possibly sanitize and move the desired source '
255 'file(s) to rtc_base_approved.\nChanged GYP files:',
256 items=violating_files)]
257 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000258
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000259def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
260 # Disallow referencing source files with paths above the GYP file location.
kjellander@webrtc.org74290b92016-06-15 17:19:06 +0200261 source_pattern = input_api.re.compile(r'\'sources\'.*?\[(.*?)\]',
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000262 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000263 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000264 violating_gyp_files = set()
265 violating_source_entries = []
266 for gyp_file in gyp_files:
kjellanderc61635c2016-02-02 02:30:07 -0800267 if 'supplement.gypi' in gyp_file.LocalPath():
268 # Exclude supplement.gypi from this check, as the LSan and TSan
269 # suppression files are located in a different location.
270 continue
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000271 contents = input_api.ReadFile(gyp_file)
272 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000273 # Find all source list entries starting with ../ in the source block
274 # (exclude overrides entries).
kjellander@webrtc.org74290b92016-06-15 17:19:06 +0200275 for file_list_match in file_pattern.finditer(source_block_match.group(1)):
276 source_file = file_list_match.group(1)
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000277 if 'overrides/' not in source_file:
278 violating_source_entries.append(source_file)
279 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000280 if violating_gyp_files:
281 return [output_api.PresubmitError(
282 'Referencing source files above the directory of the GYP file is not '
283 'allowed. Please introduce new GYP targets and/or GYP files in the '
284 'proper location instead.\n'
285 'Invalid source entries:\n'
286 '%s\n'
287 'Violating GYP files:' % '\n'.join(violating_source_entries),
288 items=violating_gyp_files)]
289 return []
290
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000291def _CheckGypChanges(input_api, output_api):
292 source_file_filter = lambda x: input_api.FilterSourceFile(
293 x, white_list=(r'.+\.(gyp|gypi)$',))
294
295 gyp_files = []
296 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000297 if f.LocalPath().startswith('webrtc'):
298 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000299
300 result = []
301 if gyp_files:
302 result.append(output_api.PresubmitNotifyResult(
303 'As you\'re changing GYP files: please make sure corresponding '
304 'BUILD.gn files are also updated.\nChanged GYP files:',
305 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000306 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000307 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000308 return result
309
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000310def _CheckUnwantedDependencies(input_api, output_api):
311 """Runs checkdeps on #include statements added in this
312 change. Breaking - rules is an error, breaking ! rules is a
313 warning.
314 """
315 # Copied from Chromium's src/PRESUBMIT.py.
316
317 # We need to wait until we have an input_api object and use this
318 # roundabout construct to import checkdeps because this file is
319 # eval-ed and thus doesn't have __file__.
320 original_sys_path = sys.path
321 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000322 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
323 'buildtools', 'checkdeps')
324 if not os.path.exists(checkdeps_path):
325 return [output_api.PresubmitError(
326 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
327 'download Chromium and setup the symlinks?' % checkdeps_path)]
328 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000329 import checkdeps
330 from cpp_checker import CppChecker
331 from rules import Rule
332 finally:
333 # Restore sys.path to what it was before.
334 sys.path = original_sys_path
335
336 added_includes = []
337 for f in input_api.AffectedFiles():
338 if not CppChecker.IsCppFile(f.LocalPath()):
339 continue
340
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200341 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000342 added_includes.append([f.LocalPath(), changed_lines])
343
344 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
345
346 error_descriptions = []
347 warning_descriptions = []
348 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
349 added_includes):
350 description_with_path = '%s\n %s' % (path, rule_description)
351 if rule_type == Rule.DISALLOW:
352 error_descriptions.append(description_with_path)
353 else:
354 warning_descriptions.append(description_with_path)
355
356 results = []
357 if error_descriptions:
358 results.append(output_api.PresubmitError(
359 'You added one or more #includes that violate checkdeps rules.',
360 error_descriptions))
361 if warning_descriptions:
362 results.append(output_api.PresubmitPromptOrNotify(
363 'You added one or more #includes of files that are temporarily\n'
364 'allowed but being removed. Can you avoid introducing the\n'
365 '#include? See relevant DEPS file(s) for details and contacts.',
366 warning_descriptions))
367 return results
368
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000369
kjellander569cf942016-02-11 05:02:59 -0800370def _CheckJSONParseErrors(input_api, output_api):
371 """Check that JSON files do not contain syntax errors."""
372
373 def FilterFile(affected_file):
374 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
375
376 def GetJSONParseError(input_api, filename):
377 try:
378 contents = input_api.ReadFile(filename)
379 input_api.json.loads(contents)
380 except ValueError as e:
381 return e
382 return None
383
384 results = []
385 for affected_file in input_api.AffectedFiles(
386 file_filter=FilterFile, include_deletes=False):
387 parse_error = GetJSONParseError(input_api,
388 affected_file.AbsoluteLocalPath())
389 if parse_error:
390 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
391 (affected_file.LocalPath(), parse_error)))
392 return results
393
394
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200395def _RunPythonTests(input_api, output_api):
396 def join(*args):
397 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
398
399 test_directories = [
400 join('tools', 'autoroller', 'unittests'),
aleloi7ebbf902016-06-20 07:39:15 -0700401 join('webrtc', 'tools', 'py_event_log_analyzer'),
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200402 ]
403
404 tests = []
405 for directory in test_directories:
406 tests.extend(
407 input_api.canned_checks.GetUnitTestsInDirectory(
408 input_api,
409 output_api,
410 directory,
411 whitelist=[r'.+_test\.py$']))
412 return input_api.RunTests(tests, parallel=True)
413
414
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000415def _CommonChecks(input_api, output_api):
416 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000417 results = []
tkchin42f580e2015-11-26 23:18:23 -0800418 # Filter out files that are in objc or ios dirs from being cpplint-ed since
419 # they do not follow C++ lint rules.
420 black_list = input_api.DEFAULT_BLACK_LIST + (
421 r".*\bobjc[\\\/].*",
hjon65ae2d82016-08-02 23:55:44 -0700422 r"webrtc\/build\/ios\/SDK\/.*",
tkchin42f580e2015-11-26 23:18:23 -0800423 )
424 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
425 results.extend(_CheckApprovedFilesLintClean(
426 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000427 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
428 black_list=(r'^.*gviz_api\.py$',
429 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000430 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200431 r'^build[\\\/].*\.py$',
432 r'^buildtools[\\\/].*\.py$',
433 r'^chromium[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700434 r'^mojo.*[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200435 r'^out.*[\\\/].*\.py$',
436 r'^testing[\\\/].*\.py$',
437 r'^third_party[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200438 r'^tools[\\\/]clang[\\\/].*\.py$',
439 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
kjellanderd620f822016-04-04 06:07:08 -0700440 r'^tools[\\\/]generate_stubs[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200441 r'^tools[\\\/]gn[\\\/].*\.py$',
442 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200443 r'^tools[\\\/]isolate_driver.py$',
kjellanderd620f822016-04-04 06:07:08 -0700444 r'^tools[\\\/]mb[\\\/].*\.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200445 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
446 r'^tools[\\\/]python[\\\/].*\.py$',
447 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
448 r'^tools[\\\/]refactoring[\\\/].*\.py$',
449 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
450 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000451 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200452 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
453 r'^tools[\\\/]valgrind[\\\/].*\.py$',
454 r'^tools[\\\/]win[\\\/].*\.py$',
455 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000456 disabled_warnings=['F0401', # Failed to import x
457 'E0611', # No package y in x
458 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200459 ],
460 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800461
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200462 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
463 # we need to have different license checks in talk/ and webrtc/ directories.
464 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200465
tkchin3cd9a302016-06-08 12:40:28 -0700466 # .m and .mm files are ObjC files. For simplicity we will consider .h files in
467 # ObjC subdirectories ObjC headers.
468 objc_filter_list = (r'.+\.m$', r'.+\.mm$', r'.+objc\/.+\.h$')
Henrik Kjellander63224672015-09-08 08:03:56 +0200469 # Skip long-lines check for DEPS, GN and GYP files.
tkchin3cd9a302016-06-08 12:40:28 -0700470 build_file_filter_list = (r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$',
471 'DEPS')
472 eighty_char_sources = lambda x: input_api.FilterSourceFile(x,
473 black_list=build_file_filter_list + objc_filter_list)
474 hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
475 white_list=objc_filter_list)
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000476 results.extend(input_api.canned_checks.CheckLongLines(
tkchin3cd9a302016-06-08 12:40:28 -0700477 input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
478 results.extend(input_api.canned_checks.CheckLongLines(
479 input_api, output_api, maxlen=100,
480 source_file_filter=hundred_char_sources))
481
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000482 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
483 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000484 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
485 input_api, output_api))
486 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
487 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800488 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000489 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
490 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000491 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000492 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800493 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200494 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000495 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000496
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000497
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000498def CheckChangeOnUpload(input_api, output_api):
499 results = []
500 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200501 results.extend(
502 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000503 return results
504
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000505
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000506def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000507 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000508 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800509 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000510 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000511 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
512 input_api, output_api))
513 results.extend(input_api.canned_checks.CheckChangeHasDescription(
514 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000515 results.extend(input_api.canned_checks.CheckChangeHasBugField(
516 input_api, output_api))
517 results.extend(input_api.canned_checks.CheckChangeHasTestField(
518 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000519 results.extend(input_api.canned_checks.CheckTreeIsOpen(
520 input_api, output_api,
521 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000522 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000523
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000524
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000525# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000526def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700527 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700528 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700529 # commit_queue.py below is a script in depot_tools directory, which has a
530 # 'builders' command to retrieve a list of CQ builders from the CQ config.
531 is_win = platform.system() == 'Windows'
532 masters = json.loads(subprocess.check_output(
533 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000534
kjellander986ee082015-06-16 04:32:13 -0700535 try_config = {}
536 for master in masters:
537 try_config.setdefault(master, {})
538 for builder in masters[master]:
539 if 'presubmit' in builder:
540 # Do not trigger presubmit builders, since they're likely to fail
541 # (e.g. OWNERS checks before finished code review), and we're running
542 # local presubmit anyway.
543 pass
544 else:
545 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000546
kjellander986ee082015-06-16 04:32:13 -0700547 return try_config