Bug 1428182 - 1. Support unified headers for Android builds; r=nalexander draft
authorJim Chen <nchen@mozilla.com>
Tue, 30 Jan 2018 14:08:22 -0500
changeset 748987 9ded282343df64d9cc4abcf7d7c6b03ac3423ff0
parent 748372 c0f08b020685f67a7ea08658731adb410f70b7e6
child 748988 fe78c114189a362cdad3d79ce67868b045328392
push id97287
push userbmo:nchen@mozilla.com
push dateTue, 30 Jan 2018 19:09:20 +0000
reviewersnalexander
bugs1428182
milestone60.0a1
Bug 1428182 - 1. Support unified headers for Android builds; r=nalexander NDK headers are grouped into a "sysroot" directory, which doesn't contain architecture-specific bits, and a "system" directory, which contains only the architecture-specific bits. Previously, both directories are the same, under platforms/android-*/arch-*/. However, with unified headers in NDK r16, the two are different, so we need to support that in the Android build scripts. Unified headers also rely on the build system defining the __ANDROID_API__ macro, so we add support for that as well. MozReview-Commit-ID: 9zBNQC3BRFl
build/autoconf/android.m4
build/moz.configure/android-ndk.configure
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -3,22 +3,22 @@ dnl License, v. 2.0. If a copy of the MP
 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 AC_DEFUN([MOZ_ANDROID_NDK],
 [
 
 case "$target" in
 *-android*|*-linuxandroid*)
     dnl $android_platform will be set for us by Python configure.
-    directory_include_args="-isystem $android_platform/usr/include"
+    directory_include_args="-isystem $android_system -isystem $android_sysroot/usr/include"
 
     # clang will do any number of interesting things with host tools unless we tell
     # it to use the NDK tools.
     extra_opts="-gcc-toolchain $(dirname $(dirname $TOOLCHAIN_PREFIX))"
-    CPPFLAGS="$extra_opts $CPPFLAGS"
+    CPPFLAGS="$extra_opts -D__ANDROID_API__=$android_version $CPPFLAGS"
     ASFLAGS="$extra_opts $ASFLAGS"
     LDFLAGS="$extra_opts $LDFLAGS"
 
     CPPFLAGS="$directory_include_args $CPPFLAGS"
     CFLAGS="-fno-short-enums -fno-exceptions $CFLAGS"
     CXXFLAGS="-fno-short-enums -fno-exceptions $CXXFLAGS $stlport_cppflags"
     ASFLAGS="$directory_include_args -DANDROID $ASFLAGS"
 
--- a/build/moz.configure/android-ndk.configure
+++ b/build/moz.configure/android-ndk.configure
@@ -145,16 +145,66 @@ def android_platform(target, android_ver
             "configuration, it should be in %s" % platform_dir)
 
     return platform_dir
 
 
 add_old_configure_assignment('android_platform', android_platform)
 
 
+@depends(android_platform, ndk, target, '--help')
+@checking('for android sysroot directory')
+@imports(_from='os.path', _import='isdir')
+def android_sysroot(android_platform, ndk, target, _):
+    if target.os != 'Android':
+        return
+
+    # NDK r15 has both unified and non-unified headers, but we only support
+    # non-unified for that NDK, so look for that first.
+    search_dirs = [
+        # (<if this directory exists>, <return this directory>)
+        (os.path.join(android_platform, 'usr', 'include'), android_platform),
+        (os.path.join(ndk, 'sysroot'), os.path.join(ndk, 'sysroot')),
+    ]
+
+    for test_dir, sysroot_dir in search_dirs:
+        if isdir(test_dir):
+            return sysroot_dir
+
+    die("Android sysroot directory not found in %s." %
+        str([sysroot_dir for test_dir, sysroot_dir in search_dirs]))
+
+
+add_old_configure_assignment('android_sysroot', android_sysroot)
+
+
+@depends(android_platform, ndk, target, '--help')
+@checking('for android system directory')
+@imports(_from='os.path', _import='isdir')
+def android_system(android_platform, ndk, target, _):
+    if target.os != 'Android':
+        return
+
+    # NDK r15 has both unified and non-unified headers, but we only support
+    # non-unified for that NDK, so look for that first.
+    search_dirs = [
+        os.path.join(android_platform, 'usr', 'include'),
+        os.path.join(ndk, 'sysroot', 'usr', 'include', target.toolchain),
+    ]
+
+    for system_dir in search_dirs:
+        if isdir(system_dir):
+            return system_dir
+
+    die("Android system directory not found in %s." % str(search_dirs))
+
+
+add_old_configure_assignment('android_system', android_system)
+
+
 @depends(target, host, ndk, '--with-android-toolchain', '--help')
 @checking('for the Android toolchain directory', lambda x: x or 'not found')
 @imports(_from='os.path', _import='isdir')
 @imports(_from='mozbuild.shellutil', _import='quote')
 def android_toolchain(target, host, ndk, toolchain, _):
     if not ndk:
         return
     if toolchain:
@@ -236,24 +286,29 @@ def stlport_cppflags(value, ndk, _):
         '-I%s' % cxx_include,
         '-I%s' % os.path.join(ndk, 'sources', 'android', 'support', 'include'),
         '-I%s' % cxxabi_include]
 
 
 add_old_configure_assignment('stlport_cppflags', stlport_cppflags)
 
 
-@depends(android_platform, android_toolchain, stlport_cppflags)
-def extra_toolchain_flags(platform_dir, toolchain_dir, stlport_cppflags):
-    if not platform_dir:
+@depends(android_system, android_sysroot, android_toolchain, android_version,
+         stlport_cppflags)
+def extra_toolchain_flags(android_system, android_sysroot, toolchain_dir,
+                          android_version, stlport_cppflags):
+    if not android_sysroot:
         return []
     flags = ['-isystem',
-             os.path.join(platform_dir, 'usr', 'include'),
+             android_system,
+             '-isystem',
+             os.path.join(android_sysroot, 'usr', 'include'),
              '-gcc-toolchain',
-             toolchain_dir]
+             toolchain_dir,
+             '-D__ANDROID_API__=%d' % android_version]
     flags.extend(stlport_cppflags if stlport_cppflags else [])
     return flags
 
 
 @depends(android_toolchain_prefix_base, android_toolchain)
 def android_toolchain_prefix(prefix_base, toolchain):
     if toolchain:
         return '%s/bin/%s-' % (toolchain, prefix_base)