haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 691 forks source link

Cabal new-build fails to create proper binary symlink #6024

Open wdanilo opened 5 years ago

wdanilo commented 5 years ago

Hi! I'm using the newest Cabal (2.4.1.0). I'm compiling GHCJS and I'm evaluating the following command:

cabal new-install . --symlink-bindir="$HOME/.cabal/bin"

Everything compiles successfully and I've got information about successful creation of symlinks, however, they are incorrect. Namely, the links point this way: /home/wdanilo/.cabal/bin/ghcjs-boot -> /home/wdanilo/.cabal/store/ghc-8.6.3/ghcjs-8.6.0.1-d9ee78562faccca853a9ec3e2136194f9bd5d3c94c4ef5725fcebd7edfda1f61/bin/ghcjs-boot -> /home/wdanilo/.cabal/store/ghc-8.6.3/ghcjs-8.6.0.1-d9ee78562faccca853a9ec3e2136194f9bd5d3c94c4ef5725fcebd7edfda1f61/bin/ghcjs-boot-8.6.0.1-8.6.2 -> /home/wdanilo/.cabal/store/ghc-8.6.3/incoming/new-24223/home/wdanilo/.cabal/store/ghc-8.6.3/ghcjs-8.6.0.1-d9ee78562faccca853a9ec3e2136194f9bd5d3c94c4ef5725fcebd7edfda1f61/libexec/ghcjs-boot

As you can see, the last path is incorrect. It contains /home/wdanilo inside and it resolves wrong.

23Skidoo commented 5 years ago

/cc @luite

23Skidoo commented 5 years ago

@wdanilo So where do you expect the last symlink to point to?

luite commented 5 years ago

I also ran into this, but haven't had much time to investigate yet.

I think this is not related to the GHCJS flavour since it's just installing the compiler, rather than using it.

The executables in the ghcjs package are private and the Setup.hs script creates the symlinks. Most of the executables are versioned: They script should create a symlink like ghcjs-pkg-8.6.0.1-8.6.5 in addition to ghcjs-pkg.

Looks like this is now broken with new-build

blackgnezdo commented 4 years ago

Another manifestation can be seen with ~/bin itself being a symlink.

lrwxrwxrwx 1 greg greg 13 Jul  8  2018 /home/greg/bin -> dot-files/bin

The symlink gets created with

% ~/bin/cabal --version
cabal-install version 3.0.0.0
compiled using version 3.0.0.0 of the Cabal library 
% ~/bin/cabal v2-install --installdir=$HOME/bin/ --overwrite-policy=always

The resulting symlink looks like this:

lrwxrwxrwx 1 greg greg 116 Nov 11 12:14 ormolu -> ../.cabal/store/ghc-8.6.3/ormolu-0.0.1.0-f2e7fe425fd15d4d71f0a2d89f6343ce5cc829b1314099327fce467751d82c91/bin/ormolu

The symlink is likely computed using ~/bin as the "basis" for relative addressing by cabal, but the symlinks are resolved by the OS that uses the real .. parent directory pointers in the filesystem. The created symlink happens to be one .. off in my case:

ls: cannot access '../.cabal/store/ghc-8.6.3/ormolu-0.0.1.0-f2e7fe425fd15d4d71f0a2d89f6343ce5cc829b1314099327fce467751d82c91/bin/ormolu': No such file or directory
-rwxr-xr-x 1 greg greg 59810560 Nov 11 12:13 ../../.cabal/store/ghc-8.6.3/ormolu-0.0.1.0-f2e7fe425fd15d4d71f0a2d89f6343ce5cc829b1314099327fce467751d82c91/bin/ormolu

A fix would be to do an explicit check of the generated relative symlink and if the path fails to work, fallback to absolute pathname as the symlink destination.