blob: be2626963a03ac0e1ab5604c6e82e677886796fc [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',
mflodman88eeac42015-12-08 09:21:28 +010021 'webrtc/modules/video_processing',
mflodmand1590b22015-12-09 07:07:59 -080022 'webrtc/video',
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010023]
24
kjellanderfd595232015-12-04 02:44:09 -080025# List of directories of "supported" native APIs. That means changes to headers
26# will be done in a compatible way following this scheme:
27# 1. Non-breaking changes are made.
28# 2. The old APIs as marked as deprecated (with comments).
29# 3. Deprecation is announced to discuss-webrtc@googlegroups.com and
30# webrtc-users@google.com (internal list).
31# 4. (later) The deprecated APIs are removed.
32# Directories marked as DEPRECATED should not be used. They're only present in
33# the list to support legacy downstream code.
kjellander53047c92015-12-02 23:56:14 -080034NATIVE_API_DIRS = (
35 'talk/app/webrtc',
36 'webrtc',
kjellanderfd595232015-12-04 02:44:09 -080037 'webrtc/base', # DEPRECATED.
38 'webrtc/common_audio/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080039 'webrtc/modules/audio_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080040 'webrtc/modules/audio_conference_mixer/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080041 'webrtc/modules/audio_device/include',
42 'webrtc/modules/audio_processing/include',
43 'webrtc/modules/bitrate_controller/include',
44 'webrtc/modules/include',
45 'webrtc/modules/remote_bitrate_estimator/include',
46 'webrtc/modules/rtp_rtcp/include',
kjellanderfd595232015-12-04 02:44:09 -080047 'webrtc/modules/rtp_rtcp/source', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080048 'webrtc/modules/utility/include',
49 'webrtc/modules/video_coding/codecs/h264/include',
50 'webrtc/modules/video_coding/codecs/i420/include',
51 'webrtc/modules/video_coding/codecs/vp8/include',
52 'webrtc/modules/video_coding/codecs/vp9/include',
53 'webrtc/modules/video_coding/include',
kjellanderfd595232015-12-04 02:44:09 -080054 'webrtc/system_wrappers/include', # DEPRECATED.
kjellander53047c92015-12-02 23:56:14 -080055 'webrtc/voice_engine/include',
56)
57
58
59def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
60 """Ensures the list of native API header directories is up to date."""
61 non_existing_paths = []
62 native_api_full_paths = [
63 input_api.os_path.join(input_api.PresubmitLocalPath(),
64 *path.split('/')) for path in NATIVE_API_DIRS]
65 for path in native_api_full_paths:
66 if not os.path.isdir(path):
67 non_existing_paths.append(path)
68 if non_existing_paths:
69 return [output_api.PresubmitError(
70 'Directories to native API headers have changed which has made the '
71 'list in PRESUBMIT.py outdated.\nPlease update it to the current '
72 'location of our native APIs.',
73 non_existing_paths)]
74 return []
75
76
77def _CheckNativeApiHeaderChanges(input_api, output_api):
78 """Checks to remind proper changing of native APIs."""
79 files = []
80 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
81 if f.LocalPath().endswith('.h'):
82 for path in NATIVE_API_DIRS:
83 if os.path.dirname(f.LocalPath()) == path:
84 files.append(f)
85
86 if files:
kjellanderffea13c2015-12-08 01:57:17 -080087 return [output_api.PresubmitNotifyResult(
kjellander53047c92015-12-02 23:56:14 -080088 'You seem to be changing native API header files. Please make sure '
89 'you:\n'
90 ' 1. Make compatible changes that don\'t break existing clients.\n'
91 ' 2. Mark the old APIs as deprecated.\n'
92 ' 3. Create a timeline and plan for when the deprecated method will '
93 'be removed (preferably 3 months or so).\n'
94 ' 4. Update/inform existing downstream code owners to stop using the '
95 'deprecated APIs: \n'
96 'send announcement to discuss-webrtc@googlegroups.com and '
97 'webrtc-users@google.com.\n'
98 ' 5. (after ~3 months) remove the deprecated API.\n'
99 'Related files:',
100 files)]
101 return []
102
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100103
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000104def _CheckNoIOStreamInHeaders(input_api, output_api):
105 """Checks to make sure no .h files include <iostream>."""
106 files = []
107 pattern = input_api.re.compile(r'^#include\s*<iostream>',
108 input_api.re.MULTILINE)
109 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
110 if not f.LocalPath().endswith('.h'):
111 continue
112 contents = input_api.ReadFile(f)
113 if pattern.search(contents):
114 files.append(f)
115
116 if len(files):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200117 return [output_api.PresubmitError(
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000118 'Do not #include <iostream> in header files, since it inserts static ' +
119 'initialization into every file including the header. Instead, ' +
120 '#include <ostream>. See http://crbug.com/94794',
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200121 files)]
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000122 return []
123
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000124
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000125def _CheckNoFRIEND_TEST(input_api, output_api):
126 """Make sure that gtest's FRIEND_TEST() macro is not used, the
127 FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
128 used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
129 problems = []
130
131 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
132 for f in input_api.AffectedFiles(file_filter=file_filter):
133 for line_num, line in f.ChangedContents():
134 if 'FRIEND_TEST(' in line:
135 problems.append(' %s:%d' % (f.LocalPath(), line_num))
136
137 if not problems:
138 return []
139 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
140 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
141 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
142
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000143
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100144def _IsLintWhitelisted(whitelist_dirs, file_path):
145 """ Checks if a file is whitelisted for lint check."""
146 for path in whitelist_dirs:
147 if os.path.dirname(file_path).startswith(path):
148 return True
149 return False
150
151
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000152def _CheckApprovedFilesLintClean(input_api, output_api,
153 source_file_filter=None):
154 """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000155 This check is based on _CheckChangeLintsClean in
156 depot_tools/presubmit_canned_checks.py but has less filters and only checks
157 added files."""
158 result = []
159
160 # Initialize cpplint.
161 import cpplint
162 # Access to a protected member _XX of a client class
163 # pylint: disable=W0212
164 cpplint._cpplint_state.ResetErrorCounts()
165
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100166 # Create a platform independent whitelist for the CPPLINT_DIRS.
167 whitelist_dirs = [input_api.os_path.join(*path.split('/'))
168 for path in CPPLINT_DIRS]
169
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000170 # Use the strictest verbosity level for cpplint.py (level 1) which is the
171 # default when running cpplint.py from command line.
172 # To make it possible to work with not-yet-converted code, we're only applying
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000173 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000174 verbosity_level = 1
175 files = []
176 for f in input_api.AffectedSourceFiles(source_file_filter):
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200177 # Note that moved/renamed files also count as added.
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100178 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000179 files.append(f.AbsoluteLocalPath())
mflodman@webrtc.org2a452092012-07-01 05:55:23 +0000180
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000181 for file_name in files:
182 cpplint.ProcessFile(file_name, verbosity_level)
183
184 if cpplint._cpplint_state.error_count > 0:
185 if input_api.is_committing:
186 # TODO(kjellander): Change back to PresubmitError below when we're
187 # confident with the lint settings.
188 res_type = output_api.PresubmitPromptWarning
189 else:
190 res_type = output_api.PresubmitPromptWarning
191 result = [res_type('Changelist failed cpplint.py check.')]
192
193 return result
194
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000195def _CheckNoRtcBaseDeps(input_api, gyp_files, output_api):
196 pattern = input_api.re.compile(r"base.gyp:rtc_base\s*'")
197 violating_files = []
198 for f in gyp_files:
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000199 gyp_exceptions = (
200 'base_tests.gyp',
201 'desktop_capture.gypi',
202 'libjingle.gyp',
henrike@webrtc.org28af6412014-11-04 15:11:46 +0000203 'libjingle_tests.gyp',
kjellander@webrtc.orge7237282015-02-26 11:12:17 +0000204 'p2p.gyp',
henrike@webrtc.org36b0c1a2014-10-01 14:40:58 +0000205 'sound.gyp',
206 'webrtc_test_common.gyp',
207 'webrtc_tests.gypi',
208 )
209 if f.LocalPath().endswith(gyp_exceptions):
210 continue
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000211 contents = input_api.ReadFile(f)
212 if pattern.search(contents):
213 violating_files.append(f)
214 if violating_files:
215 return [output_api.PresubmitError(
216 'Depending on rtc_base is not allowed. Change your dependency to '
217 'rtc_base_approved and possibly sanitize and move the desired source '
218 'file(s) to rtc_base_approved.\nChanged GYP files:',
219 items=violating_files)]
220 return []
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000221
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000222def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api):
223 # Disallow referencing source files with paths above the GYP file location.
224 source_pattern = input_api.re.compile(r'sources.*?\[(.*?)\]',
225 re.MULTILINE | re.DOTALL)
kjellander@webrtc.orga33f05e2015-01-29 14:29:45 +0000226 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'")
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000227 violating_gyp_files = set()
228 violating_source_entries = []
229 for gyp_file in gyp_files:
230 contents = input_api.ReadFile(gyp_file)
231 for source_block_match in source_pattern.finditer(contents):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000232 # Find all source list entries starting with ../ in the source block
233 # (exclude overrides entries).
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000234 for file_list_match in file_pattern.finditer(source_block_match.group(0)):
kjellander@webrtc.orgc98f6f32015-03-04 07:08:11 +0000235 source_file = file_list_match.group(0)
236 if 'overrides/' not in source_file:
237 violating_source_entries.append(source_file)
238 violating_gyp_files.add(gyp_file)
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000239 if violating_gyp_files:
240 return [output_api.PresubmitError(
241 'Referencing source files above the directory of the GYP file is not '
242 'allowed. Please introduce new GYP targets and/or GYP files in the '
243 'proper location instead.\n'
244 'Invalid source entries:\n'
245 '%s\n'
246 'Violating GYP files:' % '\n'.join(violating_source_entries),
247 items=violating_gyp_files)]
248 return []
249
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000250def _CheckGypChanges(input_api, output_api):
251 source_file_filter = lambda x: input_api.FilterSourceFile(
252 x, white_list=(r'.+\.(gyp|gypi)$',))
253
254 gyp_files = []
255 for f in input_api.AffectedSourceFiles(source_file_filter):
kjellander@webrtc.org3398a4a2014-11-24 10:05:37 +0000256 if f.LocalPath().startswith('webrtc'):
257 gyp_files.append(f)
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000258
259 result = []
260 if gyp_files:
261 result.append(output_api.PresubmitNotifyResult(
262 'As you\'re changing GYP files: please make sure corresponding '
263 'BUILD.gn files are also updated.\nChanged GYP files:',
264 items=gyp_files))
henrike@webrtc.org83fe69d2014-09-30 21:54:26 +0000265 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api))
kjellander@webrtc.orgf68ffca2015-01-27 13:13:24 +0000266 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000267 return result
268
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000269def _CheckUnwantedDependencies(input_api, output_api):
270 """Runs checkdeps on #include statements added in this
271 change. Breaking - rules is an error, breaking ! rules is a
272 warning.
273 """
274 # Copied from Chromium's src/PRESUBMIT.py.
275
276 # We need to wait until we have an input_api object and use this
277 # roundabout construct to import checkdeps because this file is
278 # eval-ed and thus doesn't have __file__.
279 original_sys_path = sys.path
280 try:
kjellander@webrtc.orgaefe61a2014-12-08 13:00:30 +0000281 checkdeps_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
282 'buildtools', 'checkdeps')
283 if not os.path.exists(checkdeps_path):
284 return [output_api.PresubmitError(
285 'Cannot find checkdeps at %s\nHave you run "gclient sync" to '
286 'download Chromium and setup the symlinks?' % checkdeps_path)]
287 sys.path.append(checkdeps_path)
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000288 import checkdeps
289 from cpp_checker import CppChecker
290 from rules import Rule
291 finally:
292 # Restore sys.path to what it was before.
293 sys.path = original_sys_path
294
295 added_includes = []
296 for f in input_api.AffectedFiles():
297 if not CppChecker.IsCppFile(f.LocalPath()):
298 continue
299
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200300 changed_lines = [line for _, line in f.ChangedContents()]
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000301 added_includes.append([f.LocalPath(), changed_lines])
302
303 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
304
305 error_descriptions = []
306 warning_descriptions = []
307 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
308 added_includes):
309 description_with_path = '%s\n %s' % (path, rule_description)
310 if rule_type == Rule.DISALLOW:
311 error_descriptions.append(description_with_path)
312 else:
313 warning_descriptions.append(description_with_path)
314
315 results = []
316 if error_descriptions:
317 results.append(output_api.PresubmitError(
318 'You added one or more #includes that violate checkdeps rules.',
319 error_descriptions))
320 if warning_descriptions:
321 results.append(output_api.PresubmitPromptOrNotify(
322 'You added one or more #includes of files that are temporarily\n'
323 'allowed but being removed. Can you avoid introducing the\n'
324 '#include? See relevant DEPS file(s) for details and contacts.',
325 warning_descriptions))
326 return results
327
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000328
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200329def _RunPythonTests(input_api, output_api):
330 def join(*args):
331 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
332
333 test_directories = [
334 join('tools', 'autoroller', 'unittests'),
335 ]
336
337 tests = []
338 for directory in test_directories:
339 tests.extend(
340 input_api.canned_checks.GetUnitTestsInDirectory(
341 input_api,
342 output_api,
343 directory,
344 whitelist=[r'.+_test\.py$']))
345 return input_api.RunTests(tests, parallel=True)
346
347
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000348def _CommonChecks(input_api, output_api):
349 """Checks common to both upload and commit."""
niklase@google.comda159d62011-05-30 11:51:34 +0000350 results = []
tkchin42f580e2015-11-26 23:18:23 -0800351 # Filter out files that are in objc or ios dirs from being cpplint-ed since
352 # they do not follow C++ lint rules.
353 black_list = input_api.DEFAULT_BLACK_LIST + (
354 r".*\bobjc[\\\/].*",
355 )
356 source_file_filter = lambda x: input_api.FilterSourceFile(x, None, black_list)
357 results.extend(_CheckApprovedFilesLintClean(
358 input_api, output_api, source_file_filter))
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000359 results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
360 black_list=(r'^.*gviz_api\.py$',
361 r'^.*gaeunit\.py$',
fischman@webrtc.org33584f92013-07-25 16:43:30 +0000362 # Embedded shell-script fakes out pylint.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200363 r'^build[\\\/].*\.py$',
364 r'^buildtools[\\\/].*\.py$',
365 r'^chromium[\\\/].*\.py$',
366 r'^google_apis[\\\/].*\.py$',
367 r'^net.*[\\\/].*\.py$',
368 r'^out.*[\\\/].*\.py$',
369 r'^testing[\\\/].*\.py$',
370 r'^third_party[\\\/].*\.py$',
371 r'^tools[\\\/]find_depot_tools.py$',
372 r'^tools[\\\/]clang[\\\/].*\.py$',
373 r'^tools[\\\/]generate_library_loader[\\\/].*\.py$',
374 r'^tools[\\\/]gn[\\\/].*\.py$',
375 r'^tools[\\\/]gyp[\\\/].*\.py$',
Henrik Kjellanderd6d27e72015-09-25 22:19:11 +0200376 r'^tools[\\\/]isolate_driver.py$',
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200377 r'^tools[\\\/]protoc_wrapper[\\\/].*\.py$',
378 r'^tools[\\\/]python[\\\/].*\.py$',
379 r'^tools[\\\/]python_charts[\\\/]data[\\\/].*\.py$',
380 r'^tools[\\\/]refactoring[\\\/].*\.py$',
381 r'^tools[\\\/]swarming_client[\\\/].*\.py$',
382 r'^tools[\\\/]vim[\\\/].*\.py$',
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000383 # TODO(phoglund): should arguably be checked.
Henrik Kjellander14771ac2015-06-02 13:10:04 +0200384 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
385 r'^tools[\\\/]valgrind[\\\/].*\.py$',
386 r'^tools[\\\/]win[\\\/].*\.py$',
387 r'^xcodebuild.*[\\\/].*\.py$',),
phoglund@webrtc.org5d3713932013-03-07 09:59:43 +0000388 disabled_warnings=['F0401', # Failed to import x
389 'E0611', # No package y in x
390 'W0232', # Class has no __init__ method
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200391 ],
392 pylintrc='pylintrc'))
393 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
394 # we need to have different license checks in talk/ and webrtc/ directories.
395 # Instead, hand-picked checks are included below.
Henrik Kjellander63224672015-09-08 08:03:56 +0200396
397 # Skip long-lines check for DEPS, GN and GYP files.
398 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
399 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000400 results.extend(input_api.canned_checks.CheckLongLines(
Henrik Kjellander63224672015-09-08 08:03:56 +0200401 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000402 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
403 input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000404 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
405 input_api, output_api))
406 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
407 input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800408 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000409 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
410 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000411 results.extend(_CheckGypChanges(input_api, output_api))
kjellander@webrtc.org3bd41562014-09-01 11:06:37 +0000412 results.extend(_CheckUnwantedDependencies(input_api, output_api))
Henrik Kjellander8d3ad822015-05-26 19:52:05 +0200413 results.extend(_RunPythonTests(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000414 return results
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000415
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000416
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000417def CheckChangeOnUpload(input_api, output_api):
418 results = []
419 results.extend(_CommonChecks(input_api, output_api))
Henrik Kjellander57e5fd22015-05-25 12:55:39 +0200420 results.extend(
421 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
niklase@google.comda159d62011-05-30 11:51:34 +0000422 return results
423
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000424
andrew@webrtc.org2442de12012-01-23 17:45:41 +0000425def CheckChangeOnCommit(input_api, output_api):
niklase@google.com1198db92011-06-09 07:07:24 +0000426 results = []
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000427 results.extend(_CommonChecks(input_api, output_api))
kjellander53047c92015-12-02 23:56:14 -0800428 results.extend(_VerifyNativeApiHeadersListIsValid(input_api, output_api))
niklase@google.com1198db92011-06-09 07:07:24 +0000429 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
andrew@webrtc.org53df1362012-01-26 21:24:23 +0000430 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
431 input_api, output_api))
432 results.extend(input_api.canned_checks.CheckChangeHasDescription(
433 input_api, output_api))
kjellander@webrtc.org51198f12012-02-21 17:53:46 +0000434 results.extend(input_api.canned_checks.CheckChangeHasBugField(
435 input_api, output_api))
436 results.extend(input_api.canned_checks.CheckChangeHasTestField(
437 input_api, output_api))
kjellander@webrtc.org12cb88c2014-02-13 11:53:43 +0000438 results.extend(input_api.canned_checks.CheckTreeIsOpen(
439 input_api, output_api,
440 json_url='http://webrtc-status.appspot.com/current?format=json'))
niklase@google.com1198db92011-06-09 07:07:24 +0000441 return results
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000442
kjellander@webrtc.orge4158642014-08-06 09:11:18 +0000443
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000444# pylint: disable=W0613
kjellander@webrtc.orgc7b8b2f2014-04-03 20:19:36 +0000445def GetPreferredTryMasters(project, change):
kjellander986ee082015-06-16 04:32:13 -0700446 cq_config_path = os.path.join(
tandrii04465d22015-06-20 04:00:49 -0700447 change.RepositoryRoot(), 'infra', 'config', 'cq.cfg')
kjellander986ee082015-06-16 04:32:13 -0700448 # commit_queue.py below is a script in depot_tools directory, which has a
449 # 'builders' command to retrieve a list of CQ builders from the CQ config.
450 is_win = platform.system() == 'Windows'
451 masters = json.loads(subprocess.check_output(
452 ['commit_queue', 'builders', cq_config_path], shell=is_win))
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000453
kjellander986ee082015-06-16 04:32:13 -0700454 try_config = {}
455 for master in masters:
456 try_config.setdefault(master, {})
457 for builder in masters[master]:
458 if 'presubmit' in builder:
459 # Do not trigger presubmit builders, since they're likely to fail
460 # (e.g. OWNERS checks before finished code review), and we're running
461 # local presubmit anyway.
462 pass
463 else:
464 try_config[master][builder] = ['defaulttests']
kjellander@webrtc.org85759802013-10-22 16:47:40 +0000465
kjellander986ee082015-06-16 04:32:13 -0700466 return try_config