Skip to content

Commit 3347bcb

Browse files
committed
No longer use build options with ghci commercialhaskell#2199
1 parent b792561 commit 3347bcb

9 files changed

Lines changed: 76 additions & 74 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Other enhancements:
6464
on discussion in [#2647](https://github.com/commercialhaskell/stack/issues/2647).
6565
* The `--main-is` flag for GHCI now implies the TARGET, fixing
6666
[#1845](https://github.com/commercialhaskell/stack/issues/1845).
67-
* `stack ghci` will now use CLI `--ghc-options`.
67+
* `stack ghci` no longer takes all build options, as many weren't useful
6868
[#2199](https://github.com/commercialhaskell/stack/issues/2199)
6969

7070
Bug fixes:

src/Stack/Ghci.hs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ data GhciOpts = GhciOpts
8989
, ghciLoadLocalDeps :: !Bool
9090
, ghciSkipIntermediate :: !Bool
9191
, ghciHidePackages :: !Bool
92-
, ghciBuildOptsCLI :: !BuildOptsCLI
92+
, ghciTargets :: ![Text]
9393
, ghciNoBuild :: !Bool
9494
} deriving Show
9595

@@ -136,12 +136,12 @@ instance Show GhciException where
136136
ghci :: M r m => GhciOpts -> m ()
137137
ghci opts@GhciOpts{..} = do
138138
-- Load source map, without explicit targets, to collect all info.
139-
(_, _, locals, _, sourceMap) <- loadSourceMap AllowNoTargets ghciBuildOptsCLI
139+
(_, _, locals, _, sourceMap) <- loadSourceMap AllowNoTargets defaultBuildOptsCLI
140140
{ boptsCLITargets = [] }
141141
-- Parse --main-is argument.
142-
mainIsTargets <- parseMainIsTargets ghciBuildOptsCLI ghciMainIs
142+
mainIsTargets <- parseMainIsTargets ghciMainIs
143143
-- Parse to either file targets or build targets
144-
etargets <- preprocessTargets ghciBuildOptsCLI
144+
etargets <- preprocessTargets ghciTargets
145145
(inputTargets, mfileTargets) <- case etargets of
146146
Left rawFileTargets -> do
147147
case mainIsTargets of
@@ -151,7 +151,7 @@ ghci opts@GhciOpts{..} = do
151151
(targetMap, fileInfo, extraFiles) <- findFileTargets locals rawFileTargets
152152
return (targetMap, Just (fileInfo, extraFiles))
153153
Right rawTargets -> do
154-
(_,_,normalTargets) <- parseTargetsFromBuildOpts AllowNoTargets ghciBuildOptsCLI
154+
(_,_,normalTargets) <- parseTargetsFromBuildOpts AllowNoTargets defaultBuildOptsCLI
155155
{ boptsCLITargets = rawTargets }
156156
return (normalTargets, Nothing)
157157
-- Make sure the targets are known.
@@ -163,16 +163,16 @@ ghci opts@GhciOpts{..} = do
163163
-- Build required dependencies and setup local packages.
164164
buildDepsAndInitialSteps opts (map (packageNameText . fst) localTargets)
165165
-- Load the list of modules _after_ building, to catch changes in unlisted dependencies (#1180)
166-
pkgs <- getGhciPkgInfos ghciBuildOptsCLI sourceMap addPkgs (fmap fst mfileTargets) localTargets
166+
pkgs <- getGhciPkgInfos sourceMap addPkgs (fmap fst mfileTargets) localTargets
167167
checkForIssues pkgs
168168
-- Finally, do the invocation of ghci
169169
runGhci opts localTargets mainIsTargets pkgs
170170

171-
preprocessTargets :: M r m => BuildOptsCLI -> m (Either [Path Abs File] [Text])
172-
preprocessTargets boptsCLI = do
171+
preprocessTargets :: M r m => [Text] -> m (Either [Path Abs File] [Text])
172+
preprocessTargets rawTargets = do
173173
let (fileTargetsRaw, normalTargets) =
174174
partition (\t -> ".hs" `T.isSuffixOf` t || ".lhs" `T.isSuffixOf` t)
175-
(boptsCLITargets boptsCLI)
175+
rawTargets
176176
fileTargets <- forM fileTargetsRaw $ \fp0 -> do
177177
let fp = T.unpack fp0
178178
mpath <- forgivingAbsence (resolveFile' fp)
@@ -184,9 +184,9 @@ preprocessTargets boptsCLI = do
184184
(False, _) -> return (Left fileTargets)
185185
_ -> return (Right normalTargets)
186186

187-
parseMainIsTargets :: M env m => BuildOptsCLI -> Maybe Text -> m (Maybe (Map PackageName SimpleTarget))
188-
parseMainIsTargets boptsCli mtarget = forM mtarget $ \target -> do
189-
(_,_,targets) <- parseTargetsFromBuildOpts AllowNoTargets boptsCli
187+
parseMainIsTargets :: M env m => Maybe Text -> m (Maybe (Map PackageName SimpleTarget))
188+
parseMainIsTargets mtarget = forM mtarget $ \target -> do
189+
(_,_,targets) <- parseTargetsFromBuildOpts AllowNoTargets defaultBuildOptsCLI
190190
{ boptsCLITargets = [target] }
191191
return targets
192192

@@ -306,7 +306,7 @@ buildDepsAndInitialSteps GhciOpts{..} targets0 = do
306306
-- If necessary, do the build, for local packagee targets, only do
307307
-- 'initialBuildSteps'.
308308
when (not ghciNoBuild && not (null targets)) $ do
309-
eres <- tryAny $ build (const (return ())) Nothing ghciBuildOptsCLI
309+
eres <- tryAny $ build (const (return ())) Nothing defaultBuildOptsCLI
310310
{ boptsCLITargets = targets
311311
, boptsCLIInitialBuildSteps = True
312312
}
@@ -341,7 +341,6 @@ runGhci GhciOpts{..} targets mainIsTargets pkgs = do
341341
genOpts = nubOrd (concatMap (concatMap (oneWordOpts . snd) . ghciPkgOpts) pkgs)
342342
(omittedOpts, ghcOpts) = partition badForGhci $
343343
concatMap (concatMap (bioOpts . snd) . ghciPkgOpts) pkgs ++
344-
map T.unpack (boptsCLIGhcOptions ghciBuildOptsCLI) ++
345344
getUserOptions Nothing ++
346345
concatMap (getUserOptions . Just . ghciPkgName) pkgs
347346
getUserOptions mpkg =
@@ -530,13 +529,12 @@ figureOutMainFile bopts mainIsTargets targets0 packages = do
530529

531530
getGhciPkgInfos
532531
:: M env m
533-
=> BuildOptsCLI
534-
-> SourceMap
532+
=> SourceMap
535533
-> [PackageName]
536534
-> Maybe (Map PackageName (Set (Path Abs File)))
537535
-> [(PackageName, (Path Abs File, SimpleTarget))]
538536
-> m [GhciPkgInfo]
539-
getGhciPkgInfos boptsCli sourceMap addPkgs mfileTargets localTargets = do
537+
getGhciPkgInfos sourceMap addPkgs mfileTargets localTargets = do
540538
menv <- getMinimalEnvOverride
541539
(installedMap, _, _, _) <- getInstalled
542540
menv
@@ -547,13 +545,12 @@ getGhciPkgInfos boptsCli sourceMap addPkgs mfileTargets localTargets = do
547545
sourceMap
548546
let localLibs = [name | (name, (_, target)) <- localTargets, hasLocalComp isCLib target]
549547
forM localTargets $ \(name, (cabalfp, target)) ->
550-
makeGhciPkgInfo boptsCli sourceMap installedMap localLibs addPkgs mfileTargets name cabalfp target
548+
makeGhciPkgInfo sourceMap installedMap localLibs addPkgs mfileTargets name cabalfp target
551549

552550
-- | Make information necessary to load the given package in GHCi.
553551
makeGhciPkgInfo
554552
:: (MonadReader r m, HasEnvConfig r, HasTerminal r, MonadLogger m, MonadIO m, MonadCatch m, MonadBaseControl IO m)
555-
=> BuildOptsCLI
556-
-> SourceMap
553+
=> SourceMap
557554
-> InstalledMap
558555
-> [PackageName]
559556
-> [PackageName]
@@ -562,16 +559,16 @@ makeGhciPkgInfo
562559
-> Path Abs File
563560
-> SimpleTarget
564561
-> m GhciPkgInfo
565-
makeGhciPkgInfo boptsCli sourceMap installedMap locals addPkgs mfileTargets name cabalfp target = do
562+
makeGhciPkgInfo sourceMap installedMap locals addPkgs mfileTargets name cabalfp target = do
566563
bopts <- asks (configBuild . getConfig)
567564
econfig <- asks getEnvConfig
568565
bconfig <- asks getBuildConfig
569566
let config =
570567
PackageConfig
571568
{ packageConfigEnableTests = True
572569
, packageConfigEnableBenchmarks = True
573-
, packageConfigFlags = getLocalFlags bconfig boptsCli name
574-
, packageConfigGhcOptions = getGhcOptions bconfig boptsCli name True True
570+
, packageConfigFlags = getLocalFlags bconfig defaultBuildOptsCLI name
571+
, packageConfigGhcOptions = getGhcOptions bconfig defaultBuildOptsCLI name True True
575572
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
576573
, packageConfigPlatform = configPlatform (getConfig bconfig)
577574
}

src/Stack/Options/BuildMonoidParser.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import Stack.Options.HaddockParser
1111
import Stack.Options.Utils
1212
import Stack.Types.Config.Build
1313

14-
buildOptsMonoidParser :: Bool -> Parser BuildOptsMonoid
14+
buildOptsMonoidParser :: GlobalOptsContext -> Parser BuildOptsMonoid
1515
buildOptsMonoidParser hide0 =
1616
transform <$> trace <*> profile <*> options
1717
where
18+
hideBool = hide0 /= BuildCmdGlobalOpts
1819
hide =
19-
hideMods hide0
20+
hideMods hideBool
21+
hideExceptGhci =
22+
hideMods (hide0 `notElem` [BuildCmdGlobalOpts, GhciCmdGlobalOpts])
2023
transform tracing profiling =
2124
enable
2225
where
@@ -60,7 +63,7 @@ buildOptsMonoidParser hide0 =
6063
"Enable profiling in libraries, executables, etc. \
6164
\for all expressions and generate a profiling report\
6265
\ in tests or benchmarks" <>
63-
hide)
66+
hideExceptGhci)
6467

6568
trace =
6669
flag
@@ -71,13 +74,13 @@ buildOptsMonoidParser hide0 =
7174
"Enable profiling in libraries, executables, etc. \
7275
\for all expressions and generate a backtrace on \
7376
\exception" <>
74-
hide)
77+
hideExceptGhci)
7578
options =
7679
BuildOptsMonoid <$> libProfiling <*> exeProfiling <*> haddock <*>
77-
haddockOptsParser hide0 <*> openHaddocks <*> haddockDeps <*>
80+
haddockOptsParser hideBool <*> openHaddocks <*> haddockDeps <*>
7881
haddockInternal <*> copyBins <*> preFetch <*> keepGoing <*>
79-
forceDirty <*> tests <*> testOptsParser hide0 <*> benches <*>
80-
benchOptsParser hide0 <*> reconfigure <*>
82+
forceDirty <*> tests <*> testOptsParser hideBool <*> benches <*>
83+
benchOptsParser hideBool <*> reconfigure <*>
8184
cabalVerbose <*> splitObjs
8285
libProfiling =
8386
firstBoolFlags
@@ -130,12 +133,12 @@ buildOptsMonoidParser hide0 =
130133
firstBoolFlags
131134
"test"
132135
"testing the package(s) in this directory/configuration"
133-
hide
136+
hideExceptGhci
134137
benches =
135138
firstBoolFlags
136139
"bench"
137140
"benchmarking the package(s) in this directory/configuration"
138-
hide
141+
hideExceptGhci
139142
reconfigure =
140143
firstBoolFlags
141144
"reconfigure"

