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 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) |
| 29 if presubmit in (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 filter(lambda t: t in affected_files, would_affect_tests): | |
|
Dirk Pranke
2012/03/22 03:05:30
nit: I'd probably do if any(f for f in affected_fi
Dan Beam
2012/03/22 03:19:31
Done. (I have little to no idea what I just did th
| |
| 30 tests = [path.join(resources, 'test_presubmit.py')] | 36 tests = [path.join(resources, 'test_presubmit.py')] |
| 31 results.extend( | 37 results.extend( |
| 32 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) | 38 input_api.canned_checks.RunUnitTests(input_api, output_api, tests)) |
| 33 | 39 |
| 34 import sys | 40 import sys |
| 35 old_path = sys.path | 41 old_path = sys.path |
| 36 | 42 |
| 37 try: | 43 try: |
| 38 sys.path.insert(0, resources) | 44 sys.path.insert(0, resources) |
| 39 from web_dev_style import css_checker, js_checker | 45 from web_dev_style import css_checker, js_checker |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 return (f.startswith(dirs) and f.endswith(('.css', '.html', '.js'))) | 56 return (f.startswith(dirs) and f.endswith(('.css', '.html', '.js'))) |
| 51 | 57 |
| 52 results.extend(css_checker.CSSChecker(input_api, output_api, | 58 results.extend(css_checker.CSSChecker(input_api, output_api, |
| 53 file_filter=file_filter).RunChecks()) | 59 file_filter=file_filter).RunChecks()) |
| 54 results.extend(js_checker.JSChecker(input_api, output_api, | 60 results.extend(js_checker.JSChecker(input_api, output_api, |
| 55 file_filter=file_filter).RunChecks()) | 61 file_filter=file_filter).RunChecks()) |
| 56 finally: | 62 finally: |
| 57 sys.path = old_path | 63 sys.path = old_path |
| 58 | 64 |
| 59 return results | 65 return results |
| OLD | NEW |