OLD | NEW |
| (Empty) |
1 # Copyright (c) 2012 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 """Presubmit script for Chromium WebUI resources. | |
6 | |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
8 for more details about the presubmit API built into gcl/git cl, and see | |
9 http://www.chromium.org/developers/web-development-style-guide for the rules | |
10 we're checking against here. | |
11 """ | |
12 | |
13 | |
14 def CheckChangeOnUpload(input_api, output_api): | |
15 return _CommonChecks(input_api, output_api) | |
16 | |
17 | |
18 def CheckChangeOnCommit(input_api, output_api): | |
19 return _CommonChecks(input_api, output_api) | |
20 | |
21 | |
22 def _CommonChecks(input_api, output_api): | |
23 """Checks common to both upload and commit.""" | |
24 results = [] | |
25 resources = input_api.PresubmitLocalPath() | |
26 | |
27 path = input_api.os_path | |
28 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) | |
29 would_affect_tests = ( | |
30 path.join(resources, 'PRESUBMIT.py'), | |
31 path.join(resources, 'test_presubmit.py'), | |
32 path.join(resources, 'web_dev_style', 'css_checker.py'), | |
33 path.join(resources, 'web_dev_style', 'js_checker.py'), | |
34 ) | |
35 if any(f for f in affected_files if f in would_affect_tests): | |
36 tests = [path.join(resources, 'test_presubmit.py')] | |
37 results.extend( | |
38 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | |
39 | |
40 import sys | |
41 old_path = sys.path | |
42 | |
43 try: | |
44 sys.path = [resources] + old_path | |
45 from web_dev_style import css_checker, js_checker | |
46 | |
47 def _html_css_js_resource(p): | |
48 return p.endswith(('.html', '.css', '.js')) and p.startswith(resources) | |
49 | |
50 BLACKLIST = ['chrome/browser/resources/pdf/index.html', | |
51 'chrome/browser/resources/pdf/index.js'] | |
52 def is_resource(maybe_resource): | |
53 return (maybe_resource.LocalPath() not in BLACKLIST and | |
54 _html_css_js_resource(maybe_resource.AbsoluteLocalPath())) | |
55 | |
56 results.extend(css_checker.CSSChecker( | |
57 input_api, output_api, file_filter=is_resource).RunChecks()) | |
58 results.extend(js_checker.JSChecker( | |
59 input_api, output_api, file_filter=is_resource).RunChecks()) | |
60 finally: | |
61 sys.path = old_path | |
62 | |
63 return results | |
OLD | NEW |