summaryrefslogtreecommitdiffstats
path: root/tools/PRESUBMIT.py
blob: 01572314c06b789f75696cab12e3b91a9cb309fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Top-level presubmit script for bisect trybot.

See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
details on the presubmit API built into gcl.
"""

import imp

def _ExamineBisectConfigFile(input_api, output_api):
  for f in input_api.AffectedFiles():
    if not f.LocalPath().endswith('run-bisect-perf-regression.cfg'):
      continue

    try:
      cfg_file = imp.load_source('config', 'run-bisect-perf-regression.cfg')

      for k, v in cfg_file.config.iteritems():
        if v:
          return f.LocalPath()
    except (IOError, AttributeError, TypeError):
      return f.LocalPath()

  return None

def _CheckNoChangesToBisectConfigFile(input_api, output_api):
  results = _ExamineBisectConfigFile(input_api, output_api)
  if results:
    return [output_api.PresubmitError(
        'The bisection config file should only contain a config dict with '
        'empty fields. Changes to this file should never be submitted.',
        items=[results])]

  return []

def CommonChecks(input_api, output_api):
  results = []
  results.extend(_CheckNoChangesToBisectConfigFile(input_api, output_api))
  return results

def CheckChangeOnUpload(input_api, output_api):
  return CommonChecks(input_api, output_api)

def CheckChangeOnCommit(input_api, output_api):
  return CommonChecks(input_api, output_api)