src/Stack/Options/BuildParser.hs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ import Stack.Types.Config
1515
import Stack.Types.FlagName
1616
import Stack.Types.PackageName
1717

18-
data BuildOptsVariant = NormalBuildOpts | GhciBuildOpts
19-
2018
-- | Parser for CLI-only build arguments
21-
buildOptsParser :: BuildOptsVariant
22-
-> BuildCommand
19+
buildOptsParser :: BuildCommand
2320
-> Parser BuildOptsCLI
24-
buildOptsParser variant cmd =
21+
buildOptsParser cmd =
2522
BuildOptsCLI <$>
26-
targetsParser variant <*>
23+
targetsParser <*>
2724
switch
2825
(long "dry-run" <>
2926
help "Don't build anything, just prepare to") <*>
@@ -85,24 +82,15 @@ buildOptsParser variant cmd =
8582
help "For target packages, only run initial build steps needed for GHCi" <>
8683
internal)
8784

88-
targetsParser :: BuildOptsVariant -> Parser [Text]
89-
targetsParser NormalBuildOpts =
85+
targetsParser :: Parser [Text]
86+
targetsParser =
9087
many
9188
(textArgument
9289
(metavar "TARGET" <>
9390
help ("If none specified, use all local packages. " <>
9491
"See https://docs.haskellstack.org/en/v" <>
9592
showVersion Meta.version <>
9693
"/build_command/#target-syntax for details.")))
97-
targetsParser GhciBuildOpts =
98-
many
99-
(textArgument
100-
(metavar "TARGET/FILE" <>
101-
help ("If none specified, use all local packages. " <>
102-
"See https://docs.haskellstack.org/en/v" <>
103-
showVersion Meta.version <>
104-
"/build_command/#target-syntax for details. " <>
105-
"If a path to a .hs or .lhs file is specified, it will be loaded.")))
10694

