1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Ensure Android SDK and build-tools versions depending on mobile target.
10 @depends(host, toolchains_base_dir, "--help")
11 @imports(_from="os.path", _import="isdir")
12 def default_android_sdk_root(host, toolchains_base_dir, _):
14 "Darwin": "android-sdk-macosx",
15 "Linux": "android-sdk-linux",
16 "WINNT": "android-sdk-windows",
17 }.get(host.kernel, "android-sdk")
18 for sdk_basename in (sdk_basename, "android-sdk"):
19 path = os.path.join(toolchains_base_dir, sdk_basename)
27 default=default_android_sdk_root,
28 help="location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux){|}",
32 @depends("--with-android-sdk")
33 @imports(_from="os.path", _import="isdir")
34 def android_sdk_root(value):
36 if not isdir(value[0]):
38 "The path you specified with --with-android-sdk (%s) is not "
39 "a directory" % value[0]
44 "You must specify --with-android-sdk=/path/to/sdk when targeting Android, "
45 "or try |mach bootstrap|."
50 def android_sdk_version():
51 return namespace(build_tools_version="30.0.2", target_sdk_version="30")
54 @depends(android_sdk_root, android_sdk_version)
55 @checking("for Android build-tools")
56 @imports(_from="os.path", _import="exists")
57 @imports(_from="os.path", _import="isdir")
58 def android_build_tools(sdk_root, sdk_version):
59 android_build_tools_base = os.path.join(sdk_root, "build-tools")
60 version = sdk_version.build_tools_version
61 if isdir(os.path.join(android_build_tools_base, version)):
62 tools = os.path.join(android_build_tools_base, version)
63 for zipalign in ("zipalign", "zipalign.exe"):
64 if exists(os.path.join(tools, zipalign)):
68 "You must install the Android build-tools version %s. "
69 "Try |mach bootstrap|. (Looked for %s/%s)"
70 % (version, android_build_tools_base, version)
74 @depends(android_sdk_root)
75 @checking("for Android tools")
76 @imports(_from="os.path", _import="isdir")
77 def android_tools(sdk_root):
78 tools = os.path.join(sdk_root, "tools")
82 die("You must install the Android tools. Try |mach bootstrap|")
85 @depends(android_sdk_root)
86 @checking("for Android platform-tools")
87 @imports(_from="os.path", _import="exists")
88 @imports(_from="os.path", _import="isdir")
89 def android_platform_tools(sdk_root):
90 tools = os.path.join(sdk_root, "platform-tools")
91 for adb in ("adb", "adb.exe"):
92 if exists(os.path.join(tools, adb)):
96 "You must install the Android platform-tools. Try |mach bootstrap|. (Looked for %s)"
101 @depends(android_sdk_root)
102 def android_emulator_path(sdk_root):
103 return [os.path.join(sdk_root, "emulator")]
107 def check_android_tools(tool, tool_dir):
109 tool.upper(), (tool, tool + ".exe"), paths=tool_dir, allow_missing=True
113 def require_tool(result):
115 die("The program %s was not found. Try |mach bootstrap|" % tool)
121 check_android_tools("zipalign", android_build_tools)
122 check_android_tools("adb", android_platform_tools)
123 check_android_tools("emulator", android_emulator_path)
125 set_config("ANDROID_SDK_ROOT", android_sdk_root)
126 set_config("ANDROID_TOOLS", android_tools)
128 set_config("ANDROID_BUILD_TOOLS_VERSION", android_sdk_version.build_tools_version)
129 set_config("ANDROID_TARGET_SDK", android_sdk_version.target_sdk_version)
130 add_old_configure_assignment(
131 "ANDROID_TARGET_SDK", android_sdk_version.target_sdk_version