blob: 5ebdba98884de1c5c78255ae539f2745a4c2e279 [file] [log] [blame]
[email protected]1ee7f892014-03-04 06:04:251# Copyright 2014 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"""Chromium presubmit script for src/extensions/browser.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
tfarina78bb92f42015-01-31 00:20:488for more details on the presubmit API built into depot_tools.
[email protected]1ee7f892014-03-04 06:04:259"""
10
Elaine Chiend9296372021-06-17 00:35:5611USE_PYTHON3 = True
12
rockot39a7fbf2015-11-13 17:29:2613import sys
14
15def _CreateHistogramValueChecker(input_api, output_api, path):
16 original_sys_path = sys.path
17
18 try:
19 sys.path.append(input_api.os_path.join(
20 input_api.PresubmitLocalPath(), '..', '..', 'tools',
21 'strict_enum_value_checker'))
22 from strict_enum_value_checker import StrictEnumValueChecker
23 finally:
24 sys.path = original_sys_path
25
26 return StrictEnumValueChecker(input_api, output_api,
27 start_marker='enum HistogramValue {', end_marker=' // Last entry:',
28 path=path)
29
30
31def _RunHistogramValueCheckers(input_api, output_api):
32 results = []
33 histogram_paths = ('extensions/browser/extension_event_histogram_value.h',
34 'extensions/browser/extension_function_histogram_value.h')
35 for path in histogram_paths:
36 results += _CreateHistogramValueChecker(input_api, output_api, path).Run()
37 return results
38
dougtb53dc592017-02-01 16:25:0039def _RunHistogramChecks(input_api, output_api, histogram_name):
40 try:
lukasza14d9a1a2017-04-28 15:23:5741 # Setup sys.path so that we can call histograms code.
dougtb53dc592017-02-01 16:25:0042 import sys
43 original_sys_path = sys.path
44 sys.path = sys.path + [input_api.os_path.join(
45 input_api.change.RepositoryRoot(),
46 'tools', 'metrics', 'histograms')]
47
48 import presubmit_bad_message_reasons
49 return presubmit_bad_message_reasons.PrecheckBadMessage(input_api,
50 output_api, histogram_name)
51 except:
52 return [output_api.PresubmitError('Could not verify histogram!')]
53 finally:
54 sys.path = original_sys_path
rockot39a7fbf2015-11-13 17:29:2655
[email protected]1ee7f892014-03-04 06:04:2556def CheckChangeOnUpload(input_api, output_api):
57 results = []
rockot39a7fbf2015-11-13 17:29:2658 results += _RunHistogramValueCheckers(input_api, output_api)
dougtb53dc592017-02-01 16:25:0059 results += _RunHistogramChecks(input_api, output_api,
60 "BadMessageReasonExtensions")
[email protected]1ee7f892014-03-04 06:04:2561 return results