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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Major changes:
Behavior changes:
* `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256)

* `stack script` now passes `-i -idir` in to the `ghc`
invocation. This makes it so that the script can import local
modules, and fixes an issue where `.hs` files in the current
directory could affect interpretation of the script. See
[#4538](https://github.com/commercialhaskell/stack/pull/4538)

Other enhancements:

* Defer loading up of files for local packages. This allows us to get
Expand Down
11 changes: 6 additions & 5 deletions src/Stack/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ import qualified RIO.Text as T
scriptCmd :: ScriptOpts -> GlobalOpts -> IO ()
scriptCmd opts go' = do
file <- resolveFile' $ soFile opts
let go = go'
let scriptDir = parent file
go = go'
{ globalConfigMonoid = (globalConfigMonoid go')
{ configMonoidInstallGHC = First $ Just True
}
, globalStackYaml = SYLNoConfig $ parent file
, globalStackYaml = SYLNoConfig scriptDir
}
withDefaultBuildConfigAndLock go $ \lk -> do
-- Some warnings in case the user somehow tries to set a
Expand Down Expand Up @@ -92,7 +93,8 @@ scriptCmd opts go' = do
withNewLocalBuildTargets targets $ Stack.Build.build Nothing lk

let ghcArgs = concat
[ ["-hide-all-packages"]
[ ["-i", "-i" ++ toFilePath scriptDir]
, ["-hide-all-packages"]
, maybeToList colorFlag
, map (\x -> "-package" ++ x)
$ Set.toList
Expand All @@ -109,13 +111,12 @@ scriptCmd opts go' = do
SEInterpret -> exec ("run" ++ compilerExeName wc)
(ghcArgs ++ toFilePath file : soArgs opts)
_ -> do
let dir = parent file
-- Use readProcessStdout_ so that (1) if GHC does send any output
-- to stdout, we capture it and stop it from being sent to our
-- stdout, which could break scripts, and (2) if there's an
-- exception, the standard output we did capture will be reported
-- to the user.
withWorkingDir (toFilePath dir) $ proc
withWorkingDir (toFilePath scriptDir) $ proc
(compilerExeName wc)
(ghcArgs ++ [toFilePath file])
(void . readProcessStdout_)
Expand Down