From 4871f8b536c55229f9e8c1e55ab82e4c3d161232 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 22 Apr 2019 15:44:54 -0700 Subject: [PATCH] env-setup.sh: Remove GNU tools in the Docker image before building This will help ensure that the GNU tools aren't hard coded anywhere as the goal of the LLVM tools is to be as compatible as possible. Closes: #122 Signed-off-by: Nathan Chancellor --- env-setup.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/env-setup.sh b/env-setup.sh index 46a6e2b..c997f9d 100755 --- a/env-setup.sh +++ b/env-setup.sh @@ -20,3 +20,32 @@ ccache --set-config=cache_dir=/travis/.ccache # Clear out the stats so we actually know the cache stats ccache -z + +# Ensure that GNU tools are not available when using LLVM tools +function remove() { + mapfile -t files < <(type -ap "${@}") + for file in "${files[@]}"; do rm -vf "${file}"; done +} + +case ${ARCH:=arm64} in + arm32*) CROSS_COMPILE=arm-linux-gnueabi- ;; + arm64) CROSS_COMPILE=aarch64-linux-gnu- ;; + ppc32) CROSS_COMPILE=powerpc-linux-gnu- ;; + ppc64le) CROSS_COMPILE=powerpc64le-linux-gnu- ;; +esac + +# Remove the target's tools +remove "${CROSS_COMPILE:-}"ar +remove "${CROSS_COMPILE:-}"gcc +[[ ${LD:-} =~ ld.lld ]] && remove ${CROSS_COMPILE:-}{ld,ld.bfd,ld.gold} + +# Remove the host tools if we are cross compiling +if [[ -n ${CROSS_COMPILE:-} ]]; then + remove ar + remove gcc + [[ ${LD:-} =~ ld.lld ]] && remove {ld,ld.bfd,ld.gold} +fi + +# Ensure that we always exit cleanly because a bash script's +# exit code is always the code of the last command +exit 0