From b73fad38425cd52008d830f7207f81873415e1a5 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Wed, 31 Aug 2016 12:01:28 -0700 Subject: Avoid using 'which' for verifying prereqs (#6994) * Use hash instead of which in build.sh * Use hash instead of which in init-tools.sh. * Use hash instead of which in gen-buildsys-clang.sh. --- src/pal/tools/gen-buildsys-clang.sh | 92 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 45 deletions(-) (limited to 'src/pal/tools/gen-buildsys-clang.sh') diff --git a/src/pal/tools/gen-buildsys-clang.sh b/src/pal/tools/gen-buildsys-clang.sh index b7945f3091..9871d7c033 100755 --- a/src/pal/tools/gen-buildsys-clang.sh +++ b/src/pal/tools/gen-buildsys-clang.sh @@ -3,35 +3,31 @@ # This file invokes cmake and generates the build system for Clang. # -if [ $# -lt 4 -o $# -gt 8 ] -then - echo "Usage..." - echo "gen-buildsys-clang.sh [build flavor] [coverage] [ninja] [cmakeargs]" - echo "Specify the path to the top level CMake file - /src/NDP" - echo "Specify the clang version to use, split into major and minor version" - echo "Specify the target architecture." - echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG." - echo "Optionally specify 'coverage' to enable code coverage build." - echo "Target ninja instead of make. ninja must be on the PATH." - echo "Pass additional arguments to CMake call." - exit 1 +if [ $# -lt 4 -o $# -gt 8 ]; then + echo "Usage..." + echo "gen-buildsys-clang.sh [build flavor] [coverage] [ninja] [cmakeargs]" + echo "Specify the path to the top level CMake file - /src/NDP" + echo "Specify the clang version to use, split into major and minor version" + echo "Specify the target architecture." + echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG." + echo "Optionally specify 'coverage' to enable code coverage build." + echo "Target ninja instead of make. ninja must be on the PATH." + echo "Pass additional arguments to CMake call." + exit 1 fi # Set up the environment to be used for building with clang. -if which "clang-$2.$3" > /dev/null 2>&1 - then - export CC="$(which clang-$2.$3)" - export CXX="$(which clang++-$2.$3)" -elif which "clang$2$3" > /dev/null 2>&1 - then - export CC="$(which clang$2$3)" - export CXX="$(which clang++$2$3)" -elif which clang > /dev/null 2>&1 - then - export CC="$(which clang)" - export CXX="$(which clang++)" +if hash "clang-$2.$3" 2>/dev/null; then + export CC="clang-$2.$3" + export CXX="clang++-$2.$3" +elif hash "clang$2$3" 2>/dev/null; then + export CC="clang$2$3" + export CXX="clang++$2$3" +elif hash clang 2>/dev/null; then + export CC="clang" + export CXX="clang++" else - echo "Unable to find Clang Compiler" + echo "Unable to find Clang compiler" exit 1 fi @@ -68,19 +64,22 @@ done OS=`uname` # Locate llvm -# This can be a little complicated, because the common use-case of Ubuntu with +# +# This can be a little complicated, because the common use case of Ubuntu with # llvm-3.5 installed uses a rather unusual llvm installation with the version -# number postfixed (i.e. llvm-ar-3.5), so we check for that first. -# On FreeBSD the version number is appended without point and dash (i.e. -# llvm-ar35). -# Additionally, OSX doesn't use the llvm- prefix. +# number postfixed (e.g. llvm-ar-3.5), so we check for that first. +# +# On FreeBSD, the version number is appended to the name without the dot and +# the dash (e.g. llvm-ar35). +# +# OS X doesn't use the llvm- prefix. if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" -o $OS = "SunOS" ]; then - llvm_prefix="llvm-" + llvm_prefix="llvm-" elif [ $OS = "Darwin" ]; then - llvm_prefix="" + llvm_prefix="" else - echo "Unable to determine build platform" - exit 1 + echo "Unable to determine build platform" + exit 1 fi desired_llvm_major_version=$2 @@ -94,26 +93,29 @@ elif [ $OS = "NetBSD" ]; then elif [ $OS = "SunOS" ]; then desired_llvm_version="" else - desired_llvm_version="-$desired_llvm_major_version.$desired_llvm_minor_version" + desired_llvm_version="-$desired_llvm_major_version.$desired_llvm_minor_version" fi -locate_llvm_exec() { - if which "$llvm_prefix$1$desired_llvm_version" > /dev/null 2>&1 - then - echo "$(which $llvm_prefix$1$desired_llvm_version)" - elif which "$llvm_prefix$1" > /dev/null 2>&1 - then - echo "$(which $llvm_prefix$1)" - else - exit 1 - fi + +locate_llvm_exec() +{ + if hash "$llvm_prefix$1$desired_llvm_version" 2>/dev/null; then + echo "$(command -v $llvm_prefix$1$desired_llvm_version)" + elif hash "$llvm_prefix$1" 2>/dev/null; then + echo "$(command -v $llvm_prefix$1)" + else + exit 1 + fi } llvm_ar="$(locate_llvm_exec ar)" [[ $? -eq 0 ]] || { echo "Unable to locate llvm-ar"; exit 1; } + llvm_link="$(locate_llvm_exec link)" [[ $? -eq 0 ]] || { echo "Unable to locate llvm-link"; exit 1; } + llvm_nm="$(locate_llvm_exec nm)" [[ $? -eq 0 ]] || { echo "Unable to locate llvm-nm"; exit 1; } + if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" -o $OS = "SunOS" ]; then llvm_objdump="$(locate_llvm_exec objdump)" [[ $? -eq 0 ]] || { echo "Unable to locate llvm-objdump"; exit 1; } -- cgit v1.2.3