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

Add --build-ghc-options flag for stack ghci (#971) #979

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 6 additions & 2 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Stack.Types.Internal
data GhciOpts = GhciOpts
{ghciTargets :: ![Text]
,ghciArgs :: ![String]
,ghciBuildGhcArgs :: ![Text]
,ghciGhcCommand :: !(Maybe FilePath)
,ghciNoLoadModules :: !Bool
,ghciAdditionalPackages :: ![String]
Expand All @@ -65,7 +66,7 @@ ghci
:: (HasConfig r, HasBuildConfig r, HasHttpManager r, MonadMask m, HasLogLevel r, HasTerminal r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m)
=> GhciOpts -> m ()
ghci GhciOpts{..} = do
(targets,mainIsTargets,pkgs) <- ghciSetup ghciMainIs ghciTargets
(targets,mainIsTargets,pkgs) <- ghciSetup ghciMainIs ghciTargets ghciBuildGhcArgs
bconfig <- asks getBuildConfig
mainFile <- figureOutMainFile mainIsTargets targets pkgs
wc <- getWhichCompiler
Expand Down Expand Up @@ -154,13 +155,15 @@ ghciSetup
:: (HasConfig r, HasHttpManager r, HasBuildConfig r, MonadMask m, HasTerminal r, HasLogLevel r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m)
=> Maybe Text
-> [Text]
-> [Text]
-> m (Map PackageName SimpleTarget, Maybe (Map PackageName SimpleTarget), [GhciPkgInfo])
ghciSetup mainIs stringTargets = do
ghciSetup mainIs stringTargets buildGhcOpts = do
(_,_,targets) <-
parseTargetsFromBuildOpts
AllowNoTargets
defaultBuildOpts
{ boptsTargets = stringTargets
, boptsGhcOptions = buildGhcOpts
}
mainIsTargets <-
case mainIs of
Expand Down Expand Up @@ -208,6 +211,7 @@ ghciSetup mainIs stringTargets = do
{ beoDisableRun = True
}
, boptsBuildSubset = BSOnlyDependencies
, boptsGhcOptions = buildGhcOpts
}
where
base = defaultBuildOpts
Expand Down
5 changes: 3 additions & 2 deletions src/Stack/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ ide
:: (HasConfig r, HasBuildConfig r, HasTerminal r, HasLogLevel r, MonadMask m, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m, HasHttpManager r)
=> [Text] -- ^ Targets.
-> [String] -- ^ GHC options.
-> [Text] -- ^ Build GHC options.
-> m ()
ide targets useropts = do
(_realTargets,_,pkgs) <- ghciSetup Nothing targets
ide targets useropts buildArgs = do
(_realTargets,_,pkgs) <- ghciSetup Nothing targets buildArgs
pwd <- getWorkingDir
(pkgopts,srcfiles) <-
liftM mconcat $
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ ghciOptsParser = GhciOpts
<*> fmap concat (many (argsOption (long "ghc-options" <>
metavar "OPTION" <>
help "Additional options passed to GHCi")))
<*> ((++)
<$> flag [] ["-Wall", "-Werror"]
( long "pedantic"
<> help "Turn on -Wall and -Werror (note: option name may change in the future"
)
<*> many (textOption (long "build-ghc-options" <>
metavar "OPTION" <>
help "Additional options passed to GHC for the build")))
<*> optional
(strOption (long "with-ghc" <>
metavar "GHC" <>
Expand Down
30 changes: 19 additions & 11 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,22 @@ main = withInterpreterArgs stackProgName $ \args isInterpreter -> do
"start"
"Start the ide-backend service"
ideCmd
((,) <$> many (textArgument
(metavar "TARGET" <>
help ("If none specified, use all " <>
"packages defined in current directory")))
<*> argsOption (long "ghc-options" <>
metavar "OPTION" <>
help "Additional options passed to GHCi" <>
value []))
((,,) <$> many (textArgument
(metavar "TARGET" <>
help ("If none specified, use all " <>
"packages defined in current directory")))
<*> argsOption (long "ghc-options" <>
metavar "OPTION" <>
help "Additional options passed to GHCi" <>
value [])
<*> ((++)
<$> flag [] ["-Wall", "-Werror"]
( long "pedantic"
<> help "Turn on -Wall and -Werror (note: option name may change in the future"
)
<*> many (textOption (long "ghc-options" <>
metavar "OPTION" <>
help "Additional options passed to GHC"))))
addCommand
"packages"
"List all available local loadable packages"
Expand Down Expand Up @@ -824,10 +832,10 @@ ghciCmd ghciOpts go@GlobalOpts{..} =
ghci ghciOpts

-- | Run ide-backend in the context of a project.
ideCmd :: ([Text], [String]) -> GlobalOpts -> IO ()
ideCmd (targets,args) go@GlobalOpts{..} =
ideCmd :: ([Text], [String], [Text]) -> GlobalOpts -> IO ()
ideCmd (targets,args,buildArgs) go@GlobalOpts{..} =
withBuildConfig go $ -- No locking needed.
ide targets args
ide targets args buildArgs

-- | Run ide-backend in the context of a project.
packagesCmd :: () -> GlobalOpts -> IO ()
Expand Down