| OLD | NEW |
| (Empty) |
| 1 # Copyright 2015 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 devil. | |
| 6 | |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | |
| 8 details on the presubmit API built into depot_tools. | |
| 9 """ | |
| 10 | |
| 11 | |
| 12 def _RunPylint(input_api, output_api): | |
| 13 return input_api.canned_checks.RunPylint( | |
| 14 input_api, | |
| 15 output_api, | |
| 16 pylintrc='pylintrc', | |
| 17 extra_paths_list=[ | |
| 18 input_api.os_path.join(input_api.PresubmitLocalPath(), '..'), | |
| 19 ]) | |
| 20 | |
| 21 | |
| 22 def _RunUnitTests(input_api, output_api): | |
| 23 def J(*dirs): | |
| 24 """Returns a path relative to presubmit directory.""" | |
| 25 return input_api.os_path.join(input_api.PresubmitLocalPath(), *dirs) | |
| 26 | |
| 27 test_env = dict(input_api.environ) | |
| 28 test_env.update({ | |
| 29 'PYTHONDONTWRITEBYTECODE': '1', | |
| 30 'PYTHONPATH': ':'.join([J(), J('..')]), | |
| 31 }) | |
| 32 | |
| 33 return input_api.canned_checks.RunUnitTests( | |
| 34 input_api, | |
| 35 output_api, | |
| 36 unit_tests=[ | |
| 37 J('devil_env_test.py'), | |
| 38 J('android', 'battery_utils_test.py'), | |
| 39 J('android', 'device_utils_test.py'), | |
| 40 J('android', 'fastboot_utils_test.py'), | |
| 41 J('android', 'md5sum_test.py'), | |
| 42 J('android', 'logcat_monitor_test.py'), | |
| 43 J('android', 'tools', 'script_common_test.py'), | |
| 44 J('utils', 'cmd_helper_test.py'), | |
| 45 J('utils', 'timeout_retry_unittest.py'), | |
| 46 ], | |
| 47 env=test_env) | |
| 48 | |
| 49 | |
| 50 def _EnsureNoPylibUse(input_api, output_api): | |
| 51 def other_python_files(f): | |
| 52 this_presubmit_file = input_api.os_path.join( | |
| 53 input_api.PresubmitLocalPath(), 'PRESUBMIT.py') | |
| 54 return (f.LocalPath().endswith('.py') | |
| 55 and not f.AbsoluteLocalPath() == this_presubmit_file) | |
| 56 | |
| 57 changed_files = input_api.AffectedSourceFiles(other_python_files) | |
| 58 import_error_re = input_api.re.compile( | |
| 59 r'(from pylib.* import)|(import pylib)') | |
| 60 | |
| 61 errors = [] | |
| 62 for f in changed_files: | |
| 63 errors.extend( | |
| 64 '%s:%d' % (f.LocalPath(), line_number) | |
| 65 for line_number, line_text in f.ChangedContents() | |
| 66 if import_error_re.search(line_text)) | |
| 67 | |
| 68 if errors: | |
| 69 return [output_api.PresubmitError( | |
| 70 'pylib modules should not be imported from devil modules.', | |
| 71 items=errors)] | |
| 72 return [] | |
| 73 | |
| 74 | |
| 75 def _CatapultMoveWarning(input_api, output_api): | |
| 76 # TODO(jbudorick): Remove this after the move is complete. | |
| 77 | |
| 78 def other_files(f): | |
| 79 this_presubmit_file = input_api.os_path.join( | |
| 80 input_api.PresubmitLocalPath(), 'PRESUBMIT.py') | |
| 81 return not f.AbsoluteLocalPath() == this_presubmit_file | |
| 82 | |
| 83 changed_files = input_api.AffectedSourceFiles(other_files) | |
| 84 if changed_files: | |
| 85 return [output_api.PresubmitNotifyResult( | |
| 86 'devil/ changes should also be made in catapult ' | |
| 87 '(https://github.com/catapult-project/catapult). ' | |
| 88 'Questions? Contact jbudorick@', | |
| 89 items=changed_files)] | |
| 90 return [] | |
| 91 | |
| 92 | |
| 93 def CommonChecks(input_api, output_api): | |
| 94 output = [] | |
| 95 output += _RunPylint(input_api, output_api) | |
| 96 output += _RunUnitTests(input_api, output_api) | |
| 97 output += _EnsureNoPylibUse(input_api, output_api) | |
| 98 output += _CatapultMoveWarning(input_api, output_api) | |
| 99 return output | |
| 100 | |
| 101 | |
| 102 def CheckChangeOnUpload(input_api, output_api): | |
| 103 return CommonChecks(input_api, output_api) | |
| 104 | |
| 105 | |
| 106 def CheckChangeOnCommit(input_api, output_api): | |
| 107 return CommonChecks(input_api, output_api) | |
| OLD | NEW |