From ec2a139c9281f8274eb9ecfa66d06ba7f7679831 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Thu, 24 Jan 2019 20:42:10 -0800 Subject: [PATCH] Have "stack script" set import search path #3377 --- ChangeLog.md | 6 ++++++ src/Stack/Script.hs | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index df1a21bbff..9db22e36f6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/Stack/Script.hs b/src/Stack/Script.hs index a733381971..568e4e00ff 100644 --- a/src/Stack/Script.hs +++ b/src/Stack/Script.hs @@ -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 @@ -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 @@ -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_)