New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`stack script --compile` errors when executing via relative path #3372

Closed
kadoban opened this Issue Aug 22, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@kadoban
Collaborator

kadoban commented Aug 22, 2017

Running a script via a relative path works fine unless you use the --compile or --optimize options.

Steps to reproduce

  1. mkdir blah
  2. vim blah/Blah.hs and paste in the contents below
  3. chmod +x blah/Blah.hs
  4. 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.

mgsloan added a commit that referenced this issue Aug 22, 2017

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Aug 22, 2017

@kadoban Thanks for the report! Pushed a fix to master. Simple fix, just need to provide the absolute path to the source file to ghc / runghc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment