Bug 1397764 - Part 2. Generate BINDGEN_CFLAGS for Android. r?chmanchester draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 29 Sep 2017 16:46:52 +0900
changeset 675909 50e848dabe8ff6fd2ef1886f6fcff1fa50ff5364
parent 675908 5568627368fbf2dce02904918e50a241713d0a85
child 734760 8cff6bb11c8e76feb0ec7cca091fe9dc6ef67693
push id83297
push userbmo:m_kato@ga2.so-net.ne.jp
push dateFri, 06 Oct 2017 07:24:10 +0000
reviewerschmanchester
bugs1397764
milestone58.0a1
Bug 1397764 - Part 2. Generate BINDGEN_CFLAGS for Android. r?chmanchester Building Fennec/Android uses cross compiler toolchain. So we have to generate clang options (include path for c++ headers and gcc headers, gcc-toolchain path and etc) from NDK path for bindgen. The following options are required for android build. (from stlport_cppflags) -I$topsrcdir/android-ndk/sources/cxx-stl/llvm-libc++/libcxx/include -I$topsrcdir/android-ndk/sources/android/support/include -I$topsrcdir/android-ndk/sources/cxx-stl/llvm-libc++abi/libcxxabi/include" (others for clang) -isystem $topsrcdir/android-ndk/platforms/android-9/arch-arm/usr/include -gcc-toolchain $topsrcdir/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -I$topsrcdir/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9/include -I$topsrcdir/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9/include-fixed" Also, since bindgen_cflags_defaults uses as default, some funcions requires '--help'. MozReview-Commit-ID: 7zfhw3IxQ2W
build/moz.configure/android-ndk.configure
build/moz.configure/toolchain.configure
--- a/build/moz.configure/android-ndk.configure
+++ b/build/moz.configure/android-ndk.configure
@@ -18,19 +18,19 @@ def min_android_version(target):
         return '21'
     return '9'
 
 js_option('--with-android-version',
           nargs=1,
           help='android platform version',
           default=min_android_version)
 
-@depends('--with-android-version', min_android_version)
+@depends('--with-android-version', min_android_version, '--help')
 @imports(_from='__builtin__', _import='ValueError')
-def android_version(value, min_version):
+def android_version(value, min_version, _):
     if not value:
         # Someone has passed --without-android-version.
         die('--with-android-version cannot be disabled.')
 
     try:
         version = int(value[0])
     except ValueError:
         die('--with-android-version expects an integer value')
@@ -38,18 +38,20 @@ def android_version(value, min_version):
     if version < int(min_version):
         die('--with-android-version must be at least %s (got %s)',
             min_version, value[0])
 
     return version
 
 add_old_configure_assignment('android_version', android_version)
 
-@depends('--with-android-ndk', build_project)
-def ndk(value, build_project):
+@depends('--with-android-ndk', build_project, '--help')
+def ndk(value, build_project, help):
+    if help:
+        return
     if build_project == 'mobile/android' and not value:
         die('You must specify --with-android-ndk=/path/to/ndk when '
             'building mobile/android')
     if value:
         return value[0]
 
 set_config('ANDROID_NDK', ndk)
 add_old_configure_assignment('android_ndk', ndk)
@@ -90,20 +92,20 @@ def ndk_minor_version(ndk_version):
         return
     (major, minor, revision) = ndk_version.split('.')
     if minor:
         return minor
     die('Unexpected NDK version string: ' + ndk_version)
 
 set_config('ANDROID_NDK_MINOR_VERSION', ndk_minor_version);
 
-@depends(target, android_version, ndk)
+@depends(target, android_version, ndk, '--help')
 @checking('for android platform directory')
 @imports(_from='os.path', _import='isdir')
-def android_platform(target, android_version, ndk):
+def android_platform(target, android_version, ndk, _):
     if target.os != 'Android':
         return
 
     if 'mips' in target.cpu:
         target_dir_name = 'mips'
     elif 'aarch64' == target.cpu:
         target_dir_name = 'arm64'
     else:
