| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Top-level presubmit script for auto-bisect. | |
| 6 | |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | |
| 8 details on the presubmit API built into gcl. | |
| 9 """ | |
| 10 | |
| 11 import imp | |
| 12 import os | |
| 13 | |
| 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 = [] | |
| 44 for f in input_api.AffectedFiles(): | |
| 45 for config_file in CONFIG_FILES: | |
| 46 if f.LocalPath().endswith(config_file): | |
| 47 results.extend(_CheckConfigFile(config_file, output_api)) | |
| 48 return results | |
| 49 | |
| 50 | |
| 51 def _CheckConfigFile(file_path, output_api): | |
| 52 """Checks one bisect config file and returns a list of presubmit results.""" | |
| 53 try: | |
| 54 config_file = imp.load_source('config', file_path) | |
| 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])] | |
| 58 | |
| 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])] | |
| 62 | |
| 63 if type(config_file.config) is not dict: | |
| 64 warning = 'Config file "config" global variable is not dict: %s' % str(e) | |
| 65 return [output_api.PresubmitError(warning, items=[file_path])] | |
| 66 | |
| 67 for k, v in config_dict.iteritems(): | |
| 68 if v != '': | |
| 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])] | |
| 74 | |
| 75 return [] | |
| OLD | NEW |