Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 WebUI resources. | 5 """Presubmit script for Chromium WebUI resources. |
|
Lei Zhang
2014/04/29 03:05:48
It's a bit weird that c/b/PRESUBMIT.py says "Presu
Dan Beam
2014/04/29 16:32:22
updated
| |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 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 | 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 | 9 http://www.chromium.org/developers/web-development-style-guide for the rules |
| 10 we're checking against here. | 10 we're checking against here. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 | 13 |
| 14 def CheckChangeOnUpload(input_api, output_api): | 14 def CheckChangeOnUpload(input_api, output_api): |
| 15 return _CommonChecks(input_api, output_api) | 15 return _CommonChecks(input_api, output_api) |
| 16 | 16 |
| 17 | 17 |
| 18 def CheckChangeOnCommit(input_api, output_api): | 18 def CheckChangeOnCommit(input_api, output_api): |
| 19 return _CommonChecks(input_api, output_api) | 19 return _CommonChecks(input_api, output_api) |
| 20 | 20 |
| 21 | 21 |
| 22 def _CommonChecks(input_api, output_api): | 22 def _CommonChecks(input_api, output_api): |
| 23 """Checks common to both upload and commit.""" | 23 """Checks common to both upload and commit.""" |
| 24 results = [] | 24 results = [] |
| 25 resources = input_api.PresubmitLocalPath() | |
| 26 | 25 |
| 27 path = input_api.os_path | 26 path = input_api.os_path |
| 27 cwd = input_api.PresubmitLocalPath() | |
| 28 resources = path.join(cwd, 'resources') | |
| 29 webui = path.join(cwd, 'ui', 'webui') | |
| 30 | |
| 28 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) | 31 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) |
| 29 would_affect_tests = ( | 32 would_affect_tests = ( |
| 30 path.join(resources, 'PRESUBMIT.py'), | 33 path.join(cwd, 'PRESUBMIT.py'), |
| 31 path.join(resources, 'test_presubmit.py'), | 34 path.join(cwd, 'test_presubmit.py'), |
| 32 path.join(resources, 'web_dev_style', 'css_checker.py'), | 35 path.join(cwd, 'web_dev_style', 'css_checker.py'), |
| 33 path.join(resources, 'web_dev_style', 'js_checker.py'), | 36 path.join(cwd, 'web_dev_style', 'js_checker.py'), |
| 34 ) | 37 ) |
| 35 if any(f for f in affected_files if f in would_affect_tests): | 38 if any(f for f in affected_files if f in would_affect_tests): |
| 36 tests = [path.join(resources, 'test_presubmit.py')] | 39 tests = [path.join(cwd, 'test_presubmit.py')] |
| 37 results.extend( | 40 results.extend( |
| 38 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | 41 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) |
| 39 | 42 |
| 40 import sys | 43 import sys |
| 41 old_path = sys.path | 44 old_path = sys.path |
| 42 | 45 |
| 43 try: | 46 try: |
| 44 sys.path = [resources] + old_path | 47 sys.path = [cwd] + old_path |
| 45 from web_dev_style import css_checker, js_checker | 48 from web_dev_style import css_checker, js_checker |
| 46 | 49 |
| 50 search_dirs = (resources, webui) | |
| 47 def _html_css_js_resource(p): | 51 def _html_css_js_resource(p): |
| 48 return p.endswith(('.html', '.css', '.js')) and p.startswith(resources) | 52 return p.endswith(('.html', '.css', '.js')) and p.startswith(search_dirs) |
| 49 | 53 |
| 50 BLACKLIST = ['chrome/browser/resources/pdf/index.html', | 54 BLACKLIST = ['chrome/browser/resources/pdf/index.html', |
| 51 'chrome/browser/resources/pdf/index.js'] | 55 'chrome/browser/resources/pdf/index.js'] |
| 52 def is_resource(maybe_resource): | 56 def is_resource(maybe_resource): |
| 53 return (maybe_resource.LocalPath() not in BLACKLIST and | 57 return (maybe_resource.LocalPath() not in BLACKLIST and |
| 54 _html_css_js_resource(maybe_resource.AbsoluteLocalPath())) | 58 _html_css_js_resource(maybe_resource.AbsoluteLocalPath())) |
| 55 | 59 |
| 56 results.extend(css_checker.CSSChecker( | 60 results.extend(css_checker.CSSChecker( |
| 57 input_api, output_api, file_filter=is_resource).RunChecks()) | 61 input_api, output_api, file_filter=is_resource).RunChecks()) |
| 58 results.extend(js_checker.JSChecker( | 62 results.extend(js_checker.JSChecker( |
| 59 input_api, output_api, file_filter=is_resource).RunChecks()) | 63 input_api, output_api, file_filter=is_resource).RunChecks()) |
| 60 finally: | 64 finally: |
| 61 sys.path = old_path | 65 sys.path = old_path |
| 62 | 66 |
| 63 return results | 67 return results |
| OLD | NEW |