10795
flagsParser :: Parser (Map.Map (Maybe PackageName) (Map.Map FlagName Bool))
10896
flagsParser =

src/Stack/Options/ConfigParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ configOptsParser hide0 =
5252
<> help "Override work directory (default: .stack-work)"
5353
<> hide
5454
))
55-
<*> buildOptsMonoidParser (hide0 /= BuildCmdGlobalOpts)
55+
<*> buildOptsMonoidParser hide0
5656
<*> dockerOptsParser True
5757
<*> nixOptsParser True
5858
<*> firstBoolFlags

src/Stack/Options/DotParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dotOptsParser externalDefault =
1919
<*> includeBase
2020
<*> depthLimit
2121
<*> fmap (maybe Set.empty Set.fromList . fmap splitNames) prunedPkgs
22-
<*> targetsParser NormalBuildOpts
22+
<*> targetsParser
2323
<*> flagsParser
2424
<*> testTargets
2525
<*> benchTargets

src/Stack/Options/GhciParser.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module Stack.Options.GhciParser where
22

3-
import Data.Monoid.Extra
4-
import Options.Applicative
5-
import Options.Applicative.Args
6-
import Options.Applicative.Builder.Extra
7-
import Stack.Config (packagesParser)
8-
import Stack.Ghci (GhciOpts (..))
9-
import Stack.Options.BuildParser
10-
import Stack.Types.Config
3+
import Data.Monoid.Extra
4+
import Data.Version (showVersion)
5+
import Options.Applicative
6+
import Options.Applicative.Args
7+
import Options.Applicative.Builder.Extra
8+
import Paths_stack as Meta
9+
import Stack.Config (packagesParser)
10+
import Stack.Ghci (GhciOpts (..))
1111

