@@ -101,8 +101,10 @@ import Distribution.Simple.Command
101101 )
102102import Distribution.Simple.Compiler
103103 ( Compiler
104+ , PackageDBX (.. )
104105 , compilerCompatVersion
105106 )
107+ import Distribution.Simple.Program.GHC
106108import Distribution.Simple.Setup
107109 ( ReplOptions (.. )
108110 , commonSetupTempFileOptions
@@ -181,10 +183,6 @@ import Distribution.Compat.Binary (decode)
181183import Distribution.Simple.Flag (fromFlagOrDefault , pattern Flag )
182184import Distribution.Simple.Program.Builtin (ghcProgram )
183185import Distribution.Simple.Program.Db (requireProgram )
184- import Distribution.Simple.Program.Run
185- ( programInvocation
186- , runProgramInvocation
187- )
188186import Distribution.Simple.Program.Types
189187 ( ConfiguredProgram (programOverrideEnv )
190188 )
@@ -364,7 +362,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
364362 -- In addition, to avoid a *third* trip through the solver, we are
365363 -- replicating the second half of 'runProjectPreBuildPhase' by hand
366364 -- here.
367- (buildCtx, compiler, replOpts', targets) <- withInstallPlan verbosity baseCtx'' $
365+ (buildCtx, compiler, platform, replOpts', targets) <- withInstallPlan verbosity baseCtx'' $
368366 \ elaboratedPlan elaboratedShared' -> do
369367 let ProjectBaseContext {.. } = baseCtx''
370368
@@ -401,13 +399,13 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
401399 , targetsMap = targets
402400 }
403401
404- ElaboratedSharedConfig {pkgConfigCompiler = compiler} = elaboratedShared'
402+ ElaboratedSharedConfig {pkgConfigCompiler = compiler, pkgConfigPlatform = platform } = elaboratedShared'
405403
406404 repl_flags = case originalComponent of
407405 Just oci -> generateReplFlags includeTransitive elaboratedPlan' oci
408406 Nothing -> []
409407
410- return (buildCtx, compiler, configureReplOptions & lReplOptionsFlags %~ (++ repl_flags), targets)
408+ return (buildCtx, compiler, platform, configureReplOptions & lReplOptionsFlags %~ (++ repl_flags), targets)
411409
412410 -- Multi Repl implementation see: https://well-typed.com/blog/2023/03/cabal-multi-unit/ for
413411 -- a high-level overview about how everything fits together.
@@ -448,7 +446,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
448446 -- Find what the unit files are, and start a repl based on all the response
449447 -- files which have been created in the directory.
450448 -- unit files for components
451- unit_files <- listDirectory dir
449+ unit_files <- ( filter ( /= " paths " )) <$> listDirectory dir
452450
453451 -- Order the unit files so that the find target becomes the active unit
454452 let active_unit_fp :: Maybe FilePath
@@ -469,26 +467,21 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings g
469467 in -- GHC considers the last unit passed to be the active one
470468 other_units ++ active_unit_files
471469
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+ }
475482
476483 -- 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
492485 else do
493486 -- single target repl
494487 replOpts'' <- case targetCtx of
0 commit comments