xref: /aosp_15_r20/external/cronet/third_party/metrics_proto/PRESUBMIT.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
12DIR_METADATA = 'DIR_METADATA'
13README = 'README.chromium'
14PRESUBMIT = 'PRESUBMIT.py'
15PRESUBMIT_TEST = 'PRESUBMIT_test.py'
16OWNERS = 'OWNERS'
17
18
19def IsMetricsProtoPath(input_api, path):
20  return input_api.os_path.dirname(path) == input_api.PresubmitLocalPath()
21
22
23def IsReadmeFile(input_api, path):
24  return (input_api.os_path.basename(path) == README and
25          IsMetricsProtoPath(input_api, path))
26
27
28def IsImportedFile(input_api, path):
29  return (not input_api.os_path.basename(path) in (PRESUBMIT, PRESUBMIT_TEST,
30                                                  OWNERS, DIR_METADATA) and
31          IsMetricsProtoPath(input_api, path))
32
33
34def CheckChange(input_api, output_api):
35  """Checks that all changes include a README update."""
36  paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles()]
37  if (any(IsImportedFile(input_api, p) for p in paths) and not
38      any(IsReadmeFile(input_api, p) for p in paths)):
39    return [output_api.PresubmitError(
40            'Modifies %s without updating %s. '
41            'Changes to these files should originate upstream.' %
42            (input_api.PresubmitLocalPath(), README))]
43  return []
44
45
46def CheckChangeOnUpload(input_api, output_api):
47  return CheckChange(input_api, output_api)
48
49
50def CheckChangeOnCommit(input_api, output_api):
51  return CheckChange(input_api, output_api)
52