def get_prebuilt_gcc(host, arch):
    tag = build_support.host_to_tag(host)
    system_subdir = 'prebuilts/ndk/current/toolchains/{}'.format(tag)
    system_path = build_support.android_path(system_subdir)
    toolchain = build_support.arch_to_toolchain(arch)
    toolchain_dir = toolchain + '-4.9'
    return os.path.join(system_path, toolchain_dir)
def build_gcc_libs(out_dir, dist_dir, args):
    print('Packaging GCC libs...')

    arches = build_support.ALL_ARCHITECTURES
    if args.arch is not None:
        arches = [args.arch]

    for arch in arches:
        toolchain = build_support.arch_to_toolchain(arch)
        triple = fixup_toolchain_triple(toolchain)
        libgcc_subdir = 'lib/gcc/{}/4.9'.format(triple)
        is64 = arch.endswith('64')
        libatomic_subdir = '{}/lib{}'.format(triple, '64' if is64 else '')

        lib_names = [
            (libatomic_subdir, 'libatomic.a'),
            (libgcc_subdir, 'libgcc.a'),
        ]

        lib_dirs = ['']
        if arch == 'arm':
            lib_dirs += [
                'armv7-a',
                'armv7-a/hard',
                'armv7-a/thumb',
                'armv7-a/thumb/hard',
                'thumb',
            ]

        libs = []
        for lib_dir in lib_dirs:
            for subdir, lib in lib_names:
                libs.append((subdir, os.path.join(lib_dir, lib)))

        install_dir = os.path.join(out_dir, 'gcclibs', triple)
        if os.path.exists(install_dir):
            shutil.rmtree(install_dir)
        os.makedirs(install_dir)

        # These are target libraries, so the OS we use here is not
        # important. We explicitly use Linux because for whatever reason
        # the Windows aarch64 toolchain doesn't include libatomic.
        gcc_path = get_prebuilt_gcc('linux', arch)
        for gcc_subdir, lib in libs:
            src = os.path.join(gcc_path, gcc_subdir, lib)
            dst = os.path.join(install_dir, lib)
            dst_dir = os.path.dirname(dst)
            if not os.path.exists(dst_dir):
                os.makedirs(dst_dir)
            shutil.copy2(src, dst)

            shutil.copy2(os.path.join(gcc_path, 'NOTICE'),
                         os.path.join(install_dir, 'NOTICE'))

        archive_name = os.path.join('gcclibs-' + arch)
        build_support.make_package(archive_name, install_dir, dist_dir)
def package_gcc(package_dir, host_tag, arch, version):
    toolchain_name = build_support.arch_to_toolchain(arch) + '-' + version
    prebuilt_path = get_gcc_prebuilt_path(host_tag)

    package_name = 'gcc-{}-{}.zip'.format(arch, host_tag)
    package_path = os.path.join(package_dir, package_name)
    if os.path.exists(package_path):
        os.unlink(package_path)
    os.chdir(prebuilt_path)
    subprocess.check_call(['zip', '-9qr', package_path, toolchain_name])
def package_gcc(package_dir, host_tag, arch, version):
    toolchain_name = build_support.arch_to_toolchain(arch) + '-' + version
    prebuilt_path = get_gcc_prebuilt_path(host_tag)

    package_name = 'gcc-{}-{}.zip'.format(arch, host_tag)
    package_path = os.path.join(package_dir, package_name)
    if os.path.exists(package_path):
        os.unlink(package_path)
    os.chdir(prebuilt_path)
    subprocess.check_call(
        ['zip', '-9qr', package_path, toolchain_name])
Exemple #5
0
def main(args):
    GCC_VERSION = '4.9'

    arches = build_support.ALL_ARCHITECTURES
    if args.arch is not None:
        arches = [args.arch]

    toolchains = sorted(
        set([build_support.arch_to_toolchain(arch) for arch in arches]))
    host_tag = build_support.host_to_tag(args.host)
    for toolchain in toolchains:
        package_gcc(args.dist_dir, host_tag, toolchain, GCC_VERSION)
