OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Presubmit script for Chromium browser code. | 5 """Presubmit script for Chromium browser code. |
6 | 6 |
7 This script currently checks HTML/CSS/JS files in resources/ and ui/webui/. | 7 This script currently checks HTML/CSS/JS files in resources/ and ui/webui/. |
8 | 8 |
9 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 9 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
10 for more details about the presubmit API built into depot_tools, and see | 10 for more details about the presubmit API built into depot_tools, and see |
11 http://www.chromium.org/developers/web-development-style-guide for the rules | 11 http://www.chromium.org/developers/web-development-style-guide for the rules |
12 checked for here. | 12 checked for here. |
13 """ | 13 """ |
14 | 14 |
15 | 15 |
16 def CheckChangeOnUpload(input_api, output_api): | 16 def CheckChangeOnUpload(input_api, output_api): |
17 return _CommonChecks(input_api, output_api) | 17 return _CommonChecks(input_api, output_api) |
18 | 18 |
19 | 19 |
20 def CheckChangeOnCommit(input_api, output_api): | 20 def CheckChangeOnCommit(input_api, output_api): |
21 return _CommonChecks(input_api, output_api) | 21 return _CommonChecks(input_api, output_api) |
22 | 22 |
| 23 def _RunHistogramChecks(input_api, output_api, histogram_name): |
| 24 try: |
| 25 # Setup sys.path so that we can call histrogram code |
| 26 import sys |
| 27 original_sys_path = sys.path |
| 28 sys.path = sys.path + [input_api.os_path.join( |
| 29 input_api.change.RepositoryRoot(), |
| 30 'tools', 'metrics', 'histograms')] |
| 31 |
| 32 import presubmit_bad_message_reasons |
| 33 return presubmit_bad_message_reasons.PrecheckBadMessage(input_api, |
| 34 output_api, histogram_name) |
| 35 except: |
| 36 return [output_api.PresubmitError('Could not verify histogram!')] |
| 37 finally: |
| 38 sys.path = original_sys_path |
| 39 |
23 | 40 |
24 def _CommonChecks(input_api, output_api): | 41 def _CommonChecks(input_api, output_api): |
25 """Checks common to both upload and commit.""" | 42 """Checks common to both upload and commit.""" |
26 results = [] | 43 results = [] |
27 | 44 |
28 path = input_api.os_path | 45 path = input_api.os_path |
29 cwd = input_api.PresubmitLocalPath() | 46 cwd = input_api.PresubmitLocalPath() |
30 resources = path.join(cwd, 'resources') | 47 resources = path.join(cwd, 'resources') |
31 webui = path.join(cwd, 'ui', 'webui') | 48 webui = path.join(cwd, 'ui', 'webui') |
32 | 49 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 _html_css_js_resource(maybe_resource.AbsoluteLocalPath())) | 85 _html_css_js_resource(maybe_resource.AbsoluteLocalPath())) |
69 | 86 |
70 results.extend(resource_checker.ResourceChecker( | 87 results.extend(resource_checker.ResourceChecker( |
71 input_api, output_api, file_filter=is_resource).RunChecks()) | 88 input_api, output_api, file_filter=is_resource).RunChecks()) |
72 results.extend(css_checker.CSSChecker( | 89 results.extend(css_checker.CSSChecker( |
73 input_api, output_api, file_filter=is_resource).RunChecks()) | 90 input_api, output_api, file_filter=is_resource).RunChecks()) |
74 results.extend(html_checker.HtmlChecker( | 91 results.extend(html_checker.HtmlChecker( |
75 input_api, output_api, file_filter=is_resource).RunChecks()) | 92 input_api, output_api, file_filter=is_resource).RunChecks()) |
76 results.extend(js_checker.JSChecker( | 93 results.extend(js_checker.JSChecker( |
77 input_api, output_api, file_filter=is_resource).RunChecks()) | 94 input_api, output_api, file_filter=is_resource).RunChecks()) |
| 95 results.extend(_RunHistogramChecks(input_api, output_api, |
| 96 "BadMessageReasonChrome")) |
78 finally: | 97 finally: |
79 sys.path = old_path | 98 sys.path = old_path |
80 | 99 |
81 return results | 100 return results |
OLD | NEW |