Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Use POSIX "command" instead of non-standard "which" #8823

Merged
merged 1 commit into from Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 3 additions & 15 deletions build.sh
Expand Up @@ -2,24 +2,16 @@

# resolve python-version to use
if [ "$PYTHON" == "" ] ; then
if which python >/dev/null 2>&1
if ! PYTHON=$(command -v python || command -v python2 || command -v python 2.7)
then
PYTHON=python
elif which python2 >/dev/null 2>&1
then
PYTHON=python2
elif which python2.7 >/dev/null 2>&1
then
PYTHON=python2.7
else
echo "Unable to locate build-dependency python2.x!" 1>&2
exit 1
fi
fi

# validate python-dependency
# useful in case of explicitly set option.
if ! which $PYTHON > /dev/null 2>&1
if ! command -v $PYTHON > /dev/null
then
echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
exit 1
Expand Down Expand Up @@ -196,11 +188,7 @@ build_native()
if [ $__UseNinja == 1 ]; then
generator="ninja"
buildFile="build.ninja"
if which ninja >/dev/null 2>&1; then
buildTool="ninja"
elif which ninja-build >/dev/null 2>&1; then
buildTool="ninja-build"
else
if ! buildTool=$(command -v ninja || command -v ninja-build); then
echo "Unable to locate ninja!" 1>&2
exit 1
fi
Expand Down
3 changes: 1 addition & 2 deletions init-tools.sh
Expand Up @@ -110,8 +110,7 @@ if [ ! -e $__INIT_TOOLS_DONE_MARKER ]; then
__DOTNET_LOCATION="https://dotnetcli.blob.core.windows.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz"
# curl has HTTPS CA trust-issues less often than wget, so lets try that first.
echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'" >> $__init_tools_log
which curl > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
if command -v curl > /dev/null; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks backwards to me, and the official builds seem to have tried to use wget when the machine should use curl.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, Sorry:I just wanted to cleanup non-idiomatic shell-code while doing the which->curl change. I will never merge multiple changes in one commit again
😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I can see how easy it would be to mix up those changes. It will be nice to have the more idiomatic/straight forward approach from now on.

wget -q -O $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
else
curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
Expand Down
8 changes: 4 additions & 4 deletions src/corefx/format-code.sh
Expand Up @@ -2,10 +2,10 @@

# OS X names clang-format as clang-format; Ubuntu uses
# clang-format-version so check for the right one
if which "clang-format-3.6" > /dev/null 2>&1 ; then
export CF="$(which clang-format-3.6)"
elif which "clang-format" > /dev/null 2>&1 ; then
export CF="$(which clang-format)"
if command -v "clang-format-3.6" > /dev/null; then
export CF="$(command -v clang-format-3.6)"
elif command -v "clang-format" > /dev/null; then
export CF="$(command -v clang-format)"
else
echo "Unable to find clang-format"
exit 1
Expand Down
26 changes: 13 additions & 13 deletions src/pal/tools/gen-buildsys-clang.sh
Expand Up @@ -18,18 +18,18 @@ then
fi

# Set up the environment to be used for building with clang.
if which "clang-$2.$3" > /dev/null 2>&1
if command -v "clang-$2.$3" > /dev/null
then
export CC="$(which clang-$2.$3)"
export CXX="$(which clang++-$2.$3)"
elif which "clang$2$3" > /dev/null 2>&1
export CC="$(command -v clang-$2.$3)"
export CXX="$(command -v clang++-$2.$3)"
elif command -v "clang$2$3" > /dev/null
then
export CC="$(which clang$2$3)"
export CXX="$(which clang++$2$3)"
elif which clang > /dev/null 2>&1
export CC="$(command -v clang$2$3)"
export CXX="$(command -v clang++$2$3)"
elif command -v clang > /dev/null
then
export CC="$(which clang)"
export CXX="$(which clang++)"
export CC="$(command -v clang)"
export CXX="$(command -v clang++)"
else
echo "Unable to find Clang Compiler"
exit 1
Expand Down Expand Up @@ -97,12 +97,12 @@ else
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
if command -v "$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
echo "$(command -v $llvm_prefix$1$desired_llvm_version)"
elif command -v "$llvm_prefix$1" > /dev/null 2>&1
then
echo "$(which $llvm_prefix$1)"
echo "$(command -v $llvm_prefix$1)"
else
exit 1
fi
Expand Down