Skip to content

Commit e9decce

Browse files
committed
Lift validatedTargets, rename r as replFlags
- Don't use -XRecordWildCards for configFlags
1 parent 943d520 commit e9decce

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

cabal-install/src/Distribution/Client/CmdRepl.hs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ multiReplDecision ctx compiler flags =
287287
-- For more details on how this works, see the module
288288
-- "Distribution.Client.ProjectOrchestration"
289289
replAction :: NixStyleFlags ReplFlags -> [String] -> GlobalFlags -> IO ()
290-
replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings' globalFlags = do
290+
replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags} targetStrings' globalFlags = do
291291
-- NOTE: The REPL will work with no targets in the context of a project if a
292292
-- single package is in the same directory as the project file. To have the
293293
-- same behaviour when the package is somewhere else we adjust the targets.
@@ -394,7 +394,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings'
394394
-- especially in the no-project case.
395395
withInstallPlan (lessVerbose verbosity) baseCtx' $ \elaboratedPlan sharedConfig -> do
396396
-- targets should be non-empty map, but there's no NonEmptyMap yet.
397-
targets <- validatedTargets (projectConfigShared (projectConfig ctx)) (pkgConfigCompiler sharedConfig) elaboratedPlan targetSelectors
397+
targets <- validatedTargets' (projectConfigShared (projectConfig ctx)) (pkgConfigCompiler sharedConfig) elaboratedPlan targetSelectors
398398

399399
let
400400
(unitId, _) = fromMaybe (error "panic: targets should be non-empty") $ safeHead $ Map.toList targets
@@ -418,7 +418,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings'
418418
let ProjectBaseContext{..} = baseCtx''
419419

420420
-- Recalculate with updated project.
421-
targets <- validatedTargets (projectConfigShared projectConfig) (pkgConfigCompiler elaboratedShared') elaboratedPlan targetSelectors
421+
targets <- validatedTargets' (projectConfigShared projectConfig) (pkgConfigCompiler elaboratedShared') elaboratedPlan targetSelectors
422422

423423
let
424424
elaboratedPlan' =
@@ -562,28 +562,7 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings'
562562
verbosity = cfgVerbosity normal flags
563563
tempFileOptions = commonSetupTempFileOptions $ configCommonFlags configFlags
564564

565-
validatedTargets ctx compiler elaboratedPlan targetSelectors = do
566-
let multi_repl_enabled = multiReplDecision ctx compiler r
567-
-- Interpret the targets on the command line as repl targets
568-
-- (as opposed to say build or haddock targets).
569-
targets <-
570-
either (reportTargetProblems verbosity) return $
571-
resolveTargetsFromSolver
572-
(selectPackageTargets multi_repl_enabled)
573-
selectComponentTarget
574-
elaboratedPlan
575-
Nothing
576-
targetSelectors
577-
578-
-- Reject multiple targets, or at least targets in different
579-
-- components. It is ok to have two module/file targets in the
580-
-- same component, but not two that live in different components.
581-
when (Set.size (distinctTargetComponents targets) > 1 && not (useMultiRepl multi_repl_enabled)) $
582-
reportTargetProblems
583-
verbosity
584-
[multipleTargetsProblem multi_repl_enabled targets]
585-
586-
return targets
565+
validatedTargets' = validatedTargets verbosity replFlags
587566

588567
-- This is the constraint setup.Cabal>=3.11. 3.11 is when Cabal options
589568
-- used for multi-repl were introduced.
@@ -597,6 +576,37 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings'
597576
, ConstraintSourceMultiRepl
598577
)
599578

579+
validatedTargets
580+
:: Verbosity
581+
-> ReplFlags
582+
-> ProjectConfigShared
583+
-> Compiler
584+
-> ElaboratedInstallPlan
585+
-> [TargetSelector]
586+
-> IO TargetsMap
587+
validatedTargets verbosity replFlags ctx compiler elaboratedPlan targetSelectors = do
588+
let multi_repl_enabled = multiReplDecision ctx compiler replFlags
589+
-- Interpret the targets on the command line as repl targets (as opposed to
590+
-- say build or haddock targets).
591+
targets <-
592+
either (reportTargetProblems verbosity) return $
593+
resolveTargetsFromSolver
594+
(selectPackageTargets multi_repl_enabled)
595+
selectComponentTarget
596+
elaboratedPlan
597+
Nothing
598+
targetSelectors
599+
600+
-- Reject multiple targets, or at least targets in different components. It is
601+
-- ok to have two module/file targets in the same component, but not two that
602+
-- live in different components.
603+
when (Set.size (distinctTargetComponents targets) > 1 && not (useMultiRepl multi_repl_enabled)) $
604+
reportTargetProblems
605+
verbosity
606+
[multipleTargetsProblem multi_repl_enabled targets]
607+
608+
return targets
609+
600610
-- | First version of GHC which supports multiple home packages
601611
minMultipleHomeUnitsVersion :: Version
602612
minMultipleHomeUnitsVersion = mkVersion [9, 4]

0 commit comments

Comments
 (0)