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