Skip to content
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

Have "stack script" set import search path #3377 #4538

Merged
merged 1 commit into from
Jan 26, 2019

Conversation

mgsloan
Copy link
Contributor

@mgsloan mgsloan commented Jan 25, 2019

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
  • The documentation has been updated, if necessary.

This issue was brought to my attention by https://github.com/rcook . The primary problem is that stack scripts can only import modules if the script is run from the same directory as the modules. However, I realized that this implies a gnarlier issue, which is that since -i isn't being passed to runghc, it will use the work dir as a search dir for imports.

This also addresses part of the problem described in #3377 , which was a difference in how imports are treated when --compile is used.

Here's a concrete example. The contents of ~/tmp/hmm.hs is

#!/usr/bin/env stack
-- stack --resolver lts-13.0 script

import Yargh

main :: IO ()
main = yargh

The contents of ~/tmp/Yargh.hs is

module Yargh where

yargh :: IO ()
yargh = putStrLn "works!"

The contents of ~/Yargh.hs is

module Yargh where

yargh :: IO ()
yargh = putStrLn "YARGH, broken!

Check out what happens when I run the script from different directories:

mgsloan@treetop:~/tmp$ ./hmm.hs                                                                               
works!                                                                                                        
mgsloan@treetop:~/tmp$ cd ../                                                                                 
mgsloan@treetop:~$ ./tmp/hmm.hs                                                                               
YARGH, broken!      

This PR resolves the issue. After applying this patch, it behaves like this:

mgsloan@treetop:~/tmp$ ./hmm.hs                                                                               
works!                                                                                                        
mgsloan@treetop:~/tmp$ cd ../                                                                         
mgsloan@treetop:~$ ./tmp/hmm.hs                                                                               
works!                      

@mgsloan mgsloan force-pushed the stack-script-import-search-path-3377 branch from dac3359 to ec2a139 Compare January 25, 2019 04:58
@rcook
Copy link

rcook commented Jan 26, 2019

Thanks!

@mihaimaruseac mihaimaruseac merged commit 38ee7fe into master Jan 26, 2019
@mihaimaruseac mihaimaruseac deleted the stack-script-import-search-path-3377 branch January 26, 2019 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants