Description
Running a script via a relative path works fine unless you use the --compile
or --optimize
options.
Steps to reproduce
mkdir blah
vim blah/Blah.hs
and paste in the contents belowchmod +x blah/Blah.hs
- Run it:
./blah/Blah.hs
#!/usr/bin/env stack
-- stack script --resolver lts-9.1 --compile
main = putStrLn "blah"
Expected
It runs and outputs blah
Actual
The following error occurs and the program doesn't run:
Running /home/whatever/.stack/programs/x86_64-linux/ghc-8.0.2/bin/ghc -hide-all-packages -packagearray -packagebase -packagebinary -packagebytestring -packagecontainers -packagedeepseq -packagedirectory -packagefilepath -packageghc -packageghc-boot -packageghc-boot-th -packageghc-prim -packageghci -packagehoopl -packagehpc -packageinteger-gmp -packagepretty -packageprocess -packagerts -packagetemplate-haskell -packagetime -packagetransformers -packageunix ./blah/Blah.hs in directory /home/whatever/blah/ exited with ExitFailure 1
<no location info>: error: can't find file: blah/Blah.hs
Stack version
$ stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
still seems to exist in
Version 1.5.1, Git revision 7b4b10bf001ac36f700b54923da05e3d44af892d (5121 commits) x86_64 hpack-0.18.1
Method of installation
- Official binary, downloaded from stackage.org or fpcomplete's package repository
It does actually work fine if you use an absolute path, like /home/whatever/blah/Blah.hs
.
Just based on the output and testing, it appears that doing something like figuring out the directory, changing to it, and then using the name of the executable as you specified it to tell GHC what to compile. Which works fine if it's in the same directory, or if you refer to it via an absolute path that will always be valid, or if it's in your $PATH
and you just call it via Blah.hs
, but fails in this case.
It works fine if you don't specify --compile
or --optimize
by the way.