commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
4k stars 843 forks source link

Having relative paths on $PATH breaks stack (with system-ghc) #5033

Open valpackett opened 5 years ago

valpackett commented 5 years ago

Steps to reproduce

With a relative path in $PATH (e.g. for this trick)

% echo $PATH
.git/safe/../../bin:/home/greg/.local/bin:/bin:/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin

try to build something with system GHC.

Expected

Should work :)

Actual

InvalidAbsFile "/path/to/current/dir/.git/safe/../../bin/ghc-8.6.5"

Stack version

% stack --version
Version 2.1.3.1 aarch64

Method of installation

dbaynard commented 5 years ago

Hi, thanks for reporting. Would you provide the --verbose log, please.

The error comes from path, but there are a number of places in the stack codebase where it might occur. The log would help identify what's going on. Thanks!

valpackett commented 5 years ago

There's not that much stuff…

2019-09-23 23:51:27.347922: [debug] Checking for project config at: /usr/home/greg/src/github.com/myfreeweb/microformats2-parser/stack.yaml
2019-09-23 23:51:27.348923: [debug] Loading project config file stack.yaml
2019-09-23 23:51:27.369298: [debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-09-22 20:51:27.368436142 UTC]
2019-09-23 23:51:27.376880: [debug] Using package location completions from a lock file
2019-09-23 23:51:27.904727: [debug] Parsing cabal file for wai-cli (from Hackage)
2019-09-23 23:51:27.916225: [debug] Asking for a supported GHC version
2019-09-23 23:51:27.916393: [debug] Getting system compiler version
2019-09-23 23:51:27.918400: [error] InvalidAbsFile "/usr/home/greg/src/github.com/myfreeweb/microformats2-parser/.git/safe/../../bin/ghc-8.6.5"
dbaynard commented 5 years ago

https://github.com/commercialhaskell/stack/blob/06cda686573cb8615f5f78f845a781fdb55a53d3/src/Stack/Setup.hs#L640-L647

dbaynard commented 5 years ago

Yeah, this is it.

https://github.com/commercialhaskell/stack/blob/06cda686573cb8615f5f78f845a781fdb55a53d3/src/Stack/Setup.hs#L1056

Calls out to this:

https://github.com/mrkkrp/path-io/blob/7260ada0b313b2c4778936c3f3563451dedd314c/Path/IO.hs#L980-L984

resolveFile :: MonadIO m
  => Path Abs Dir      -- ^ Base directory
  -> FilePath          -- ^ Path to resolve
  -> m (Path Abs File)
resolveFile b p = liftIO $ D.canonicalizePath (toFilePath b F.</> p) >>= parseAbsFile

It seems canonicalizePath doesn't handle internal ...

Since some indirections (symbolic links on all systems, .. on non-Windows systems, and junction points on Windows) are dependent on the state of the existing filesystem, the function can only make a conservative attempt by removing such indirections from the longest prefix of the path that still points to an existing file or directory.

I think this is possibly an issue with path-io — I recommend you open an issue there and see what they think.