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. |
| 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() | 25 resources = input_api.PresubmitLocalPath() |
| 26 | 26 |
| 27 path = input_api.os_path | 27 path = input_api.os_path |
| 28 presubmit = path.join(resources, 'PRESUBMIT.py') | 28 would_affect_tests = ( |
| 29 if presubmit in (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()): | 29 path.join(resources, 'PRESUBMIT.py'), |
| 30 tests = [path.join(resources, 'test_presubmit.py')] | 30 path.join(resources, 'test_presubmit.py'), |
| 31 results.extend( | 31 path.join(resources, 'web_dev_style', 'css_checker.py'), |
| 32 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | 32 path.join(resources, 'web_dev_style', 'js_checker.py'), |
| 33 ) | |
| 34 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) | |
| 35 for presubmit in would_affect_tests: | |
|
Tyler Breisacher (Chromium)
2012/03/21 20:19:55
I think there might be a nicer way to express this
Dan Beam
2012/03/21 20:44:50
Done.
| |
| 36 if presubmit in affected_files: | |
| 37 tests = [path.join(resources, 'test_presubmit.py')] | |
| 38 results.extend( | |
| 39 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | |
| 40 break | |
| 33 | 41 |
| 34 import sys | 42 import sys |
| 35 old_path = sys.path | 43 old_path = sys.path |
| 36 | 44 |
| 37 try: | 45 try: |
| 38 sys.path.insert(0, resources) | 46 sys.path.insert(0, resources) |
| 39 from web_dev_style import css_checker, js_checker | 47 from web_dev_style import css_checker, js_checker |
| 40 | 48 |
| 41 # TODO(dbeam): Remove this directory filter eventually when ready. | 49 # TODO(dbeam): Remove this directory filter eventually when ready. |
| 42 dirs = ( | 50 dirs = ( |
| 43 path.join(resources, 'extensions'), | 51 path.join(resources, 'extensions'), |
| 44 path.join(resources, 'ntp4'), | 52 path.join(resources, 'ntp4'), |
| 45 path.join(resources, 'options2'), | 53 path.join(resources, 'options2'), |
| 46 path.join(resources, 'uber'), | 54 path.join(resources, 'uber'), |
| 47 ) | 55 ) |
| 48 def file_filter(affected_file): | 56 def file_filter(affected_file): |
| 49 f = affected_file.AbsoluteLocalPath() | 57 f = affected_file.AbsoluteLocalPath() |
| 50 return (f.startswith(dirs) and f.endswith(('.css', '.html', '.js'))) | 58 return (f.startswith(dirs) and f.endswith(('.css', '.html', '.js'))) |
| 51 | 59 |
| 52 results.extend(css_checker.CSSChecker(input_api, output_api, | 60 results.extend(css_checker.CSSChecker(input_api, output_api, |
| 53 file_filter=file_filter).RunChecks()) | 61 file_filter=file_filter).RunChecks()) |
| 54 results.extend(js_checker.JSChecker(input_api, output_api, | 62 results.extend(js_checker.JSChecker(input_api, output_api, |
| 55 file_filter=file_filter).RunChecks()) | 63 file_filter=file_filter).RunChecks()) |
| 56 finally: | 64 finally: |
| 57 sys.path = old_path | 65 sys.path = old_path |
| 58 | 66 |
| 59 return results | 67 return results |
| OLD | NEW |