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

Unified Diff: build/android/pylib/constants/__init__.py

Issue 1502033002: Revert of [Android] Add a configurable environment for devil/. (RELAND 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/forwarder.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/constants/__init__.py
diff --git a/build/android/pylib/constants/__init__.py b/build/android/pylib/constants/__init__.py
index 1a48723d584e308175ccf2a05cf504246d9b89b7..772af93c50ef77c3729e264e2e803ce7755f5d38 100644
--- a/build/android/pylib/constants/__init__.py
+++ b/build/android/pylib/constants/__init__.py
@@ -16,7 +16,6 @@
import devil.android.sdk.keyevent
from devil.android.sdk import version_codes
from devil.constants import exit_codes
-
keyevent = devil.android.sdk.keyevent
@@ -244,12 +243,42 @@
GetBuildType() if build_type is None else build_type))
-# TODO(jbudorick): Convert existing callers to AdbWrapper.GetAdbPath() and
-# remove this.
+def _Memoize(func):
+ def Wrapper():
+ try:
+ return func._result
+ except AttributeError:
+ func._result = func()
+ return func._result
+ return Wrapper
+
+
+def SetAdbPath(adb_path):
+ os.environ['ADB_PATH'] = adb_path
+
+
def GetAdbPath():
- from devil.android.sdk import adb_wrapper
- return adb_wrapper.AdbWrapper.GetAdbPath()
-
+ # Check if a custom adb path as been set. If not, try to find adb
+ # on the system.
+ if os.environ.get('ADB_PATH'):
+ return os.environ.get('ADB_PATH')
+ else:
+ return _FindAdbPath()
+
+
+@_Memoize
+def _FindAdbPath():
+ if os.environ.get('ANDROID_SDK_ROOT'):
+ return 'adb'
+ # If envsetup.sh hasn't been sourced and there's no adb in the path,
+ # set it here.
+ try:
+ with file(os.devnull, 'w') as devnull:
+ subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull)
+ return 'adb'
+ except OSError:
+ logging.debug('No adb found in $PATH, fallback to checked in binary.')
+ return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb')
# Exit codes
ERROR_EXIT_CODE = exit_codes.ERROR
« 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