2019-02-02 00:12:51 +03:00
|
|
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
|
|
# vim: set filetype=python:
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
# Ensure Android SDK and build-tools versions depending on mobile target.
|
|
|
|
|
|
|
|
|
2019-06-08 02:25:01 +03:00
|
|
|
@depends(host, mozbuild_state_path, '--help')
|
2019-02-02 00:12:51 +03:00
|
|
|
@imports('os')
|
2019-06-08 02:25:01 +03:00
|
|
|
def default_android_sdk_root(host, mozbuild_state_path, _):
|
2019-02-02 00:12:51 +03:00
|
|
|
sdk_basename = {
|
|
|
|
'Darwin': 'android-sdk-macosx',
|
|
|
|
'Linux': 'android-sdk-linux',
|
|
|
|
'WINNT': 'android-sdk-windows',
|
|
|
|
}.get(host.kernel)
|
2019-06-08 01:20:48 +03:00
|
|
|
if sdk_basename:
|
|
|
|
path = os.path.join(mozbuild_state_path, sdk_basename)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
return path
|
2019-02-02 00:12:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
option('--with-android-sdk', nargs=1,
|
|
|
|
default=default_android_sdk_root,
|
|
|
|
help='location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux){|}')
|
|
|
|
|
|
|
|
|
|
|
|
@depends('--with-android-sdk')
|
|
|
|
@imports(_from='os.path', _import='isdir')
|
|
|
|
def android_sdk_root(value):
|
2019-06-08 01:20:48 +03:00
|
|
|
if value:
|
|
|
|
if not isdir(value[0]):
|
|
|
|
die("The path you specified with --with-android-sdk (%s) is not "
|
|
|
|
"a directory" % value[0])
|
2019-02-02 00:12:51 +03:00
|
|
|
return value[0]
|
|
|
|
|
|
|
|
die("You must specify --with-android-sdk=/path/to/sdk when targeting Android, "
|
|
|
|
"or try |mach bootstrap|.")
|
|
|
|
|
|
|
|
|
|
|
|
@depends('--help')
|
|
|
|
def android_sdk_version(_):
|
2019-07-20 20:27:53 +03:00
|
|
|
return namespace(build_tools_versions=['28.0.3'], target_sdk_version='28')
|
2019-02-02 00:12:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
@depends(android_sdk_root, android_sdk_version)
|
|
|
|
@checking('for Android build-tools')
|
|
|
|
@imports(_from='os.path', _import='exists')
|
|
|
|
@imports(_from='os.path', _import='isdir')
|
|
|
|
def android_build_tools(sdk_root, sdk_version):
|
|
|
|
android_build_tools_base = os.path.join(sdk_root, 'build-tools')
|
2019-02-08 19:56:13 +03:00
|
|
|
versions = sdk_version.build_tools_versions
|
|
|
|
for version in versions:
|
2019-02-02 00:12:51 +03:00
|
|
|
if isdir(os.path.join(android_build_tools_base, version)):
|
|
|
|
tools = os.path.join(android_build_tools_base, version)
|
|
|
|
for zipalign in ('zipalign', 'zipalign.exe'):
|
|
|
|
if exists(os.path.join(tools, zipalign)):
|
|
|
|
return [tools]
|
|
|
|
|
|
|
|
die("You must install the Android build-tools version %s. "
|
|
|
|
"Try |mach bootstrap|. (Looked for %s/%s)" %
|
|
|
|
(versions[0], android_build_tools_base, versions[0]))
|
|
|
|
|
|
|
|
|
|
|
|
@depends(android_sdk_root)
|
|
|
|
@checking('for Android tools')
|
|
|
|
@imports(_from='os.path', _import='isdir')
|
|
|
|
def android_tools(sdk_root):
|
|
|
|
tools = os.path.join(sdk_root, 'tools')
|
|
|
|
if isdir(tools):
|
|
|
|
return tools
|
|
|
|
|
|
|
|
die("You must install the Android tools. Try |mach bootstrap|")
|
|
|
|
|
|
|
|
|
|
|
|
@depends(android_sdk_root)
|
|
|
|
@checking('for Android platform-tools')
|
|
|
|
@imports(_from='os.path', _import='exists')
|
|
|
|
@imports(_from='os.path', _import='isdir')
|
|
|
|
def android_platform_tools(sdk_root):
|
|
|
|
tools = os.path.join(sdk_root, 'platform-tools')
|
|
|
|
for adb in ('adb', 'adb.exe'):
|
|
|
|
if exists(os.path.join(tools, adb)):
|
|
|
|
return [tools]
|
|
|
|
|
|
|
|
die("You must install the Android platform-tools. Try |mach bootstrap|. (Looked for %s)" %
|
|
|
|
tools)
|
|
|
|
|
|
|
|
|
|
|
|
@depends(android_sdk_root)
|
|
|
|
def android_emulator_path(sdk_root):
|
|
|
|
return [os.path.join(sdk_root, 'emulator')]
|
|
|
|
|
|
|
|
|
|
|
|
@template
|
|
|
|
def check_android_tools(tool, tool_dir):
|
|
|
|
check = check_prog(tool.upper(), (tool, tool + '.exe'), paths=tool_dir,
|
|
|
|
allow_missing=True)
|
|
|
|
|
|
|
|
@depends(check)
|
|
|
|
def require_tool(result):
|
|
|
|
if result is None:
|
|
|
|
die('The program %s was not found. Try |mach bootstrap|' % tool)
|
|
|
|
return result
|
|
|
|
|
|
|
|
return require_tool
|
|
|
|
|
|
|
|
|
|
|
|
check_android_tools('zipalign', android_build_tools)
|
|
|
|
check_android_tools('adb', android_platform_tools)
|
|
|
|
check_android_tools('emulator', android_emulator_path)
|
|
|
|
|
|
|
|
set_config('ANDROID_SDK_ROOT', android_sdk_root)
|
|
|
|
set_config('ANDROID_TOOLS', android_tools)
|
|
|
|
|
|
|
|
set_config('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)
|
|
|
|
add_old_configure_assignment('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)
|