From 3d4e36806abb069a9e0087ae95152f0dd9fc45e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 1 Aug 2022 11:48:04 +0300 Subject: [PATCH] Avoid using the nonstandard "which" command This command isn't a standard tool; different distributions have different implementations, and e.g. Fedora doesn't ship it by default. Settle on using "command -v $tool >/dev/null" for tests about whether a tool is available. (We could also use "hash $tool 2>/dev/null" as we already had in build-all.sh, but settling on using "command -v" everywhere, for consistency and simplicity.) --- build-all.sh | 2 +- build-compiler-rt.sh | 2 +- build-libcxx.sh | 2 +- build-libssp.sh | 4 ++-- build-lldb-mi.sh | 2 +- build-llvm.sh | 8 ++++---- build-make.sh | 2 +- build-mingw-w64-tools.sh | 2 +- build-mingw-w64.sh | 2 +- build-openmp.sh | 2 +- build-python.sh | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build-all.sh b/build-all.sh index 9fd308a..5055250 100755 --- a/build-all.sh +++ b/build-all.sh @@ -60,7 +60,7 @@ if [ -z "$PREFIX" ]; then fi for dep in git curl cmake; do - if ! hash $dep 2>/dev/null; then + if ! command -v $dep >/dev/null; then echo "$dep not installed. Please install it and retry" 1>&2 exit 1 fi diff --git a/build-compiler-rt.sh b/build-compiler-rt.sh index 1794d8d..b05ac73 100755 --- a/build-compiler-rt.sh +++ b/build-compiler-rt.sh @@ -47,7 +47,7 @@ if [ ! -d llvm-project/compiler-rt ] || [ -n "$SYNC" ]; then CHECKOUT_ONLY=1 ./build-llvm.sh fi -if [ -n "$(which ninja)" ]; then +if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" NINJA=1 BUILDCMD=ninja diff --git a/build-libcxx.sh b/build-libcxx.sh index 9880379..daebaf0 100755 --- a/build-libcxx.sh +++ b/build-libcxx.sh @@ -55,7 +55,7 @@ LLVM_PATH="$(pwd)/llvm" cd runtimes -if [ -n "$(which ninja)" ]; then +if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" NINJA=1 BUILDCMD=ninja diff --git a/build-libssp.sh b/build-libssp.sh index e991058..9af811c 100755 --- a/build-libssp.sh +++ b/build-libssp.sh @@ -22,7 +22,7 @@ if [ $# -lt 1 ]; then fi MAKE=make -if [ -n "$(which gmake)" ]; then +if command -v gmake >/dev/null; then MAKE=gmake fi @@ -37,7 +37,7 @@ export PATH="$PREFIX/bin:$PATH" : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} download() { - if [ -n "$(which wget)" ]; then + if command -v wget >/dev/null; then if [ -n "$2" ]; then wget -O "$2" "$1" else diff --git a/build-lldb-mi.sh b/build-lldb-mi.sh index df51651..a0e7702 100755 --- a/build-lldb-mi.sh +++ b/build-lldb-mi.sh @@ -51,7 +51,7 @@ if [ -n "$SYNC" ] || [ -n "$CHECKOUT" ]; then cd .. fi -if [ -n "$(which ninja)" ]; then +if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" NINJA=1 BUILDCMD=ninja diff --git a/build-llvm.sh b/build-llvm.sh index 3856957..cca1ea6 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -125,7 +125,7 @@ fi [ -z "$CHECKOUT_ONLY" ] || exit 0 -if [ -n "$(which ninja)" ]; then +if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" NINJA=1 BUILDCMD=ninja @@ -165,8 +165,8 @@ if [ -n "$HOST" ]; then break fi done - if [ -z "$native" ] && [ -n "$(which llvm-tblgen)" ]; then - native="$(dirname $(which llvm-tblgen))" + if [ -z "$native" ] && command -v llvm-tblgen >/dev/null; then + native="$(dirname $(command -v llvm-tblgen))" suffix="" if [ -x "$native/llvm-tblgen.exe" ]; then suffix=".exe" @@ -191,7 +191,7 @@ if [ -n "$HOST" ]; then CMAKEFLAGS="$CMAKEFLAGS -DCLANG_PSEUDO_GEN=$native/clang-pseudo-gen$suffix" fi fi - CROSS_ROOT=$(cd $(dirname $(which $HOST-gcc))/../$HOST && pwd) + CROSS_ROOT=$(cd $(dirname $(command -v $HOST-gcc))/../$HOST && pwd) CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$CROSS_ROOT" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY" diff --git a/build-make.sh b/build-make.sh index f894317..ed16002 100755 --- a/build-make.sh +++ b/build-make.sh @@ -45,7 +45,7 @@ PREFIX="$(cd "$PREFIX" && pwd)" : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} download() { - if [ -n "$(which wget)" ]; then + if command -v wget >/dev/null; then wget "$1" else curl -LO "$1" diff --git a/build-mingw-w64-tools.sh b/build-mingw-w64-tools.sh index 614439a..b6ea7f8 100755 --- a/build-mingw-w64-tools.sh +++ b/build-mingw-w64-tools.sh @@ -49,7 +49,7 @@ fi cd mingw-w64 MAKE=make -if [ -n "$(which gmake)" ]; then +if command -v gmake >/dev/null; then MAKE=gmake fi diff --git a/build-mingw-w64.sh b/build-mingw-w64.sh index 7d7cda0..54786e6 100755 --- a/build-mingw-w64.sh +++ b/build-mingw-w64.sh @@ -62,7 +62,7 @@ fi [ -z "$CHECKOUT_ONLY" ] || exit 0 MAKE=make -if [ -n "$(which gmake)" ]; then +if command -v gmake >/dev/null; then MAKE=gmake fi diff --git a/build-openmp.sh b/build-openmp.sh index f73515a..a10bcb1 100755 --- a/build-openmp.sh +++ b/build-openmp.sh @@ -35,7 +35,7 @@ fi cd llvm-project/openmp -if [ -n "$(which ninja)" ]; then +if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" NINJA=1 BUILDCMD=ninja diff --git a/build-python.sh b/build-python.sh index 7255ecf..a8e8501 100755 --- a/build-python.sh +++ b/build-python.sh @@ -48,7 +48,7 @@ if [ -z "$CHECKOUT_ONLY" ]; then fi MAKE=make -if [ -n "$(which gmake)" ]; then +if command -v gmake >/dev/null; then MAKE=gmake fi