PRESUBMIT.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. """Chromium presubmit script for src/extensions/browser.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details on the presubmit API built into depot_tools.
  7. """
  8. USE_PYTHON3 = True
  9. import sys
  10. def _CreateHistogramValueChecker(input_api, output_api, path):
  11. original_sys_path = sys.path
  12. try:
  13. sys.path.append(input_api.os_path.join(
  14. input_api.PresubmitLocalPath(), '..', '..', 'tools',
  15. 'strict_enum_value_checker'))
  16. from strict_enum_value_checker import StrictEnumValueChecker
  17. finally:
  18. sys.path = original_sys_path
  19. return StrictEnumValueChecker(input_api, output_api,
  20. start_marker='enum HistogramValue {', end_marker=' // Last entry:',
  21. path=path)
  22. def _RunHistogramValueCheckers(input_api, output_api):
  23. results = []
  24. histogram_paths = ('extensions/browser/extension_event_histogram_value.h',
  25. 'extensions/browser/extension_function_histogram_value.h')
  26. for path in histogram_paths:
  27. results += _CreateHistogramValueChecker(input_api, output_api, path).Run()
  28. return results
  29. def _RunHistogramChecks(input_api, output_api, histogram_name):
  30. try:
  31. # Setup sys.path so that we can call histograms code.
  32. import sys
  33. original_sys_path = sys.path
  34. sys.path = sys.path + [input_api.os_path.join(
  35. input_api.change.RepositoryRoot(),
  36. 'tools', 'metrics', 'histograms')]
  37. import presubmit_bad_message_reasons
  38. return presubmit_bad_message_reasons.PrecheckBadMessage(input_api,
  39. output_api, histogram_name)
  40. except:
  41. return [output_api.PresubmitError('Could not verify histogram!')]
  42. finally:
  43. sys.path = original_sys_path
  44. def CheckChangeOnUpload(input_api, output_api):
  45. results = []
  46. results += _RunHistogramValueCheckers(input_api, output_api)
  47. results += _RunHistogramChecks(input_api, output_api,
  48. "BadMessageReasonExtensions")
  49. return results