Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: build/android/pylib/constants/__init__.py

Issue 1416703003: [Android] Add a configurable environment for devil/. (RELAND 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
20 keyevent = devil.android.sdk.keyevent 21 keyevent = devil.android.sdk.keyevent
21 22
22 23
23 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT', 24 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT',
24 os.path.abspath(os.path.join(os.path.dirname(__file__), 25 os.path.abspath(os.path.join(os.path.dirname(__file__),
25 os.pardir, os.pardir, os.pardir, os.pardir))) 26 os.pardir, os.pardir, os.pardir, os.pardir)))
26 27
27 PackageInfo = collections.namedtuple('PackageInfo', 28 PackageInfo = collections.namedtuple('PackageInfo',
28 ['package', 'activity', 'cmdline_file', 'devtools_socket', 29 ['package', 'activity', 'cmdline_file', 'devtools_socket',
29 'test_package']) 30 'test_package'])
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 """ 237 """
237 if 'CHROMIUM_OUTPUT_DIR' in os.environ: 238 if 'CHROMIUM_OUTPUT_DIR' in os.environ:
238 return os.path.abspath(os.path.join( 239 return os.path.abspath(os.path.join(
239 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR'))) 240 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR')))
240 241
241 return os.path.abspath(os.path.join( 242 return os.path.abspath(os.path.join(
242 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'), 243 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
243 GetBuildType() if build_type is None else build_type)) 244 GetBuildType() if build_type is None else build_type))
244 245
245 246
246 def _Memoize(func): 247 # TODO(jbudorick): Convert existing callers to AdbWrapper.GetAdbPath() and
247 def Wrapper(): 248 # remove this.
248 try: 249 def GetAdbPath():
249 return func._result 250 from devil.android.sdk import adb_wrapper
250 except AttributeError: 251 return adb_wrapper.AdbWrapper.GetAdbPath()
251 func._result = func()
252 return func._result
253 return Wrapper
254 252
255 253
256 def SetAdbPath(adb_path):
257 os.environ['ADB_PATH'] = adb_path
258
259
260 def GetAdbPath():
261 # Check if a custom adb path as been set. If not, try to find adb
262 # on the system.
263 if os.environ.get('ADB_PATH'):
264 return os.environ.get('ADB_PATH')
265 else:
266 return _FindAdbPath()
267
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
283 # Exit codes 254 # Exit codes
284 ERROR_EXIT_CODE = exit_codes.ERROR 255 ERROR_EXIT_CODE = exit_codes.ERROR
285 INFRA_EXIT_CODE = exit_codes.INFRA 256 INFRA_EXIT_CODE = exit_codes.INFRA
286 WARNING_EXIT_CODE = exit_codes.WARNING 257 WARNING_EXIT_CODE = exit_codes.WARNING
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698