Skip to content

Commit

Permalink
Improve realpath function and detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zrhoffman committed May 30, 2024
1 parent 17b71e3 commit a30432f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions build/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
#
# shellcheck shell=ash

if ! type -p realpath; then
# macOS's version of realpath does not resolve symlinks, so we add a function
# for it.
if ! realpath -e . >/dev/null 2>&1; then
# by default, macOS does not have realpath
realpath() {
local path="$1"
shift
ls "$(
cd "$(dirname "$0")"
cd "$(dirname "$path")"
pwd -P # -P resolves symlinks
)/$(basename "$0")"
)/$(basename "$path")"
}
export -f realpath
fi;
Expand Down
11 changes: 7 additions & 4 deletions pkg
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# macOS does not come with realpath, so we add a function for it.
if ! type -p realpath; then
# macOS's version of realpath does not resolve symlinks, so we add a function
# for it.
if ! realpath -e . >/dev/null 2>&1; then
# by default, macOS does not have realpath
realpath() {
local path="$1"
shift
ls "$(
cd "$(dirname "$0")"
cd "$(dirname "$path")"
pwd -P # -P resolves symlinks
)/$(basename "$0")"
)/$(basename "$path")"
}
export -f realpath
fi;
Expand Down

0 comments on commit a30432f

Please sign in to comment.