Skip to content

Commit

Permalink
Have "stack script" set import search path #3377
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Jan 25, 2019
1 parent 570172b commit ec2a139
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
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
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

0 comments on commit ec2a139

Please sign in to comment.