OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 auto-bisect. | 5 """Top-level presubmit script for auto-bisect. |
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. | 8 details on the presubmit API. |
9 """ | 9 """ |
10 | 10 |
11 import imp | 11 import imp |
12 import subprocess | 12 import subprocess |
13 import os | 13 import os |
14 | 14 |
15 # Paths to bisect config files relative to src/tools. | 15 # Paths to bisect config files relative to this script. |
16 CONFIG_FILES = [ | 16 CONFIG_FILES = [ |
17 'auto_bisect/config.cfg', | 17 'bisect.cfg', |
18 'run-perf-test.cfg' | 18 os.path.join(os.path.pardir, 'run-perf-test.cfg'), |
19 ] | 19 ] |
20 | 20 |
21 | |
22 def CheckChangeOnUpload(input_api, output_api): | 21 def CheckChangeOnUpload(input_api, output_api): |
23 return _CommonChecks(input_api, output_api) | 22 return _CommonChecks(input_api, output_api) |
24 | 23 |
25 | 24 |
26 def CheckChangeOnCommit(input_api, output_api): | 25 def CheckChangeOnCommit(input_api, output_api): |
27 return _CommonChecks(input_api, output_api) | 26 return _CommonChecks(input_api, output_api) |
28 | 27 |
29 | 28 |
30 def _CommonChecks(input_api, output_api): | 29 def _CommonChecks(input_api, output_api): |
31 """Does all presubmit checks for auto-bisect.""" | 30 """Does all presubmit checks for auto-bisect.""" |
32 results = [] | 31 results = [] |
33 results.extend(_CheckAllConfigFiles(input_api, output_api)) | 32 results.extend(_CheckAllConfigFiles(input_api, output_api)) |
34 results.extend(_RunUnitTests(input_api, output_api)) | 33 results.extend(_RunUnitTests(input_api, output_api)) |
35 results.extend(_RunPyLint(input_api, output_api)) | 34 results.extend(_RunPyLint(input_api, output_api)) |
36 return results | 35 return results |
37 | 36 |
38 | 37 |
39 def _CheckAllConfigFiles(input_api, output_api): | 38 def _CheckAllConfigFiles(input_api, output_api): |
40 """Checks all bisect config files and returns a list of presubmit results.""" | 39 """Checks all bisect config files and returns a list of presubmit results.""" |
41 results = [] | 40 results = [] |
42 for f in input_api.AffectedFiles(): | 41 script_path = input_api.PresubmitLocalPath() |
43 for config_file in CONFIG_FILES: | 42 for config_file in CONFIG_FILES: |
44 if f.LocalPath().endswith(config_file): | 43 file_path = os.path.join(script_path, config_file) |
45 results.extend(_CheckConfigFile(config_file, output_api)) | 44 results.extend(_CheckConfigFile(file_path, output_api)) |
46 return results | 45 return results |
47 | 46 |
48 | 47 |
49 def _CheckConfigFile(file_path, output_api): | 48 def _CheckConfigFile(file_path, output_api): |
50 """Checks one bisect config file and returns a list of presubmit results.""" | 49 """Checks one bisect config file and returns a list of presubmit results.""" |
51 try: | 50 try: |
52 config_file = imp.load_source('config', file_path) | 51 config_file = imp.load_source('config', file_path) |
53 except IOError as e: | 52 except IOError as e: |
54 warning = 'Failed to read config file %s: %s' % (file_path, str(e)) | 53 warning = 'Failed to read config file %s: %s' % (file_path, str(e)) |
55 return [output_api.PresubmitError(warning, items=[file_path])] | 54 return [output_api.PresubmitError(warning, items=[file_path])] |
56 | 55 |
57 if not hasattr(config_file.config): | 56 if not hasattr(config_file, 'config'): |
58 warning = 'Config file has no "config" global variable: %s' % str(e) | 57 warning = 'Config file has no "config" global variable: %s' % str(e) |
59 return [output_api.PresubmitError(warning, items=[file_path])] | 58 return [output_api.PresubmitError(warning, items=[file_path])] |
60 | 59 |
61 if type(config_file.config) is not dict: | 60 if type(config_file.config) is not dict: |
62 warning = 'Config file "config" global variable is not dict: %s' % str(e) | 61 warning = 'Config file "config" global variable is not dict: %s' % str(e) |
63 return [output_api.PresubmitError(warning, items=[file_path])] | 62 return [output_api.PresubmitError(warning, items=[file_path])] |
64 | 63 |
65 for k, v in config_file.config.iteritems(): | 64 for k, v in config_file.config.iteritems(): |
66 if v != '': | 65 if v != '': |
67 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v)) | 66 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v)) |
(...skipping 21 matching lines...) Expand all Loading... |
89 """Runs unit tests for auto-bisect.""" | 88 """Runs unit tests for auto-bisect.""" |
90 telemetry_path = os.path.join( | 89 telemetry_path = os.path.join( |
91 input_api.PresubmitLocalPath(), os.path.pardir, 'telemetry') | 90 input_api.PresubmitLocalPath(), os.path.pardir, 'telemetry') |
92 mock_path = os.path.join( | 91 mock_path = os.path.join( |
93 input_api.PresubmitLocalPath(),os.path.pardir, os.path.pardir, | 92 input_api.PresubmitLocalPath(),os.path.pardir, os.path.pardir, |
94 'third_party', 'pymock') | 93 'third_party', 'pymock') |
95 tests = input_api.canned_checks.GetPylint( | 94 tests = input_api.canned_checks.GetPylint( |
96 input_api, output_api, extra_paths_list=[telemetry_path, mock_path]) | 95 input_api, output_api, extra_paths_list=[telemetry_path, mock_path]) |
97 return input_api.RunTests(tests) | 96 return input_api.RunTests(tests) |
98 | 97 |
OLD | NEW |