def main(args):
    GCC_VERSION = '4.9'

    arches = build_support.ALL_ARCHITECTURES
    if args.arch is not None:
        arches = [args.arch]

    print('Building gdbservers: {}'.format(' '.join(arches)))
    for arch in arches:
        toolchain = build_support.arch_to_toolchain(arch)
        toolchain_name = '-'.join([toolchain, GCC_VERSION])
        build_cmd = [
            'bash', 'build-gdbserver.sh', build_support.toolchain_path(),
            build_support.ndk_path(), toolchain_name, build_support.jobs_arg(),
        ]

        build_support.build(build_cmd, args)
Exemple #7
0
def make_standalone_toolchain(arch, platform, toolchain, install_dir):
    ndk_dir = os.environ['NDK']
    make_standalone_toolchain_path = os.path.join(
        ndk_dir, 'build/tools/make-standalone-toolchain.sh')

    cmd = [make_standalone_toolchain_path, '--install-dir=' + install_dir]

    if arch is not None:
        cmd.append('--arch=' + arch)
    if platform is not None:
        cmd.append('--platform=' + platform)

    if toolchain is not None:
        toolchain_triple = build_support.arch_to_toolchain(arch)
        name = '{}-{}'.format(toolchain_triple, toolchain)
        cmd.append('--toolchain=' + name)

    subprocess.check_call(cmd)
Exemple #8
0
def main(args):
    GCC_VERSION = '4.9'

    arches = build_support.ALL_ARCHITECTURES
    if args.arch is not None:
        arches = [args.arch]

    print('Building gdbservers: {}'.format(' '.join(arches)))
    for arch in arches:
        toolchain = build_support.arch_to_toolchain(arch)
        toolchain_name = '-'.join([toolchain, GCC_VERSION])
        build_cmd = [
            'bash',
            'build-gdbserver.sh',
            build_support.toolchain_path(),
            build_support.ndk_path(),
            toolchain_name,
            build_support.jobs_arg(),
        ]

        build_support.build(build_cmd, args)
Exemple #9
0
def expand_packages(package, host, arches):
    """Expands package definition tuple into list of full package names.

    >>> expand_packages('gcc-{arch}-{host}', 'linux', ['arm64', 'x86_64'])
    ['gcc-arm64-linux-x86_64', 'gcc-x86_64-linux-x86_64']

    >>> expand_packages('gcclibs-{arch}', 'linux', ['arm64', 'x86_64'])
    ['gcclibs-arm64', 'gcclibs-x86_64']

    >>> expand_packages('llvm-{host}', 'linux', ['arm'])
    ['llvm-linux-x86_64']

    >>> expand_packages('platforms', 'linux', ['arm'])
    ['platforms']

    >>> expand_packages('libc++-{abi}', 'linux', ['arm'])
    ['libc++-armeabi', 'libc++-armeabi-v7a']

    >>> expand_packages('binutils/{triple}', 'linux', ['arm', 'x86_64'])
    ['binutils/arm-linux-androideabi', 'binutils/x86_64-linux-android']

    >> expand_packages('toolchains/{toolchain}-4.9', 'linux', ['arm', 'x86'])
    ['toolchains/arm-linux-androideabi-4.9', 'toolchains/x86-4.9']
    """
    host_tag = build_support.host_to_tag(host)
    seen_packages = set()
    packages = []
    for arch in arches:
        triple = build_support.arch_to_triple(arch)
        toolchain = build_support.arch_to_toolchain(arch)
        for abi in build_support.arch_to_abis(arch):
            expanded = package.format(abi=abi,
                                      arch=arch,
                                      host=host_tag,
                                      triple=triple,
                                      toolchain=toolchain)
            if expanded not in seen_packages:
                packages.append(expanded)
            seen_packages.add(expanded)
    return packages
