diff --git a/src/Stack/Options.hs b/src/Stack/Options.hs index dcf94cedef..9c1cbc0af6 100644 --- a/src/Stack/Options.hs +++ b/src/Stack/Options.hs @@ -621,6 +621,10 @@ execOptsExtraParser = eoPlainParser <|> ExecOptsEmbellished <$> eoEnvSettingsParser <*> eoPackagesParser + <*> boolFlags False + "add-ghci-packages" + "prefix the executed command line with the same -package (etc.) args that would be used for GHCI" + idm where eoEnvSettingsParser :: Parser EnvSettings eoEnvSettingsParser = EnvSettings diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index d9b70125ef..b07670ab84 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -383,6 +383,7 @@ data ExecOptsExtra | ExecOptsEmbellished { eoEnvSettings :: !EnvSettings , eoPackages :: ![String] + , eoGhciPackages :: !Bool } deriving (Show) diff --git a/src/main/Main.hs b/src/main/Main.hs index 27e745b531..81a8f53285 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -23,6 +23,7 @@ import Data.Attoparsec.Interpreter (getInterpreterArgs) import qualified Data.ByteString.Lazy as L import Data.IORef import Data.List +import Data.List.Extra (nubOrd) import qualified Data.Map as Map import qualified Data.Map.Strict as M import Data.Maybe @@ -1025,12 +1026,25 @@ execCmd ExecOpts {..} go@GlobalOpts{..} = } munlockFile lk -- Unlock before transferring control away. menv <- liftIO $ configEnvOverride config eoEnvSettings - exec menv cmd args + + if eoCmd == ExecGhc || eoGhciPackages + then do + pkgOpts <- genOpts . extract <$> ghciSetup ghciOpts + exec menv cmd $ ("-i" : "-hide-all-packages" : pkgOpts) ++ args + else + exec menv cmd args where execCompiler cmdPrefix args = do wc <- getWhichCompiler let cmd = cmdPrefix ++ compilerExeName wc return (cmd, args) + ghciOpts :: GhciOpts + ghciOpts = GhciOpts True [] Nothing False [] Nothing False False False defaultBuildOpts + extract (_, _, x) = x + genOpts :: [GhciPkgInfo] -> [String] + genOpts pkgs = nubOrd (concatMap (concatMap (oneWordOpts . snd) . ghciPkgOpts) pkgs) + oneWordOpts bio = bioOneWordOpts bio ++ bioPackageFlags bio + -- | Evaluate some haskell code inline. evalCmd :: EvalOpts -> GlobalOpts -> IO () diff --git a/stack.cabal b/stack.cabal index af18a91f3d..aae3418161 100644 --- a/stack.cabal +++ b/stack.cabal @@ -257,6 +257,7 @@ executable stack , conduit , transformers , http-client + , extra default-language: Haskell2010 if os(windows) build-depends: Win32