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 # We support Android SDK version 21 and up by default.
52 # See the --enable-android-min-sdk option below.
54 # Warning: Before increasing the with-android-min-sdk value, please note several places in
55 # and out of tree have to be changed. Otherwise, places like Treeherder or archive.mozilla.org
56 # will advertise a bad API level. This may confuse people. As an example, please look at
58 # If you think you can't handle the whole set of changes, please reach out to the Release
61 build_tools_version="34.0.0",
62 target_sdk_version="34",
68 "--with-android-min-sdk",
69 default=android_sdk_version.min_sdk_version,
70 help="Impose a minimum Firefox for Android SDK version",
74 @depends("--with-android-min-sdk", android_sdk_version.target_sdk_version)
75 @imports(_from="__builtin__", _import="ValueError")
76 def valid_android_min_sdk(min_sdk_version, target_sdk_version):
77 if not min_sdk_version:
78 die("--without-android-min-sdk is not a valid option")
80 if int(min_sdk_version[0]) > int(target_sdk_version):
82 "--with-android-min-sdk is expected to be less than {}".format(
87 die("--with-android-min-sdk takes a numerical value")
88 return min_sdk_version[0]
91 set_config("MOZ_ANDROID_MIN_SDK_VERSION", valid_android_min_sdk)
94 @depends(android_sdk_root, android_sdk_version)
95 @checking("for Android build-tools")
96 @imports(_from="os.path", _import="exists")
97 @imports(_from="os.path", _import="isdir")
98 def android_build_tools(sdk_root, sdk_version):
99 android_build_tools_base = os.path.join(sdk_root, "build-tools")
100 version = sdk_version.build_tools_version
101 if isdir(os.path.join(android_build_tools_base, version)):
102 tools = os.path.join(android_build_tools_base, version)
103 for zipalign in ("zipalign", "zipalign.exe"):
104 if exists(os.path.join(tools, zipalign)):
108 "You must install the Android build-tools version %s. "
109 "Try |mach bootstrap|. (Looked for %s/%s)"
110 % (version, android_build_tools_base, version)
114 @depends(android_sdk_root)
115 @checking("for Android platform-tools")
116 @imports(_from="os.path", _import="exists")
117 @imports(_from="os.path", _import="isdir")
118 def android_platform_tools(sdk_root):
119 tools = os.path.join(sdk_root, "platform-tools")
120 for adb in ("adb", "adb.exe"):
121 if exists(os.path.join(tools, adb)):
125 "You must install the Android platform-tools. Try |mach bootstrap|. (Looked for %s)"
130 @depends(android_sdk_root)
131 def android_emulator_path(sdk_root):
132 return [os.path.join(sdk_root, "emulator")]
136 def check_android_tools(tool, tool_dir):
138 tool.upper(), (tool, tool + ".exe"), paths=tool_dir, allow_missing=True
142 def require_tool(result):
144 die("The program %s was not found. Try |mach bootstrap|" % tool)
150 check_android_tools("zipalign", android_build_tools)
151 check_android_tools("adb", android_platform_tools)
152 check_android_tools("emulator", android_emulator_path)
154 set_config("ANDROID_SDK_ROOT", android_sdk_root)
156 set_config("ANDROID_BUILD_TOOLS_VERSION", android_sdk_version.build_tools_version)
157 set_config("ANDROID_TARGET_SDK", android_sdk_version.target_sdk_version)