Skip to content

Commit

Permalink
Fix readlink -f on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
aherrmann committed Jul 29, 2020
1 parent cfb0433 commit 232390b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bazel_tools/packaging/package-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
case "$(uname -s)" in
Darwin)
abspath() { python -c 'import os.path, sys; sys.stdout.write(os.path.abspath(sys.argv[1]))' "$@"; }
canonicalpath() { python -c 'import os.path, sys; sys.stdout.write(os.path.realpath(sys.argv[1]))' "$@"; }
;;
*)
abspath() { realpath -s "$@"; }
canonicalpath() { realpath -f "$@"; }
;;
esac

Expand Down Expand Up @@ -67,7 +69,7 @@ OUT=$(abspath $2)
shift 2
NAME=$(basename $SRC)
mkdir -p $WORKDIR/$NAME/lib
export ORIGIN=$(dirname $(readlink -f $SRC)) # for rpaths relative to binary
export ORIGIN=$(dirname $(canonicalpath $SRC)) # for rpaths relative to binary

# Copy in resources, if any.
if [ $# -gt 0 ]; then
Expand Down Expand Up @@ -157,7 +159,7 @@ elif [[ "$(uname -s)" == "Darwin" ]]; then
cp $SRC $WORKDIR/$NAME/$NAME
chmod u+w $WORKDIR/$NAME/$NAME
function copy_deps() {
local from_original=$(readlink -f $1)
local from_original=$(canonicalpath $1)
local from_copied=$2
local needed="$(/usr/bin/otool -L "$from_copied" | sed -n -e '1d' -e 's/^\s*\([^ ]*\).*$/\1/p')"
# Note that it is crucial that we resolve loader_path relative to from_original instead of from_copied
Expand Down

0 comments on commit 232390b

Please sign in to comment.