blob: b7a352e28c30aaf5ee294e32215f545e1f9f532e [file] [log] [blame]
[email protected]c920ad22012-02-02 18:26:041# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]3d235242009-05-15 12:40:482# 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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
[email protected]2a74d372011-03-29 19:05:508details on the presubmit API built into depot_tools.
[email protected]3d235242009-05-15 12:40:489"""
10
[email protected]627ea672011-03-11 23:29:0311
[email protected]d52417c2011-09-02 20:13:1712def CommonChecks(input_api, output_api, tests_to_black_list):
[email protected]3c9f7ca2011-04-01 14:52:3813 results = []
[email protected]3c9f7ca2011-04-01 14:52:3814 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
[email protected]bf38a7e2010-12-14 18:15:5415 black_list = list(input_api.DEFAULT_BLACK_LIST) + [
[email protected]5d0dc432011-01-03 02:40:3716 r'^cpplint\.py$',
[email protected]63c2c1d2011-09-07 21:41:5517 r'^cpplint_chromium\.py$',
[email protected]ccbb7812011-04-06 13:36:2318 r'^python_bin[\/\\].+',
[email protected]c920ad22012-02-02 18:26:0419 r'^site-packages-py[0-9]\.[0-9][\/\\].+',
[email protected]ccbb7812011-04-06 13:36:2320 r'^svn_bin[\/\\].+',
[email protected]0927b7e2011-11-11 16:06:2221 r'^testing_support[\/\\]_rietveld[\/\\].+']
[email protected]ff9a2172012-04-24 16:55:3222 disabled_warnings = [
23 'R0401', # Cyclic import
24 'W0613', # Unused argument
25 ]
[email protected]3c9f7ca2011-04-01 14:52:3826 results.extend(input_api.canned_checks.RunPylint(
[email protected]e94aedc2010-12-13 21:11:3027 input_api,
28 output_api,
[email protected]57e48b82011-06-15 17:34:5929 white_list=[r'.*\.py$'],
[email protected]ff9a2172012-04-24 16:55:3230 black_list=black_list,
31 disabled_warnings=disabled_warnings))
[email protected]3c9f7ca2011-04-01 14:52:3832
33 # TODO(maruel): Make sure at least one file is modified first.
34 # TODO(maruel): If only tests are modified, only run them.
[email protected]3c9f7ca2011-04-01 14:52:3835 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
36 input_api,
37 output_api,
38 'tests',
[email protected]fae707b2011-09-15 18:57:5839 whitelist=[r'.*test\.py$'],
[email protected]d52417c2011-09-02 20:13:1740 blacklist=tests_to_black_list))
[email protected]3c9f7ca2011-04-01 14:52:3841 return results
[email protected]2a74d372011-03-29 19:05:5042
43
[email protected]899e1c12011-04-07 17:03:1844def RunGitClTests(input_api, output_api):
[email protected]2a74d372011-03-29 19:05:5045 """Run all the shells scripts in the directory test.
46 """
[email protected]c98c0c52011-04-06 13:39:4347 if input_api.platform == 'win32':
48 # Skip for now as long as the test scripts are bash scripts.
49 return []
50
[email protected]2a74d372011-03-29 19:05:5051 # First loads a local Rietveld instance.
52 import sys
53 old_sys_path = sys.path
54 try:
55 sys.path = [input_api.PresubmitLocalPath()] + sys.path
[email protected]0927b7e2011-11-11 16:06:2256 from testing_support import local_rietveld
[email protected]2a74d372011-03-29 19:05:5057 server = local_rietveld.LocalRietveld()
58 finally:
59 sys.path = old_sys_path
60
[email protected]ccbb7812011-04-06 13:36:2361 results = []
[email protected]2a74d372011-03-29 19:05:5062 try:
63 # Start a local rietveld instance to test against.
64 server.start_server()
65 test_path = input_api.os_path.abspath(
66 input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'))
[email protected]ccbb7812011-04-06 13:36:2367 for test in input_api.os_listdir(test_path):
[email protected]2a74d372011-03-29 19:05:5068 # test-lib.sh is not an actual test so it should not be run. The other
69 # tests are tests known to fail.
70 DISABLED_TESTS = (
71 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh')
72 if test in DISABLED_TESTS or not test.endswith('.sh'):
73 continue
74
75 print('Running %s' % test)
[email protected]ccbb7812011-04-06 13:36:2376 try:
[email protected]899e1c12011-04-07 17:03:1877 if input_api.verbose:
[email protected]ccbb7812011-04-06 13:36:2378 input_api.subprocess.check_call(
79 [input_api.os_path.join(test_path, test)], cwd=test_path)
80 else:
81 input_api.subprocess.check_output(
[email protected]87e6d332011-09-09 19:01:2882 [input_api.os_path.join(test_path, test)], cwd=test_path,
83 stderr=input_api.subprocess.STDOUT)
[email protected]ccbb7812011-04-06 13:36:2384 except (OSError, input_api.subprocess.CalledProcessError), e:
85 results.append(output_api.PresubmitError('%s failed\n%s' % (test, e)))
[email protected]2a74d372011-03-29 19:05:5086 except local_rietveld.Failure, e:
[email protected]ccbb7812011-04-06 13:36:2387 results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
[email protected]2a74d372011-03-29 19:05:5088 finally:
89 server.stop_server()
[email protected]ccbb7812011-04-06 13:36:2390 return results
[email protected]ce30ef72009-05-25 15:20:4291
92
[email protected]e94aedc2010-12-13 21:11:3093def CheckChangeOnUpload(input_api, output_api):
[email protected]d52417c2011-09-02 20:13:1794 # Do not run integration tests on upload since they are way too slow.
95 tests_to_black_list = [
96 r'^checkout_test\.py$',
97 r'^gclient_smoketest\.py$',
98 r'^scm_unittest\.py$',
99 ]
100 return CommonChecks(input_api, output_api, tests_to_black_list)
[email protected]e94aedc2010-12-13 21:11:30101
102
[email protected]ce30ef72009-05-25 15:20:42103def CheckChangeOnCommit(input_api, output_api):
104 output = []
[email protected]d52417c2011-09-02 20:13:17105 output.extend(CommonChecks(input_api, output_api, []))
[email protected]e94aedc2010-12-13 21:11:30106 output.extend(input_api.canned_checks.CheckDoNotSubmit(
107 input_api,
108 output_api))
[email protected]d52417c2011-09-02 20:13:17109 output.extend(RunGitClTests(input_api, output_api))
[email protected]7b305e82009-05-19 18:24:20110 return output