@@ -87,6 +87,13 @@ data GhciPkgInfo = GhciPkgInfo
87
87
, ghciPkgPackage :: ! Package
88
88
} deriving Show
89
89
90
+ -- | Loaded package description and related info.
91
+ data GhciPkgDesc = GhciPkgDesc
92
+ { ghciDescPkg :: ! Package
93
+ , ghciDescCabalFp :: ! (Path Abs File )
94
+ , ghciDescTarget :: ! Target
95
+ }
96
+
90
97
-- Mapping from a module name to a map with all of the paths that use
91
98
-- that name. Each of those paths is associated with a set of components
92
99
-- that contain it. Purpose of this complex structure is for use in
@@ -154,15 +161,31 @@ ghci opts@GhciOpts{..} = do
154
161
nonLocalTargets <- getAllNonLocalTargets inputTargets
155
162
-- Check if additional package arguments are sensible.
156
163
addPkgs <- checkAdditionalPackages ghciAdditionalPackages
164
+ -- Load package descriptions.
165
+ pkgDescs <- loadGhciPkgDescs buildOptsCLI localTargets
166
+ -- If necessary, ask user about which main module to load.
167
+ bopts <- view buildOptsL
168
+ mainFile <-
169
+ if ghciNoLoadModules
170
+ then return Nothing
171
+ else do
172
+ -- Figure out package files, in order to ask the user
173
+ -- about which main module to load. See the note below for
174
+ -- why this is done again after the build. This could
175
+ -- potentially be done more efficiently, because all we
176
+ -- need is the location of main modules, not the rest.
177
+ pkgs0 <- getGhciPkgInfos sourceMap addPkgs (fmap fst mfileTargets) pkgDescs
178
+ figureOutMainFile bopts mainIsTargets localTargets pkgs0
157
179
-- Build required dependencies and setup local packages.
158
180
stackYaml <- view stackYamlL
159
181
buildDepsAndInitialSteps opts (map (packageNameText . fst ) localTargets)
160
182
targetWarnings stackYaml localTargets nonLocalTargets mfileTargets
161
- -- Load the list of modules _after_ building, to catch changes in unlisted dependencies (#1180)
162
- pkgs <- getGhciPkgInfos buildOptsCLI sourceMap addPkgs (fmap fst mfileTargets) localTargets
183
+ -- Load the list of modules _after_ building, to catch changes in
184
+ -- unlisted dependencies (#1180)
185
+ pkgs <- getGhciPkgInfos sourceMap addPkgs (fmap fst mfileTargets) pkgDescs
163
186
checkForIssues pkgs
164
187
-- Finally, do the invocation of ghci
165
- runGhci opts localTargets mainIsTargets pkgs (maybe [] snd mfileTargets) (nonLocalTargets ++ addPkgs)
188
+ runGhci opts localTargets mainFile pkgs (maybe [] snd mfileTargets) (nonLocalTargets ++ addPkgs)
166
189
167
190
preprocessTargets :: HasEnvConfig env => BuildOptsCLI -> [Text ] -> RIO env (Either [Path Abs File ] (Map PackageName Target ))
168
191
preprocessTargets buildOptsCLI rawTargets = do
@@ -321,12 +344,12 @@ runGhci
321
344
:: HasEnvConfig env
322
345
=> GhciOpts
323
346
-> [(PackageName , (Path Abs File , Target ))]
324
- -> Maybe (Map PackageName Target )
347
+ -> Maybe (Path Abs File )
325
348
-> [GhciPkgInfo ]
326
349
-> [Path Abs File ]
327
350
-> [PackageName ]
328
351
-> RIO env ()
329
- runGhci GhciOpts {.. } targets mainIsTargets pkgs extraFiles exposePackages = do
352
+ runGhci GhciOpts {.. } targets mainFile pkgs extraFiles exposePackages = do
330
353
config <- view configL
331
354
wc <- view $ actualCompilerVersionL. whichCompilerL
332
355
let pkgopts = hidePkgOpts ++ genOpts ++ ghcOpts
@@ -407,8 +430,6 @@ runGhci GhciOpts{..} targets mainIsTargets pkgs extraFiles exposePackages = do
407
430
else do
408
431
checkForDuplicateModules pkgs
409
432
isIntero <- checkIsIntero
410
- bopts <- view buildOptsL
411
- mainFile <- figureOutMainFile bopts mainIsTargets targets pkgs
412
433
scriptOptions <- writeGhciScript tmpDirectory (renderScript isIntero pkgs mainFile ghciOnlyMain extraFiles)
413
434
execGhci (macrosOptions ++ scriptOptions)
414
435
@@ -561,41 +582,24 @@ figureOutMainFile bopts mainIsTargets targets0 packages = do
561
582
sampleMainIsArg (pkg,comp,_) =
562
583
" --main-is " <> packageNameText pkg <> " :" <> renderComp comp
563
584
564
- getGhciPkgInfos
585
+ loadGhciPkgDescs
565
586
:: HasEnvConfig env
566
587
=> BuildOptsCLI
567
- -> SourceMap
568
- -> [PackageName ]
569
- -> Maybe (Map PackageName (Set (Path Abs File )))
570
588
-> [(PackageName , (Path Abs File , Target ))]
571
- -> RIO env [GhciPkgInfo ]
572
- getGhciPkgInfos buildOptsCLI sourceMap addPkgs mfileTargets localTargets = do
573
- (installedMap, _, _, _) <- getInstalled
574
- GetInstalledOpts
575
- { getInstalledProfiling = False
576
- , getInstalledHaddock = False
577
- , getInstalledSymbols = False
578
- }
579
- sourceMap
580
- let localLibs = [name | (name, (_, target)) <- localTargets, hasLocalComp isCLib target]
589
+ -> RIO env [GhciPkgDesc ]
590
+ loadGhciPkgDescs buildOptsCLI localTargets =
581
591
forM localTargets $ \ (name, (cabalfp, target)) ->
582
- makeGhciPkgInfo buildOptsCLI sourceMap installedMap localLibs addPkgs mfileTargets name cabalfp target
592
+ loadGhciPkgDesc buildOptsCLI name cabalfp target
583
593
584
- -- | Make information necessary to load the given package in GHCi .
585
- makeGhciPkgInfo
594
+ -- | Load package description information for a ghci target .
595
+ loadGhciPkgDesc
586
596
:: HasEnvConfig env
587
597
=> BuildOptsCLI
588
- -> SourceMap
589
- -> InstalledMap
590
- -> [PackageName ]
591
- -> [PackageName ]
592
- -> Maybe (Map PackageName (Set (Path Abs File )))
593
598
-> PackageName
594
599
-> Path Abs File
595
600
-> Target
596
- -> RIO env GhciPkgInfo
597
- makeGhciPkgInfo buildOptsCLI sourceMap installedMap locals addPkgs mfileTargets name cabalfp target = do
598
- bopts <- view buildOptsL
601
+ -> RIO env GhciPkgDesc
602
+ loadGhciPkgDesc buildOptsCLI name cabalfp target = do
599
603
econfig <- view envConfigL
600
604
bconfig <- view buildConfigL
601
605
compilerVersion <- view actualCompilerVersionL
@@ -633,15 +637,59 @@ makeGhciPkgInfo buildOptsCLI sourceMap installedMap locals addPkgs mfileTargets
633
637
(C. updatePackageDescription bi x)
634
638
(C. updatePackageDescription bi y))
635
639
mbuildinfo
640
+ return GhciPkgDesc
641
+ { ghciDescPkg = pkg
642
+ , ghciDescCabalFp = cabalfp
643
+ , ghciDescTarget = target
644
+ }
636
645
646
+ getGhciPkgInfos
647
+ :: HasEnvConfig env
648
+ => SourceMap
649
+ -> [PackageName ]
650
+ -> Maybe (Map PackageName (Set (Path Abs File )))
651
+ -> [GhciPkgDesc ]
652
+ -> RIO env [GhciPkgInfo ]
653
+ getGhciPkgInfos sourceMap addPkgs mfileTargets localTargets = do
654
+ (installedMap, _, _, _) <- getInstalled
655
+ GetInstalledOpts
656
+ { getInstalledProfiling = False
657
+ , getInstalledHaddock = False
658
+ , getInstalledSymbols = False
659
+ }
660
+ sourceMap
661
+ let localLibs =
662
+ [ packageName (ghciDescPkg desc)
663
+ | desc <- localTargets
664
+ , hasLocalComp isCLib (ghciDescTarget desc)
665
+ ]
666
+ forM localTargets $ \ pkgDesc ->
667
+ makeGhciPkgInfo sourceMap installedMap localLibs addPkgs mfileTargets pkgDesc
668
+
669
+ -- | Make information necessary to load the given package in GHCi.
670
+ makeGhciPkgInfo
671
+ :: HasEnvConfig env
672
+ => SourceMap
673
+ -> InstalledMap
674
+ -> [PackageName ]
675
+ -> [PackageName ]
676
+ -> Maybe (Map PackageName (Set (Path Abs File )))
677
+ -> GhciPkgDesc
678
+ -> RIO env GhciPkgInfo
679
+ makeGhciPkgInfo sourceMap installedMap locals addPkgs mfileTargets pkgDesc = do
680
+ bopts <- view buildOptsL
681
+ let pkg = ghciDescPkg pkgDesc
682
+ cabalfp = ghciDescCabalFp pkgDesc
683
+ target = ghciDescTarget pkgDesc
684
+ name = packageName pkg
637
685
(mods,files,opts) <- getPackageOpts (packageOpts pkg) sourceMap installedMap locals addPkgs cabalfp
638
686
let filteredOpts = filterWanted opts
639
687
filterWanted = M. filterWithKey (\ k _ -> k `S.member` allWanted)
640
688
allWanted = wantedPackageComponents bopts target pkg
641
689
setMapMaybe f = S. fromList . mapMaybe f . S. toList
642
690
return
643
691
GhciPkgInfo
644
- { ghciPkgName = packageName pkg
692
+ { ghciPkgName = name
645
693
, ghciPkgOpts = M. toList filteredOpts
646
694
, ghciPkgDir = parent cabalfp
647
695
, ghciPkgModules = unionModuleMaps $
0 commit comments