maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 1 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 2 | # 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 depot tools. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 8 | details on the presubmit API built into depot_tools. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 9 | """ |
| 10 | |
dpranke@chromium.org | 627ea67 | 2011-03-11 23:29:03 +0000 | [diff] [blame] | 11 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 12 | def CommonChecks(input_api, output_api): |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 13 | results = [] |
maruel@chromium.org | 725f1c3 | 2011-04-01 20:24:54 +0000 | [diff] [blame] | 14 | import sys |
| 15 | if not sys.version.startswith('2.5'): |
| 16 | # Depot_tools has the particularity that it needs to be tested on python |
| 17 | # 2.5. But we don't want the presubmit check to fail if it is not installed. |
| 18 | results.append(output_api.PresubmitNotifyResult( |
| 19 | 'You should install python 2.5 and run ln -s $(which python2.5) python.' |
| 20 | '\n' |
| 21 | 'A great place to put this symlink is in depot_tools.\n' |
| 22 | 'Otherwise, you break depot_tools on python 2.5, you get to keep the ' |
| 23 | 'pieces.')) |
| 24 | |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 25 | |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 26 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 27 | black_list = list(input_api.DEFAULT_BLACK_LIST) + [ |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 28 | r'^cpplint\.py$', |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 29 | r'^python_bin[\/\\].+', |
| 30 | r'^svn_bin[\/\\].+', |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 31 | r'^tests[\/\\]\w+?[\/\\].+'] |
| 32 | results.extend(input_api.canned_checks.RunPylint( |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 33 | input_api, |
| 34 | output_api, |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 35 | white_list=[r'.*\.py$', r'^git-try$'], |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 36 | black_list=black_list)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 37 | |
| 38 | # TODO(maruel): Make sure at least one file is modified first. |
| 39 | # TODO(maruel): If only tests are modified, only run them. |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 40 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 41 | input_api, |
| 42 | output_api, |
| 43 | 'tests', |
maruel@chromium.org | 899e1c1 | 2011-04-07 17:03:18 +0000 | [diff] [blame] | 44 | whitelist=[r'.*test\.py$'])) |
| 45 | results.extend(RunGitClTests(input_api, output_api)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 46 | return results |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 47 | |
| 48 | |
maruel@chromium.org | 899e1c1 | 2011-04-07 17:03:18 +0000 | [diff] [blame] | 49 | def RunGitClTests(input_api, output_api): |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 50 | """Run all the shells scripts in the directory test. |
| 51 | """ |
maruel@chromium.org | c98c0c5 | 2011-04-06 13:39:43 +0000 | [diff] [blame] | 52 | if input_api.platform == 'win32': |
| 53 | # Skip for now as long as the test scripts are bash scripts. |
| 54 | return [] |
| 55 | |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 56 | # First loads a local Rietveld instance. |
| 57 | import sys |
| 58 | old_sys_path = sys.path |
| 59 | try: |
| 60 | sys.path = [input_api.PresubmitLocalPath()] + sys.path |
| 61 | from tests import local_rietveld # pylint: disable=W0403 |
| 62 | server = local_rietveld.LocalRietveld() |
| 63 | finally: |
| 64 | sys.path = old_sys_path |
| 65 | |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 66 | results = [] |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 67 | try: |
| 68 | # Start a local rietveld instance to test against. |
| 69 | server.start_server() |
| 70 | test_path = input_api.os_path.abspath( |
| 71 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests')) |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 72 | for test in input_api.os_listdir(test_path): |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 73 | # test-lib.sh is not an actual test so it should not be run. The other |
| 74 | # tests are tests known to fail. |
| 75 | DISABLED_TESTS = ( |
| 76 | 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh') |
| 77 | if test in DISABLED_TESTS or not test.endswith('.sh'): |
| 78 | continue |
| 79 | |
| 80 | print('Running %s' % test) |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 81 | try: |
maruel@chromium.org | 899e1c1 | 2011-04-07 17:03:18 +0000 | [diff] [blame] | 82 | if input_api.verbose: |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 83 | input_api.subprocess.check_call( |
| 84 | [input_api.os_path.join(test_path, test)], cwd=test_path) |
| 85 | else: |
| 86 | input_api.subprocess.check_output( |
| 87 | [input_api.os_path.join(test_path, test)], cwd=test_path) |
| 88 | except (OSError, input_api.subprocess.CalledProcessError), e: |
| 89 | results.append(output_api.PresubmitError('%s failed\n%s' % (test, e))) |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 90 | except local_rietveld.Failure, e: |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 91 | results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args))) |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 92 | finally: |
| 93 | server.stop_server() |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 94 | return results |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 95 | |
| 96 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 97 | def CheckChangeOnUpload(input_api, output_api): |
| 98 | return CommonChecks(input_api, output_api) |
| 99 | |
| 100 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 101 | def CheckChangeOnCommit(input_api, output_api): |
| 102 | output = [] |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 103 | output.extend(CommonChecks(input_api, output_api)) |
| 104 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 105 | input_api, |
| 106 | output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 107 | return output |