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 # pylint: disable=W0212 | 6 # pylint: disable=W0212 |
7 | 7 |
8 import collections | 8 import collections |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 def _Memoize(func): | 239 def _Memoize(func): |
240 def Wrapper(): | 240 def Wrapper(): |
241 try: | 241 try: |
242 return func._result | 242 return func._result |
243 except AttributeError: | 243 except AttributeError: |
244 func._result = func() | 244 func._result = func() |
245 return func._result | 245 return func._result |
246 return Wrapper | 246 return Wrapper |
247 | 247 |
248 | 248 |
| 249 def SetAdbPath(adb_path): |
| 250 os.environ['ADB_PATH'] = adb_path |
| 251 |
| 252 |
| 253 def GetAdbPath(): |
| 254 # Check if a custom adb path as been set. If not, try to find adb |
| 255 # on the system. |
| 256 if os.environ.get('ADB_PATH'): |
| 257 return os.environ.get('ADB_PATH') |
| 258 else: |
| 259 return _FindAdbPath() |
| 260 |
| 261 |
249 @_Memoize | 262 @_Memoize |
250 def GetAdbPath(): | 263 def _FindAdbPath(): |
251 if os.environ.get('ANDROID_SDK_ROOT'): | 264 if os.environ.get('ANDROID_SDK_ROOT'): |
252 return 'adb' | 265 return 'adb' |
253 # If envsetup.sh hasn't been sourced and there's no adb in the path, | 266 # If envsetup.sh hasn't been sourced and there's no adb in the path, |
254 # set it here. | 267 # set it here. |
255 try: | 268 try: |
256 with file(os.devnull, 'w') as devnull: | 269 with file(os.devnull, 'w') as devnull: |
257 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull) | 270 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull) |
258 return 'adb' | 271 return 'adb' |
259 except OSError: | 272 except OSError: |
260 logging.debug('No adb found in $PATH, fallback to checked in binary.') | 273 logging.debug('No adb found in $PATH, fallback to checked in binary.') |
261 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb') | 274 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb') |
262 | 275 |
263 | |
264 # Exit codes | 276 # Exit codes |
265 ERROR_EXIT_CODE = 1 | 277 ERROR_EXIT_CODE = 1 |
266 WARNING_EXIT_CODE = 88 | 278 WARNING_EXIT_CODE = 88 |
OLD | NEW |