| 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 """Defines a set of constants shared by test runners and other scripts.""" | 5 """Defines a set of constants shared by test runners and other scripts.""" |
| 6 | 6 |
| 7 # TODO(jbudorick): Split these constants into coherent modules. | 7 # TODO(jbudorick): Split these constants into coherent modules. |
| 8 | 8 |
| 9 # pylint: disable=W0212 | 9 # pylint: disable=W0212 |
| 10 | 10 |
| 11 import collections | 11 import collections |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import subprocess | 14 import subprocess |
| 15 | 15 |
| 16 import devil.android.sdk.keyevent | 16 import devil.android.sdk.keyevent |
| 17 from devil.android.sdk import version_codes | 17 from devil.android.sdk import version_codes |
| 18 | 18 |
| 19 |
| 19 keyevent = devil.android.sdk.keyevent | 20 keyevent = devil.android.sdk.keyevent |
| 20 | 21 |
| 21 | 22 |
| 22 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT', | 23 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT', |
| 23 os.path.abspath(os.path.join(os.path.dirname(__file__), | 24 os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 24 os.pardir, os.pardir, os.pardir, os.pardir))) | 25 os.pardir, os.pardir, os.pardir, os.pardir))) |
| 25 | 26 |
| 26 PackageInfo = collections.namedtuple('PackageInfo', | 27 PackageInfo = collections.namedtuple('PackageInfo', |
| 27 ['package', 'activity', 'cmdline_file', 'devtools_socket', | 28 ['package', 'activity', 'cmdline_file', 'devtools_socket', |
| 28 'test_package']) | 29 'test_package']) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 """ | 235 """ |
| 235 if 'CHROMIUM_OUTPUT_DIR' in os.environ: | 236 if 'CHROMIUM_OUTPUT_DIR' in os.environ: |
| 236 return os.path.abspath(os.path.join( | 237 return os.path.abspath(os.path.join( |
| 237 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR'))) | 238 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR'))) |
| 238 | 239 |
| 239 return os.path.abspath(os.path.join( | 240 return os.path.abspath(os.path.join( |
| 240 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'), | 241 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
| 241 GetBuildType() if build_type is None else build_type)) | 242 GetBuildType() if build_type is None else build_type)) |
| 242 | 243 |
| 243 | 244 |
| 244 def _Memoize(func): | 245 # TODO(jbudorick): Convert existing callers to AdbWrapper.GetAdbPath() and |
| 245 def Wrapper(): | 246 # remove this. |
| 246 try: | 247 def GetAdbPath(): |
| 247 return func._result | 248 from devil.android.sdk import adb_wrapper |
| 248 except AttributeError: | 249 return adb_wrapper.AdbWrapper.GetAdbPath() |
| 249 func._result = func() | |
| 250 return func._result | |
| 251 return Wrapper | |
| 252 | 250 |
| 253 | 251 |
| 254 def SetAdbPath(adb_path): | |
| 255 os.environ['ADB_PATH'] = adb_path | |
| 256 | |
| 257 | |
| 258 def GetAdbPath(): | |
| 259 # Check if a custom adb path as been set. If not, try to find adb | |
| 260 # on the system. | |
| 261 if os.environ.get('ADB_PATH'): | |
| 262 return os.environ.get('ADB_PATH') | |
| 263 else: | |
| 264 return _FindAdbPath() | |
| 265 | |
| 266 | |
| 267 @_Memoize | |
| 268 def _FindAdbPath(): | |
| 269 if os.environ.get('ANDROID_SDK_ROOT'): | |
| 270 return 'adb' | |
| 271 # If envsetup.sh hasn't been sourced and there's no adb in the path, | |
| 272 # set it here. | |
| 273 try: | |
| 274 with file(os.devnull, 'w') as devnull: | |
| 275 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull) | |
| 276 return 'adb' | |
| 277 except OSError: | |
| 278 logging.debug('No adb found in $PATH, fallback to checked in binary.') | |
| 279 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb') | |
| 280 | |
| 281 # Exit codes | 252 # Exit codes |
| 282 ERROR_EXIT_CODE = 1 | 253 ERROR_EXIT_CODE = 1 |
| 283 INFRA_EXIT_CODE = 87 | 254 INFRA_EXIT_CODE = 87 |
| 284 WARNING_EXIT_CODE = 88 | 255 WARNING_EXIT_CODE = 88 |
| OLD | NEW |