1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 20:11:20 +00:00

util/android, get_apk_versions: try to find 'aapt' in $PATH as well

Some Linux distro provide android build-tools in packages, we should also try
to find 'aapt' in $PATH if it cannot be found in $ANDROID_HOME.
This commit is contained in:
Yingshiuan Pan 2017-11-27 10:48:42 +08:00 committed by marcbonnici
parent 7ce1044eff
commit 57a8e62be9
2 changed files with 37 additions and 23 deletions

View File

@ -10,22 +10,29 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from wlauto.exceptions import WAError, ToolError
from wlauto.utils.doc import format_simple_table
from wlauto.utils.misc import check_output, get_null, which
def get_aapt_path():
"""Return the full path to aapt tool."""
sdk_path = os.getenv('ANDROID_HOME')
if not sdk_path:
raise ToolError('Please make sure you have Android SDK installed and have ANDROID_HOME set.')
build_tools_directory = os.path.join(sdk_path, 'build-tools')
versions = os.listdir(build_tools_directory)
for version in reversed(sorted(versions)):
aapt_path = os.path.join(build_tools_directory, version, 'aapt')
if os.path.isfile(aapt_path):
logging.debug('Found aapt for version {}'.format(version))
return aapt_path
if sdk_path:
build_tools_directory = os.path.join(sdk_path, 'build-tools')
versions = os.listdir(build_tools_directory)
for version in reversed(sorted(versions)):
aapt_path = os.path.join(build_tools_directory, version, 'aapt')
if os.path.isfile(aapt_path):
logging.debug('Found aapt for version {}'.format(version))
return aapt_path
else:
raise ToolError('aapt not found. Please make sure at least one Android platform is installed.')
else:
raise ToolError('aapt not found. Please make sure at least one Android platform is installed.')
logging.debug("ANDROID_HOME is not set, try to find in $PATH.")
aapt_path = which('aapt')
if aapt_path:
logging.debug('Using aapt from {}'.format(aapt_path))
return aapt_path
raise ToolError('Please make sure you have Android SDK installed and have ANDROID_HOME set.')
def get_apks(path):

View File

@ -27,7 +27,7 @@ import re
from wlauto.exceptions import DeviceError, ConfigError, HostError, WAError
from wlauto.utils.misc import (check_output, escape_single_quotes,
escape_double_quotes, get_null,
escape_double_quotes, get_null, which,
CalledProcessErrorWithStderr, ABI_MAP)
@ -458,19 +458,26 @@ def _initialize_without_android_home(env):
def _init_common(env):
logger.debug('ANDROID_HOME: {}'.format(env.android_home))
build_tools_directory = os.path.join(env.android_home, 'build-tools')
if not os.path.isdir(build_tools_directory):
msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)'
raise HostError(msg.format(env.android_home))
versions = os.listdir(build_tools_directory)
for version in reversed(sorted(versions)):
aapt_path = os.path.join(build_tools_directory, version, 'aapt')
if os.path.isfile(aapt_path):
logger.debug('Using aapt for version {}'.format(version))
env.aapt = aapt_path
break
if os.path.isdir(build_tools_directory):
versions = os.listdir(build_tools_directory)
for version in reversed(sorted(versions)):
aapt_path = os.path.join(build_tools_directory, version, 'aapt')
if os.path.isfile(aapt_path):
logger.debug('Using aapt for version {}'.format(version))
env.aapt = aapt_path
break
else:
raise HostError('aapt not found. Please make sure at least one Android platform is installed.')
else:
raise HostError('aapt not found. Please make sure at least one Android platform is installed.')
# User may already installed 'aapt' from package provided by distro's
# Try finding in $PATH
aapt_path = which('aapt')
if aapt_path:
logger.debug('Using aapt from {}'.format(aapt_path))
env.aapt = aapt_path
else:
msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)'
raise HostError(msg.format(env.android_home))
def _check_env():
global android_home, platform_tools, adb, aapt # pylint: disable=W0603