blob: 471d938a5125800bfeb8c5c5806d6decc43cde15 [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]34071032014-03-18 17:23:4811import fnmatch
12import os
13
[email protected]627ea672011-03-11 23:29:0314
[email protected]d52417c2011-09-02 20:13:1715def CommonChecks(input_api, output_api, tests_to_black_list):
[email protected]3c9f7ca2011-04-01 14:52:3816 results = []
[email protected]3c9f7ca2011-04-01 14:52:3817 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
[email protected]bf38a7e2010-12-14 18:15:5418 black_list = list(input_api.DEFAULT_BLACK_LIST) + [
[email protected]f7bb4cf2015-12-04 23:30:3819 r'^\.recipe_deps[\/\\].*',
[email protected]4c396942016-02-02 16:13:0120 r'^infra[\/\\]\.recipe_deps[\/\\].*',
[email protected]5d0dc432011-01-03 02:40:3721 r'^cpplint\.py$',
[email protected]63c2c1d2011-09-07 21:41:5522 r'^cpplint_chromium\.py$',
[email protected]7cc38e82015-01-08 22:28:3423 r'^external_bin[\/\\].+',
[email protected]154c36c2013-12-12 14:13:4424 r'^python[0-9]*_bin[\/\\].+',
[email protected]f7bb4cf2015-12-04 23:30:3825 r'^recipes\.py$',
[email protected]c920ad22012-02-02 18:26:0426 r'^site-packages-py[0-9]\.[0-9][\/\\].+',
[email protected]ccbb7812011-04-06 13:36:2327 r'^svn_bin[\/\\].+',
[email protected]150aa7b2015-11-09 19:20:5528 r'^testing_support[\/\\]_rietveld[\/\\].+']
[email protected]34071032014-03-18 17:23:4829 if os.path.exists('.gitignore'):
30 with open('.gitignore') as fh:
31 lines = [l.strip() for l in fh.readlines()]
32 black_list.extend([fnmatch.translate(l) for l in lines if
33 l and not l.startswith('#')])
34 if os.path.exists('.git/info/exclude'):
35 with open('.git/info/exclude') as fh:
36 lines = [l.strip() for l in fh.readlines()]
37 black_list.extend([fnmatch.translate(l) for l in lines if
38 l and not l.startswith('#')])
[email protected]ff9a2172012-04-24 16:55:3239 disabled_warnings = [
40 'R0401', # Cyclic import
41 'W0613', # Unused argument
42 ]
[email protected]69ae86a2014-01-17 03:55:4543 pylint = input_api.canned_checks.GetPylint(
44 input_api,
45 output_api,
46 white_list=[r'.*\.py$'],
47 black_list=black_list,
48 disabled_warnings=disabled_warnings)
49 # TODO(maruel): Make sure at least one file is modified first.
50 # TODO(maruel): If only tests are modified, only run them.
51 unit_tests = input_api.canned_checks.GetUnitTestsInDirectory(
52 input_api,
53 output_api,
54 'tests',
55 whitelist=[r'.*test\.py$'],
56 blacklist=tests_to_black_list)
57 tests = pylint
58 if not input_api.platform.startswith(('cygwin', 'win32')):
59 tests.extend(unit_tests)
60 else:
61 print('Warning: not running unit tests on Windows')
62 results.extend(input_api.RunTests(tests))
[email protected]3c9f7ca2011-04-01 14:52:3863 return results
[email protected]2a74d372011-03-29 19:05:5064
65
[email protected]899e1c12011-04-07 17:03:1866def RunGitClTests(input_api, output_api):
[email protected]2a74d372011-03-29 19:05:5067 """Run all the shells scripts in the directory test.
68 """
[email protected]c98c0c52011-04-06 13:39:4369 if input_api.platform == 'win32':
70 # Skip for now as long as the test scripts are bash scripts.
71 return []
72
[email protected]2a74d372011-03-29 19:05:5073 # First loads a local Rietveld instance.
74 import sys
75 old_sys_path = sys.path
76 try:
77 sys.path = [input_api.PresubmitLocalPath()] + sys.path
[email protected]0927b7e2011-11-11 16:06:2278 from testing_support import local_rietveld
[email protected]2a74d372011-03-29 19:05:5079 server = local_rietveld.LocalRietveld()
80 finally:
81 sys.path = old_sys_path
82
[email protected]ccbb7812011-04-06 13:36:2383 results = []
[email protected]2a74d372011-03-29 19:05:5084 try:
85 # Start a local rietveld instance to test against.
86 server.start_server()
87 test_path = input_api.os_path.abspath(
88 input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'))
[email protected]ccbb7812011-04-06 13:36:2389 for test in input_api.os_listdir(test_path):
[email protected]2a74d372011-03-29 19:05:5090 # test-lib.sh is not an actual test so it should not be run. The other
91 # tests are tests known to fail.
92 DISABLED_TESTS = (
93 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh')
94 if test in DISABLED_TESTS or not test.endswith('.sh'):
95 continue
96
97 print('Running %s' % test)
[email protected]ccbb7812011-04-06 13:36:2398 try:
[email protected]899e1c12011-04-07 17:03:1899 if input_api.verbose:
[email protected]ccbb7812011-04-06 13:36:23100 input_api.subprocess.check_call(
101 [input_api.os_path.join(test_path, test)], cwd=test_path)
102 else:
103 input_api.subprocess.check_output(
[email protected]87e6d332011-09-09 19:01:28104 [input_api.os_path.join(test_path, test)], cwd=test_path,
105 stderr=input_api.subprocess.STDOUT)
[email protected]ccbb7812011-04-06 13:36:23106 except (OSError, input_api.subprocess.CalledProcessError), e:
107 results.append(output_api.PresubmitError('%s failed\n%s' % (test, e)))
[email protected]2a74d372011-03-29 19:05:50108 except local_rietveld.Failure, e:
[email protected]ccbb7812011-04-06 13:36:23109 results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
[email protected]2a74d372011-03-29 19:05:50110 finally:
111 server.stop_server()
[email protected]ccbb7812011-04-06 13:36:23112 return results
[email protected]ce30ef72009-05-25 15:20:42113
114
[email protected]e94aedc2010-12-13 21:11:30115def CheckChangeOnUpload(input_api, output_api):
[email protected]d52417c2011-09-02 20:13:17116 # Do not run integration tests on upload since they are way too slow.
117 tests_to_black_list = [
118 r'^checkout_test\.py$',
119 r'^gclient_smoketest\.py$',
120 r'^scm_unittest\.py$',
[email protected]58565622013-03-17 23:18:37121 r'^subprocess2_test\.py$',
[email protected]d52417c2011-09-02 20:13:17122 ]
123 return CommonChecks(input_api, output_api, tests_to_black_list)
[email protected]e94aedc2010-12-13 21:11:30124
125
[email protected]ce30ef72009-05-25 15:20:42126def CheckChangeOnCommit(input_api, output_api):
127 output = []
[email protected]d52417c2011-09-02 20:13:17128 output.extend(CommonChecks(input_api, output_api, []))
[email protected]e94aedc2010-12-13 21:11:30129 output.extend(input_api.canned_checks.CheckDoNotSubmit(
130 input_api,
131 output_api))
[email protected]d52417c2011-09-02 20:13:17132 output.extend(RunGitClTests(input_api, output_api))
[email protected]7b305e82009-05-19 18:24:20133 return output