blob: c875e48f00d9bec495598fa169ed8ca0bfa31c56 [file] [log] [blame]
[email protected]a18130a2012-01-03 17:52:081# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ca8d19842009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d19842009-02-19 16:33:129"""
10
[email protected]eea609a2011-11-18 13:10:1211
[email protected]379e7dd2010-01-28 17:39:2112_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5413 r"^breakpad[\\\/].*",
[email protected]40d1dbb2012-10-26 07:18:0014 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
15 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
[email protected]8886ffcb2013-02-12 04:56:2816 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
[email protected]a18130a2012-01-03 17:52:0817 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
[email protected]3e4eb112011-01-18 03:29:5418 r"^skia[\\\/].*",
19 r"^v8[\\\/].*",
20 r".*MakeFile$",
[email protected]1084ccc2012-03-14 03:22:5321 r".+_autogen\.h$",
[email protected]ce145c02012-09-06 09:49:3422 r".+[\\\/]pnacl_shim\.c$",
[email protected]e07b6ac72013-08-20 00:30:4223 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
[email protected]d2600602014-02-19 00:09:1924 r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js"
[email protected]4306417642009-06-11 00:33:4025)
[email protected]ca8d19842009-02-19 16:33:1226
jochen9ea8fdbc2014-09-25 13:21:3527# The NetscapePlugIn library is excluded from pan-project as it will soon
28# be deleted together with the rest of the NPAPI and it's not worthwhile to
29# update the coding style until then.
[email protected]3de922f2013-12-20 13:27:3830_TESTRUNNER_PATHS = (
[email protected]de28fed2e2014-02-01 14:36:3231 r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
[email protected]3de922f2013-12-20 13:27:3832)
33
[email protected]06e6d0ff2012-12-11 01:36:4434# Fragment of a regular expression that matches C++ and Objective-C++
35# implementation files.
36_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
37
38# Regular expression that matches code only used for test binaries
39# (best effort).
40_TEST_CODE_EXCLUDED_PATHS = (
joaodasilva718f87672014-08-30 09:25:4941 r'.*[\\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4442 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
[email protected]6e04f8c2014-01-29 18:08:3243 r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
[email protected]e2d7e6f2013-04-23 12:57:1244 _IMPLEMENTATION_EXTENSIONS,
[email protected]06e6d0ff2012-12-11 01:36:4445 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
joaodasilva718f87672014-08-30 09:25:4946 r'.*[\\\/](test|tool(s)?)[\\\/].*',
[email protected]ef070cc2013-05-03 11:53:0547 # content_shell is used for running layout tests.
joaodasilva718f87672014-08-30 09:25:4948 r'content[\\\/]shell[\\\/].*',
[email protected]06e6d0ff2012-12-11 01:36:4449 # At request of folks maintaining this folder.
joaodasilva718f87672014-08-30 09:25:4950 r'chrome[\\\/]browser[\\\/]automation[\\\/].*',
[email protected]7b054982013-11-27 00:44:4751 # Non-production example code.
joaodasilva718f87672014-08-30 09:25:4952 r'mojo[\\\/]examples[\\\/].*',
[email protected]8176de12014-06-20 19:07:0853 # Launcher for running iOS tests on the simulator.
joaodasilva718f87672014-08-30 09:25:4954 r'testing[\\\/]iossim[\\\/]iossim\.mm$',
[email protected]06e6d0ff2012-12-11 01:36:4455)
[email protected]ca8d19842009-02-19 16:33:1256
[email protected]eea609a2011-11-18 13:10:1257_TEST_ONLY_WARNING = (
58 'You might be calling functions intended only for testing from\n'
59 'production code. It is OK to ignore this warning if you know what\n'
60 'you are doing, as the heuristics used to detect the situation are\n'
[email protected]b0149772014-03-27 16:47:5861 'not perfect. The commit queue will not block on this warning.')
[email protected]eea609a2011-11-18 13:10:1262
63
[email protected]cf9b78f2012-11-14 11:40:2864_INCLUDE_ORDER_WARNING = (
65 'Your #include order seems to be broken. Send mail to\n'
66 '[email protected] if this is not the case.')
67
68
[email protected]127f18ec2012-06-16 05:05:5969_BANNED_OBJC_FUNCTIONS = (
70 (
71 'addTrackingRect:',
[email protected]23e6cbc2012-06-16 18:51:2072 (
73 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
[email protected]127f18ec2012-06-16 05:05:5974 'prohibited. Please use CrTrackingArea instead.',
75 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
76 ),
77 False,
78 ),
79 (
[email protected]eaae1972014-04-16 04:17:2680 r'/NSTrackingArea\W',
[email protected]23e6cbc2012-06-16 18:51:2081 (
82 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
[email protected]127f18ec2012-06-16 05:05:5983 'instead.',
84 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
85 ),
86 False,
87 ),
88 (
89 'convertPointFromBase:',
[email protected]23e6cbc2012-06-16 18:51:2090 (
91 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:5992 'Please use |convertPoint:(point) fromView:nil| instead.',
93 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
94 ),
95 True,
96 ),
97 (
98 'convertPointToBase:',
[email protected]23e6cbc2012-06-16 18:51:2099 (
100 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59101 'Please use |convertPoint:(point) toView:nil| instead.',
102 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
103 ),
104 True,
105 ),
106 (
107 'convertRectFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20108 (
109 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59110 'Please use |convertRect:(point) fromView:nil| instead.',
111 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
112 ),
113 True,
114 ),
115 (
116 'convertRectToBase:',
[email protected]23e6cbc2012-06-16 18:51:20117 (
118 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59119 'Please use |convertRect:(point) toView:nil| instead.',
120 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
121 ),
122 True,
123 ),
124 (
125 'convertSizeFromBase:',
[email protected]23e6cbc2012-06-16 18:51:20126 (
127 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59128 'Please use |convertSize:(point) fromView:nil| instead.',
129 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
130 ),
131 True,
132 ),
133 (
134 'convertSizeToBase:',
[email protected]23e6cbc2012-06-16 18:51:20135 (
136 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
[email protected]127f18ec2012-06-16 05:05:59137 'Please use |convertSize:(point) toView:nil| instead.',
138 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
139 ),
140 True,
141 ),
142)
143
144
145_BANNED_CPP_FUNCTIONS = (
[email protected]23e6cbc2012-06-16 18:51:20146 # Make sure that gtest's FRIEND_TEST() macro is not used; the
147 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
[email protected]e00ccc92012-11-01 17:32:30148 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
[email protected]23e6cbc2012-06-16 18:51:20149 (
150 'FRIEND_TEST(',
151 (
[email protected]e3c945502012-06-26 20:01:49152 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
[email protected]23e6cbc2012-06-16 18:51:20153 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
154 ),
155 False,
[email protected]7345da02012-11-27 14:31:49156 (),
[email protected]23e6cbc2012-06-16 18:51:20157 ),
158 (
159 'ScopedAllowIO',
160 (
[email protected]e3c945502012-06-26 20:01:49161 'New code should not use ScopedAllowIO. Post a task to the blocking',
162 'pool or the FILE thread instead.',
[email protected]23e6cbc2012-06-16 18:51:20163 ),
[email protected]e3c945502012-06-26 20:01:49164 True,
[email protected]7345da02012-11-27 14:31:49165 (
thestig75844fdb2014-09-09 19:47:10166 r"^base[\\\/]process[\\\/]process_metrics_linux\.cc$",
[email protected]b01b9e22014-06-03 22:20:19167 r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_loader\.cc$",
alematee4016bb2014-11-12 17:38:51168 r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]"
169 "customization_document_browsertest\.cc$",
philipj3f9d5bde2014-08-28 14:09:09170 r"^components[\\\/]crash[\\\/]app[\\\/]breakpad_mac\.mm$",
[email protected]de7d61ff2013-08-20 11:30:41171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
jamesra03ae492014-10-03 04:26:48173 r"^mojo[\\\/]edk[\\\/]embedder[\\\/]" +
174 r"simple_platform_shared_buffer_posix\.cc$",
[email protected]398ad132013-04-02 15:11:01175 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
[email protected]1f52a572014-05-12 23:21:54176 r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$",
[email protected]7345da02012-11-27 14:31:49177 ),
[email protected]23e6cbc2012-06-16 18:51:20178 ),
[email protected]52657f62013-05-20 05:30:31179 (
180 'SkRefPtr',
181 (
182 'The use of SkRefPtr is prohibited. ',
183 'Please use skia::RefPtr instead.'
184 ),
185 True,
186 (),
187 ),
188 (
189 'SkAutoRef',
190 (
191 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
192 'Please use skia::RefPtr instead.'
193 ),
194 True,
195 (),
196 ),
197 (
198 'SkAutoTUnref',
199 (
200 'The use of SkAutoTUnref is dangerous because it implicitly ',
201 'converts to a raw pointer. Please use skia::RefPtr instead.'
202 ),
203 True,
204 (),
205 ),
206 (
207 'SkAutoUnref',
208 (
209 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
210 'because it implicitly converts to a raw pointer. ',
211 'Please use skia::RefPtr instead.'
212 ),
213 True,
214 (),
215 ),
[email protected]d89eec82013-12-03 14:10:59216 (
217 r'/HANDLE_EINTR\(.*close',
218 (
219 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
220 'descriptor will be closed, and it is incorrect to retry the close.',
221 'Either call close directly and ignore its return value, or wrap close',
222 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
223 ),
224 True,
225 (),
226 ),
227 (
228 r'/IGNORE_EINTR\((?!.*close)',
229 (
230 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
231 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
232 ),
233 True,
234 (
235 # Files that #define IGNORE_EINTR.
236 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
237 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
238 ),
239 ),
[email protected]ec5b3f02014-04-04 18:43:43240 (
241 r'/v8::Extension\(',
242 (
243 'Do not introduce new v8::Extensions into the code base, use',
244 'gin::Wrappable instead. See http://crbug.com/334679',
245 ),
246 True,
[email protected]f55c90ee62014-04-12 00:50:03247 (
joaodasilva718f87672014-08-30 09:25:49248 r'extensions[\\\/]renderer[\\\/]safe_builtins\.*',
[email protected]f55c90ee62014-04-12 00:50:03249 ),
[email protected]ec5b3f02014-04-04 18:43:43250 ),
[email protected]127f18ec2012-06-16 05:05:59251)
252
mlamouria82272622014-09-16 18:45:04253_IPC_ENUM_TRAITS_DEPRECATED = (
254 'You are using IPC_ENUM_TRAITS() in your code. It has been deprecated.\n'
255 'See http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc')
256
[email protected]127f18ec2012-06-16 05:05:59257
[email protected]b00342e7f2013-03-26 16:21:54258_VALID_OS_MACROS = (
259 # Please keep sorted.
260 'OS_ANDROID',
[email protected]f4440b42014-03-19 05:47:01261 'OS_ANDROID_HOST',
[email protected]b00342e7f2013-03-26 16:21:54262 'OS_BSD',
263 'OS_CAT', # For testing.
264 'OS_CHROMEOS',
265 'OS_FREEBSD',
266 'OS_IOS',
267 'OS_LINUX',
268 'OS_MACOSX',
269 'OS_NACL',
hidehikof7295f22014-10-28 11:57:21270 'OS_NACL_NONSFI',
271 'OS_NACL_SFI',
[email protected]b00342e7f2013-03-26 16:21:54272 'OS_OPENBSD',
273 'OS_POSIX',
[email protected]eda7afa12014-02-06 12:27:37274 'OS_QNX',
[email protected]b00342e7f2013-03-26 16:21:54275 'OS_SOLARIS',
[email protected]b00342e7f2013-03-26 16:21:54276 'OS_WIN',
277)
278
279
[email protected]55459852011-08-10 15:17:19280def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
281 """Attempts to prevent use of functions intended only for testing in
282 non-testing code. For now this is just a best-effort implementation
283 that ignores header files and may have some false positives. A
284 better implementation would probably need a proper C++ parser.
285 """
286 # We only scan .cc files and the like, as the declaration of
287 # for-testing functions in header files are hard to distinguish from
288 # calls to such functions without a proper C++ parser.
[email protected]06e6d0ff2012-12-11 01:36:44289 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
[email protected]55459852011-08-10 15:17:19290
[email protected]23501822014-05-14 02:06:09291 base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?'
[email protected]55459852011-08-10 15:17:19292 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
[email protected]23501822014-05-14 02:06:09293 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern)
[email protected]55459852011-08-10 15:17:19294 exclusion_pattern = input_api.re.compile(
295 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
296 base_function_pattern, base_function_pattern))
297
298 def FilterFile(affected_file):
[email protected]06e6d0ff2012-12-11 01:36:44299 black_list = (_EXCLUDED_PATHS +
300 _TEST_CODE_EXCLUDED_PATHS +
301 input_api.DEFAULT_BLACK_LIST)
[email protected]55459852011-08-10 15:17:19302 return input_api.FilterSourceFile(
303 affected_file,
304 white_list=(file_inclusion_pattern, ),
305 black_list=black_list)
306
307 problems = []
308 for f in input_api.AffectedSourceFiles(FilterFile):
309 local_path = f.LocalPath()
[email protected]825d27182014-01-02 21:24:24310 for line_number, line in f.ChangedContents():
[email protected]2fdd1f362013-01-16 03:56:03311 if (inclusion_pattern.search(line) and
[email protected]de4f7d22013-05-23 14:27:46312 not comment_pattern.search(line) and
[email protected]2fdd1f362013-01-16 03:56:03313 not exclusion_pattern.search(line)):
[email protected]55459852011-08-10 15:17:19314 problems.append(
[email protected]2fdd1f362013-01-16 03:56:03315 '%s:%d\n %s' % (local_path, line_number, line.strip()))
[email protected]55459852011-08-10 15:17:19316
317 if problems:
[email protected]f7051d52013-04-02 18:31:42318 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
[email protected]2fdd1f362013-01-16 03:56:03319 else:
320 return []
[email protected]55459852011-08-10 15:17:19321
322
[email protected]10689ca2011-09-02 02:31:54323def _CheckNoIOStreamInHeaders(input_api, output_api):
324 """Checks to make sure no .h files include <iostream>."""
325 files = []
326 pattern = input_api.re.compile(r'^#include\s*<iostream>',
327 input_api.re.MULTILINE)
328 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
329 if not f.LocalPath().endswith('.h'):
330 continue
331 contents = input_api.ReadFile(f)
332 if pattern.search(contents):
333 files.append(f)
334
335 if len(files):
336 return [ output_api.PresubmitError(
[email protected]6c063c62012-07-11 19:11:06337 'Do not #include <iostream> in header files, since it inserts static '
338 'initialization into every file including the header. Instead, '
[email protected]10689ca2011-09-02 02:31:54339 '#include <ostream>. See http://crbug.com/94794',
340 files) ]
341 return []
342
343
[email protected]72df4e782012-06-21 16:28:18344def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
345 """Checks to make sure no source files use UNIT_TEST"""
346 problems = []
347 for f in input_api.AffectedFiles():
348 if (not f.LocalPath().endswith(('.cc', '.mm'))):
349 continue
350
351 for line_num, line in f.ChangedContents():
[email protected]549f86a2013-11-19 13:00:04352 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
[email protected]72df4e782012-06-21 16:28:18353 problems.append(' %s:%d' % (f.LocalPath(), line_num))
354
355 if not problems:
356 return []
357 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
358 '\n'.join(problems))]
359
mcasas2ece52702014-12-02 15:37:23360def _CheckUmaHistogramChanges(input_api, output_api):
361 """Check that UMA histogram names in touched lines can still be found in other
362 lines of the patch or in histograms.xml. Note that this check would not catch
363 the reverse: changes in histograms.xml not matched in the code itself."""
364
365 touched_histograms = []
366 histograms_xml_modifications = []
367 pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"')
368 for f in input_api.AffectedFiles():
369 # If histograms.xml itself is modified, keep the modified lines for later.
370 if (f.LocalPath().endswith(('histograms.xml'))):
371 histograms_xml_modifications = f.ChangedContents()
372 continue
373 if (not f.LocalPath().endswith(('cc', 'mm', 'cpp'))):
374 continue
375 for line_num, line in f.ChangedContents():
376 found = pattern.search(line)
377 if found:
378 touched_histograms.append([found.group(1), f, line_num])
379
380 # Search for the touched histogram names in the local modifications to
381 # histograms.xml, and if not found on the base file.
382 problems = []
383 for histogram_name, f, line_num in touched_histograms:
384 histogram_name_found = False
385 for line_num, line in histograms_xml_modifications:
386 if histogram_name in line:
387 histogram_name_found = True;
388 break;
389 if histogram_name_found:
390 continue
391
392 with open('tools/metrics/histograms/histograms.xml') as histograms_xml:
393 for line in histograms_xml:
394 if histogram_name in line:
395 histogram_name_found = True;
396 break;
397 if histogram_name_found:
398 continue
399 problems.append(' [%s:%d] %s' % (f.LocalPath(), line_num, histogram_name))
400
401 if not problems:
402 return []
403 return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have '
404 'been modified and the associated histogram name has no match in either '
405 'metrics/histograms.xml or the modifications of it:', problems)]
406
[email protected]72df4e782012-06-21 16:28:18407
[email protected]8ea5d4b2011-09-13 21:49:22408def _CheckNoNewWStrings(input_api, output_api):
409 """Checks to make sure we don't introduce use of wstrings."""
[email protected]55463aa62011-10-12 00:48:27410 problems = []
[email protected]8ea5d4b2011-09-13 21:49:22411 for f in input_api.AffectedFiles():
[email protected]b5c24292011-11-28 14:38:20412 if (not f.LocalPath().endswith(('.cc', '.h')) or
scottmge6f04402014-11-05 01:59:57413 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or
414 '/win/' in f.LocalPath()):
[email protected]b5c24292011-11-28 14:38:20415 continue
[email protected]8ea5d4b2011-09-13 21:49:22416
[email protected]a11dbe9b2012-08-07 01:32:58417 allowWString = False
[email protected]b5c24292011-11-28 14:38:20418 for line_num, line in f.ChangedContents():
[email protected]a11dbe9b2012-08-07 01:32:58419 if 'presubmit: allow wstring' in line:
420 allowWString = True
421 elif not allowWString and 'wstring' in line:
[email protected]55463aa62011-10-12 00:48:27422 problems.append(' %s:%d' % (f.LocalPath(), line_num))
[email protected]a11dbe9b2012-08-07 01:32:58423 allowWString = False
424 else:
425 allowWString = False
[email protected]8ea5d4b2011-09-13 21:49:22426
[email protected]55463aa62011-10-12 00:48:27427 if not problems:
428 return []
429 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
[email protected]a11dbe9b2012-08-07 01:32:58430 ' If you are calling a cross-platform API that accepts a wstring, '
431 'fix the API.\n' +
[email protected]55463aa62011-10-12 00:48:27432 '\n'.join(problems))]
[email protected]8ea5d4b2011-09-13 21:49:22433
434
[email protected]2a8ac9c2011-10-19 17:20:44435def _CheckNoDEPSGIT(input_api, output_api):
436 """Make sure .DEPS.git is never modified manually."""
437 if any(f.LocalPath().endswith('.DEPS.git') for f in
438 input_api.AffectedFiles()):
439 return [output_api.PresubmitError(
440 'Never commit changes to .DEPS.git. This file is maintained by an\n'
441 'automated system based on what\'s in DEPS and your changes will be\n'
442 'overwritten.\n'
[email protected]cb706912014-06-28 20:46:34443 'See https://sites.google.com/a/chromium.org/dev/developers/how-tos/get-the-code#Rolling_DEPS\n'
[email protected]2a8ac9c2011-10-19 17:20:44444 'for more information')]
445 return []
446
447
tandriief664692014-09-23 14:51:47448def _CheckValidHostsInDEPS(input_api, output_api):
449 """Checks that DEPS file deps are from allowed_hosts."""
450 # Run only if DEPS file has been modified to annoy fewer bystanders.
451 if all(f.LocalPath() != 'DEPS' for f in input_api.AffectedFiles()):
452 return []
453 # Outsource work to gclient verify
454 try:
455 input_api.subprocess.check_output(['gclient', 'verify'])
456 return []
457 except input_api.subprocess.CalledProcessError, error:
458 return [output_api.PresubmitError(
459 'DEPS file must have only git dependencies.',
460 long_text=error.output)]
461
462
[email protected]127f18ec2012-06-16 05:05:59463def _CheckNoBannedFunctions(input_api, output_api):
464 """Make sure that banned functions are not used."""
465 warnings = []
466 errors = []
467
468 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
469 for f in input_api.AffectedFiles(file_filter=file_filter):
470 for line_num, line in f.ChangedContents():
471 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
[email protected]eaae1972014-04-16 04:17:26472 matched = False
473 if func_name[0:1] == '/':
474 regex = func_name[1:]
475 if input_api.re.search(regex, line):
476 matched = True
477 elif func_name in line:
478 matched = True
479 if matched:
[email protected]127f18ec2012-06-16 05:05:59480 problems = warnings;
481 if error:
482 problems = errors;
483 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
484 for message_line in message:
485 problems.append(' %s' % message_line)
486
487 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
488 for f in input_api.AffectedFiles(file_filter=file_filter):
489 for line_num, line in f.ChangedContents():
[email protected]7345da02012-11-27 14:31:49490 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
491 def IsBlacklisted(affected_file, blacklist):
492 local_path = affected_file.LocalPath()
493 for item in blacklist:
494 if input_api.re.match(item, local_path):
495 return True
496 return False
497 if IsBlacklisted(f, excluded_paths):
498 continue
[email protected]d89eec82013-12-03 14:10:59499 matched = False
500 if func_name[0:1] == '/':
501 regex = func_name[1:]
502 if input_api.re.search(regex, line):
503 matched = True
504 elif func_name in line:
505 matched = True
506 if matched:
[email protected]127f18ec2012-06-16 05:05:59507 problems = warnings;
508 if error:
509 problems = errors;
510 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
511 for message_line in message:
512 problems.append(' %s' % message_line)
513
514 result = []
515 if (warnings):
516 result.append(output_api.PresubmitPromptWarning(
517 'Banned functions were used.\n' + '\n'.join(warnings)))
518 if (errors):
519 result.append(output_api.PresubmitError(
520 'Banned functions were used.\n' + '\n'.join(errors)))
521 return result
522
523
[email protected]6c063c62012-07-11 19:11:06524def _CheckNoPragmaOnce(input_api, output_api):
525 """Make sure that banned functions are not used."""
526 files = []
527 pattern = input_api.re.compile(r'^#pragma\s+once',
528 input_api.re.MULTILINE)
529 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
530 if not f.LocalPath().endswith('.h'):
531 continue
532 contents = input_api.ReadFile(f)
533 if pattern.search(contents):
534 files.append(f)
535
536 if files:
537 return [output_api.PresubmitError(
538 'Do not use #pragma once in header files.\n'
539 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
540 files)]
541 return []
542
[email protected]127f18ec2012-06-16 05:05:59543
[email protected]e7479052012-09-19 00:26:12544def _CheckNoTrinaryTrueFalse(input_api, output_api):
545 """Checks to make sure we don't introduce use of foo ? true : false."""
546 problems = []
547 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
548 for f in input_api.AffectedFiles():
549 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
550 continue
551
552 for line_num, line in f.ChangedContents():
553 if pattern.match(line):
554 problems.append(' %s:%d' % (f.LocalPath(), line_num))
555
556 if not problems:
557 return []
558 return [output_api.PresubmitPromptWarning(
559 'Please consider avoiding the "? true : false" pattern if possible.\n' +
560 '\n'.join(problems))]
561
562
[email protected]55f9f382012-07-31 11:02:18563def _CheckUnwantedDependencies(input_api, output_api):
564 """Runs checkdeps on #include statements added in this
565 change. Breaking - rules is an error, breaking ! rules is a
566 warning.
567 """
mohan.reddyf21db962014-10-16 12:26:47568 import sys
[email protected]55f9f382012-07-31 11:02:18569 # We need to wait until we have an input_api object and use this
570 # roundabout construct to import checkdeps because this file is
571 # eval-ed and thus doesn't have __file__.
572 original_sys_path = sys.path
573 try:
574 sys.path = sys.path + [input_api.os_path.join(
[email protected]5298cc982014-05-29 20:53:47575 input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
[email protected]55f9f382012-07-31 11:02:18576 import checkdeps
577 from cpp_checker import CppChecker
578 from rules import Rule
579 finally:
580 # Restore sys.path to what it was before.
581 sys.path = original_sys_path
582
583 added_includes = []
584 for f in input_api.AffectedFiles():
585 if not CppChecker.IsCppFile(f.LocalPath()):
586 continue
587
588 changed_lines = [line for line_num, line in f.ChangedContents()]
589 added_includes.append([f.LocalPath(), changed_lines])
590
[email protected]26385172013-05-09 23:11:35591 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
[email protected]55f9f382012-07-31 11:02:18592
593 error_descriptions = []
594 warning_descriptions = []
595 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
596 added_includes):
597 description_with_path = '%s\n %s' % (path, rule_description)
598 if rule_type == Rule.DISALLOW:
599 error_descriptions.append(description_with_path)
600 else:
601 warning_descriptions.append(description_with_path)
602
603 results = []
604 if error_descriptions:
605 results.append(output_api.PresubmitError(
606 'You added one or more #includes that violate checkdeps rules.',
607 error_descriptions))
608 if warning_descriptions:
[email protected]f7051d52013-04-02 18:31:42609 results.append(output_api.PresubmitPromptOrNotify(
[email protected]55f9f382012-07-31 11:02:18610 'You added one or more #includes of files that are temporarily\n'
611 'allowed but being removed. Can you avoid introducing the\n'
612 '#include? See relevant DEPS file(s) for details and contacts.',
613 warning_descriptions))
614 return results
615
616
[email protected]fbcafe5a2012-08-08 15:31:22617def _CheckFilePermissions(input_api, output_api):
618 """Check that all files have their permissions properly set."""
[email protected]791507202014-02-03 23:19:15619 if input_api.platform == 'win32':
620 return []
mohan.reddyf21db962014-10-16 12:26:47621 args = [input_api.python_executable, 'tools/checkperms/checkperms.py',
622 '--root', input_api.change.RepositoryRoot()]
[email protected]fbcafe5a2012-08-08 15:31:22623 for f in input_api.AffectedFiles():
624 args += ['--file', f.LocalPath()]
[email protected]f0d330f2014-01-30 01:44:34625 checkperms = input_api.subprocess.Popen(args,
626 stdout=input_api.subprocess.PIPE)
627 errors = checkperms.communicate()[0].strip()
[email protected]fbcafe5a2012-08-08 15:31:22628 if errors:
[email protected]f0d330f2014-01-30 01:44:34629 return [output_api.PresubmitError('checkperms.py failed.',
630 errors.splitlines())]
631 return []
[email protected]fbcafe5a2012-08-08 15:31:22632
633
[email protected]c8278b32012-10-30 20:35:49634def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
635 """Makes sure we don't include ui/aura/window_property.h
636 in header files.
637 """
638 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
639 errors = []
640 for f in input_api.AffectedFiles():
641 if not f.LocalPath().endswith('.h'):
642 continue
643 for line_num, line in f.ChangedContents():
644 if pattern.match(line):
645 errors.append(' %s:%d' % (f.LocalPath(), line_num))
646
647 results = []
648 if errors:
649 results.append(output_api.PresubmitError(
650 'Header files should not include ui/aura/window_property.h', errors))
651 return results
652
653
[email protected]cf9b78f2012-11-14 11:40:28654def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
655 """Checks that the lines in scope occur in the right order.
656
657 1. C system files in alphabetical order
658 2. C++ system files in alphabetical order
659 3. Project's .h files
660 """
661
662 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
663 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
664 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
665
666 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
667
668 state = C_SYSTEM_INCLUDES
669
670 previous_line = ''
[email protected]728b9bb2012-11-14 20:38:57671 previous_line_num = 0
[email protected]cf9b78f2012-11-14 11:40:28672 problem_linenums = []
673 for line_num, line in scope:
674 if c_system_include_pattern.match(line):
675 if state != C_SYSTEM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57676 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28677 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57678 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28679 elif cpp_system_include_pattern.match(line):
680 if state == C_SYSTEM_INCLUDES:
681 state = CPP_SYSTEM_INCLUDES
682 elif state == CUSTOM_INCLUDES:
[email protected]728b9bb2012-11-14 20:38:57683 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28684 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57685 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28686 elif custom_include_pattern.match(line):
687 if state != CUSTOM_INCLUDES:
688 state = CUSTOM_INCLUDES
689 elif previous_line and previous_line > line:
[email protected]728b9bb2012-11-14 20:38:57690 problem_linenums.append((line_num, previous_line_num))
[email protected]cf9b78f2012-11-14 11:40:28691 else:
692 problem_linenums.append(line_num)
693 previous_line = line
[email protected]728b9bb2012-11-14 20:38:57694 previous_line_num = line_num
[email protected]cf9b78f2012-11-14 11:40:28695
696 warnings = []
[email protected]728b9bb2012-11-14 20:38:57697 for (line_num, previous_line_num) in problem_linenums:
698 if line_num in changed_linenums or previous_line_num in changed_linenums:
[email protected]cf9b78f2012-11-14 11:40:28699 warnings.append(' %s:%d' % (file_path, line_num))
700 return warnings
701
702
[email protected]ac294a12012-12-06 16:38:43703def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
[email protected]cf9b78f2012-11-14 11:40:28704 """Checks the #include order for the given file f."""
705
[email protected]2299dcf2012-11-15 19:56:24706 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
[email protected]23093b62013-09-20 12:16:30707 # Exclude the following includes from the check:
708 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
709 # specific order.
710 # 2) <atlbase.h>, "build/build_config.h"
711 excluded_include_pattern = input_api.re.compile(
712 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
[email protected]2299dcf2012-11-15 19:56:24713 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
[email protected]3e83618c2013-10-09 22:32:33714 # Match the final or penultimate token if it is xxxtest so we can ignore it
715 # when considering the special first include.
716 test_file_tag_pattern = input_api.re.compile(
717 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
[email protected]0e5c1852012-12-18 20:17:11718 if_pattern = input_api.re.compile(
719 r'\s*#\s*(if|elif|else|endif|define|undef).*')
720 # Some files need specialized order of includes; exclude such files from this
721 # check.
722 uncheckable_includes_pattern = input_api.re.compile(
723 r'\s*#include '
724 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
[email protected]cf9b78f2012-11-14 11:40:28725
726 contents = f.NewContents()
727 warnings = []
728 line_num = 0
729
[email protected]ac294a12012-12-06 16:38:43730 # Handle the special first include. If the first include file is
731 # some/path/file.h, the corresponding including file can be some/path/file.cc,
732 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
733 # etc. It's also possible that no special first include exists.
[email protected]3e83618c2013-10-09 22:32:33734 # If the included file is some/path/file_platform.h the including file could
735 # also be some/path/file_xxxtest_platform.h.
736 including_file_base_name = test_file_tag_pattern.sub(
737 '', input_api.os_path.basename(f.LocalPath()))
738
[email protected]ac294a12012-12-06 16:38:43739 for line in contents:
740 line_num += 1
741 if system_include_pattern.match(line):
742 # No special first include -> process the line again along with normal
743 # includes.
744 line_num -= 1
745 break
746 match = custom_include_pattern.match(line)
747 if match:
748 match_dict = match.groupdict()
[email protected]3e83618c2013-10-09 22:32:33749 header_basename = test_file_tag_pattern.sub(
750 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
751
752 if header_basename not in including_file_base_name:
[email protected]2299dcf2012-11-15 19:56:24753 # No special first include -> process the line again along with normal
754 # includes.
755 line_num -= 1
[email protected]ac294a12012-12-06 16:38:43756 break
[email protected]cf9b78f2012-11-14 11:40:28757
758 # Split into scopes: Each region between #if and #endif is its own scope.
759 scopes = []
760 current_scope = []
761 for line in contents[line_num:]:
762 line_num += 1
[email protected]0e5c1852012-12-18 20:17:11763 if uncheckable_includes_pattern.match(line):
[email protected]4436c9e2014-01-07 23:19:54764 continue
[email protected]2309b0fa02012-11-16 12:18:27765 if if_pattern.match(line):
[email protected]cf9b78f2012-11-14 11:40:28766 scopes.append(current_scope)
767 current_scope = []
[email protected]962f117e2012-11-22 18:11:56768 elif ((system_include_pattern.match(line) or
769 custom_include_pattern.match(line)) and
770 not excluded_include_pattern.match(line)):
[email protected]cf9b78f2012-11-14 11:40:28771 current_scope.append((line_num, line))
772 scopes.append(current_scope)
773
774 for scope in scopes:
775 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
776 changed_linenums))
777 return warnings
778
779
780def _CheckIncludeOrder(input_api, output_api):
781 """Checks that the #include order is correct.
782
783 1. The corresponding header for source files.
784 2. C system files in alphabetical order
785 3. C++ system files in alphabetical order
786 4. Project's .h files in alphabetical order
787
[email protected]ac294a12012-12-06 16:38:43788 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
789 these rules separately.
[email protected]cf9b78f2012-11-14 11:40:28790 """
[email protected]e120b012014-08-15 19:08:35791 def FileFilterIncludeOrder(affected_file):
792 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
793 return input_api.FilterSourceFile(affected_file, black_list=black_list)
[email protected]cf9b78f2012-11-14 11:40:28794
795 warnings = []
[email protected]e120b012014-08-15 19:08:35796 for f in input_api.AffectedFiles(file_filter=FileFilterIncludeOrder):
[email protected]ac294a12012-12-06 16:38:43797 if f.LocalPath().endswith(('.cc', '.h')):
798 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
799 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
[email protected]cf9b78f2012-11-14 11:40:28800
801 results = []
802 if warnings:
[email protected]f7051d52013-04-02 18:31:42803 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
[email protected]120cf540d2012-12-10 17:55:53804 warnings))
[email protected]cf9b78f2012-11-14 11:40:28805 return results
806
807
[email protected]70ca77752012-11-20 03:45:03808def _CheckForVersionControlConflictsInFile(input_api, f):
809 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
810 errors = []
811 for line_num, line in f.ChangedContents():
812 if pattern.match(line):
813 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
814 return errors
815
816
817def _CheckForVersionControlConflicts(input_api, output_api):
818 """Usually this is not intentional and will cause a compile failure."""
819 errors = []
820 for f in input_api.AffectedFiles():
821 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
822
823 results = []
824 if errors:
825 results.append(output_api.PresubmitError(
826 'Version control conflict markers found, please resolve.', errors))
827 return results
828
829
[email protected]06e6d0ff2012-12-11 01:36:44830def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
831 def FilterFile(affected_file):
832 """Filter function for use with input_api.AffectedSourceFiles,
833 below. This filters out everything except non-test files from
834 top-level directories that generally speaking should not hard-code
835 service URLs (e.g. src/android_webview/, src/content/ and others).
836 """
837 return input_api.FilterSourceFile(
838 affected_file,
[email protected]78bb39d62012-12-11 15:11:56839 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
[email protected]06e6d0ff2012-12-11 01:36:44840 black_list=(_EXCLUDED_PATHS +
841 _TEST_CODE_EXCLUDED_PATHS +
842 input_api.DEFAULT_BLACK_LIST))
843
[email protected]de4f7d22013-05-23 14:27:46844 base_pattern = '"[^"]*google\.com[^"]*"'
845 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
846 pattern = input_api.re.compile(base_pattern)
[email protected]06e6d0ff2012-12-11 01:36:44847 problems = [] # items are (filename, line_number, line)
848 for f in input_api.AffectedSourceFiles(FilterFile):
849 for line_num, line in f.ChangedContents():
[email protected]de4f7d22013-05-23 14:27:46850 if not comment_pattern.search(line) and pattern.search(line):
[email protected]06e6d0ff2012-12-11 01:36:44851 problems.append((f.LocalPath(), line_num, line))
852
853 if problems:
[email protected]f7051d52013-04-02 18:31:42854 return [output_api.PresubmitPromptOrNotify(
[email protected]06e6d0ff2012-12-11 01:36:44855 'Most layers below src/chrome/ should not hardcode service URLs.\n'
[email protected]b0149772014-03-27 16:47:58856 'Are you sure this is correct?',
[email protected]06e6d0ff2012-12-11 01:36:44857 [' %s:%d: %s' % (
858 problem[0], problem[1], problem[2]) for problem in problems])]
[email protected]2fdd1f362013-01-16 03:56:03859 else:
860 return []
[email protected]06e6d0ff2012-12-11 01:36:44861
862
[email protected]d2530012013-01-25 16:39:27863def _CheckNoAbbreviationInPngFileName(input_api, output_api):
864 """Makes sure there are no abbreviations in the name of PNG files.
865 """
[email protected]4053a48e2013-01-25 21:43:04866 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
[email protected]d2530012013-01-25 16:39:27867 errors = []
868 for f in input_api.AffectedFiles(include_deletes=False):
869 if pattern.match(f.LocalPath()):
870 errors.append(' %s' % f.LocalPath())
871
872 results = []
873 if errors:
874 results.append(output_api.PresubmitError(
875 'The name of PNG files should not have abbreviations. \n'
876 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
877 'Contact [email protected] if you have questions.', errors))
878 return results
879
880
[email protected]14a6131c2014-01-08 01:15:41881def _FilesToCheckForIncomingDeps(re, changed_lines):
[email protected]f32e2d1e2013-07-26 21:39:08882 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
[email protected]14a6131c2014-01-08 01:15:41883 a set of DEPS entries that we should look up.
884
885 For a directory (rather than a specific filename) we fake a path to
886 a specific filename by adding /DEPS. This is chosen as a file that
887 will seldom or never be subject to per-file include_rules.
888 """
[email protected]2b438d62013-11-14 17:54:14889 # We ignore deps entries on auto-generated directories.
890 AUTO_GENERATED_DIRS = ['grit', 'jni']
[email protected]f32e2d1e2013-07-26 21:39:08891
892 # This pattern grabs the path without basename in the first
893 # parentheses, and the basename (if present) in the second. It
894 # relies on the simple heuristic that if there is a basename it will
895 # be a header file ending in ".h".
896 pattern = re.compile(
897 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
[email protected]2b438d62013-11-14 17:54:14898 results = set()
[email protected]f32e2d1e2013-07-26 21:39:08899 for changed_line in changed_lines:
900 m = pattern.match(changed_line)
901 if m:
902 path = m.group(1)
[email protected]2b438d62013-11-14 17:54:14903 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
[email protected]14a6131c2014-01-08 01:15:41904 if m.group(2):
905 results.add('%s%s' % (path, m.group(2)))
906 else:
907 results.add('%s/DEPS' % path)
[email protected]f32e2d1e2013-07-26 21:39:08908 return results
909
910
[email protected]e871964c2013-05-13 14:14:55911def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
912 """When a dependency prefixed with + is added to a DEPS file, we
913 want to make sure that the change is reviewed by an OWNER of the
914 target file or directory, to avoid layering violations from being
915 introduced. This check verifies that this happens.
916 """
917 changed_lines = set()
918 for f in input_api.AffectedFiles():
919 filename = input_api.os_path.basename(f.LocalPath())
920 if filename == 'DEPS':
921 changed_lines |= set(line.strip()
922 for line_num, line
923 in f.ChangedContents())
924 if not changed_lines:
925 return []
926
[email protected]14a6131c2014-01-08 01:15:41927 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
928 changed_lines)
[email protected]e871964c2013-05-13 14:14:55929 if not virtual_depended_on_files:
930 return []
931
932 if input_api.is_committing:
933 if input_api.tbr:
934 return [output_api.PresubmitNotifyResult(
935 '--tbr was specified, skipping OWNERS check for DEPS additions')]
936 if not input_api.change.issue:
937 return [output_api.PresubmitError(
938 "DEPS approval by OWNERS check failed: this change has "
939 "no Rietveld issue number, so we can't check it for approvals.")]
940 output = output_api.PresubmitError
941 else:
942 output = output_api.PresubmitNotifyResult
943
944 owners_db = input_api.owners_db
945 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
946 input_api,
947 owners_db.email_regexp,
948 approval_needed=input_api.is_committing)
949
950 owner_email = owner_email or input_api.change.author_email
951
[email protected]de4f7d22013-05-23 14:27:46952 reviewers_plus_owner = set(reviewers)
[email protected]e71c6082013-05-22 02:28:51953 if owner_email:
[email protected]de4f7d22013-05-23 14:27:46954 reviewers_plus_owner.add(owner_email)
[email protected]e871964c2013-05-13 14:14:55955 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
956 reviewers_plus_owner)
[email protected]14a6131c2014-01-08 01:15:41957
958 # We strip the /DEPS part that was added by
959 # _FilesToCheckForIncomingDeps to fake a path to a file in a
960 # directory.
961 def StripDeps(path):
962 start_deps = path.rfind('/DEPS')
963 if start_deps != -1:
964 return path[:start_deps]
965 else:
966 return path
967 unapproved_dependencies = ["'+%s'," % StripDeps(path)
[email protected]e871964c2013-05-13 14:14:55968 for path in missing_files]
969
970 if unapproved_dependencies:
971 output_list = [
[email protected]14a6131c2014-01-08 01:15:41972 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
[email protected]e871964c2013-05-13 14:14:55973 '\n '.join(sorted(unapproved_dependencies)))]
974 if not input_api.is_committing:
975 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
976 output_list.append(output(
977 'Suggested missing target path OWNERS:\n %s' %
978 '\n '.join(suggested_owners or [])))
979 return output_list
980
981 return []
982
983
[email protected]85218562013-11-22 07:41:40984def _CheckSpamLogging(input_api, output_api):
985 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
986 black_list = (_EXCLUDED_PATHS +
987 _TEST_CODE_EXCLUDED_PATHS +
988 input_api.DEFAULT_BLACK_LIST +
[email protected]6f742dd02013-11-26 23:19:50989 (r"^base[\\\/]logging\.h$",
[email protected]80f360a2014-01-23 01:36:19990 r"^base[\\\/]logging\.cc$",
[email protected]8dc338c2013-12-09 16:28:48991 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
[email protected]6e268db2013-12-04 01:41:46992 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
[email protected]4de75262013-12-18 23:16:12993 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
994 r"startup_browser_creator\.cc$",
[email protected]fe0e6e12013-12-04 05:52:58995 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
[email protected]8cf6f842014-08-08 21:33:16996 r"chrome[\\\/]browser[\\\/]diagnostics[\\\/]" +
[email protected]f5b9a3f342014-08-08 22:06:03997 r"diagnostics_writer\.cc$",
[email protected]9f13b602014-08-07 02:59:15998 r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$",
999 r"^chromecast[\\\/]",
1000 r"^cloud_print[\\\/]",
[email protected]9056e732014-01-08 06:25:251001 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
1002 r"gl_helper_benchmark\.cc$",
thestigc9e38a22014-09-13 01:02:111003 r"^courgette[\\\/]courgette_tool\.cc$",
[email protected]9f13b602014-08-07 02:59:151004 r"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$",
prashant.nb0252f62014-11-08 05:02:111005 r"^ipc[\\\/]ipc_logging\.cc$",
[email protected]9c36d922014-03-24 16:47:521006 r"^native_client_sdk[\\\/]",
[email protected]cdbdced2013-11-27 21:35:501007 r"^remoting[\\\/]base[\\\/]logging\.h$",
[email protected]67c96ab2013-12-17 02:05:361008 r"^remoting[\\\/]host[\\\/].*",
[email protected]8232f8fd2013-12-14 00:52:311009 r"^sandbox[\\\/]linux[\\\/].*",
[email protected]0b7a21e2014-02-11 18:38:131010 r"^tools[\\\/]",
thestig22dfc4012014-09-05 08:29:441011 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",
1012 r"^webkit[\\\/]browser[\\\/]fileapi[\\\/]" +
1013 r"dump_file_system.cc$",))
[email protected]85218562013-11-22 07:41:401014 source_file_filter = lambda x: input_api.FilterSourceFile(
1015 x, white_list=(file_inclusion_pattern,), black_list=black_list)
1016
1017 log_info = []
1018 printf = []
1019
1020 for f in input_api.AffectedSourceFiles(source_file_filter):
1021 contents = input_api.ReadFile(f, 'rb')
mohan.reddyf21db962014-10-16 12:26:471022 if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
[email protected]85218562013-11-22 07:41:401023 log_info.append(f.LocalPath())
mohan.reddyf21db962014-10-16 12:26:471024 elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
[email protected]85210652013-11-28 05:50:131025 log_info.append(f.LocalPath())
[email protected]18b466b2013-12-02 22:01:371026
mohan.reddyf21db962014-10-16 12:26:471027 if input_api.re.search(r"\bprintf\(", contents):
[email protected]18b466b2013-12-02 22:01:371028 printf.append(f.LocalPath())
mohan.reddyf21db962014-10-16 12:26:471029 elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents):
[email protected]85218562013-11-22 07:41:401030 printf.append(f.LocalPath())
1031
1032 if log_info:
1033 return [output_api.PresubmitError(
1034 'These files spam the console log with LOG(INFO):',
1035 items=log_info)]
1036 if printf:
1037 return [output_api.PresubmitError(
1038 'These files spam the console log with printf/fprintf:',
1039 items=printf)]
1040 return []
1041
1042
[email protected]49aa76a2013-12-04 06:59:161043def _CheckForAnonymousVariables(input_api, output_api):
1044 """These types are all expected to hold locks while in scope and
1045 so should never be anonymous (which causes them to be immediately
1046 destroyed)."""
1047 they_who_must_be_named = [
1048 'base::AutoLock',
1049 'base::AutoReset',
1050 'base::AutoUnlock',
1051 'SkAutoAlphaRestore',
1052 'SkAutoBitmapShaderInstall',
1053 'SkAutoBlitterChoose',
1054 'SkAutoBounderCommit',
1055 'SkAutoCallProc',
1056 'SkAutoCanvasRestore',
1057 'SkAutoCommentBlock',
1058 'SkAutoDescriptor',
1059 'SkAutoDisableDirectionCheck',
1060 'SkAutoDisableOvalCheck',
1061 'SkAutoFree',
1062 'SkAutoGlyphCache',
1063 'SkAutoHDC',
1064 'SkAutoLockColors',
1065 'SkAutoLockPixels',
1066 'SkAutoMalloc',
1067 'SkAutoMaskFreeImage',
1068 'SkAutoMutexAcquire',
1069 'SkAutoPathBoundsUpdate',
1070 'SkAutoPDFRelease',
1071 'SkAutoRasterClipValidate',
1072 'SkAutoRef',
1073 'SkAutoTime',
1074 'SkAutoTrace',
1075 'SkAutoUnref',
1076 ]
1077 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
1078 # bad: base::AutoLock(lock.get());
1079 # not bad: base::AutoLock lock(lock.get());
1080 bad_pattern = input_api.re.compile(anonymous)
1081 # good: new base::AutoLock(lock.get())
1082 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
1083 errors = []
1084
1085 for f in input_api.AffectedFiles():
1086 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
1087 continue
1088 for linenum, line in f.ChangedContents():
1089 if bad_pattern.search(line) and not good_pattern.search(line):
1090 errors.append('%s:%d' % (f.LocalPath(), linenum))
1091
1092 if errors:
1093 return [output_api.PresubmitError(
1094 'These lines create anonymous variables that need to be named:',
1095 items=errors)]
1096 return []
1097
1098
[email protected]5fe0f8742013-11-29 01:04:591099def _CheckCygwinShell(input_api, output_api):
1100 source_file_filter = lambda x: input_api.FilterSourceFile(
1101 x, white_list=(r'.+\.(gyp|gypi)$',))
1102 cygwin_shell = []
1103
1104 for f in input_api.AffectedSourceFiles(source_file_filter):
1105 for linenum, line in f.ChangedContents():
1106 if 'msvs_cygwin_shell' in line:
1107 cygwin_shell.append(f.LocalPath())
1108 break
1109
1110 if cygwin_shell:
1111 return [output_api.PresubmitError(
1112 'These files should not use msvs_cygwin_shell (the default is 0):',
1113 items=cygwin_shell)]
1114 return []
1115
[email protected]85218562013-11-22 07:41:401116
[email protected]999261d2014-03-03 20:08:081117def _CheckUserActionUpdate(input_api, output_api):
1118 """Checks if any new user action has been added."""
[email protected]2f92dec2014-03-07 19:21:521119 if any('actions.xml' == input_api.os_path.basename(f) for f in
[email protected]999261d2014-03-03 20:08:081120 input_api.LocalPaths()):
[email protected]2f92dec2014-03-07 19:21:521121 # If actions.xml is already included in the changelist, the PRESUBMIT
1122 # for actions.xml will do a more complete presubmit check.
[email protected]999261d2014-03-03 20:08:081123 return []
1124
[email protected]999261d2014-03-03 20:08:081125 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm'))
1126 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)'
[email protected]2f92dec2014-03-07 19:21:521127 current_actions = None
[email protected]999261d2014-03-03 20:08:081128 for f in input_api.AffectedFiles(file_filter=file_filter):
1129 for line_num, line in f.ChangedContents():
1130 match = input_api.re.search(action_re, line)
1131 if match:
[email protected]2f92dec2014-03-07 19:21:521132 # Loads contents in tools/metrics/actions/actions.xml to memory. It's
1133 # loaded only once.
1134 if not current_actions:
1135 with open('tools/metrics/actions/actions.xml') as actions_f:
1136 current_actions = actions_f.read()
1137 # Search for the matched user action name in |current_actions|.
[email protected]999261d2014-03-03 20:08:081138 for action_name in match.groups():
[email protected]2f92dec2014-03-07 19:21:521139 action = 'name="{0}"'.format(action_name)
1140 if action not in current_actions:
[email protected]999261d2014-03-03 20:08:081141 return [output_api.PresubmitPromptWarning(
1142 'File %s line %d: %s is missing in '
[email protected]2f92dec2014-03-07 19:21:521143 'tools/metrics/actions/actions.xml. Please run '
1144 'tools/metrics/actions/extract_actions.py to update.'
[email protected]999261d2014-03-03 20:08:081145 % (f.LocalPath(), line_num, action_name))]
1146 return []
1147
1148
[email protected]99171a92014-06-03 08:44:471149def _GetJSONParseError(input_api, filename, eat_comments=True):
1150 try:
1151 contents = input_api.ReadFile(filename)
1152 if eat_comments:
1153 json_comment_eater = input_api.os_path.join(
1154 input_api.PresubmitLocalPath(),
1155 'tools', 'json_comment_eater', 'json_comment_eater.py')
1156 process = input_api.subprocess.Popen(
1157 [input_api.python_executable, json_comment_eater],
1158 stdin=input_api.subprocess.PIPE,
1159 stdout=input_api.subprocess.PIPE,
1160 universal_newlines=True)
1161 (contents, _) = process.communicate(input=contents)
1162
1163 input_api.json.loads(contents)
1164 except ValueError as e:
1165 return e
1166 return None
1167
1168
1169def _GetIDLParseError(input_api, filename):
1170 try:
1171 contents = input_api.ReadFile(filename)
1172 idl_schema = input_api.os_path.join(
1173 input_api.PresubmitLocalPath(),
1174 'tools', 'json_schema_compiler', 'idl_schema.py')
1175 process = input_api.subprocess.Popen(
1176 [input_api.python_executable, idl_schema],
1177 stdin=input_api.subprocess.PIPE,
1178 stdout=input_api.subprocess.PIPE,
1179 stderr=input_api.subprocess.PIPE,
1180 universal_newlines=True)
1181 (_, error) = process.communicate(input=contents)
1182 return error or None
1183 except ValueError as e:
1184 return e
1185
1186
1187def _CheckParseErrors(input_api, output_api):
1188 """Check that IDL and JSON files do not contain syntax errors."""
1189 actions = {
1190 '.idl': _GetIDLParseError,
1191 '.json': _GetJSONParseError,
1192 }
1193 # These paths contain test data and other known invalid JSON files.
1194 excluded_patterns = [
joaodasilva718f87672014-08-30 09:25:491195 r'test[\\\/]data[\\\/]',
1196 r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$',
[email protected]99171a92014-06-03 08:44:471197 ]
1198 # Most JSON files are preprocessed and support comments, but these do not.
1199 json_no_comments_patterns = [
joaodasilva718f87672014-08-30 09:25:491200 r'^testing[\\\/]',
[email protected]99171a92014-06-03 08:44:471201 ]
1202 # Only run IDL checker on files in these directories.
1203 idl_included_patterns = [
joaodasilva718f87672014-08-30 09:25:491204 r'^chrome[\\\/]common[\\\/]extensions[\\\/]api[\\\/]',
1205 r'^extensions[\\\/]common[\\\/]api[\\\/]',
[email protected]99171a92014-06-03 08:44:471206 ]
1207
1208 def get_action(affected_file):
1209 filename = affected_file.LocalPath()
1210 return actions.get(input_api.os_path.splitext(filename)[1])
1211
1212 def MatchesFile(patterns, path):
1213 for pattern in patterns:
1214 if input_api.re.search(pattern, path):
1215 return True
1216 return False
1217
1218 def FilterFile(affected_file):
1219 action = get_action(affected_file)
1220 if not action:
1221 return False
1222 path = affected_file.LocalPath()
1223
1224 if MatchesFile(excluded_patterns, path):
1225 return False
1226
1227 if (action == _GetIDLParseError and
1228 not MatchesFile(idl_included_patterns, path)):
1229 return False
1230 return True
1231
1232 results = []
1233 for affected_file in input_api.AffectedFiles(
1234 file_filter=FilterFile, include_deletes=False):
1235 action = get_action(affected_file)
1236 kwargs = {}
1237 if (action == _GetJSONParseError and
1238 MatchesFile(json_no_comments_patterns, affected_file.LocalPath())):
1239 kwargs['eat_comments'] = False
1240 parse_error = action(input_api,
1241 affected_file.AbsoluteLocalPath(),
1242 **kwargs)
1243 if parse_error:
1244 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
1245 (affected_file.LocalPath(), parse_error)))
1246 return results
1247
1248
[email protected]760deea2013-12-10 19:33:491249def _CheckJavaStyle(input_api, output_api):
1250 """Runs checkstyle on changed java files and returns errors if any exist."""
mohan.reddyf21db962014-10-16 12:26:471251 import sys
[email protected]760deea2013-12-10 19:33:491252 original_sys_path = sys.path
1253 try:
1254 sys.path = sys.path + [input_api.os_path.join(
1255 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1256 import checkstyle
1257 finally:
1258 # Restore sys.path to what it was before.
1259 sys.path = original_sys_path
1260
1261 return checkstyle.RunCheckstyle(
1262 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1263
1264
mnaganov9b9b1fe82014-12-11 16:30:361265def _CheckForCopyrightedCode(input_api, output_api):
1266 """Verifies that newly added code doesn't contain copyrighted material
1267 and is properly licensed under the standard Chromium license.
1268
1269 As there can be false positives, we maintain a whitelist file. This check
1270 also verifies that the whitelist file is up to date.
1271 """
1272 import sys
1273 original_sys_path = sys.path
1274 try:
1275 sys.path = sys.path + [input_api.os_path.join(
1276 input_api.PresubmitLocalPath(), 'android_webview', 'tools')]
1277 import copyright_scanner
1278 finally:
1279 # Restore sys.path to what it was before.
1280 sys.path = original_sys_path
1281
1282 return copyright_scanner.ScanAtPresubmit(input_api, output_api)
1283
1284
[email protected]fd20b902014-05-09 02:14:531285_DEPRECATED_CSS = [
1286 # Values
1287 ( "-webkit-box", "flex" ),
1288 ( "-webkit-inline-box", "inline-flex" ),
1289 ( "-webkit-flex", "flex" ),
1290 ( "-webkit-inline-flex", "inline-flex" ),
1291 ( "-webkit-min-content", "min-content" ),
1292 ( "-webkit-max-content", "max-content" ),
1293
1294 # Properties
1295 ( "-webkit-background-clip", "background-clip" ),
1296 ( "-webkit-background-origin", "background-origin" ),
1297 ( "-webkit-background-size", "background-size" ),
1298 ( "-webkit-box-shadow", "box-shadow" ),
1299
1300 # Functions
1301 ( "-webkit-gradient", "gradient" ),
1302 ( "-webkit-repeating-gradient", "repeating-gradient" ),
1303 ( "-webkit-linear-gradient", "linear-gradient" ),
1304 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ),
1305 ( "-webkit-radial-gradient", "radial-gradient" ),
1306 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ),
1307]
1308
1309def _CheckNoDeprecatedCSS(input_api, output_api):
1310 """ Make sure that we don't use deprecated CSS
[email protected]9a48e3f82014-05-22 00:06:251311 properties, functions or values. Our external
1312 documentation is ignored by the hooks as it
1313 needs to be consumed by WebKit. """
[email protected]fd20b902014-05-09 02:14:531314 results = []
dbeam070cfe62014-10-22 06:44:021315 file_inclusion_pattern = (r".+\.css$",)
[email protected]9a48e3f82014-05-22 00:06:251316 black_list = (_EXCLUDED_PATHS +
1317 _TEST_CODE_EXCLUDED_PATHS +
1318 input_api.DEFAULT_BLACK_LIST +
1319 (r"^chrome/common/extensions/docs",
1320 r"^chrome/docs",
1321 r"^native_client_sdk"))
1322 file_filter = lambda f: input_api.FilterSourceFile(
1323 f, white_list=file_inclusion_pattern, black_list=black_list)
[email protected]fd20b902014-05-09 02:14:531324 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1325 for line_num, line in fpath.ChangedContents():
1326 for (deprecated_value, value) in _DEPRECATED_CSS:
dbeam070cfe62014-10-22 06:44:021327 if deprecated_value in line:
[email protected]fd20b902014-05-09 02:14:531328 results.append(output_api.PresubmitError(
1329 "%s:%d: Use of deprecated CSS %s, use %s instead" %
1330 (fpath.LocalPath(), line_num, deprecated_value, value)))
1331 return results
1332
mohan.reddyf21db962014-10-16 12:26:471333
dbeam070cfe62014-10-22 06:44:021334_DEPRECATED_JS = [
1335 ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ),
1336 ( "__defineGetter__", "Object.defineProperty" ),
1337 ( "__defineSetter__", "Object.defineProperty" ),
1338]
1339
1340def _CheckNoDeprecatedJS(input_api, output_api):
1341 """Make sure that we don't use deprecated JS in Chrome code."""
1342 results = []
1343 file_inclusion_pattern = (r".+\.js$",) # TODO(dbeam): .html?
1344 black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS +
1345 input_api.DEFAULT_BLACK_LIST)
1346 file_filter = lambda f: input_api.FilterSourceFile(
1347 f, white_list=file_inclusion_pattern, black_list=black_list)
1348 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1349 for lnum, line in fpath.ChangedContents():
1350 for (deprecated, replacement) in _DEPRECATED_JS:
1351 if deprecated in line:
1352 results.append(output_api.PresubmitError(
1353 "%s:%d: Use of deprecated JS %s, use %s instead" %
1354 (fpath.LocalPath(), lnum, deprecated, replacement)))
1355 return results
1356
1357
[email protected]22c9bd72011-03-27 16:47:391358def _CommonChecks(input_api, output_api):
1359 """Checks common to both upload and commit."""
1360 results = []
1361 results.extend(input_api.canned_checks.PanProjectChecks(
[email protected]3de922f2013-12-20 13:27:381362 input_api, output_api,
1363 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
[email protected]66daa702011-05-28 14:41:461364 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]55459852011-08-10 15:17:191365 results.extend(
[email protected]760deea2013-12-10 19:33:491366 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
[email protected]10689ca2011-09-02 02:31:541367 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
[email protected]72df4e782012-06-21 16:28:181368 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
[email protected]8ea5d4b2011-09-13 21:49:221369 results.extend(_CheckNoNewWStrings(input_api, output_api))
[email protected]2a8ac9c2011-10-19 17:20:441370 results.extend(_CheckNoDEPSGIT(input_api, output_api))
[email protected]127f18ec2012-06-16 05:05:591371 results.extend(_CheckNoBannedFunctions(input_api, output_api))
[email protected]6c063c62012-07-11 19:11:061372 results.extend(_CheckNoPragmaOnce(input_api, output_api))
[email protected]e7479052012-09-19 00:26:121373 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
[email protected]55f9f382012-07-31 11:02:181374 results.extend(_CheckUnwantedDependencies(input_api, output_api))
[email protected]fbcafe5a2012-08-08 15:31:221375 results.extend(_CheckFilePermissions(input_api, output_api))
[email protected]c8278b32012-10-30 20:35:491376 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
[email protected]2309b0fa02012-11-16 12:18:271377 results.extend(_CheckIncludeOrder(input_api, output_api))
[email protected]70ca77752012-11-20 03:45:031378 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
[email protected]b8079ae4a2012-12-05 19:56:491379 results.extend(_CheckPatchFiles(input_api, output_api))
[email protected]06e6d0ff2012-12-11 01:36:441380 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
[email protected]d2530012013-01-25 16:39:271381 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
[email protected]b00342e7f2013-03-26 16:21:541382 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
lliabraa35bab3932014-10-01 12:16:441383 results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api))
danakj3c84d0c2014-10-06 15:35:461384 # TODO(danakj): Remove this when base/move.h is removed.
1385 results.extend(_CheckForUsingSideEffectsOfPass(input_api, output_api))
[email protected]e871964c2013-05-13 14:14:551386 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
[email protected]9f919cc2013-07-31 03:04:041387 results.extend(
1388 input_api.canned_checks.CheckChangeHasNoTabs(
1389 input_api,
1390 output_api,
1391 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
[email protected]85218562013-11-22 07:41:401392 results.extend(_CheckSpamLogging(input_api, output_api))
[email protected]49aa76a2013-12-04 06:59:161393 results.extend(_CheckForAnonymousVariables(input_api, output_api))
[email protected]5fe0f8742013-11-29 01:04:591394 results.extend(_CheckCygwinShell(input_api, output_api))
[email protected]999261d2014-03-03 20:08:081395 results.extend(_CheckUserActionUpdate(input_api, output_api))
[email protected]fd20b902014-05-09 02:14:531396 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
dbeam070cfe62014-10-22 06:44:021397 results.extend(_CheckNoDeprecatedJS(input_api, output_api))
[email protected]99171a92014-06-03 08:44:471398 results.extend(_CheckParseErrors(input_api, output_api))
mlamouria82272622014-09-16 18:45:041399 results.extend(_CheckForIPCRules(input_api, output_api))
mnaganov9b9b1fe82014-12-11 16:30:361400 results.extend(_CheckForCopyrightedCode(input_api, output_api))
[email protected]2299dcf2012-11-15 19:56:241401
1402 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1403 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1404 input_api, output_api,
1405 input_api.PresubmitLocalPath(),
[email protected]6be63382013-01-21 15:42:381406 whitelist=[r'^PRESUBMIT_test\.py$']))
[email protected]22c9bd72011-03-27 16:47:391407 return results
[email protected]1f7b4172010-01-28 01:17:341408
[email protected]b337cb5b2011-01-23 21:24:051409
[email protected]66daa702011-05-28 14:41:461410def _CheckAuthorizedAuthor(input_api, output_api):
1411 """For non-googler/chromites committers, verify the author's email address is
1412 in AUTHORS.
1413 """
[email protected]9bb9cb82011-06-13 20:43:011414 # TODO(maruel): Add it to input_api?
1415 import fnmatch
1416
[email protected]66daa702011-05-28 14:41:461417 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:011418 if not author:
1419 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:461420 return []
[email protected]c99663292011-05-31 19:46:081421 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:461422 input_api.PresubmitLocalPath(), 'AUTHORS')
1423 valid_authors = (
1424 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1425 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:181426 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]d8b50be2011-06-15 14:19:441427 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]5861efb2013-01-07 18:33:231428 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
[email protected]66daa702011-05-28 14:41:461429 return [output_api.PresubmitPromptWarning(
1430 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1431 '\n'
1432 'http://www.chromium.org/developers/contributing-code and read the '
1433 '"Legal" section\n'
1434 'If you are a chromite, verify the contributor signed the CLA.') %
1435 author)]
1436 return []
1437
1438
[email protected]b8079ae4a2012-12-05 19:56:491439def _CheckPatchFiles(input_api, output_api):
1440 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1441 if f.LocalPath().endswith(('.orig', '.rej'))]
1442 if problems:
1443 return [output_api.PresubmitError(
1444 "Don't commit .rej and .orig files.", problems)]
[email protected]2fdd1f362013-01-16 03:56:031445 else:
1446 return []
[email protected]b8079ae4a2012-12-05 19:56:491447
1448
[email protected]b00342e7f2013-03-26 16:21:541449def _DidYouMeanOSMacro(bad_macro):
1450 try:
1451 return {'A': 'OS_ANDROID',
1452 'B': 'OS_BSD',
1453 'C': 'OS_CHROMEOS',
1454 'F': 'OS_FREEBSD',
1455 'L': 'OS_LINUX',
1456 'M': 'OS_MACOSX',
1457 'N': 'OS_NACL',
1458 'O': 'OS_OPENBSD',
1459 'P': 'OS_POSIX',
1460 'S': 'OS_SOLARIS',
1461 'W': 'OS_WIN'}[bad_macro[3].upper()]
1462 except KeyError:
1463 return ''
1464
1465
1466def _CheckForInvalidOSMacrosInFile(input_api, f):
1467 """Check for sensible looking, totally invalid OS macros."""
1468 preprocessor_statement = input_api.re.compile(r'^\s*#')
1469 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1470 results = []
1471 for lnum, line in f.ChangedContents():
1472 if preprocessor_statement.search(line):
1473 for match in os_macro.finditer(line):
1474 if not match.group(1) in _VALID_OS_MACROS:
1475 good = _DidYouMeanOSMacro(match.group(1))
1476 did_you_mean = ' (did you mean %s?)' % good if good else ''
1477 results.append(' %s:%d %s%s' % (f.LocalPath(),
1478 lnum,
1479 match.group(1),
1480 did_you_mean))
1481 return results
1482
1483
1484def _CheckForInvalidOSMacros(input_api, output_api):
1485 """Check all affected files for invalid OS macros."""
1486 bad_macros = []
1487 for f in input_api.AffectedFiles():
1488 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1489 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1490
1491 if not bad_macros:
1492 return []
1493
1494 return [output_api.PresubmitError(
1495 'Possibly invalid OS macro[s] found. Please fix your code\n'
1496 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1497
lliabraa35bab3932014-10-01 12:16:441498
1499def _CheckForInvalidIfDefinedMacrosInFile(input_api, f):
1500 """Check all affected files for invalid "if defined" macros."""
1501 ALWAYS_DEFINED_MACROS = (
1502 "TARGET_CPU_PPC",
1503 "TARGET_CPU_PPC64",
1504 "TARGET_CPU_68K",
1505 "TARGET_CPU_X86",
1506 "TARGET_CPU_ARM",
1507 "TARGET_CPU_MIPS",
1508 "TARGET_CPU_SPARC",
1509 "TARGET_CPU_ALPHA",
1510 "TARGET_IPHONE_SIMULATOR",
1511 "TARGET_OS_EMBEDDED",
1512 "TARGET_OS_IPHONE",
1513 "TARGET_OS_MAC",
1514 "TARGET_OS_UNIX",
1515 "TARGET_OS_WIN32",
1516 )
1517 ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)')
1518 results = []
1519 for lnum, line in f.ChangedContents():
1520 for match in ifdef_macro.finditer(line):
1521 if match.group(1) in ALWAYS_DEFINED_MACROS:
1522 always_defined = ' %s is always defined. ' % match.group(1)
1523 did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1)
1524 results.append(' %s:%d %s\n\t%s' % (f.LocalPath(),
1525 lnum,
1526 always_defined,
1527 did_you_mean))
1528 return results
1529
1530
1531def _CheckForInvalidIfDefinedMacros(input_api, output_api):
1532 """Check all affected files for invalid "if defined" macros."""
1533 bad_macros = []
1534 for f in input_api.AffectedFiles():
1535 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')):
1536 bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f))
1537
1538 if not bad_macros:
1539 return []
1540
1541 return [output_api.PresubmitError(
1542 'Found ifdef check on always-defined macro[s]. Please fix your code\n'
1543 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.',
1544 bad_macros)]
1545
1546
danakj3c84d0c2014-10-06 15:35:461547def _CheckForUsingSideEffectsOfPass(input_api, output_api):
1548 """Check all affected files for using side effects of Pass."""
1549 errors = []
1550 for f in input_api.AffectedFiles():
1551 if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')):
1552 for lnum, line in f.ChangedContents():
1553 # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297.
mohan.reddyf21db962014-10-16 12:26:471554 if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line):
danakj3c84d0c2014-10-06 15:35:461555 errors.append(output_api.PresubmitError(
1556 ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' +
1557 'See crbug.com/418297.') % (f.LocalPath(), lnum)))
1558 return errors
1559
1560
mlamouria82272622014-09-16 18:45:041561def _CheckForIPCRules(input_api, output_api):
1562 """Check for same IPC rules described in
1563 http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc
1564 """
1565 base_pattern = r'IPC_ENUM_TRAITS\('
1566 inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern)
1567 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern)
1568
1569 problems = []
1570 for f in input_api.AffectedSourceFiles(None):
1571 local_path = f.LocalPath()
1572 if not local_path.endswith('.h'):
1573 continue
1574 for line_number, line in f.ChangedContents():
1575 if inclusion_pattern.search(line) and not comment_pattern.search(line):
1576 problems.append(
1577 '%s:%d\n %s' % (local_path, line_number, line.strip()))
1578
1579 if problems:
1580 return [output_api.PresubmitPromptWarning(
1581 _IPC_ENUM_TRAITS_DEPRECATED, problems)]
1582 else:
1583 return []
1584
[email protected]b00342e7f2013-03-26 16:21:541585
[email protected]1f7b4172010-01-28 01:17:341586def CheckChangeOnUpload(input_api, output_api):
1587 results = []
1588 results.extend(_CommonChecks(input_api, output_api))
tandriief664692014-09-23 14:51:471589 results.extend(_CheckValidHostsInDEPS(input_api, output_api))
aurimas8d3bc1c52014-10-15 01:02:171590 results.extend(_CheckJavaStyle(input_api, output_api))
mcasas2ece52702014-12-02 15:37:231591 results.extend(_CheckUmaHistogramChanges(input_api, output_api))
scottmg39b29952014-12-08 18:31:281592 results.extend(
1593 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541594 return results
[email protected]ca8d19842009-02-19 16:33:121595
1596
[email protected]1bfb8322014-04-23 01:02:411597def GetTryServerMasterForBot(bot):
1598 """Returns the Try Server master for the given bot.
1599
[email protected]0bb112362014-07-26 04:38:321600 It tries to guess the master from the bot name, but may still fail
1601 and return None. There is no longer a default master.
1602 """
1603 # Potentially ambiguous bot names are listed explicitly.
1604 master_map = {
[email protected]1bfb8322014-04-23 01:02:411605 'linux_gpu': 'tryserver.chromium.gpu',
[email protected]5c5f13042014-05-09 21:28:301606 'mac_gpu': 'tryserver.chromium.gpu',
[email protected]d263d5b2014-04-30 01:15:551607 'win_gpu': 'tryserver.chromium.gpu',
[email protected]0bb112362014-07-26 04:38:321608 'chromium_presubmit': 'tryserver.chromium.linux',
1609 'blink_presubmit': 'tryserver.chromium.linux',
1610 'tools_build_presubmit': 'tryserver.chromium.linux',
[email protected]1bfb8322014-04-23 01:02:411611 }
[email protected]0bb112362014-07-26 04:38:321612 master = master_map.get(bot)
1613 if not master:
1614 if 'gpu' in bot:
1615 master = 'tryserver.chromium.gpu'
1616 elif 'linux' in bot or 'android' in bot or 'presubmit' in bot:
1617 master = 'tryserver.chromium.linux'
1618 elif 'win' in bot:
1619 master = 'tryserver.chromium.win'
1620 elif 'mac' in bot or 'ios' in bot:
1621 master = 'tryserver.chromium.mac'
1622 return master
[email protected]1bfb8322014-04-23 01:02:411623
1624
[email protected]38c6a512013-12-18 23:48:011625def GetDefaultTryConfigs(bots=None):
1626 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1627
1628 To add tests to this list, they MUST be in the the corresponding master's
1629 gatekeeper config. For example, anything on master.chromium would be closed by
1630 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1631
1632 If 'bots' is specified, will only return configurations for bots in that list.
1633 """
1634
1635 standard_tests = [
1636 'base_unittests',
1637 'browser_tests',
1638 'cacheinvalidation_unittests',
1639 'check_deps',
1640 'check_deps2git',
1641 'content_browsertests',
1642 'content_unittests',
1643 'crypto_unittests',
[email protected]38c6a512013-12-18 23:48:011644 'gpu_unittests',
1645 'interactive_ui_tests',
1646 'ipc_tests',
1647 'jingle_unittests',
1648 'media_unittests',
1649 'net_unittests',
1650 'ppapi_unittests',
1651 'printing_unittests',
1652 'sql_unittests',
1653 'sync_unit_tests',
1654 'unit_tests',
1655 # Broken in release.
1656 #'url_unittests',
1657 #'webkit_unit_tests',
1658 ]
1659
[email protected]38c6a512013-12-18 23:48:011660 builders_and_tests = {
1661 # TODO(maruel): Figure out a way to run 'sizes' where people can
1662 # effectively update the perf expectation correctly. This requires a
1663 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1664 # incremental build. Reference:
1665 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1666 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1667 # of this step as a try job failure.
1668 'android_aosp': ['compile'],
scottmgd4724062014-09-20 00:27:091669 'android_arm64_dbg_recipe': ['slave_steps'],
1670 'android_chromium_gn_compile_dbg': ['compile'],
[email protected]5a65d3042014-05-07 14:26:011671 'android_chromium_gn_compile_rel': ['compile'],
scottmgd4724062014-09-20 00:27:091672 'android_clang_dbg_recipe': ['slave_steps'],
[email protected]5bd4f0cd2014-08-22 21:59:291673 'android_dbg_tests_recipe': ['slave_steps'],
[email protected]38c6a512013-12-18 23:48:011674 'ios_dbg_simulator': [
1675 'compile',
1676 'base_unittests',
1677 'content_unittests',
1678 'crypto_unittests',
1679 'url_unittests',
1680 'net_unittests',
1681 'sql_unittests',
tfarina201471d2014-10-02 18:12:111682 'ui_base_unittests',
[email protected]38c6a512013-12-18 23:48:011683 ],
1684 'ios_rel_device': ['compile'],
scottmgd4724062014-09-20 00:27:091685 'ios_rel_device_ninja': ['compile'],
[email protected]971b08ce2014-03-19 22:03:561686 'mac_asan': ['compile'],
[email protected]38c6a512013-12-18 23:48:011687 #TODO(stip): Change the name of this builder to reflect that it's release.
[email protected]71afb4ec2014-02-07 02:45:131688 'linux_gtk': standard_tests,
[email protected]971b08ce2014-03-19 22:03:561689 'linux_chromeos_asan': ['compile'],
sergeyberezin937b35322014-11-25 21:44:091690 'linux_chromium_asan_rel': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431691 'linux_chromium_chromeos_clang_dbg': ['defaulttests'],
sergeyberezin937b35322014-11-25 21:44:091692 'linux_chromium_chromeos_compile_dbg_ng': ['defaulttests'],
John Abd-El-Maleka2226a62014-10-22 16:48:071693 'linux_chromium_chromeos_rel': ['defaulttests'],
sergeyberezin937b35322014-11-25 21:44:091694 'linux_chromium_chromeos_rel_ng': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431695 'linux_chromium_compile_dbg': ['defaulttests'],
sergeyberezin937b35322014-11-25 21:44:091696 'linux_chromium_compile_dbg_32_ng': ['compile'],
scottmgd4724062014-09-20 00:27:091697 'linux_chromium_gn_dbg': ['compile'],
[email protected]5a65d3042014-05-07 14:26:011698 'linux_chromium_gn_rel': ['defaulttests'],
John Abd-El-Maleka2226a62014-10-22 16:48:071699 'linux_chromium_rel': ['defaulttests'],
Paweł Hajdan, Jr60f82282014-10-30 10:55:061700 'linux_chromium_rel_ng': ['defaulttests'],
[email protected]d910b6082014-02-27 18:15:431701 'linux_chromium_clang_dbg': ['defaulttests'],
[email protected]1bfb8322014-04-23 01:02:411702 'linux_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021703 'linux_nacl_sdk_build': ['compile'],
[email protected]d910b6082014-02-27 18:15:431704 'mac_chromium_compile_dbg': ['defaulttests'],
sergeyberezin937b35322014-11-25 21:44:091705 'mac_chromium_compile_dbg_ng': ['defaulttests'],
John Abd-El-Maleka2226a62014-10-22 16:48:071706 'mac_chromium_rel': ['defaulttests'],
Paweł Hajdan, Jr60f82282014-10-30 10:55:061707 'mac_chromium_rel_ng': ['defaulttests'],
[email protected]5c5f13042014-05-09 21:28:301708 'mac_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021709 'mac_nacl_sdk_build': ['compile'],
[email protected]0094fa12014-03-13 03:18:281710 'win_chromium_compile_dbg': ['defaulttests'],
[email protected]c17144e42014-04-15 09:32:431711 'win_chromium_dbg': ['defaulttests'],
John Abd-El-Maleka2226a62014-10-22 16:48:071712 'win_chromium_rel': ['defaulttests'],
Paweł Hajdan, Jr60f82282014-10-30 10:55:061713 'win_chromium_rel_ng': ['defaulttests'],
John Abd-El-Maleka2226a62014-10-22 16:48:071714 'win_chromium_x64_rel': ['defaulttests'],
Paweł Hajdan, Jr60f82282014-10-30 10:55:061715 'win_chromium_x64_rel_ng': ['defaulttests'],
[email protected]d263d5b2014-04-30 01:15:551716 'win_gpu': ['defaulttests'],
[email protected]9780bac2014-01-11 00:12:021717 'win_nacl_sdk_build': ['compile'],
danakjc89745a2014-09-16 01:33:031718 'win8_chromium_rel': ['defaulttests'],
[email protected]38c6a512013-12-18 23:48:011719 }
1720
[email protected]38c6a512013-12-18 23:48:011721 if bots:
[email protected]1bfb8322014-04-23 01:02:411722 filtered_builders_and_tests = dict((bot, set(builders_and_tests[bot]))
1723 for bot in bots)
[email protected]38c6a512013-12-18 23:48:011724 else:
[email protected]1bfb8322014-04-23 01:02:411725 filtered_builders_and_tests = dict(
1726 (bot, set(tests))
1727 for bot, tests in builders_and_tests.iteritems())
1728
1729 # Build up the mapping from tryserver master to bot/test.
1730 out = dict()
1731 for bot, tests in filtered_builders_and_tests.iteritems():
1732 out.setdefault(GetTryServerMasterForBot(bot), {})[bot] = tests
1733 return out
[email protected]38c6a512013-12-18 23:48:011734
1735
[email protected]ca8d19842009-02-19 16:33:121736def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:541737 results = []
[email protected]1f7b4172010-01-28 01:17:341738 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:511739 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1740 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1741 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:541742 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:271743 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:341744 input_api,
1745 output_api,
[email protected]2fdd1f362013-01-16 03:56:031746 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:271747
[email protected]3e4eb112011-01-18 03:29:541748 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1749 input_api, output_api))
[email protected]c4b47562011-12-05 23:39:411750 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1751 input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:541752 return results
[email protected]ca8d19842009-02-19 16:33:121753
1754
[email protected]7468ac522014-03-12 23:35:571755def GetPreferredTryMasters(project, change):
mohan.reddyf21db962014-10-16 12:26:471756 import re
[email protected]4ce995ea2012-06-27 02:13:101757 files = change.LocalPaths()
1758
joaodasilva718f87672014-08-30 09:25:491759 if not files or all(re.search(r'[\\\/]OWNERS$', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571760 return {}
[email protected]3019c902012-06-29 00:09:031761
joaodasilva718f87672014-08-30 09:25:491762 if all(re.search(r'\.(m|mm)$|(^|[\\\/_])mac[\\\/_.]', f) for f in files):
[email protected]d96b1f42014-02-27 19:17:521763 return GetDefaultTryConfigs([
sergeyberezin937b35322014-11-25 21:44:091764 'mac_chromium_compile_dbg_ng',
Paweł Hajdan, Jr60f82282014-10-30 10:55:061765 'mac_chromium_rel_ng',
[email protected]d96b1f42014-02-27 19:17:521766 ])
[email protected]d668899a2012-09-06 18:16:591767 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
[email protected]02a7f6362014-08-13 02:04:161768 return GetDefaultTryConfigs([
scottmg6be3500f2014-12-04 17:08:271769 'win8_chromium_rel',
[email protected]02a7f6362014-08-13 02:04:161770 'win_chromium_dbg',
Paweł Hajdan, Jrec444ad2014-11-25 16:21:411771 'win_chromium_rel',
scottmg6be3500f2014-12-04 17:08:271772 'win_chromium_x64_rel',
[email protected]02a7f6362014-08-13 02:04:161773 ])
joaodasilva718f87672014-08-30 09:25:491774 if all(re.search(r'(^|[\\\/_])android[\\\/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011775 return GetDefaultTryConfigs([
1776 'android_aosp',
[email protected]5bd4f0cd2014-08-22 21:59:291777 'android_dbg_tests_recipe',
[email protected]38c6a512013-12-18 23:48:011778 ])
joaodasilva718f87672014-08-30 09:25:491779 if all(re.search(r'[\\\/_]ios[\\\/_.]', f) for f in files):
[email protected]38c6a512013-12-18 23:48:011780 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
[email protected]4ce995ea2012-06-27 02:13:101781
[email protected]7468ac522014-03-12 23:35:571782 builders = [
sergeyberezin937b35322014-11-25 21:44:091783 'android_aosp',
scottmgd4724062014-09-20 00:27:091784 'android_arm64_dbg_recipe',
[email protected]5a65d3042014-05-07 14:26:011785 'android_chromium_gn_compile_rel',
scottmgd4724062014-09-20 00:27:091786 'android_chromium_gn_compile_dbg',
scottmgd4724062014-09-20 00:27:091787 'android_clang_dbg_recipe',
[email protected]5bd4f0cd2014-08-22 21:59:291788 'android_dbg_tests_recipe',
[email protected]3e2f0402012-11-02 16:28:011789 'ios_dbg_simulator',
1790 'ios_rel_device',
scottmgd4724062014-09-20 00:27:091791 'ios_rel_device_ninja',
sergeyberezin937b35322014-11-25 21:44:091792 'linux_chromium_asan_rel',
1793 'linux_chromium_chromeos_compile_dbg_ng',
1794 'linux_chromium_chromeos_rel_ng',
1795 'linux_chromium_compile_dbg_32_ng',
scottmgd4724062014-09-20 00:27:091796 'linux_chromium_gn_dbg',
[email protected]5a65d3042014-05-07 14:26:011797 'linux_chromium_gn_rel',
Paweł Hajdan, Jr60f82282014-10-30 10:55:061798 'linux_chromium_rel_ng',
[email protected]1bfb8322014-04-23 01:02:411799 'linux_gpu',
sergeyberezin937b35322014-11-25 21:44:091800 'mac_chromium_compile_dbg_ng',
Paweł Hajdan, Jr60f82282014-10-30 10:55:061801 'mac_chromium_rel_ng',
[email protected]5c5f13042014-05-09 21:28:301802 'mac_gpu',
[email protected]0094fa12014-03-13 03:18:281803 'win_chromium_compile_dbg',
Paweł Hajdan, Jrec444ad2014-11-25 16:21:411804 'win_chromium_rel',
1805 'win_chromium_x64_rel',
[email protected]d263d5b2014-04-30 01:15:551806 'win_gpu',
danakjc89745a2014-09-16 01:33:031807 'win8_chromium_rel',
[email protected]7468ac522014-03-12 23:35:571808 ]
[email protected]911753b2012-08-02 12:11:541809
1810 # Match things like path/aura/file.cc and path/file_aura.cc.
[email protected]95c989162012-11-29 05:58:251811 # Same for chromeos.
joaodasilva718f87672014-08-30 09:25:491812 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files):
[email protected]7468ac522014-03-12 23:35:571813 builders.extend([
1814 'linux_chromeos_asan',
[email protected]7468ac522014-03-12 23:35:571815 ])
[email protected]4ce995ea2012-06-27 02:13:101816
[email protected]7468ac522014-03-12 23:35:571817 return GetDefaultTryConfigs(builders)