Exemple #10
0
def make_standalone_toolchain(arch, platform, toolchain, install_dir):
    ndk_dir = os.environ['NDK']
    make_standalone_toolchain_path = os.path.join(
        ndk_dir, 'build/instruments/make-standalone-toolchain.sh')

    cmd = [make_standalone_toolchain_path, '--install-dir=' + install_dir]

    if arch is not None:
        cmd.append('--arch=' + arch)
    if platform is not None:
        cmd.append('--platform=' + platform)

    if toolchain is not None:
        toolchain_triple = build_support.arch_to_toolchain(arch)
        name = '{}-{}'.format(toolchain_triple, toolchain)
        cmd.append('--toolchain=' + name)

    proc = subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT)
    out, _ = proc.communicate()
    return proc.returncode == 0, out
Exemple #11
0
def expand_packages(package, host, arches):
    """Expands package definition tuple into list of full package names.

    >>> expand_packages('gcc-{arch}-{host}', 'linux', ['arm64', 'x86_64'])
    ['gcc-arm64-linux-x86_64', 'gcc-x86_64-linux-x86_64']

    >>> expand_packages('gcclibs-{arch}', 'linux', ['arm64', 'x86_64'])
    ['gcclibs-arm64', 'gcclibs-x86_64']

    >>> expand_packages('llvm-{host}', 'linux', ['arm'])
    ['llvm-linux-x86_64']

    >>> expand_packages('platforms', 'linux', ['arm'])
    ['platforms']

    >>> expand_packages('libc++-{abi}', 'linux', ['arm'])
    ['libc++-armeabi', 'libc++-armeabi-v7a', 'libc++-armeabi-v7a-hard']

    >>> expand_packages('binutils/{triple}', 'linux', ['arm', 'x86_64'])
    ['binutils/arm-linux-androideabi', 'binutils/x86_64-linux-android']

    >> expand_packages('toolchains/{toolchain}-4.9', 'linux', ['arm', 'x86'])
    ['toolchains/arm-linux-androideabi-4.9', 'toolchains/x86-4.9']
    """
    host_tag = build_support.host_to_tag(host)
    seen_packages = set()
    packages = []
    for arch in arches:
        triple = build_support.arch_to_triple(arch)
        toolchain = build_support.arch_to_toolchain(arch)
        for abi in build_support.arch_to_abis(arch):
            expanded = package.format(
                abi=abi, arch=arch, host=host_tag, triple=triple,
                toolchain=toolchain)
            if expanded not in seen_packages:
                packages.append(expanded)
            seen_packages.add(expanded)
    return packages
def build_binutils(out_dir, dist_dir, args):
    print('Extracting binutils package from GCC...')

    arches = build_support.ALL_ARCHITECTURES
    if args.arch is not None:
        arches = [args.arch]

    host_tag = build_support.host_to_tag(args.system)

    for arch in arches:
        toolchain = build_support.arch_to_toolchain(arch)
        toolchain_path = get_prebuilt_gcc(args.system, arch)

        triple = fixup_toolchain_triple(toolchain)

        install_dir = os.path.join(out_dir, 'binutils', triple)
        if os.path.exists(install_dir):
            shutil.rmtree(install_dir)
        os.makedirs(install_dir)

        has_gold = True
        if host_tag == 'windows':
            # Note: 64-bit Windows is fine.
            has_gold = False
        if arch in ('mips', 'mips64'):
            has_gold = False

        is_windows = host_tag.startswith('windows')
        for file_name in get_binutils_files(triple, has_gold, is_windows):
            install_file(file_name, toolchain_path, install_dir)

        license_path = build_support.android_path(
            'toolchain/binutils/binutils-2.25/COPYING')
        shutil.copy2(license_path, os.path.join(install_dir, 'NOTICE'))

        pack_binutils(arch, host_tag, dist_dir, install_dir)