From 38e325f25aa1d3432691218cf00a60c3c1d81e8a Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 8 Aug 2018 16:20:42 -0700 Subject: Install "GCC" wrappers that call Clang. These are provided to ease porting to new NDKs for projects that are not actually sensitive to changes in compiler, just changes to compiler install path. Test: ./checkbuild.py && path/to/arm-linux-androideabi-gcc --help Bug: https://github.com/android-ndk/ndk/issues/758 Change-Id: I8becbf764c37800b5670f412f63302c638252674 --- checkbuild.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'checkbuild.py') diff --git a/checkbuild.py b/checkbuild.py index de059e42f..6a4d0aebb 100755 --- a/checkbuild.py +++ b/checkbuild.py @@ -37,6 +37,7 @@ import os import re import shutil import site +import stat import subprocess import sys import tempfile @@ -458,6 +459,7 @@ class Binutils(ndk.builds.Module): install_path = self.get_install_path(out_dir, host, arch) toolchain_path = get_binutils_prebuilt_path(host, arch) ndk.builds.install_directory(toolchain_path, install_path) + self.install_mock_gcc(out_dir, install_path, host, arch) # We still need libgcc/libatomic. Copy them from the old GCC prebuilts. for subarch in get_subarches(arch): @@ -507,6 +509,62 @@ class Binutils(ndk.builds.Module): libwinpthread = os.path.join(clang_bin, 'libwinpthread-1.dll') shutil.copy2(libwinpthread, bfd_plugins) + def install_mock_gcc(self, out_dir, install_path, host, arch): + """Installs gcc scripts that invoke clang. + + These are provided to ease porting to new NDKs for projects that are + not actually sensitive to changes in compiler, just changes to compiler + install path. + """ + is_win = host.startswith('windows') + exe = '.exe' if is_win else '' + cmd = '.cmd' if is_win else '' + clang_install_path = os.path.relpath( + Clang().get_install_path(out_dir, host, arch), + os.path.join(install_path, 'bin')) + + shortcuts = {'gcc': 'clang', 'g++': 'clang++'} + for src, dst in shortcuts.items(): + triple = ndk.abis.arch_to_triple(arch) + gcc = os.path.join(install_path, 'bin', triple + '-' + src + cmd) + clang = os.path.join(clang_install_path, 'bin', dst + exe) + if is_win: + self.install_cmd_clang_shortcut(gcc, clang, triple) + else: + self.install_sh_clang_shortcut(gcc, clang, triple) + + def install_cmd_clang_shortcut(self, gcc, clang, triple): + clang = clang.replace('/', '\\') + with open(gcc, 'w') as gcc_script: + gcc_script.write( + textwrap.dedent("""\ + @echo off + setlocal + call :find_bin + + set "_BIN_DIR=" && %_BIN_DIR%{clang} -target {triple} %* + if ERRORLEVEL 1 exit /b 1 + goto :done + + :find_bin + rem Accommodate a quoted arg0, e.g.: "clang" + rem https://github.com/android-ndk/ndk/issues/616 + set _BIN_DIR=%~dp0 + exit /b + + :done + """.format(clang=clang, triple=triple))) + + def install_sh_clang_shortcut(self, gcc, clang, triple): + with open(gcc, 'w') as gcc_script: + gcc_script.write( + textwrap.dedent("""\ + #!/bin/bash + exec `dirname $0`/{clang} -target {triple} "$@" + """.format(clang=clang, triple=triple))) + mode = os.stat(gcc).st_mode + os.chmod(gcc, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + class ShaderTools(ndk.builds.InvokeBuildModule): name = 'shader-tools' -- cgit v1.2.3