Revert of Roll src/third_party/skia 1340039:e942bee (patchset #1 id:1 of https:/...
[chromium-blink-merge.git] / tools / auto_bisect / PRESUBMIT.py
blob380cb0072e17fcc5af55e3fbbdd16efea514d03f
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.
5 """Top-level presubmit script for auto-bisect.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API.
9 """
11 import imp
12 import subprocess
13 import os
15 # Paths to bisect config files relative to this script.
16 CONFIG_FILES = [
17 'bisect.cfg',
18 os.path.join(os.path.pardir, 'run-perf-test.cfg'),
22 def CheckChangeOnUpload(input_api, output_api):
23 return _CommonChecks(input_api, output_api)
26 def CheckChangeOnCommit(input_api, output_api):
27 return _CommonChecks(input_api, output_api)
30 def _CommonChecks(input_api, output_api):
31 """Does all presubmit checks for auto-bisect."""
32 results = []
33 results.extend(_CheckAllConfigFiles(input_api, output_api))
34 results.extend(_RunUnitTests(input_api, output_api))
35 results.extend(_RunPyLint(input_api, output_api))
36 return results
39 def _CheckAllConfigFiles(input_api, output_api):
40 """Checks all bisect config files and returns a list of presubmit results."""
41 results = []
42 script_path = input_api.PresubmitLocalPath()
43 for config_file in CONFIG_FILES:
44 file_path = os.path.join(script_path, config_file)
45 results.extend(_CheckConfigFile(file_path, output_api))
46 return results
49 def _CheckConfigFile(file_path, output_api):
50 """Checks one bisect config file and returns a list of presubmit results."""
51 try:
52 config_file = imp.load_source('config', file_path)
53 except IOError as e:
54 warning = 'Failed to read config file %s: %s' % (file_path, str(e))
55 return [output_api.PresubmitError(warning, items=[file_path])]
57 if not hasattr(config_file, 'config'):
58 warning = 'Config file has no "config" global variable: %s' % str(e)
59 return [output_api.PresubmitError(warning, items=[file_path])]
61 if type(config_file.config) is not dict:
62 warning = 'Config file "config" global variable is not dict: %s' % str(e)
63 return [output_api.PresubmitError(warning, items=[file_path])]
65 for k, v in config_file.config.iteritems():
66 if v != '':
67 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v))
68 warning += ('\nThe bisection config file should only contain a config '
69 'dict with empty fields. Changes to this file should not '
70 'be submitted.')
71 return [output_api.PresubmitError(warning, items=[file_path])]
73 return []
76 def _RunUnitTests(input_api, output_api):
77 """Runs unit tests for auto-bisect."""
78 repo_root = input_api.change.RepositoryRoot()
79 auto_bisect_dir = os.path.join(repo_root, 'tools', 'auto_bisect')
80 test_runner = os.path.join(auto_bisect_dir, 'run_tests')
81 return_code = subprocess.call(['python', test_runner])
82 if return_code:
83 message = 'Auto-bisect unit tests did not all pass.'
84 return [output_api.PresubmitError(message)]
85 return []
88 def _RunPyLint(input_api, output_api):
89 """Runs unit tests for auto-bisect."""
90 telemetry_path = os.path.join(
91 input_api.PresubmitLocalPath(), os.path.pardir, 'telemetry')
92 mock_path = os.path.join(
93 input_api.PresubmitLocalPath(), os.path.pardir, os.path.pardir,
94 'third_party', 'pymock')
95 disabled_warnings = [
96 'relative-import',
98 tests = input_api.canned_checks.GetPylint(
99 input_api, output_api, disabled_warnings=disabled_warnings,
100 extra_paths_list=[telemetry_path, mock_path])
101 return input_api.RunTests(tests)