Skip to content

Commit cf2d095

Browse files
committed
Improve zsh compatibility when detecting the current working tree directory.
1 parent a3044bf commit cf2d095

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

tools/macos_buildenv.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
# Ignored in case of a source call, but needed for bash specific sourcing detection
3+
24
set -o pipefail
35

46
# shellcheck disable=SC2091
@@ -15,13 +17,19 @@ realpath() {
1517
cd "${OLDPWD}" || exit 1
1618
}
1719

18-
# some hackery is required to be compatible with both bash and zsh
19-
THIS_SCRIPT_NAME=${BASH_SOURCE[0]}
20-
[ -z "$THIS_SCRIPT_NAME" ] && THIS_SCRIPT_NAME=$0
20+
# Get script file location, compatible with bash and zsh
21+
if [ -n "$BASH_VERSION" ]; then
22+
THIS_SCRIPT_NAME="${BASH_SOURCE[0]}"
23+
elif [ -n "$ZSH_VERSION" ]; then
24+
# shellcheck disable=SC2296
25+
THIS_SCRIPT_NAME="${(%):-%N}"
26+
else
27+
THIS_SCRIPT_NAME="$0"
28+
fi
2129

2230
HOST_ARCH=$(uname -m) # One of x86_64, arm64, i386, ppc or ppc64
2331

24-
if [ "$HOST_ARCH" == "x86_64" ]; then
32+
if [ "$HOST_ARCH" = "x86_64" ]; then
2533
if [ -n "${BUILDENV_ARM64}" ]; then
2634
VCPKG_TARGET_TRIPLET="arm64-osx-min1100-release"
2735
BUILDENV_BRANCH="2.5-rel"

0 commit comments

Comments
 (0)