@@ -100,8 +100,10 @@ import Distribution.Simple.Command
100
100
)
101
101
import Distribution.Simple.Compiler
102
102
( Compiler
103
+ , PackageDBX (.. )
103
104
, compilerCompatVersion
104
105
)
106
+ import Distribution.Simple.Program.GHC
105
107
import Distribution.Simple.Setup
106
108
( ReplOptions (.. )
107
109
, commonSetupTempFileOptions
@@ -181,10 +183,6 @@ import Distribution.Compat.Binary (decode)
181
183
import Distribution.Simple.Flag (fromFlagOrDefault , pattern Flag )
182
184
import Distribution.Simple.Program.Builtin (ghcProgram )
183
185
import Distribution.Simple.Program.Db (requireProgram )
184
- import Distribution.Simple.Program.Run
185
- ( programInvocation
186
- , runProgramInvocation
187
- )
188
186
import Distribution.Simple.Program.Types
189
187
( ConfiguredProgram (programOverrideEnv )
190
188
)
@@ -364,7 +362,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
364
362
-- In addition, to avoid a *third* trip through the solver, we are
365
363
-- replicating the second half of 'runProjectPreBuildPhase' by hand
366
364
-- here.
367
- (buildCtx, compiler, replOpts', targets) <- withInstallPlan verbosity baseCtx'' $
365
+ (buildCtx, compiler, platform, replOpts', targets) <- withInstallPlan verbosity baseCtx'' $
368
366
\ elaboratedPlan elaboratedShared' -> do
369
367
let ProjectBaseContext {.. } = baseCtx''
370
368
@@ -401,13 +399,13 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
401
399
, targetsMap = targets
402
400
}
403
401
404
- ElaboratedSharedConfig {pkgConfigCompiler = compiler} = elaboratedShared'
402
+ ElaboratedSharedConfig {pkgConfigCompiler = compiler, pkgConfigPlatform = platform } = elaboratedShared'
405
403
406
404
repl_flags = case originalComponent of
407
405
Just oci -> generateReplFlags includeTransitive elaboratedPlan' oci
408
406
Nothing -> []
409
407
410
- return (buildCtx, compiler, configureReplOptions & lReplOptionsFlags %~ (++ repl_flags), targets)
408
+ return (buildCtx, compiler, platform, configureReplOptions & lReplOptionsFlags %~ (++ repl_flags), targets)
411
409
412
410
-- Multi Repl implementation see: https://well-typed.com/blog/2023/03/cabal-multi-unit/ for
413
411
-- a high-level overview about how everything fits together.
@@ -448,7 +446,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
448
446
-- Find what the unit files are, and start a repl based on all the response
449
447
-- files which have been created in the directory.
450
448
-- unit files for components
451
- unit_files <- listDirectory dir
449
+ unit_files <- ( filter ( /= " paths " )) <$> listDirectory dir
452
450
453
451
-- Order the unit files so that the find target becomes the active unit
454
452
let active_unit_fp :: Maybe FilePath
@@ -469,26 +467,21 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
469
467
in -- GHC considers the last unit passed to be the active one
470
468
other_units ++ active_unit_files
471
469
472
- render_j Serial = " 1"
473
- render_j (UseSem n) = show @ Int n
474
- render_j (NumJobs mn) = maybe " " (show @ Int ) mn
470
+ convertParStrat :: ParStratX Int -> ParStratX String
471
+ convertParStrat Serial = Serial
472
+ convertParStrat (UseSem n) = NumJobs (Just n)
473
+ convertParStrat (NumJobs mn) = NumJobs mn
474
+
475
+ let ghc_opts =
476
+ mempty
477
+ { ghcOptMode = Flag GhcModeInteractive
478
+ , ghcOptUnitFiles = map (dir </> ) unit_files_ordered
479
+ , ghcOptNumJobs = Flag (convertParStrat (buildSettingNumJobs (buildSettings ctx)))
480
+ , ghcOptPackageDBs = [GlobalPackageDB ]
481
+ }
475
482
476
483
-- run ghc --interactive with
477
- runProgramInvocation verbosity $
478
- programInvocation ghcProg' $
479
- concat $
480
- [ " --interactive"
481
- , " -package-env"
482
- , " -" -- to ignore ghc.environment.* files
483
- , " -j"
484
- , render_j (buildSettingNumJobs (buildSettings ctx))
485
- ]
486
- : [ [" -unit" , " @" ++ dir </> unit]
487
- | unit <- unit_files_ordered
488
- , unit /= " paths"
489
- ]
490
-
491
- pure ()
484
+ runGHCWithResponseFile " ghci_multi.rsp" Nothing tempFileOptions verbosity ghcProg' compiler platform Nothing ghc_opts
492
485
else do
493
486
-- single target repl
494
487
replOpts'' <- case targetCtx of
0 commit comments