blob: 24a50348ec59ae6e0e992f4d5596b4af38bec458 [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',
jbauchf91e6d02016-01-24 23:05:21 -080023 'webrtc/modules/bitrate_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/sound',
30 'webrtc/tools',
mflodmand1590b22015-12-09 07:07:59 -080031 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010032]
33
kjellanderfd595232015-12-04 02:44:09 -080034# List of directories of "supported" native APIs. That means changes to headers
35# will be done in a compatible way following this scheme:
36# 1. Non-breaking changes are made.
37# 2. The old APIs as marked as deprecated (with comments).
38# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
39# webrtc-users@google.com (internal list).
40# 4. (later) The deprecated APIs are removed.
41# Directories marked as DEPRECATED should not be used. They're only present in
42# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080043NATIVE_API_DIRS = (
44 'talk/app/webrtc',
45 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080046 'webrtc/base', # DEPRECATED.
47 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080048 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080049 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080050 'webrtc/modules/audio_device/include',
51 'webrtc/modules/audio_processing/include',
52 'webrtc/modules/bitrate_controller/include',
53 'webrtc/modules/include',
54 'webrtc/modules/remote_bitrate_estimator/include',
55 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080056 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080057 'webrtc/modules/utility/include',
58 'webrtc/modules/video_coding/codecs/h264/include',
59 'webrtc/modules/video_coding/codecs/i420/include',
60 'webrtc/modules/video_coding/codecs/vp8/include',
61 'webrtc/modules/video_coding/codecs/vp9/include',
62 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080063 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080064 'webrtc/voice_engine/include',
65)
66
67
68def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
69 """Ensures the list of native API header directories is up to date."""
70 non_existing_paths = []
71 native_api_full_paths = [
72 input_api.os_path.join(input_api.PresubmitLocalPath(),
73 *path.split('/')) for path in NATIVE_API_DIRS]
74 for path in native_api_full_paths:
75 if not os.path.isdir(path):
76 non_existing_paths.append(path)
77 if non_existing_paths:
78 return [output_api.PresubmitError(
79 'Directories to native API headers have changed which has made the '
80 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
81 'location of our native APIs.',
82 non_existing_paths)]
83 return []
84
85
86def _CheckNativeApiHeaderChanges(input_api, output_api):
87 """Checks to remind proper changing of native APIs."""
88 files = []
89 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
90 if f.LocalPath().endswith('.h'):
91 for path in NATIVE_API_DIRS:
92 if os.path.dirname(f.LocalPath()) == path:
93 files.append(f)
94
95 if files:
kjellanderffea13c2015-12-08 01:57:17 -080096 return [output_api.PresubmitNotifyResult(
kjellander53047c92015-12-02 23:56:14 -080097 'You seem to be changing native API header files. Please make sure '
98 'you:\n'
99 ' 1. Make compatible changes that don\'t break existing clients.\n'
100 ' 2. Mark the old APIs as deprecated.\n'
101 ' 3. Create a timeline and plan for when the deprecated method will '
102 'be removed (preferably 3 months or so).\n'
103 ' 4. Update/inform existing downstream code owners to stop using the '
104 'deprecated APIs: \n'
105 'send announcement to discuss-webrtc@googlegroups.com and '
106 'webrtc-users@google.com.\n'
107 ' 5. (after ~3 months) remove the deprecated API.\n'
108 'Related files:',
109 files)]
110 return []
111
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100112
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000113def _CheckNoIOStreamInHeaders(input_api, output_api):
114 """Checks to make sure no .h files include <iostream>."""
115 files = []
116 pattern = input_api.re.compile(r'^#include\s*<iostream>',
117 input_api.re.MULTILINE)
118 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
119 if not f.LocalPath().endswith('.h'):
120 continue
121 contents = input_api.ReadFile(f)
122 if pattern.search(contents):
123 files.append(f)
124
125 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200126 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000127 'Do not #include <iostream> in header files, since it inserts static ' +
128 'initialization into every file including the header. Instead, ' +
129 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200130 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000131 return []
132
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000133
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000134def _CheckNoFRIEND_TEST(input_api, output_api):
135 """Make sure that gtest's FRIEND_TEST() macro is not used, the
136 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
137 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
138 problems = []
139
140 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
141 for f in input_api.AffectedFiles(file_filter=file_filter):
142 for line_num, line in f.ChangedContents():
143 if 'FRIEND_TEST(' in line:
144 problems.append(' %s:%d' % (f.LocalPath(), line_num))
145
146 if not problems:
147 return []
148 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
149 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
150 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
151
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000152
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100153def _IsLintWhitelisted(whitelist_dirs, file_path):
154 """ Checks if a file is whitelisted for lint check."""
155 for path in whitelist_dirs:
156 if os.path.dirname(file_path).startswith(path):
157 return True
158 return False
159
160
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000161def _CheckApprovedFilesLintClean(input_api, output_api,
162 source_file_filter=None):
163 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000164 This check is based on _CheckChangeLintsClean in
165 depot_tools/presubmit_canned_checks.py but has less filters and only checks
166 added files."""
167 result = []
168
169 # Initialize cpplint.
170 import cpplint
171 # Access to a protected member _XX of a client class
172 # pylint: disable=W0212
173 cpplint._cpplint_state.ResetErrorCounts()
174
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100175 # Create a platform independent whitelist for the CPPLINT_DIRS.
176 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
177 for path in CPPLINT_DIRS]
178
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000179 # Use the strictest verbosity level for cpplint.py (level 1) which is the
180 # default when running cpplint.py from command line.
181 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000182 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000183 verbosity_level = 1
184 files = []
185 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200186 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100187 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000188 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000189
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000190 for file_name in files:
191 cpplint.ProcessFile(file_name, verbosity_level)
192
193 if cpplint._cpplint_state.error_count > 0:
194 if input_api.is_committing:
195 # TODO(kjellander): Change back to PresubmitError below when we're
196 # confident with the lint settings.
197 res_type = output_api.PresubmitPromptWarning
198 else:
199 res_type = output_api.PresubmitPromptWarning
200 result = [res_type('Changelist failed cpplint.py check.')]
201
202 return result
203
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000204def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
205 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
206 violating_files = []
207 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000208 gyp_exceptions = (
209 'base_tests.gyp',
210 'desktop_capture.gypi',
211 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000212 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000213 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000214 'sound.gyp',
215 'webrtc_test_common.gyp',
216 'webrtc_tests.gypi',
217 )
218 if f.LocalPath().endswith(gyp_exceptions):
219 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000220 contents = input_api.ReadFile(f)
221 if pattern.search(contents):
222 violating_files.append(f)
223 if violating_files:
224 return [output_api.PresubmitError(
225 'Depending on rtc_base is not allowed. Change your dependency to '
226 'rtc_base_approved and possibly sanitize and move the desired source '
227 'file(s) to rtc_base_approved.\nChanged GYP files:',
228 items=violating_files)]
229 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000230
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000231def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
232 # Disallow referencing source files with paths above the GYP file location.
233 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
234 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000235 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000236 violating_gyp_files = set()
237 violating_source_entries = []
238 for gyp_file in gyp_files:
kjellanderc61635c2016-02-02 02:30:07 -0800239 if 'supplement.gypi' in gyp_file.LocalPath():
240 # Exclude supplement.gypi from this check, as the LSan and TSan
241 # suppression files are located in a different location.
242 continue
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000243 contents = input_api.ReadFile(gyp_file)
244 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000245 # Find all source list entries starting with ../ in the source block
246 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000247 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000248 source_file = file_list_match.group(0)
249 if 'overrides/' not in source_file:
250 violating_source_entries.append(source_file)
251 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000252 if violating_gyp_files:
253 return [output_api.PresubmitError(
254 'Referencing source files above the directory of the GYP file is not '
255 'allowed. Please introduce new GYP targets and/or GYP files in the '
256 'proper location instead.\n'
257 'Invalid source entries:\n'
258 '%s\n'
259 'Violating GYP files:' % '\n'.join(violating_source_entries),
260 items=violating_gyp_files)]
261 return []
262
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000263def _CheckGypChanges(input_api, output_api):
264 source_file_filter = lambda x: input_api.FilterSourceFile(
265 x, white_list=(r'.+\.(gyp|gypi)$',))
266
267 gyp_files = []
268 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000269 if f.LocalPath().startswith('webrtc'):
270 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000271
272 result = []
273 if gyp_files:
274 result.append(output_api.PresubmitNotifyResult(
275 'As you\'re changing GYP files: please make sure corresponding '
276 'BUILD.gn files are also updated.\nChanged GYP files:',
277 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000278 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000279 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000280 return result
281
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000282def _CheckUnwantedDependencies(input_api, output_api):
283 """Runs checkdeps on #include statements added in this
284 change. Breaking - rules is an error, breaking ! rules is a
285 warning.
286 """
287 # Copied from Chromium's src/PRESUBMIT.py.
288
289 # We need to wait until we have an input_api object and use this
290 # roundabout construct to import checkdeps because this file is
291 # eval-ed and thus doesn't have __file__.
292 original_sys_path = sys.path
293 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000294 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
295 'buildtools', 'checkdeps')
296 if not os.path.exists(checkdeps_path):
297 return [output_api.PresubmitError(
298 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
299 'download Chromium and setup the symlinks?' % checkdeps_path)]
300 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000301 import checkdeps
302 from cpp_checker import CppChecker
303 from rules import Rule
304 finally:
305 # Restore sys.path to what it was before.
306 sys.path = original_sys_path
307
308 added_includes = []
309 for f in input_api.AffectedFiles():
310 if not CppChecker.IsCppFile(f.LocalPath()):
311 continue
312
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200313 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000314 added_includes.append([f.LocalPath(), changed_lines])
315
316 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
317
318 error_descriptions = []
319 warning_descriptions = []
320 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
321 added_includes):
322 description_with_path = '%s\n %s' % (path, rule_description)
323 if rule_type == Rule.DISALLOW:
324 error_descriptions.append(description_with_path)
325 else:
326 warning_descriptions.append(description_with_path)
327
328 results = []
329 if error_descriptions:
330 results.append(output_api.PresubmitError(
331 'You added one or more #includes that violate checkdeps rules.',
332 error_descriptions))
333 if warning_descriptions:
334 results.append(output_api.PresubmitPromptOrNotify(
335 'You added one or more #includes of files that are temporarily\n'
336 'allowed but being removed. Can you avoid introducing the\n'
337 '#include? See relevant DEPS file(s) for details and contacts.',
338 warning_descriptions))
339 return results
340
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000341
kjellander569cf942016-02-11 05:02:59 -0800342def _CheckJSONParseErrors(input_api, output_api):
343 """Check that JSON files do not contain syntax errors."""
344
345 def FilterFile(affected_file):
346 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
347
348 def GetJSONParseError(input_api, filename):
349 try:
350 contents = input_api.ReadFile(filename)
351 input_api.json.loads(contents)
352 except ValueError as e:
353 return e
354 return None
355
356 results = []
357 for affected_file in input_api.AffectedFiles(
358 file_filter=FilterFile, include_deletes=False):
359 parse_error = GetJSONParseError(input_api,
360 affected_file.AbsoluteLocalPath())
361 if parse_error:
362 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
363 (affected_file.LocalPath(), parse_error)))
364 return results
365
366
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200367def _RunPythonTests(input_api, output_api):
368 def join(*args):
369 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
370
371 test_directories = [
372 join('tools', 'autoroller', 'unittests'),
373 ]
374
375 tests = []
376 for directory in test_directories:
377 tests.extend(
378 input_api.canned_checks.GetUnitTestsInDirectory(
379 input_api,
380 output_api,
381 directory,
382 whitelist=[r'.+_test\.py$']))
383 return input_api.RunTests(tests, parallel=True)
384
385
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000386def _CommonChecks(input_api, output_api):
387 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000388 results = []
tkchin42f580e2015-11-26 23:18:23 -0800389 # Filter out files that are in objc or ios dirs from being cpplint-ed since
390 # they do not follow C++ lint rules.
391 black_list = input_api.DEFAULT_BLACK_LIST + (
392 r".*\bobjc[\\\/].*",
393 )
394 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
395 results.extend(_CheckApprovedFilesLintClean(
396 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000397 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
398 black_list=(r'^.*gviz_api\.py$',
399 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000400 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200401 r'^build[\\\/].*\.py$',
402 r'^buildtools[\\\/].*\.py$',
403 r'^chromium[\\\/].*\.py$',
404 r'^google_apis[\\\/].*\.py$',
405 r'^net.*[\\\/].*\.py$',
406 r'^out.*[\\\/].*\.py$',
407 r'^testing[\\\/].*\.py$',
408 r'^third_party[\\\/].*\.py$',
409 r'^tools[\\\/]find_depot_tools.py$',
410 r'^tools[\\\/]clang[\\\/].*\.py$',
411 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
412 r'^tools[\\\/]gn[\\\/].*\.py$',
413 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200414 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200415 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
416 r'^tools[\\\/]python[\\\/].*\.py$',
417 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
418 r'^tools[\\\/]refactoring[\\\/].*\.py$',
419 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
420 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000421 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200422 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
423 r'^tools[\\\/]valgrind[\\\/].*\.py$',
424 r'^tools[\\\/]win[\\\/].*\.py$',
425 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000426 disabled_warnings=['F0401', # Failed to import x
427 'E0611', # No package y in x
428 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200429 ],
430 pylintrc='pylintrc'))
kjellander569cf942016-02-11 05:02:59 -0800431
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200432 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
433 # we need to have different license checks in talk/ and webrtc/ directories.
434 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200435
436 # Skip long-lines check for DEPS, GN and GYP files.
437 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
438 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000439 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200440 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000441 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
442 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000443 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
444 input_api, output_api))
445 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
446 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800447 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000448 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
449 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000450 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000451 results.extend(_CheckUnwantedDependencies(input_api, output_api))
kjellander569cf942016-02-11 05:02:59 -0800452 results.extend(_CheckJSONParseErrors(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200453 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000454 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000455
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000456
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000457def CheckChangeOnUpload(input_api, output_api):
458 results = []
459 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200460 results.extend(
461 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000462 return results
463
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000464
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000465def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000466 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000467 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800468 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000469 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000470 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
471 input_api, output_api))
472 results.extend(input_api.canned_checks.CheckChangeHasDescription(
473 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000474 results.extend(input_api.canned_checks.CheckChangeHasBugField(
475 input_api, output_api))
476 results.extend(input_api.canned_checks.CheckChangeHasTestField(
477 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000478 results.extend(input_api.canned_checks.CheckTreeIsOpen(
479 input_api, output_api,
480 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000481 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000482
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000483
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000484# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000485def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700486 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700487 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700488 # commit_queue.py below is a script in depot_tools directory, which has a
489 # 'builders' command to retrieve a list of CQ builders from the CQ config.
490 is_win = platform.system() == 'Windows'
491 masters = json.loads(subprocess.check_output(
492 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000493
kjellander986ee082015-06-16 04:32:13 -0700494 try_config = {}
495 for master in masters:
496 try_config.setdefault(master, {})
497 for builder in masters[master]:
498 if 'presubmit' in builder:
499 # Do not trigger presubmit builders, since they're likely to fail
500 # (e.g. OWNERS checks before finished code review), and we're running
501 # local presubmit anyway.
502 pass
503 else:
504 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000505
kjellander986ee082015-06-16 04:32:13 -0700506 return try_config