[email protected] | 1ee7f89 | 2014-03-04 06:04:25 | [diff] [blame] | 1 | # 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 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
tfarina | 78bb92f4 | 2015-01-31 00:20:48 | [diff] [blame] | 8 | for more details on the presubmit API built into depot_tools. |
[email protected] | 1ee7f89 | 2014-03-04 06:04:25 | [diff] [blame] | 9 | """ |
| 10 | |
Elaine Chien | d929637 | 2021-06-17 00:35:56 | [diff] [blame] | 11 | USE_PYTHON3 = True |
| 12 | |
rockot | 39a7fbf | 2015-11-13 17:29:26 | [diff] [blame] | 13 | import sys |
| 14 | |
| 15 | def _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 | |
| 31 | def _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 | |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 39 | def _RunHistogramChecks(input_api, output_api, histogram_name): |
| 40 | try: |
lukasza | 14d9a1a | 2017-04-28 15:23:57 | [diff] [blame] | 41 | # Setup sys.path so that we can call histograms code. |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 42 | 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 |
rockot | 39a7fbf | 2015-11-13 17:29:26 | [diff] [blame] | 55 | |
[email protected] | 1ee7f89 | 2014-03-04 06:04:25 | [diff] [blame] | 56 | def CheckChangeOnUpload(input_api, output_api): |
| 57 | results = [] |
rockot | 39a7fbf | 2015-11-13 17:29:26 | [diff] [blame] | 58 | results += _RunHistogramValueCheckers(input_api, output_api) |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 59 | results += _RunHistogramChecks(input_api, output_api, |
| 60 | "BadMessageReasonExtensions") |
[email protected] | 1ee7f89 | 2014-03-04 06:04:25 | [diff] [blame] | 61 | return results |