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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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): | 415 def _CheckGNCheck(input_api, output_api): |
416 """Checks that gn gen and gn check pass""" | 416 """Checks that gn gen and gn check pass""" |
| 417 import os.path |
417 | 418 |
418 class _TemporaryDirectory(object): | 419 class _TemporaryDirectory(object): |
419 """Context manager for tempfile.mkdtemp()""" | 420 """Context manager for tempfile.mkdtemp()""" |
420 def __enter__(self): | 421 def __enter__(self): |
421 self.path = input_api.tempfile.mkdtemp() | 422 self.path = input_api.tempfile.mkdtemp() |
422 return self.path | 423 return self.path |
423 | 424 |
424 def __exit__(self, exc_type, exc_value, traceback): | 425 def __exit__(self, exc_type, exc_value, traceback): |
425 # input_api does not include shutil or any nice way to delete | 426 # input_api does not include shutil or any nice way to delete |
426 # a directory, so we hackishly import it here. | 427 # a directory, so we hackishly import it here. |
427 import shutil | 428 import shutil |
428 shutil.rmtree(self.path) | 429 shutil.rmtree(self.path) |
429 | 430 |
430 with _TemporaryDirectory() as out_dir: | 431 available_os = [None] |
431 try: | 432 # android tools directory is used as a sentinel to check if the current |
432 input_api.subprocess.check_output(['gn', 'gen', out_dir]) | 433 # checkout is an android checkout. |
433 except input_api.subprocess.CalledProcessError, error: | 434 android_tools_dir = os.path.join(input_api.change.RepositoryRoot(), |
434 return [output_api.PresubmitError( | 435 'third_party', 'android_tools') |
435 'gn gen must not fail.', long_text=error.output)] | 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)] |
436 | 448 |
437 # TODO(eseidel): Currently only these are known to pass, | 449 # TODO(eseidel): Currently only these are known to pass, once everything |
438 # once everything passes we can just call 'gn check' once without a filter! | 450 # passes we can just call 'gn check' once without a filter! |
439 KNOWN_PASSING = [ | 451 KNOWN_PASSING = [ |
440 '//examples/*', | 452 '//examples/*', |
441 '//mojo/*', | 453 '//mojo/*', |
442 '//services/*', | 454 '//services/*', |
443 '//shell/*', | 455 '//shell/*', |
444 ] | |
445 if input_api.platform != 'win32': | |
446 KNOWN_PASSING += [ | |
447 '//sky/*', | |
448 ] | 456 ] |
449 for target_filter in KNOWN_PASSING: | 457 if input_api.platform != 'win32': |
450 try: | 458 KNOWN_PASSING += [ |
451 input_api.subprocess.check_output(['gn', 'check', out_dir, | 459 '//sky/*', |
452 target_filter]) | 460 ] |
453 except input_api.subprocess.CalledProcessError, error: | 461 for target_filter in KNOWN_PASSING: |
454 error_title = 'gn check %s must not fail.' % target_filter | 462 try: |
455 return [output_api.PresubmitError(error_title, long_text=error.output)] | 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)] |
456 return [] | 469 return [] |
457 | 470 |
458 | 471 |
459 def _CheckNoBannedFunctions(input_api, output_api): | 472 def _CheckNoBannedFunctions(input_api, output_api): |
460 """Make sure that banned functions are not used.""" | 473 """Make sure that banned functions are not used.""" |
461 warnings = [] | 474 warnings = [] |
462 errors = [] | 475 errors = [] |
463 | 476 |
464 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) | 477 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
465 for f in input_api.AffectedFiles(file_filter=file_filter): | 478 for f in input_api.AffectedFiles(file_filter=file_filter): |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 builders = [ | 1592 builders = [ |
1580 'Mojo Linux Try', | 1593 'Mojo Linux Try', |
1581 'Mojo Linux (dbg) Try', | 1594 'Mojo Linux (dbg) Try', |
1582 'Mojo Android Builder Try', | 1595 'Mojo Android Builder Try', |
1583 'Mojo Android Builder (dbg) Try', | 1596 'Mojo Android Builder (dbg) Try', |
1584 'Mojo ChromeOS Builder Try', | 1597 'Mojo ChromeOS Builder Try', |
1585 'Mojo ChromeOS Builder (dbg) Try', | 1598 'Mojo ChromeOS Builder (dbg) Try', |
1586 ] | 1599 ] |
1587 | 1600 |
1588 return GetDefaultTryConfigs(builders) | 1601 return GetDefaultTryConfigs(builders) |
OLD | NEW |