ghci wrapper generated by Hadrian doesn't work via symlink
Summary
ghci wrapper script generated by Hadrian doesn't work if it is called via a symbolic link in a different directory.
Steps to reproduce
On a Mac with ghcup,
$ ghcup install ghc 9.2.1
$ ghcup unset ghc
$ ~/.ghcup/bin/ghci-9.2.1
Then I get
/Users/aratamizuki/.ghcup/bin/ghci-9.2.1: line 12: /Users/aratamizuki/.ghcup/bin/ghc: No such file or directory
/Users/aratamizuki/.ghcup/bin/ghci-9.2.1: line 12: exec: /Users/aratamizuki/.ghcup/bin/ghc: cannot execute: No such file or directory
The situation is,
-
~/.ghcup/bin/ghci-9.2.1
is a symlink to~/.ghcup/ghc/9.2.1/bin/ghci
-
~/.ghcup/ghc/9.2.1/bin/ghci
is a symlink to~/.ghcup/ghc/9.2.1/bin/ghci-9.2.1
-
~/.ghcup/ghc/9.2.1/bin/ghci-9.2.1
contains:
#!/bin/sh
exedir="/Users/aratamizuki/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/bin"
exeprog="ghci-9.2.1"
executablename="/Users/aratamizuki/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/bin/ghci-9.2.1"
bindir="/Users/aratamizuki/.ghcup/ghc/9.2.1/bin"
libdir="/Users/aratamizuki/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/lib"
docdir="/Users/aratamizuki/.ghcup/ghc/9.2.1/share/doc/ghc-9.2.1"
includedir="/Users/aratamizuki/.ghcup/ghc/9.2.1/include"
DIR=`dirname "$0"`
executable="$DIR/ghc"
exec $executable --interactive "$@"
Here, $DIR
becomes the directory of the symlink (~/.ghcup/bin
), not the wrapper script (~/.ghcup/ghc/9.2.1/bin
).
It should probably use $bindir
instead of `dirname $0`
.
Expected behavior
GHCi should start.
Environment
- GHC version used: GHC 9.2.1
- Operating System: macOS 11
- System Architecture: x86_64 or arm64