From a37ec7adfbf0832c08839751f1ce7bbe5de4de05 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 1 Sep 2016 09:15:22 -0700 Subject: [PATCH] Revert "Avoid using 'which' for verifying prereqs" --- build.sh | 18 +++++--- init-tools.sh | 14 +++--- src/pal/tools/gen-buildsys-clang.sh | 92 ++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 61 deletions(-) diff --git a/build.sh b/build.sh index 6ede273..5959abd 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,15 @@ #!/usr/bin/env bash # resolve python-version to use -if [ "$PYTHON" == "" ]; then - if hash python 2>/dev/null; then +if [ "$PYTHON" == "" ] ; then + if which python >/dev/null 2>&1 + then PYTHON=python - elif hash python2 2>/dev/null; then + elif which python2 >/dev/null 2>&1 + then PYTHON=python2 - elif hash python2.7 2>/dev/null; then + elif which python2.7 >/dev/null 2>&1 + then PYTHON=python2.7 else echo "Unable to locate build-dependency python2.x!" 1>&2 @@ -16,7 +19,8 @@ fi # validate python-dependency # useful in case of explicitly set option. -if ! hash $PYTHON 2>/dev/null; then +if ! which $PYTHON > /dev/null 2>&1 +then echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2 exit 1 fi @@ -149,9 +153,9 @@ build_coreclr() if [ $__UseNinja == 1 ]; then generator="ninja" buildFile="build.ninja" - if hash ninja 2>/dev/null; then + if which ninja >/dev/null 2>&1; then buildTool="ninja" - elif hash ninja-build 2>/dev/null; then + elif which ninja-build >/dev/null 2>&1; then buildTool="ninja-build" else echo "Unable to locate ninja!" 1>&2 diff --git a/init-tools.sh b/init-tools.sh index 5b3b702..e6966cc 100755 --- a/init-tools.sh +++ b/init-tools.sh @@ -85,15 +85,15 @@ if [ ! -e $__PROJECT_JSON_FILE ]; then if [ ! -e $__DOTNET_PATH ]; then # curl has HTTPS CA trust-issues less often than wget, so lets try that first. - if hash curl 2>/dev/null; then - curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL - echo "curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL" + which curl > /dev/null 2> /dev/null + if [ $? -ne 0 ]; then + mkdir -p "$__DOTNET_PATH" + wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL + echo "wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL" else - mkdir -p "$__DOTNET_PATH" - wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL - echo "wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL" + curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL + echo "curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL" fi - cd $__DOTNET_PATH tar -xf $__DOTNET_PATH/dotnet.tar if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then diff --git a/src/pal/tools/gen-buildsys-clang.sh b/src/pal/tools/gen-buildsys-clang.sh index 9871d7c..b7945f3 100755 --- a/src/pal/tools/gen-buildsys-clang.sh +++ b/src/pal/tools/gen-buildsys-clang.sh @@ -3,31 +3,35 @@ # 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 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++" +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++)" else - echo "Unable to find Clang compiler" + echo "Unable to find Clang Compiler" exit 1 fi @@ -64,22 +68,19 @@ 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 (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. +# 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. 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 @@ -93,29 +94,26 @@ 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 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 +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 } 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; } -- 2.7.4