@@ -133,21 +135,21 @@ add_old_configure_assignment('android_pl
 
 @depends(android_platform)
 def extra_toolchain_flags(platform_dir):
     if not platform_dir:
         return []
     return ['-idirafter',
             os.path.join(platform_dir, 'usr', 'include')]
 
-@depends(target, host, ndk, '--with-android-toolchain')
+@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):
+def android_toolchain(target, host, ndk, toolchain, _):
     if not ndk:
         return
     if toolchain:
         return toolchain[0]
     else:
         if target.cpu == 'arm' and target.endianness == 'little':
             target_base = 'arm-linux-androideabi'
         elif target.cpu == 'x86':
@@ -170,35 +172,39 @@ def android_toolchain(target, host, ndk,
             log.debug('Trying %s' % quote(toolchain))
         if isdir(toolchain):
             return toolchain
         die('You have to specify --with-android-toolchain='
             '/path/to/ndk/toolchain.')
 
 set_config('ANDROID_TOOLCHAIN', android_toolchain)
 
-@depends(target, android_toolchain)
-def android_toolchain_prefix(target, toolchain):
+@depends(target)
+def android_toolchain_prefix_base(target):
+    if target.cpu == 'x86':
+        # Ideally, the --target should just have the right x86 variant
+        # in the first place.
+        return 'i686-linux-android'
+    return target.toolchain
+
+@depends(android_toolchain_prefix_base, android_toolchain)
+def android_toolchain_prefix(prefix_base, toolchain):
     if toolchain:
-        if target.cpu == 'x86':
-            # Ideally, the --target should just have the right x86 variant
-            # in the first place.
-            return '%s/bin/i686-linux-android-' % toolchain
-        return '%s/bin/%s-' % (toolchain, target.toolchain)
+        return '%s/bin/%s-' % (toolchain, prefix_base)
 
 imply_option('--with-toolchain-prefix', android_toolchain_prefix,
              reason='--with-android-ndk')
 
 option(env='STLPORT_CPPFLAGS',
        nargs=1,
        help='Options compiler should pass for standard C++ library')
 
-@depends('STLPORT_CPPFLAGS', ndk)
+@depends('STLPORT_CPPFLAGS', ndk, '--help')
 @imports(_from='os.path', _import='isdir')
-def stlport_cppflags(value, ndk):
+def stlport_cppflags(value, ndk, _):
     if value and len(value):
         return value
     if not ndk:
         return
 
     ndk_base = os.path.join(ndk, 'sources', 'cxx-stl')
     cxx_base = os.path.join(ndk_base, 'llvm-libc++')
     cxx_include = os.path.join(cxx_base, 'libcxx', 'include')
@@ -221,8 +227,24 @@ def stlport_cppflags(value, ndk):
     # functions, locale-specific C library functions, multibyte support,
     # etc.
     return "-I%s -I%s -I%s" % (cxx_include,
                                os.path.join(ndk, 'sources', 'android',
                                             'support', 'include'),
                                cxxabi_include)
 
 add_old_configure_assignment('stlport_cppflags', stlport_cppflags)
+
+@depends(stlport_cppflags, android_platform, android_toolchain,
+         android_toolchain_prefix_base, '--help')
+def bindgen_cflags_defaults(stlport_cppflags, android_platform, toolchain,
+                            toolchain_prefix, _):
+    if not stlport_cppflags:
+        return
+
+    gcc_include = os.path.join(toolchain, 'lib', 'gcc', toolchain_prefix, '4.9')
+
+    cflags_format = "%s -isystem %s -gcc-toolchain %s -I%s -I%s"
+    return cflags_format % (stlport_cppflags,
+                            os.path.join(android_platform, 'usr', 'include'),
+                            toolchain,
+                            os.path.join(gcc_include, 'include'),
+                            os.path.join(gcc_include, 'include-fixed'))
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -963,16 +963,17 @@ include('compile-checks.configure')
                      check_msg='for 64-bit OS'))
 def check_have_64_bit(have_64_bit, compiler_have_64_bit):
     if have_64_bit != compiler_have_64_bit:
         configure_error('The target compiler does not agree with configure '
                         'about the target bitness.')
 
 option(env='BINDGEN_CFLAGS',
        nargs=1,
+       default=bindgen_cflags_defaults,
        help='Options bindgen should pass to the C/C++ parser')
 
 @depends('BINDGEN_CFLAGS')
 @checking('bindgen cflags', lambda s: s if s and s.strip() else 'no')
 def bindgen_cflags(value):
     if value and len(value):
         # Reformat the env value for substitution into a toml list.
         flags = value[0].split()