1212
-- | Parser for GHCI options
1313
ghciOptsParser :: Parser GhciOpts
@@ -31,5 +31,12 @@ ghciOptsParser = GhciOpts
3131
<*> switch (long "load-local-deps" <> help "Load all local dependencies of your targets")
3232
<*> switch (long "skip-intermediate-deps" <> help "Skip loading intermediate target dependencies")
3333
<*> boolFlags True "package-hiding" "package hiding" idm
34-
<*> buildOptsParser GhciBuildOpts Build
34+
<*> many
35+
(textArgument
36+
(metavar "TARGET/FILE" <>
37+
help ("If none specified, use all local packages. " <>
38+
"See https://docs.haskellstack.org/en/v" <>
39+
showVersion Meta.version <>
40+
"/build_command/#target-syntax for details. " <>
41+
"If a path to a .hs or .lhs file is specified, it will be loaded.")))
3542
<*> switch (long "no-build" <> help "Don't build before launching GHCi (deprecated, should be unneeded)")

src/Stack/Options/Utils.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ data GlobalOptsContext
1616
= OuterGlobalOpts -- ^ Global options before subcommand name
1717
| OtherCmdGlobalOpts -- ^ Global options following any other subcommand
1818
| BuildCmdGlobalOpts
19+
| GhciCmdGlobalOpts
1920
deriving (Show, Eq)

