OLD | NEW |
---|---|
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Top-level presubmit script for depot tools. | 5 """Top-level presubmit script for depot tools. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
8 details on the presubmit API built into depot_tools. | 8 details on the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
11 | 11 |
12 def CommonChecks(input_api, output_api): | 12 def CommonChecks(input_api, output_api): |
13 results = [] | 13 results = [] |
14 import sys | 14 import sys |
15 if not sys.version.startswith('2.5'): | 15 if not sys.version.startswith('2.5'): |
16 # Depot_tools has the particularity that it needs to be tested on python | 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. | 17 # 2.5. But we don't want the presubmit check to fail if it is not installed. |
18 results.append(output_api.PresubmitNotifyResult( | 18 results.append(output_api.PresubmitNotifyResult( |
19 'You should install python 2.5 and run ln -s $(which python2.5) python.' | 19 'You should install python 2.5 and run ln -s $(which python2.5) python.' |
20 '\n' | 20 '\n' |
21 'A great place to put this symlink is in depot_tools.\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 ' | 22 'Otherwise, you break depot_tools on python 2.5, you get to keep the ' |
23 'pieces.')) | 23 'pieces.')) |
24 | 24 |
25 | 25 |
26 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) | 26 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
27 black_list = list(input_api.DEFAULT_BLACK_LIST) + [ | 27 black_list = list(input_api.DEFAULT_BLACK_LIST) + [ |
28 r'^cpplint\.py$', | 28 r'^cpplint\.py$', |
29 r'^python_bin[\/\\].+', | |
30 r'^svn_bin[\/\\].+', | |
29 r'^tests[\/\\]\w+?[\/\\].+'] | 31 r'^tests[\/\\]\w+?[\/\\].+'] |
30 results.extend(input_api.canned_checks.RunPylint( | 32 results.extend(input_api.canned_checks.RunPylint( |
31 input_api, | 33 input_api, |
32 output_api, | 34 output_api, |
33 white_list=[r'.*\.py$', r'^git-try$'], | 35 white_list=[r'.*\.py$', r'^git-try$'], |
34 black_list=black_list)) | 36 black_list=black_list)) |
35 | 37 |
36 # TODO(maruel): Make sure at least one file is modified first. | 38 # TODO(maruel): Make sure at least one file is modified first. |
37 # TODO(maruel): If only tests are modified, only run them. | 39 # TODO(maruel): If only tests are modified, only run them. |
38 verbose = False | 40 verbose = False |
39 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 41 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
40 input_api, | 42 input_api, |
41 output_api, | 43 output_api, |
42 'tests', | 44 'tests', |
43 whitelist=[r'.*test\.py$'], | 45 whitelist=[r'.*test\.py$'], |
44 verbose=verbose)) | 46 verbose=verbose)) |
45 results.extend(RunGitClTests(input_api, output_api)) | 47 results.extend(RunGitClTests(input_api, output_api, verbose=verbose)) |
46 return results | 48 return results |
47 | 49 |
48 | 50 |
49 def RunGitClTests(input_api, output_api): | 51 def RunGitClTests(input_api, output_api, verbose): |
50 """Run all the shells scripts in the directory test. | 52 """Run all the shells scripts in the directory test. |
51 """ | 53 """ |
52 # Not exposed from InputApi. | |
53 from os import listdir | |
54 | |
55 # First loads a local Rietveld instance. | 54 # First loads a local Rietveld instance. |
56 import sys | 55 import sys |
57 old_sys_path = sys.path | 56 old_sys_path = sys.path |
58 try: | 57 try: |
59 sys.path = [input_api.PresubmitLocalPath()] + sys.path | 58 sys.path = [input_api.PresubmitLocalPath()] + sys.path |
60 from tests import local_rietveld # pylint: disable=W0403 | 59 from tests import local_rietveld # pylint: disable=W0403 |
61 server = local_rietveld.LocalRietveld() | 60 server = local_rietveld.LocalRietveld() |
62 finally: | 61 finally: |
63 sys.path = old_sys_path | 62 sys.path = old_sys_path |
64 | 63 |
65 # Set to True for testing. | 64 results = [] |
66 verbose = False | |
67 if verbose: | |
68 stdout = None | |
69 stderr = None | |
70 else: | |
71 stdout = input_api.subprocess.PIPE | |
72 stderr = input_api.subprocess.STDOUT | |
73 output = [] | |
74 try: | 65 try: |
75 # Start a local rietveld instance to test against. | 66 # Start a local rietveld instance to test against. |
76 server.start_server() | 67 server.start_server() |
77 test_path = input_api.os_path.abspath( | 68 test_path = input_api.os_path.abspath( |
78 input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests')) | 69 input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests')) |
79 for test in listdir(test_path): | 70 for test in input_api.os_listdir(test_path): |
80 # test-lib.sh is not an actual test so it should not be run. The other | 71 # test-lib.sh is not an actual test so it should not be run. The other |
81 # tests are tests known to fail. | 72 # tests are tests known to fail. |
82 DISABLED_TESTS = ( | 73 DISABLED_TESTS = ( |
83 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh') | 74 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh') |
84 if test in DISABLED_TESTS or not test.endswith('.sh'): | 75 if test in DISABLED_TESTS or not test.endswith('.sh'): |
85 continue | 76 continue |
86 | 77 |
87 print('Running %s' % test) | 78 print('Running %s' % test) |
88 proc = input_api.subprocess.Popen( | 79 try: |
89 [input_api.os_path.join(test_path, test)], | 80 if verbose: |
90 cwd=test_path, | 81 input_api.subprocess.check_call( |
91 stdout=stdout, | 82 [input_api.os_path.join(test_path, test)], cwd=test_path) |
92 stderr=stderr) | 83 else: |
93 proc.communicate() | 84 input_api.subprocess.check_output( |
94 if proc.returncode != 0: | 85 [input_api.os_path.join(test_path, test)], cwd=test_path) |
95 output.append(output_api.PresubmitError('%s failed' % test)) | 86 except (OSError, input_api.subprocess.CalledProcessError), e: |
87 results.append(output_api.PresubmitError('%s failed\n%s' % (test, e))) | |
Dirk Pranke
2011/04/05 21:11:42
Maybe something to change separate from this patch
| |
96 except local_rietveld.Failure, e: | 88 except local_rietveld.Failure, e: |
97 output.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args))) | 89 results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args))) |
98 finally: | 90 finally: |
99 server.stop_server() | 91 server.stop_server() |
100 return output | 92 return results |
101 | 93 |
102 | 94 |
103 def CheckChangeOnUpload(input_api, output_api): | 95 def CheckChangeOnUpload(input_api, output_api): |
104 return CommonChecks(input_api, output_api) | 96 return CommonChecks(input_api, output_api) |
105 | 97 |
106 | 98 |
107 def CheckChangeOnCommit(input_api, output_api): | 99 def CheckChangeOnCommit(input_api, output_api): |
108 output = [] | 100 output = [] |
109 output.extend(CommonChecks(input_api, output_api)) | 101 output.extend(CommonChecks(input_api, output_api)) |
110 output.extend(input_api.canned_checks.CheckDoNotSubmit( | 102 output.extend(input_api.canned_checks.CheckDoNotSubmit( |
111 input_api, | 103 input_api, |
112 output_api)) | 104 output_api)) |
113 return output | 105 return output |
OLD | NEW |