DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d38398e5144e)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


js_option('--with-android-ndk', nargs=1,
          help='location where the Android NDK can be found')

js_option('--with-android-toolchain', nargs=1,
          help='location of the Android toolchain')

js_option('--with-android-gnu-compiler-version', nargs=1,
          help='GNU compiler version to use')

min_android_version = dependable(lambda: '9')

js_option('--with-android-version',
          nargs=1,
          help='android platform version',
          default=min_android_version)

@depends('--with-android-version', min_android_version)
@imports(_from='__builtin__', _import='ValueError')
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')

    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):
    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)

@depends(target, android_version, ndk)
@checking('for android platform directory')
@imports(_from='os.path', _import='isdir')
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:
        target_dir_name = target.cpu

    # Not all Android releases have their own platform release. We use
    # the next lower platform version in these cases.
    if android_version in (11, 10):
        platform_version = 9
    elif android_version in (20, 22):
        platform_version = android_version - 1
    else:
        platform_version = android_version

    platform_dir = os.path.join(ndk,
                                'platforms',
                                'android-%s' % platform_version,
                                'arch-%s' % target_dir_name)

    if not isdir(platform_dir):
        die("Android platform directory not found. With the current "
            "configuration, it should be in %s" % platform_dir)

    return platform_dir

add_old_configure_assignment('android_platform', android_platform)

@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',
         '--with-android-gnu-compiler-version')
@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, gnu_compiler_version):
    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':
            target_base = 'x86'
        elif target.cpu == 'mips32' and target.endianness == 'little':
            target_base = 'mipsel-linux-android'
        elif target.cpu == 'aarch64' and target.endianness == 'little':
            target_base = 'aarch64-linux-android'
        else:
            die('Target cpu is not supported.')

        toolchain_format = '%s/toolchains/%s-%s/prebuilt/%s-%s'

        for version in gnu_compiler_version or ['4.9', '4.8', '4.7']:
            toolchain = toolchain_format % (ndk, target_base, version,
                                            host.kernel.lower(), host.cpu)
            log.debug('Trying %s' % quote(toolchain))
            if not isdir(toolchain) and host.cpu == 'x86_64':
                toolchain = toolchain_format % (ndk, target_base, version,
                                                host.kernel.lower(), 'x86')
                log.debug('Trying %s' % quote(toolchain))
            if isdir(toolchain):
                return toolchain
        else:
            if gnu_compiler_version:
                die('Your --with-android-gnu-compiler-version may be wrong')
            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):
    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)

imply_option('--with-toolchain-prefix', android_toolchain_prefix,
             reason='--with-android-ndk')