• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Presubmit script for metrics_proto.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details on the presubmit API built into gcl.
9"""
10
11
12README = 'README.chromium'
13PRESUBMIT = 'PRESUBMIT.py'
14PRESUBMIT_TEST = 'PRESUBMIT_test.py'
15OWNERS = 'OWNERS'
16
17
18def IsMetricsProtoPath(input_api, path):
19  return input_api.os_path.dirname(path) == input_api.PresubmitLocalPath()
20
21
22def IsReadmeFile(input_api, path):
23  return (input_api.os_path.basename(path) == README and
24          IsMetricsProtoPath(input_api, path))
25
26
27def IsImportedFile(input_api, path):
28  return (not input_api.os_path.basename(path) in(PRESUBMIT, PRESUBMIT_TEST,
29                                                  OWNERS) and
30          IsMetricsProtoPath(input_api, path))
31
32
33def CheckChange(input_api, output_api):
34  """Checks that all changes include a README update."""
35  paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles()]
36  if (any(IsImportedFile(input_api, p) for p in paths) and not
37      any(IsReadmeFile(input_api, p) for p in paths)):
38    return [output_api.PresubmitError(
39            'Modifies %s without updating %s. '
40            'Changes to these files should originate upstream.' %
41            (input_api.PresubmitLocalPath(), README))]
42  return []
43
44
45def CheckChangeOnUpload(input_api, output_api):
46  return CheckChange(input_api, output_api)
47
48
49def CheckChangeOnCommit(input_api, output_api):
50  return CheckChange(input_api, output_api)
51