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/.
8 @depends(toolchains_base_dir, "--help")
9 @imports(_from="os.path", _import="isdir")
10 @imports(_from="mozboot.android", _import="NDK_VERSION")
11 def default_android_ndk_root(toolchains_base_dir, _):
12 for ndk in ("android-ndk-%s" % NDK_VERSION, "android-ndk"):
13 path = os.path.join(toolchains_base_dir, ndk)
21 default=default_android_ndk_root,
22 help="location where the Android NDK can be found{|}",
25 option("--with-android-toolchain", nargs=1, help="location of the Android toolchain")
28 "--with-android-lldb-server", nargs=1, help="location of the Android LLDB server"
32 "--with-android-googlevr-sdk", nargs=1, help="location of the Android GoogleVR SDK"
37 def min_android_version():
38 # Sync with android_sdk_version
43 "--with-android-version",
45 help="android platform version{|}",
46 default=min_android_version,
50 @depends("--with-android-version", min_android_version)
51 @imports(_from="__builtin__", _import="ValueError")
52 def android_version(value, min_version):
54 # Someone has passed --without-android-version.
55 die("--with-android-version cannot be disabled.")
58 version = int(value[0])
60 die("--with-android-version expects an integer value")
62 if version < int(min_version):
64 "--with-android-version must be at least %s (got %s)", min_version, value[0]
70 @depends("--with-android-ndk")
71 @imports(_from="os.path", _import="isdir")
74 if not isdir(value[0]):
76 "The path you specified with --with-android-ndk (%s) is not "
77 "a directory" % value[0]
82 "You must specify --with-android-ndk=/path/to/ndk when targeting Android, "
83 "or try |mach bootstrap|."
87 set_config("ANDROID_NDK", ndk)
91 @checking("for android ndk version")
92 @imports(_from="__builtin__", _import="open")
93 @imports(_from="mozboot.android", _import="NDK_VERSION")
94 @imports(_from="mozboot.android", _import="get_ndk_version")
95 @imports(_from="mozboot.android", _import="GetNdkVersionError")
98 # Building 'js/src' for non-Android.
102 major, minor, human = get_ndk_version(ndk)
103 except GetNdkVersionError as e:
106 if NDK_VERSION != human:
108 "The only supported version of the NDK is %s (have %s)\n"
109 "Please run |mach bootstrap| "
110 "to install the correct NDK." % (NDK_VERSION, human)
118 set_config("ANDROID_NDK_MAJOR_VERSION", ndk_version.major)
119 set_config("ANDROID_NDK_MINOR_VERSION", ndk_version.minor)
122 @imports(_from="os.path", _import="isdir")
123 @imports(_from="mozbuild.shellutil", _import="quote")
124 def host_dir(host, base_dir):
125 dir_format = "%s/%s-%s"
126 host_kernel = "windows" if host.kernel == "WINNT" else host.kernel.lower()
128 dir = dir_format % (base_dir, host_kernel, host.cpu)
129 log.debug("Trying %s" % quote(dir))
130 if not isdir(dir) and host.cpu == "x86_64":
131 dir = dir_format % (base_dir, host_kernel, "x86")
132 log.debug("Trying %s" % quote(dir))
133 if not isdir(dir) and host.kernel == "Darwin" and host.cpu == "aarch64":
134 dir = dir_format % (base_dir, host_kernel, "x86_64")
135 log.debug("Trying %s" % quote(dir))
140 @depends(host, ndk, "--with-android-toolchain")
141 @checking("for the Android toolchain directory", lambda x: x or "not found")
142 def android_toolchain(host, ndk, toolchain):
148 toolchain = host_dir(host, os.path.join(ndk, "toolchains", "llvm", "prebuilt"))
151 die("You have to specify --with-android-toolchain=" "/path/to/ndk/toolchain.")
154 @depends(target, android_toolchain)
155 @checking("for android sysroot directory")
156 @imports(_from="os.path", _import="isdir")
157 def android_sysroot(target, android_toolchain):
158 if target.os != "Android":
162 os.path.join(android_toolchain, "sysroot"),
165 for sysroot_dir in search_dirs:
166 if isdir(sysroot_dir):
170 "Android sysroot directory not found in %s."
171 % str([sysroot_dir for sysroot_dir in search_dirs])
175 @depends(target, host, ndk, "--with-android-lldb-server")
176 @checking("for the Android LLDB server", lambda x: x or "not found")
177 @imports(_from="os", _import="listdir")
178 @imports(_from="os.path", _import="isdir")
179 @imports(_from="os.path", _import="isfile")
180 @imports(_from="mozbuild.shellutil", _import="quote")
181 def android_lldb_server(target, host, ndk, lldb):
187 clang_format = "toolchains/llvm/prebuilt/%s-%s/lib/clang"
188 llvm_lib = "lib/linux"
190 host_kernel = "windows" if host.kernel == "WINNT" else host.kernel.lower()
191 clang_path = os.path.join(ndk, clang_format % (host_kernel, host.cpu))
192 if not isdir(clang_path) and host.kernel == "Darwin" and host.cpu == "aarch64":
193 clang_path = os.path.join(ndk, clang_format % (host_kernel, "x86_64"))
194 log.debug("Listing subdirectories of %s" % quote(clang_path))
196 x for x in listdir(clang_path) if isdir(os.path.join(clang_path, x))
198 log.debug("Got %r" % clang_subdirs)
199 if len(clang_subdirs) == 0:
201 "Could not resolve lldb-server in %s. Please specify --with-android-lldb-server=/path/to/android/lldb-server"
204 sorted_versions = sorted(clang_subdirs, key=Version)
205 highest_version = sorted_versions[-1]
206 log.warning("Using highest version available: %s" % quote(highest_version))
208 " Available versions: "
209 + ", ".join(str(version) for version in sorted_versions)
212 "(To use an older version, please specify --with-android-lldb-server=/path/to/desired/android/lldb-server)"
215 if target.cpu == "x86":
218 target_cpu = target.cpu
220 full_path = os.path.join(
221 clang_path, highest_version, llvm_lib, target_cpu, "lldb-server"
223 log.debug("Trying %s" % quote(full_path))
225 if isfile(full_path):
227 die("Please specify --with-android-lldb-server=/path/to/android/lldb-server")
230 set_config("ANDROID_LLDB_SERVER", android_lldb_server)
236 help="Options linker should pass for standard C++ library",
240 @depends("STLPORT_LIBS", ndk)
241 @imports(_from="os.path", _import="isfile")
242 def stlport_libs(value, ndk):
243 if value and len(value):
248 return ["-static-libstdc++"]
251 set_config("STLPORT_LIBS", stlport_libs)
254 @depends(android_sysroot, android_toolchain)
255 def extra_toolchain_flags(android_sysroot, toolchain_dir):
256 if not android_sysroot:
259 "--sysroot={}".format(android_sysroot),
260 "--gcc-toolchain={}".format(toolchain_dir),
265 add_old_configure_assignment("extra_android_flags", extra_toolchain_flags)
268 @depends(extra_toolchain_flags)
269 def bindgen_cflags_android(toolchain_flags):
270 return toolchain_flags
273 @depends("--with-android-googlevr-sdk", target)
274 @checking("for GoogleVR SDK", lambda x: x.result)
275 @imports(_from="os.path", _import="exists")
276 @imports(_from="os.path", _import="abspath")
277 def googlevr_sdk(value, target):
279 return namespace(result="Not specified")
280 path = abspath(value[0])
282 die("Could not find GoogleVR SDK %s", path)
283 include = "%s/libraries/headers/" % path
284 if "arm" == target.cpu:
286 elif "aarch64" == target.cpu:
288 elif "x86" == target.cpu:
291 die("Unsupported GoogleVR cpu architecture %s" % target.cpu)
293 libs = "{0}/libraries/jni/{1}/".format(path, arch)
297 "Could not find GoogleVR NDK at %s. Did you try running "
298 "'./gradlew :extractNdk' in %s?",
311 set_define("MOZ_ANDROID_GOOGLE_VR", googlevr_sdk.enabled)
312 set_config("MOZ_ANDROID_GOOGLE_VR", googlevr_sdk.enabled)
313 set_config("MOZ_ANDROID_GOOGLE_VR_INCLUDE", googlevr_sdk.include)
314 set_config("MOZ_ANDROID_GOOGLE_VR_LIBS", googlevr_sdk.libs)