Skip to content

Commit 9264e56

Browse files
committed
Allow solver to work with ghc- resolver (fixes #3397)
1 parent 1940926 commit 9264e56

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/Stack/BuildPlan.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,12 @@ checkSnapBuildPlan
396396
-> [GenericPackageDescription]
397397
-> Maybe (Map PackageName (Map FlagName Bool))
398398
-> SnapshotDef
399+
-> Maybe (CompilerVersion 'CVActual)
399400
-> RIO env BuildPlanCheck
400-
checkSnapBuildPlan root gpds flags snapshotDef = do
401+
checkSnapBuildPlan root gpds flags snapshotDef mactualCompiler = do
401402
platform <- view platformL
402403
menv <- getMinimalEnvOverride
403-
rs <- loadSnapshot menv Nothing root snapshotDef
404+
rs <- loadSnapshot menv mactualCompiler root snapshotDef
404405

405406
let
406407
compiler = lsCompilerVersion rs
@@ -447,6 +448,12 @@ selectBestSnapshot root gpds snaps = do
447448

448449
getResult snap = do
449450
result <- checkSnapBuildPlan root gpds Nothing snap
451+
-- We know that we're only dealing with ResolverSnapshot
452+
-- here, where we can rely on the global package hints.
453+
-- Therefore, we don't use an actual compiler. For more
454+
-- info, see comments on
455+
-- Stack.Solver.checkSnapBuildPlanActual.
456+
Nothing
450457
reportResult result snap
451458
return (snap, result)
452459

src/Stack/Init.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ checkBundleResolver
430430
(Either [PackageName] ( Map PackageName (Map FlagName Bool)
431431
, Map PackageName Version))
432432
checkBundleResolver whichCmd stackYaml initOpts bundle sd = do
433-
result <- checkSnapBuildPlan (parent stackYaml) gpds Nothing sd
433+
result <- checkSnapBuildPlanActual (parent stackYaml) gpds Nothing sd
434434
case result of
435435
BuildPlanCheckOk f -> return $ Right (f, Map.empty)
436436
BuildPlanCheckPartial f e -> do

src/Stack/Solver.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Stack.Solver
1414
, mergeConstraints
1515
, solveExtraDeps
1616
, solveResolverSpec
17+
, checkSnapBuildPlanActual
1718
-- * Internal - for tests
1819
, parseCabalOutputLine
1920
) where
@@ -647,7 +648,7 @@ solveExtraDeps modStackYaml = do
647648
srcConstraints = mergeConstraints oldSrcs oldSrcFlags
648649
extraConstraints = mergeConstraints oldExtraVersions oldExtraFlags
649650

650-
resolverResult <- checkSnapBuildPlan (parent stackYaml) gpds (Just oldSrcFlags) sd
651+
resolverResult <- checkSnapBuildPlanActual (parent stackYaml) gpds (Just oldSrcFlags) sd
651652
resultSpecs <- case resolverResult of
652653
BuildPlanCheckOk flags ->
653654
return $ Just (mergeConstraints oldSrcs flags, Map.empty)
@@ -753,6 +754,31 @@ solveExtraDeps modStackYaml = do
753754
, " - Adjust resolver.\n"
754755
]
755756

757+
-- | Same as 'checkSnapBuildPLan', but set up a real GHC if needed.
758+
--
759+
-- If we're using a Stackage snapshot, we can use the snapshot hints
760+
-- to determine global library information. This will not be available
761+
-- for custom and GHC resolvers, however. Therefore, we insist that it
762+
-- be installed first. Fortunately, the standard `stack solver`
763+
-- behavior only chooses Stackage snapshots, so the common case will
764+
-- not force the installation of a bunch of GHC versions.
765+
checkSnapBuildPlanActual
766+
:: (HasConfig env, HasGHCVariant env)
767+
=> Path Abs Dir -- ^ project root, used for checking out necessary files
768+
-> [C.GenericPackageDescription]
769+
-> Maybe (Map PackageName (Map FlagName Bool))
770+
-> SnapshotDef
771+
-> RIO env BuildPlanCheck
772+
checkSnapBuildPlanActual root gpds flags sd = do
773+
let forNonSnapshot = (Just . snd) <$> setupCabalEnv (sdWantedCompilerVersion sd)
774+
mactualCompiler <-
775+
case sdResolver sd of
776+
ResolverSnapshot _ -> return Nothing
777+
ResolverCompiler _ -> forNonSnapshot
778+
ResolverCustom _ _ -> forNonSnapshot
779+
780+
checkSnapBuildPlan root gpds flags sd mactualCompiler
781+
756782
prettyPath
757783
:: forall r t m. (MonadIO m, RelPath (Path r t) ~ Path Rel t, AnyPath (Path r t))
758784
=> Path r t -> m String

0 commit comments

Comments
 (0)