| 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 bisect/perf trybot. | 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 built into gcl. | 8 details on the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import imp | 11 import imp |
| 12 import os | 12 import os |
| 13 | 13 |
| 14 def _ExamineConfigFiles(input_api): | 14 # Paths to bisect config files relative to src/tools. |
| 15 CONFIG_FILES = [ |
| 16 'auto_bisect/config.cfg', |
| 17 'run-perf-test.cfg' |
| 18 ] |
| 19 |
| 20 PYLINT_BLACKLIST = [] |
| 21 PYLINT_DISABLED_WARNINGS = [] |
| 22 |
| 23 |
| 24 def CheckChangeOnUpload(input_api, output_api): |
| 25 return _CommonChecks(input_api, output_api) |
| 26 |
| 27 |
| 28 def CheckChangeOnCommit(input_api, output_api): |
| 29 return _CommonChecks(input_api, output_api) |
| 30 |
| 31 |
| 32 def _CommonChecks(input_api, output_api): |
| 33 """Does all presubmit checks for auto-bisect.""" |
| 34 # TODO(qyearsley) Run bisect unit test. |
| 35 # TODO(qyearsley) Run pylint on all auto-bisect py files but not other files. |
| 36 results = [] |
| 37 results.extend(_CheckAllConfigFiles(input_api, output_api)) |
| 38 return results |
| 39 |
| 40 |
| 41 def _CheckAllConfigFiles(input_api, output_api): |
| 42 """Checks all bisect config files and returns a list of presubmit results.""" |
| 43 results = [] |
| 15 for f in input_api.AffectedFiles(): | 44 for f in input_api.AffectedFiles(): |
| 16 if (not f.LocalPath().endswith('run-bisect-perf-regression.cfg') and | 45 for config_file in CONFIG_FILES: |
| 17 not f.LocalPath().endswith('run-perf-test.cfg')): | 46 if f.LocalPath().endswith(config_file): |
| 18 continue | 47 results.extend(_CheckConfigFile(config_file, output_api)) |
| 48 return results |
| 19 | 49 |
| 20 try: | |
| 21 cfg_file = imp.load_source('config', os.path.basename(f.LocalPath())) | |
| 22 | 50 |
| 23 for k, v in cfg_file.config.iteritems(): | 51 def _CheckConfigFile(file_path, output_api): |
| 24 if v: | 52 """Checks one bisect config file and returns a list of presubmit results.""" |
| 25 return f.LocalPath() | 53 try: |
| 26 except (IOError, AttributeError, TypeError): | 54 config_file = imp.load_source('config', file_path) |
| 27 return f.LocalPath() | 55 except IOError as e: |
| 56 warning = 'Failed to read config file %s: %s' % (file_path, str(e)) |
| 57 return [output_api.PresubmitError(warning, items=[file_path])] |
| 28 | 58 |
| 29 return None | 59 if not hasattr(config_file.config): |
| 60 warning = 'Config file has no "config" global variable: %s' % str(e) |
| 61 return [output_api.PresubmitError(warning, items=[file_path])] |
| 30 | 62 |
| 31 def _CheckNoChangesToBisectConfigFile(input_api, output_api): | 63 if type(config_file.config) is not dict: |
| 32 results = _ExamineConfigFiles(input_api) | 64 warning = 'Config file "config" global variable is not dict: %s' % str(e) |
| 33 if results: | 65 return [output_api.PresubmitError(warning, items=[file_path])] |
| 34 return [output_api.PresubmitError( | 66 |
| 35 'The bisection config file should only contain a config dict with ' | 67 for k, v in config_dict.iteritems(): |
| 36 'empty fields. Changes to this file should never be submitted.', | 68 if v != '': |
| 37 items=[results])] | 69 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v)) |
| 70 warning += ('\nThe bisection config file should only contain a config ' |
| 71 'dict with empty fields. Changes to this file should not ' |
| 72 'be submitted.') |
| 73 return [output_api.PresubmitError(warning, items=[file_path])] |
| 38 | 74 |
| 39 return [] | 75 return [] |
| 40 | |
| 41 def CommonChecks(input_api, output_api): | |
| 42 results = [] | |
| 43 results.extend(_CheckNoChangesToBisectConfigFile(input_api, output_api)) | |
| 44 return results | |
| 45 | |
| 46 def CheckChangeOnUpload(input_api, output_api): | |
| 47 return CommonChecks(input_api, output_api) | |
| 48 | |
| 49 def CheckChangeOnCommit(input_api, output_api): | |
| 50 return CommonChecks(input_api, output_api) | |
| OLD | NEW |