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