chrisha@chromium.org | c920ad2 | 2012-02-02 18:26:04 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 12 | def CommonChecks(input_api, output_api, tests_to_black_list): |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 13 | results = [] |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 14 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 15 | black_list = list(input_api.DEFAULT_BLACK_LIST) + [ |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 16 | r'^cpplint\.py$', |
asvitkine@chromium.org | 63c2c1d | 2011-09-07 21:41:55 +0000 | [diff] [blame] | 17 | r'^cpplint_chromium\.py$', |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 18 | r'^python_bin[\/\\].+', |
chrisha@chromium.org | c920ad2 | 2012-02-02 18:26:04 +0000 | [diff] [blame] | 19 | r'^site-packages-py[0-9]\.[0-9][\/\\].+', |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 20 | r'^svn_bin[\/\\].+', |
maruel@chromium.org | 0927b7e | 2011-11-11 16:06:22 +0000 | [diff] [blame] | 21 | r'^testing_support[\/\\]_rietveld[\/\\].+'] |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 22 | results.extend(input_api.canned_checks.RunPylint( |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 23 | input_api, |
| 24 | output_api, |
maruel@chromium.org | 57e48b8 | 2011-06-15 17:34:59 +0000 | [diff] [blame] | 25 | white_list=[r'.*\.py$'], |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 26 | black_list=black_list)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 27 | |
| 28 | # TODO(maruel): Make sure at least one file is modified first. |
| 29 | # TODO(maruel): If only tests are modified, only run them. |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 30 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 31 | input_api, |
| 32 | output_api, |
| 33 | 'tests', |
maruel@chromium.org | fae707b | 2011-09-15 18:57:58 +0000 | [diff] [blame] | 34 | whitelist=[r'.*test\.py$'], |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 35 | blacklist=tests_to_black_list)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 36 | return results |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 37 | |
| 38 | |
maruel@chromium.org | 899e1c1 | 2011-04-07 17:03:18 +0000 | [diff] [blame] | 39 | def RunGitClTests(input_api, output_api): |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 40 | """Run all the shells scripts in the directory test. |
| 41 | """ |
maruel@chromium.org | c98c0c5 | 2011-04-06 13:39:43 +0000 | [diff] [blame] | 42 | if input_api.platform == 'win32': |
| 43 | # Skip for now as long as the test scripts are bash scripts. |
| 44 | return [] |
| 45 | |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 46 | # First loads a local Rietveld instance. |
| 47 | import sys |
| 48 | old_sys_path = sys.path |
| 49 | try: |
| 50 | sys.path = [input_api.PresubmitLocalPath()] + sys.path |
maruel@chromium.org | 0927b7e | 2011-11-11 16:06:22 +0000 | [diff] [blame] | 51 | from testing_support import local_rietveld |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 52 | server = local_rietveld.LocalRietveld() |
| 53 | finally: |
| 54 | sys.path = old_sys_path |
| 55 | |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 56 | results = [] |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 57 | try: |
| 58 | # Start a local rietveld instance to test against. |
| 59 | server.start_server() |
| 60 | test_path = input_api.os_path.abspath( |
| 61 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests')) |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 62 | for test in input_api.os_listdir(test_path): |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 63 | # test-lib.sh is not an actual test so it should not be run. The other |
| 64 | # tests are tests known to fail. |
| 65 | DISABLED_TESTS = ( |
| 66 | 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh') |
| 67 | if test in DISABLED_TESTS or not test.endswith('.sh'): |
| 68 | continue |
| 69 | |
| 70 | print('Running %s' % test) |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 71 | try: |
maruel@chromium.org | 899e1c1 | 2011-04-07 17:03:18 +0000 | [diff] [blame] | 72 | if input_api.verbose: |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 73 | input_api.subprocess.check_call( |
| 74 | [input_api.os_path.join(test_path, test)], cwd=test_path) |
| 75 | else: |
| 76 | input_api.subprocess.check_output( |
maruel@chromium.org | 87e6d33 | 2011-09-09 19:01:28 +0000 | [diff] [blame] | 77 | [input_api.os_path.join(test_path, test)], cwd=test_path, |
| 78 | stderr=input_api.subprocess.STDOUT) |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 79 | except (OSError, input_api.subprocess.CalledProcessError), e: |
| 80 | results.append(output_api.PresubmitError('%s failed\n%s' % (test, e))) |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 81 | except local_rietveld.Failure, e: |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 82 | 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] | 83 | finally: |
| 84 | server.stop_server() |
maruel@chromium.org | ccbb781 | 2011-04-06 13:36:23 +0000 | [diff] [blame] | 85 | return results |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 86 | |
| 87 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 88 | def CheckChangeOnUpload(input_api, output_api): |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 89 | # Do not run integration tests on upload since they are way too slow. |
| 90 | tests_to_black_list = [ |
| 91 | r'^checkout_test\.py$', |
| 92 | r'^gclient_smoketest\.py$', |
| 93 | r'^scm_unittest\.py$', |
| 94 | ] |
| 95 | return CommonChecks(input_api, output_api, tests_to_black_list) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 96 | |
| 97 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 98 | def CheckChangeOnCommit(input_api, output_api): |
| 99 | output = [] |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 100 | output.extend(CommonChecks(input_api, output_api, [])) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 101 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 102 | input_api, |
| 103 | output_api)) |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 104 | output.extend(RunGitClTests(input_api, output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 105 | return output |