Skip to content

Commit 282e548

Browse files
authored
Merge pull request #6172 from commercialhaskell/add-dep
Reorganise checkCallStackAndAddDep
2 parents 6778069 + 688dcb5 commit 282e548

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/Stack/Build/ConstructPlan.hs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,14 @@ getCachedDepOrAddDep name = do
553553
pure res
554554
Nothing -> checkCallStackAndAddDep name
555555

556-
-- | Given a 'PackageName', adds all of the build tasks to build the package.
557-
-- First checks that the package name is not already in the call stack.
556+
-- | Given a 'PackageName', known not to be in the library map, adds all of the
557+
-- build tasks to build the package. First checks that the package name is not
558+
-- already in the call stack.
558559
checkCallStackAndAddDep ::
559560
PackageName
560561
-> M (Either ConstructPlanException AddDepRes)
561562
checkCallStackAndAddDep name = do
562563
ctx <- ask
563-
let mpackageInfo = Map.lookup name $ combinedMap ctx
564564
res <- if name `elem` callStack ctx
565565
then do
566566
logDebugPlanS "checkCallStackAndAddDep" $
@@ -569,17 +569,19 @@ checkCallStackAndAddDep name = do
569569
<> ": "
570570
<> fromString (show $ map packageNameString (callStack ctx))
571571
pure $ Left $ DependencyCycleDetected $ name : callStack ctx
572-
else local (\ctx' -> ctx' { callStack = name : callStack ctx' }) $ do
573-
case mpackageInfo of
574-
-- TODO look up in the package index and see if there's a
575-
-- recommendation available
576-
Nothing -> do
577-
logDebugPlanS "checkCallStackAndAddDep" $
578-
"No package info for "
579-
<> fromString (packageNameString name)
580-
<> "."
581-
pure $ Left $ UnknownPackage name
582-
Just packageInfo -> addDep name packageInfo
572+
else case Map.lookup name $ combinedMap ctx of
573+
-- TODO look up in the package index and see if there's a
574+
-- recommendation available
575+
Nothing -> do
576+
logDebugPlanS "checkCallStackAndAddDep" $
577+
"No package info for "
578+
<> fromString (packageNameString name)
579+
<> "."
580+
pure $ Left $ UnknownPackage name
581+
Just packageInfo ->
582+
-- Add the current package name to the head of the call stack.
583+
local (\ctx' -> ctx' { callStack = name : callStack ctx' }) $
584+
addDep name packageInfo
583585
updateLibMap name res
584586
pure res
585587

0 commit comments

Comments
 (0)