mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils/android: Remove PATH manipulation
Android tools detection was manipulating os.environ['PATH'] which has an impact beyond devlib (and even beyond the current process as it will be inherited by any child). Remove that hack and instead use global variables to get adb and fastboot paths. These tools are now detected by _AndroidEnvironment() like the others.
This commit is contained in:
parent
19c51547d1
commit
926aee1833
@ -88,12 +88,6 @@ INTENT_FLAGS = {
|
|||||||
'ACTIVITY_CLEAR_TASK' : 0x00008000
|
'ACTIVITY_CLEAR_TASK' : 0x00008000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# These were not set or not set to anything meaningful, so just keep them for
|
|
||||||
# backward compat but they are not lazily detected.
|
|
||||||
adb = None
|
|
||||||
fastboot = None
|
|
||||||
|
|
||||||
# Lazy init of some globals
|
# Lazy init of some globals
|
||||||
def __getattr__(attr):
|
def __getattr__(attr):
|
||||||
env = _AndroidEnvironment()
|
env = _AndroidEnvironment()
|
||||||
@ -597,7 +591,6 @@ def adb_shell(device, command, timeout=None, check_exit_code=False,
|
|||||||
# Homogenise this behaviour by running the command then echoing the exit
|
# Homogenise this behaviour by running the command then echoing the exit
|
||||||
# code of the executed command itself.
|
# code of the executed command itself.
|
||||||
command = r'({}); echo "\n$?"'.format(command)
|
command = r'({}); echo "\n$?"'.format(command)
|
||||||
|
|
||||||
command = su_cmd.format(quote(command)) if as_root else command
|
command = su_cmd.format(quote(command)) if as_root else command
|
||||||
command = ('shell', command)
|
command = ('shell', command)
|
||||||
parts, env = _get_adb_parts(command, device, adb_server, adb_port, quote_adb=False)
|
parts, env = _get_adb_parts(command, device, adb_server, adb_port, quote_adb=False)
|
||||||
@ -732,7 +725,7 @@ def adb_list_devices(adb_server=None, adb_port=None):
|
|||||||
def _get_adb_parts(command, device=None, adb_server=None, adb_port=None, quote_adb=True):
|
def _get_adb_parts(command, device=None, adb_server=None, adb_port=None, quote_adb=True):
|
||||||
_quote = quote if quote_adb else lambda x: x
|
_quote = quote if quote_adb else lambda x: x
|
||||||
parts = (
|
parts = (
|
||||||
'adb',
|
adb,
|
||||||
*(('-H', _quote(adb_server)) if adb_server is not None else ()),
|
*(('-H', _quote(adb_server)) if adb_server is not None else ()),
|
||||||
*(('-P', _quote(str(adb_port))) if adb_port is not None else ()),
|
*(('-P', _quote(str(adb_port))) if adb_port is not None else ()),
|
||||||
*(('-s', _quote(device)) if device is not None else ()),
|
*(('-s', _quote(device)) if device is not None else ()),
|
||||||
@ -798,19 +791,15 @@ class _AndroidEnvironment:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _from_android_home(cls, android_home):
|
def _from_android_home(cls, android_home):
|
||||||
if android_home:
|
|
||||||
logger.debug('Using ANDROID_HOME from the environment.')
|
logger.debug('Using ANDROID_HOME from the environment.')
|
||||||
platform_tools = os.path.join(android_home, 'platform-tools')
|
platform_tools = os.path.join(android_home, 'platform-tools')
|
||||||
|
|
||||||
# TODO: that is very fishy
|
|
||||||
os.environ['PATH'] = platform_tools + os.pathsep + os.environ['PATH']
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'android_home': android_home,
|
'android_home': android_home,
|
||||||
'platform_tools': platform_tools,
|
'platform_tools': platform_tools,
|
||||||
**cls._init_common(
|
'adb': os.path.join(platform_tools, 'adb'),
|
||||||
android_home=android_home,
|
'fastboot': os.path.join(platform_tools, 'fastboot'),
|
||||||
)
|
**cls._init_common(android_home)
|
||||||
}
|
}
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
@ -825,6 +814,8 @@ class _AndroidEnvironment:
|
|||||||
return {
|
return {
|
||||||
'android_home': android_home,
|
'android_home': android_home,
|
||||||
'platform_tools': platform_tools,
|
'platform_tools': platform_tools,
|
||||||
|
'adb': adb_path,
|
||||||
|
'fastboot': which('fastboot'),
|
||||||
**cls._init_common(android_home)
|
**cls._init_common(android_home)
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user