@@ -66,7 +66,7 @@ data GhciOpts = GhciOpts
66
66
, ghciMainIs :: ! (Maybe Text )
67
67
, ghciLoadLocalDeps :: ! Bool
68
68
, ghciSkipIntermediate :: ! Bool
69
- , ghciHidePackages :: ! Bool
69
+ , ghciHidePackages :: ! ( Maybe Bool )
70
70
, ghciNoBuild :: ! Bool
71
71
, ghciOnlyMain :: ! Bool
72
72
} deriving Show
@@ -138,31 +138,19 @@ ghci opts@GhciOpts{..} = do
138
138
return (targetMap, Just (fileInfo, extraFiles))
139
139
-- Get a list of all the local target packages.
140
140
localTargets <- getAllLocalTargets opts inputTargets mainIsTargets sourceMap
141
+ -- Get a list of all the non-local target packages.
142
+ nonLocalTargets <- getAllNonLocalTargets inputTargets
141
143
-- Check if additional package arguments are sensible.
142
144
addPkgs <- checkAdditionalPackages ghciAdditionalPackages
143
145
-- Build required dependencies and setup local packages.
144
146
stackYaml <- view stackYamlL
145
147
buildDepsAndInitialSteps opts (map (packageNameText . fst ) localTargets)
146
- when (M. null inputTargets && isNothing mfileTargets) $
147
- prettyWarn $ vsep
148
- [ flow " No targets specified, so ghci will not use any options from your package.yaml / *.cabal files."
149
- , " "
150
- , flow " Potential ways to resolve this:"
151
- , bulletedList
152
- [ fillSep
153
- [ flow " If you want to use the package.yaml / *.cabal package in the current directory, use"
154
- , styleShell " stack init"
155
- , flow " to create a new stack.yaml."
156
- ]
157
- , flow " Add to the 'packages' field of" <+> display stackYaml
158
- ]
159
- , " "
160
- ]
148
+ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets
161
149
-- Load the list of modules _after_ building, to catch changes in unlisted dependencies (#1180)
162
150
pkgs <- getGhciPkgInfos buildOptsCLI sourceMap addPkgs (fmap fst mfileTargets) localTargets
163
151
checkForIssues pkgs
164
152
-- Finally, do the invocation of ghci
165
- runGhci opts localTargets mainIsTargets pkgs (maybe [] snd mfileTargets)
153
+ runGhci opts localTargets mainIsTargets pkgs (maybe [] snd mfileTargets) (nonLocalTargets ++ addPkgs)
166
154
167
155
preprocessTargets :: HasEnvConfig env => BuildOptsCLI -> [Text ] -> RIO env (Either [Path Abs File ] (Map PackageName Target ))
168
156
preprocessTargets buildOptsCLI rawTargets = do
@@ -286,6 +274,14 @@ getAllLocalTargets GhciOpts{..} targets0 mainIsTargets sourceMap = do
286
274
]
287
275
return (directlyWanted ++ extraLoadDeps)
288
276
277
+ getAllNonLocalTargets
278
+ :: Map PackageName Target
279
+ -> RIO env [PackageName ]
280
+ getAllNonLocalTargets targets = do
281
+ let isNonLocal (TargetAll Dependency ) = True
282
+ isNonLocal _ = False
283
+ return $ map fst $ filter (isNonLocal . snd ) (M. toList targets)
284
+
289
285
buildDepsAndInitialSteps :: HasEnvConfig env => GhciOpts -> [Text ] -> RIO env ()
290
286
buildDepsAndInitialSteps GhciOpts {.. } targets0 = do
291
287
let targets = targets0 ++ map T. pack ghciAdditionalPackages
@@ -317,14 +313,24 @@ runGhci
317
313
-> Maybe (Map PackageName Target )
318
314
-> [GhciPkgInfo ]
319
315
-> [Path Abs File ]
316
+ -> [PackageName ]
320
317
-> RIO env ()
321
- runGhci GhciOpts {.. } targets mainIsTargets pkgs extraFiles = do
318
+ runGhci GhciOpts {.. } targets mainIsTargets pkgs extraFiles exposePackages = do
322
319
config <- view configL
323
320
wc <- view $ actualCompilerVersionL. whichCompilerL
324
- let pkgopts = hidePkgOpt ++ genOpts ++ ghcOpts
325
- hidePkgOpt = if null pkgs || not ghciHidePackages then [] else [" -hide-all-packages" ]
321
+ let pkgopts = hidePkgOpts ++ genOpts ++ ghcOpts
322
+ shouldHidePackages =
323
+ case ghciHidePackages of
324
+ -- Default to not hiding anything if there's nothing to
325
+ -- expose.
326
+ Nothing -> not (null pkgs && null exposePackages)
327
+ Just x -> x
328
+ hidePkgOpts =
329
+ if shouldHidePackages
330
+ then " -hide-all-packages" : concatMap (\ n -> [" -package" , packageNameString n]) exposePackages
331
+ else []
326
332
oneWordOpts bio
327
- | ghciHidePackages = bioOneWordOpts bio ++ bioPackageFlags bio
333
+ | shouldHidePackages = bioOneWordOpts bio ++ bioPackageFlags bio
328
334
| otherwise = bioOneWordOpts bio
329
335
genOpts = nubOrd (concatMap (concatMap (oneWordOpts . snd ) . ghciPkgOpts) pkgs)
330
336
(omittedOpts, ghcOpts) = partition badForGhci $
@@ -700,6 +706,40 @@ checkForDuplicateModules pkgs = do
700
706
M. toList $ M. fromListWith (++) $
701
707
concatMap (\ pkg -> map ((, [ghciPkgName pkg]) . C. display) (S. toList (ghciPkgModules pkg))) pkgs
702
708
709
+ targetWarnings
710
+ :: HasRunner env
711
+ => Path Abs File
712
+ -> [(PackageName , (Path Abs File , Target ))]
713
+ -> [PackageName ]
714
+ -> Maybe (Map PackageName (Set (Path Abs File )), [Path Abs File ])
715
+ -> RIO env ()
716
+ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets = do
717
+ unless (null nonLocalTargets) $
718
+ prettyWarnL
719
+ [ flow " Some targets"
720
+ , parens $ fillSep $ punctuate " ," $ map (styleGood . display) nonLocalTargets
721
+ , flow " are not local packages, and so cannot be directly loaded."
722
+ , flow " In future versions of stack, this might be supported - see"
723
+ , styleUrl " https://github.com/commercialhaskell/stack/issues/1441"
724
+ , " ."
725
+ , flow " It can still be useful to specify these, as they will be passed to ghci via -package flags."
726
+ ]
727
+ when (null localTargets && isNothing mfileTargets) $
728
+ prettyWarn $ vsep
729
+ [ flow " No local targets specified, so ghci will not use any options from your package.yaml / *.cabal files."
730
+ , " "
731
+ , flow " Potential ways to resolve this:"
732
+ , bulletedList
733
+ [ fillSep
734
+ [ flow " If you want to use the package.yaml / *.cabal package in the current directory, use"
735
+ , styleShell " stack init"
736
+ , flow " to create a new stack.yaml."
737
+ ]
738
+ , flow " Add to the 'packages' field of" <+> display stackYaml
739
+ ]
740
+ , " "
741
+ ]
742
+
703
743
-- Adds in intermediate dependencies between ghci targets. Note that it
704
744
-- will return a Lib component for these intermediate dependencies even
705
745
-- if they don't have a library (but that's fine for the usage within
0 commit comments