Skip to content

Commit 38ee7fe

Browse files
Merge pull request #4538 from commercialhaskell/stack-script-import-search-path-3377
Have "stack script" set import search path #3377
2 parents 48f4bef + ec2a139 commit 38ee7fe

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Major changes:
4646
Behavior changes:
4747
* `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256)
4848

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

5157
* Defer loading up of files for local packages. This allows us to get

src/Stack/Script.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ import qualified RIO.Text as T
3535
scriptCmd :: ScriptOpts -> GlobalOpts -> IO ()
3636
scriptCmd opts go' = do
3737
file <- resolveFile' $ soFile opts
38-
let go = go'
38+
let scriptDir = parent file
39+
go = go'
3940
{ globalConfigMonoid = (globalConfigMonoid go')
4041
{ configMonoidInstallGHC = First $ Just True
4142
}
42-
, globalStackYaml = SYLNoConfig $ parent file
43+
, globalStackYaml = SYLNoConfig scriptDir
4344
}
4445
withDefaultBuildConfigAndLock go $ \lk -> do
4546
-- Some warnings in case the user somehow tries to set a
@@ -92,7 +93,8 @@ scriptCmd opts go' = do
9293
withNewLocalBuildTargets targets $ Stack.Build.build Nothing lk
9394

9495
let ghcArgs = concat
95-
[ ["-hide-all-packages"]
96+
[ ["-i", "-i" ++ toFilePath scriptDir]
97+
, ["-hide-all-packages"]
9698
, maybeToList colorFlag
9799
, map (\x -> "-package" ++ x)
98100
$ Set.toList
@@ -109,13 +111,12 @@ scriptCmd opts go' = do
109111
SEInterpret -> exec ("run" ++ compilerExeName wc)
110112
(ghcArgs ++ toFilePath file : soArgs opts)
111113
_ -> do
112-
let dir = parent file
113114
-- Use readProcessStdout_ so that (1) if GHC does send any output
114115
-- to stdout, we capture it and stop it from being sent to our
115116
-- stdout, which could break scripts, and (2) if there's an
116117
-- exception, the standard output we did capture will be reported
117118
-- to the user.
118-
withWorkingDir (toFilePath dir) $ proc
119+
withWorkingDir (toFilePath scriptDir) $ proc
119120
(compilerExeName wc)
120121
(ghcArgs ++ [toFilePath file])
121122
(void . readProcessStdout_)

0 commit comments

Comments
 (0)