Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / build / moz.configure / android-ndk.configure
blobdd09142e4bd516cb3a14e03014fa3ede053be321
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)
14         if isdir(path):
15             return path
18 option(
19     "--with-android-ndk",
20     nargs=1,
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")
27 option(
28     "--with-android-lldb-server", nargs=1, help="location of the Android LLDB server"
31 option(
32     "--with-android-googlevr-sdk", nargs=1, help="location of the Android GoogleVR SDK"
36 @dependable
37 def min_android_version():
38     # Sync with android_sdk_version
39     return "21"
42 option(
43     "--with-android-version",
44     nargs=1,
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):
53     if not value:
54         # Someone has passed --without-android-version.
55         die("--with-android-version cannot be disabled.")
57     try:
58         version = int(value[0])
59     except ValueError:
60         die("--with-android-version expects an integer value")
62     if version < int(min_version):
63         die(
64             "--with-android-version must be at least %s (got %s)", min_version, value[0]
65         )
67     return version
70 @depends("--with-android-ndk")
71 @imports(_from="os.path", _import="isdir")
72 def ndk(value):
73     if value:
74         if not isdir(value[0]):
75             die(
76                 "The path you specified with --with-android-ndk (%s) is not "
77                 "a directory" % value[0]
78             )
79         return value[0]
81     die(
82         "You must specify --with-android-ndk=/path/to/ndk when targeting Android, "
83         "or try |mach bootstrap|."
84     )
87 set_config("ANDROID_NDK", ndk)
90 @depends(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")
96 def ndk_version(ndk):
97     if not ndk:
98         # Building 'js/src' for non-Android.
99         return
101     try:
102         major, minor, human = get_ndk_version(ndk)
103     except GetNdkVersionError as e:
104         die(str(e))
106     if NDK_VERSION != human:
107         die(
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)
111         )
112     return namespace(
113         major=major,
114         minor=minor,
115     )
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))
136     if isdir(dir):
137         return 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):
143     if not ndk:
144         return
145     if toolchain:
146         return toolchain[0]
148     toolchain = host_dir(host, os.path.join(ndk, "toolchains", "llvm", "prebuilt"))
149     if toolchain:
150         return toolchain
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":
159         return
161     search_dirs = [
162         os.path.join(android_toolchain, "sysroot"),
163     ]
165     for sysroot_dir in search_dirs:
166         if isdir(sysroot_dir):
167             return sysroot_dir
169     die(
170         "Android sysroot directory not found in %s."
171         % str([sysroot_dir for sysroot_dir in search_dirs])
172     )
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):
182     if not ndk:
183         return
184     if lldb:
185         return lldb[0]
186     else:
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))
195         clang_subdirs = [
196             x for x in listdir(clang_path) if isdir(os.path.join(clang_path, x))
197         ]
198         log.debug("Got %r" % clang_subdirs)
199         if len(clang_subdirs) == 0:
200             die(
201                 "Could not resolve lldb-server in %s. Please specify --with-android-lldb-server=/path/to/android/lldb-server"
202                 % quote(clang_path)
203             )
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))
207         log.warning(
208             " Available versions: "
209             + ", ".join(str(version) for version in sorted_versions)
210         )
211         log.warning(
212             "(To use an older version, please specify --with-android-lldb-server=/path/to/desired/android/lldb-server)"
213         )
215         if target.cpu == "x86":
216             target_cpu = "i386"
217         else:
218             target_cpu = target.cpu
220         full_path = os.path.join(
221             clang_path, highest_version, llvm_lib, target_cpu, "lldb-server"
222         )
223         log.debug("Trying %s" % quote(full_path))
225         if isfile(full_path):
226             return full_path
227         die("Please specify --with-android-lldb-server=/path/to/android/lldb-server")
230 set_config("ANDROID_LLDB_SERVER", android_lldb_server)
233 option(
234     env="STLPORT_LIBS",
235     nargs=1,
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):
244         return value.split()
245     if not ndk:
246         return
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:
257         return []
258     flags = [
259         "--sysroot={}".format(android_sysroot),
260         "--gcc-toolchain={}".format(toolchain_dir),
261     ]
262     return flags
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):
278     if not value:
279         return namespace(result="Not specified")
280     path = abspath(value[0])
281     if not exists(path):
282         die("Could not find GoogleVR SDK %s", path)
283     include = "%s/libraries/headers/" % path
284     if "arm" == target.cpu:
285         arch = "armeabi-v7a"
286     elif "aarch64" == target.cpu:
287         arch = "arm64-v8a"
288     elif "x86" == target.cpu:
289         arch = "x86"
290     else:
291         die("Unsupported GoogleVR cpu architecture %s" % target.cpu)
293     libs = "{0}/libraries/jni/{1}/".format(path, arch)
295     if not exists(libs):
296         die(
297             "Could not find GoogleVR NDK at %s. Did you try running "
298             "'./gradlew :extractNdk' in %s?",
299             libs,
300             path,
301         )
303     return namespace(
304         result=path,
305         include=include,
306         libs=libs,
307         enabled=True,
308     )
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)