dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 1 | # Copyright 2017 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 to check that BadMessage enums in histograms.xml |
| 6 | match the corresponding bad_message.h file. |
| 7 | """ |
| 8 | |
lukasza | 14d9a1a | 2017-04-28 15:23:57 | [diff] [blame] | 9 | def CheckChangeOnCommit(input_api, output_api): |
| 10 | return _CommonChecks(input_api, output_api) |
| 11 | |
| 12 | def CheckChangeOnUpload(input_api, output_api): |
| 13 | return _CommonChecks(input_api, output_api) |
| 14 | |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 15 | def _RunHistogramChecks(input_api, output_api, histogram_name): |
| 16 | try: |
lukasza | 14d9a1a | 2017-04-28 15:23:57 | [diff] [blame] | 17 | # Setup sys.path so that we can call histograms code. |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 18 | import sys |
| 19 | original_sys_path = sys.path |
| 20 | sys.path = sys.path + [input_api.os_path.join( |
| 21 | input_api.change.RepositoryRoot(), |
| 22 | 'tools', 'metrics', 'histograms')] |
| 23 | |
| 24 | import presubmit_bad_message_reasons |
| 25 | return presubmit_bad_message_reasons.PrecheckBadMessage(input_api, |
| 26 | output_api, histogram_name) |
| 27 | except Exception as e: |
| 28 | return [output_api.PresubmitError("Error verifying histogram (%s)." |
| 29 | % str(e))] |
| 30 | finally: |
| 31 | sys.path = original_sys_path |
| 32 | |
lukasza | 14d9a1a | 2017-04-28 15:23:57 | [diff] [blame] | 33 | def _CommonChecks(input_api, output_api): |
dougt | b53dc59 | 2017-02-01 16:25:00 | [diff] [blame] | 34 | return _RunHistogramChecks(input_api, output_api, "BadMessageReasonContent") |