OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
9 """ | 9 """ |
10 | 10 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 # Outsource work to gclient verify | 405 # Outsource work to gclient verify |
406 try: | 406 try: |
407 input_api.subprocess.check_output(['gclient', 'verify']) | 407 input_api.subprocess.check_output(['gclient', 'verify']) |
408 return [] | 408 return [] |
409 except input_api.subprocess.CalledProcessError, error: | 409 except input_api.subprocess.CalledProcessError, error: |
410 return [output_api.PresubmitError( | 410 return [output_api.PresubmitError( |
411 'DEPS file must have only git dependencies.', | 411 'DEPS file must have only git dependencies.', |
412 long_text=error.output)] | 412 long_text=error.output)] |
413 | 413 |
414 | 414 |
415 def _CheckGNCheck(input_api, output_api): | |
416 """Checks that gn gen and gn check pass""" | |
417 import os.path | |
418 | |
419 class _TemporaryDirectory(object): | |
420 """Context manager for tempfile.mkdtemp()""" | |
421 def __enter__(self): | |
422 self.path = input_api.tempfile.mkdtemp() | |
423 return self.path | |
424 | |
425 def __exit__(self, exc_type, exc_value, traceback): | |
426 # input_api does not include shutil or any nice way to delete | |
427 # a directory, so we hackishly import it here. | |
428 import shutil | |
429 shutil.rmtree(self.path) | |
430 | |
431 available_os = [None] | |
432 # android tools directory is used as a sentinel to check if the current | |
433 # checkout is an android checkout. | |
434 android_tools_dir = os.path.join(input_api.change.RepositoryRoot(), | |
435 'third_party', 'android_tools') | |
436 if os.path.isdir(android_tools_dir): | |
437 available_os.append('android') | |
438 for target_os in available_os: | |
439 with _TemporaryDirectory() as out_dir: | |
440 try: | |
441 command = ['gn', 'gen', out_dir] | |
442 if target_os: | |
443 command.append('--args=%s' % r'''os="android"''') | |
444 input_api.subprocess.check_output(command) | |
445 except input_api.subprocess.CalledProcessError, error: | |
446 return [output_api.PresubmitError( | |
447 'gn gen must not fail.', long_text=error.output)] | |
448 | |
449 # TODO(eseidel): Currently only these are known to pass, once everything | |
450 # passes we can just call 'gn check' once without a filter! | |
451 KNOWN_PASSING = [ | |
452 '//examples/*', | |
453 '//mojo/*', | |
454 '//services/*', | |
455 '//shell/*', | |
456 ] | |
457 if input_api.platform != 'win32': | |
458 KNOWN_PASSING += [ | |
459 '//sky/*', | |
460 ] | |
461 for target_filter in KNOWN_PASSING: | |
462 try: | |
463 input_api.subprocess.check_output(['gn', 'check', out_dir, | |
464 target_filter]) | |
465 except input_api.subprocess.CalledProcessError, error: | |
466 error_title = 'gn check %s must not fail.' % target_filter | |
467 return [output_api.PresubmitError(error_title, | |
468 long_text=error.output)] | |
469 return [] | |
470 | |
471 | |
472 def _CheckNoBannedFunctions(input_api, output_api): | 415 def _CheckNoBannedFunctions(input_api, output_api): |
473 """Make sure that banned functions are not used.""" | 416 """Make sure that banned functions are not used.""" |
474 warnings = [] | 417 warnings = [] |
475 errors = [] | 418 errors = [] |
476 | 419 |
477 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) | 420 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
478 for f in input_api.AffectedFiles(file_filter=file_filter): | 421 for f in input_api.AffectedFiles(file_filter=file_filter): |
479 for line_num, line in f.ChangedContents(): | 422 for line_num, line in f.ChangedContents(): |
480 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: | 423 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
481 matched = False | 424 matched = False |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 output_api, | 1267 output_api, |
1325 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1268 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1326 results.extend(_CheckSpamLogging(input_api, output_api)) | 1269 results.extend(_CheckSpamLogging(input_api, output_api)) |
1327 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1270 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1328 results.extend(_CheckCygwinShell(input_api, output_api)) | 1271 results.extend(_CheckCygwinShell(input_api, output_api)) |
1329 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1272 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
1330 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1273 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
1331 results.extend(_CheckParseErrors(input_api, output_api)) | 1274 results.extend(_CheckParseErrors(input_api, output_api)) |
1332 results.extend(_CheckForIPCRules(input_api, output_api)) | 1275 results.extend(_CheckForIPCRules(input_api, output_api)) |
1333 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) | 1276 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) |
1334 results.extend(_CheckGNCheck(input_api, output_api)) | |
1335 results.extend(_CheckForMojoURL(input_api, output_api)) | 1277 results.extend(_CheckForMojoURL(input_api, output_api)) |
1336 | 1278 |
1337 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1279 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
1338 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1280 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
1339 input_api, output_api, | 1281 input_api, output_api, |
1340 input_api.PresubmitLocalPath(), | 1282 input_api.PresubmitLocalPath(), |
1341 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1283 whitelist=[r'^PRESUBMIT_test\.py$'])) |
1342 return results | 1284 return results |
1343 | 1285 |
1344 | 1286 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 builders = [ | 1534 builders = [ |
1593 'Mojo Linux Try', | 1535 'Mojo Linux Try', |
1594 'Mojo Linux (dbg) Try', | 1536 'Mojo Linux (dbg) Try', |
1595 'Mojo Android Builder Try', | 1537 'Mojo Android Builder Try', |
1596 'Mojo Android Builder (dbg) Try', | 1538 'Mojo Android Builder (dbg) Try', |
1597 'Mojo ChromeOS Builder Try', | 1539 'Mojo ChromeOS Builder Try', |
1598 'Mojo ChromeOS Builder (dbg) Try', | 1540 'Mojo ChromeOS Builder (dbg) Try', |
1599 ] | 1541 ] |
1600 | 1542 |
1601 return GetDefaultTryConfigs(builders) | 1543 return GetDefaultTryConfigs(builders) |
OLD | NEW |