src/main/Main.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,27 @@ commandLineHandler progName isInterpreter = complicatedOptions
229229
addBuildCommand' "build"
230230
"Build the package(s) in this directory/configuration"
231231
buildCmd
232-
(buildOptsParser NormalBuildOpts Build)
232+
(buildOptsParser Build)
233233
addBuildCommand' "install"
234234
"Shortcut for 'build --copy-bins'"
235235
buildCmd
236-
(buildOptsParser NormalBuildOpts Install)
236+
(buildOptsParser Install)
237237
addCommand' "uninstall"
238238
"DEPRECATED: This command performs no actions, and is present for documentation only"
239239
uninstallCmd
240240
(many $ strArgument $ metavar "IGNORED")
241241
addBuildCommand' "test"
242242
"Shortcut for 'build --test'"
243243
buildCmd
244-
(buildOptsParser NormalBuildOpts Test)
244+
(buildOptsParser Test)
245245
addBuildCommand' "bench"
246246
"Shortcut for 'build --bench'"
247247
buildCmd
248-
(buildOptsParser NormalBuildOpts Bench)
248+
(buildOptsParser Bench)
249249
addBuildCommand' "haddock"
250250
"Shortcut for 'build --haddock'"
251251
buildCmd
252-
(buildOptsParser NormalBuildOpts Haddock)
252+
(buildOptsParser Haddock)
253253
addCommand' "new"
254254
"Create a new project from a template. Run `stack templates' to see available templates."
255255
newCmd
@@ -344,14 +344,14 @@ commandLineHandler progName isInterpreter = complicatedOptions
344344
"Execute a command"
345345
execCmd
346346
(execOptsParser Nothing)
347-
addCommand' "ghci"
348-
"Run ghci in the context of package(s) (experimental)"
349-
ghciCmd
350-
ghciOptsParser
351-
addCommand' "repl"
352-
"Run ghci in the context of package(s) (experimental) (alias for 'ghci')"
353-
ghciCmd
354-
ghciOptsParser
347+
addGhciCommand' "ghci"
348+
"Run ghci in the context of package(s) (experimental)"
349+
ghciCmd
350+
ghciOptsParser
351+
addGhciCommand' "repl"
352+
"Run ghci in the context of package(s) (experimental) (alias for 'ghci')"
353+
ghciCmd
354+
ghciOptsParser
355355
addCommand' "runghc"
356356
"Run runghc"
357357
execCmd
@@ -461,6 +461,12 @@ commandLineHandler progName isInterpreter = complicatedOptions
461461
addBuildCommand' cmd title constr =
462462
addCommand cmd title globalFooter constr (globalOpts BuildCmdGlobalOpts)
463463

464+
-- Additional helper that hides global options and shows some ghci options
465+
addGhciCommand' :: String -> String -> (a -> GlobalOpts -> IO ()) -> Parser a
466+
-> AddCommand
467+
addGhciCommand' cmd title constr =
468+
addCommand cmd title globalFooter constr (globalOpts GhciCmdGlobalOpts)
469+
464470
globalOpts :: GlobalOptsContext -> Parser GlobalOptsMonoid
465471
globalOpts kind =
466472
extraHelpOption hide progName (Docker.dockerCmdName ++ "*") Docker.dockerHelpOptName <*>

0 commit comments

Comments
 (0)