Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / build / moz.configure / android-ndk.configure
blobc19023a1eaf7dab6c71b0b907474a4b56b2e7ab4
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/lib64/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) != 1:
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         log.debug("Found version %s" % quote(clang_subdirs[0]))
206         if target.cpu == "x86":
207             target_cpu = "i386"
208         else:
209             target_cpu = target.cpu
211         full_path = os.path.join(
212             clang_path, clang_subdirs[0], llvm_lib, target_cpu, "lldb-server"
213         )
214         log.debug("Trying %s" % quote(full_path))
216         if isfile(full_path):
217             return full_path
218         die("Please specify --with-android-lldb-server=/path/to/android/lldb-server")
221 set_config("ANDROID_LLDB_SERVER", android_lldb_server)
224 option(
225     env="STLPORT_LIBS",
226     nargs=1,
227     help="Options linker should pass for standard C++ library",
231 @depends("STLPORT_LIBS", ndk)
232 @imports(_from="os.path", _import="isfile")
233 def stlport_libs(value, ndk):
234     if value and len(value):
235         return value.split()
236     if not ndk:
237         return
239     return ["-static-libstdc++"]
242 set_config("STLPORT_LIBS", stlport_libs)
245 @depends(android_sysroot, android_toolchain)
246 def extra_toolchain_flags(android_sysroot, toolchain_dir):
247     if not android_sysroot:
248         return []
249     flags = [
250         "--sysroot={}".format(android_sysroot),
251         "--gcc-toolchain={}".format(toolchain_dir),
252     ]
253     return flags
256 add_old_configure_assignment("extra_android_flags", extra_toolchain_flags)
259 @depends(extra_toolchain_flags)
260 def bindgen_cflags_android(toolchain_flags):
261     return toolchain_flags
264 @depends("--with-android-googlevr-sdk", target)
265 @checking("for GoogleVR SDK", lambda x: x.result)
266 @imports(_from="os.path", _import="exists")
267 @imports(_from="os.path", _import="abspath")
268 def googlevr_sdk(value, target):
269     if not value:
270         return namespace(result="Not specified")
271     path = abspath(value[0])
272     if not exists(path):
273         die("Could not find GoogleVR SDK %s", path)
274     include = "%s/libraries/headers/" % path
275     if "arm" == target.cpu:
276         arch = "armeabi-v7a"
277     elif "aarch64" == target.cpu:
278         arch = "arm64-v8a"
279     elif "x86" == target.cpu:
280         arch = "x86"
281     else:
282         die("Unsupported GoogleVR cpu architecture %s" % target.cpu)
284     libs = "{0}/libraries/jni/{1}/".format(path, arch)
286     if not exists(libs):
287         die(
288             "Could not find GoogleVR NDK at %s. Did you try running "
289             "'./gradlew :extractNdk' in %s?",
290             libs,
291             path,
292         )
294     return namespace(
295         result=path,
296         include=include,
297         libs=libs,
298         enabled=True,
299     )
302 set_define("MOZ_ANDROID_GOOGLE_VR", googlevr_sdk.enabled)
303 set_config("MOZ_ANDROID_GOOGLE_VR", googlevr_sdk.enabled)
304 set_config("MOZ_ANDROID_GOOGLE_VR_INCLUDE", googlevr_sdk.include)
305 set_config("MOZ_ANDROID_GOOGLE_VR_LIBS", googlevr_sdk.libs)