@@ -308,10 +308,13 @@ constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap
308
308
inSourceMap pname = pname `Map.member` smDeps sourceMap ||
309
309
pname `Map.member` smProject sourceMap
310
310
311
+ getSources :: Version -> RIO env (Map PackageName PackageSource )
311
312
getSources globalCabalVersion = do
312
313
let loadLocalPackage' pp = do
313
314
lp <- loadLocalPackage pp
314
- pure lp { lpPackage = applyForceCustomBuild globalCabalVersion $ lpPackage lp }
315
+ let lpPackage' =
316
+ applyForceCustomBuild globalCabalVersion $ lpPackage lp
317
+ pure lp { lpPackage = lpPackage' }
315
318
pPackages <- for (smProject sourceMap) $ \ pp -> do
316
319
lp <- loadLocalPackage' pp
317
320
pure $ PSFilePath lp
@@ -508,7 +511,7 @@ addFinal lp package isAllInOne buildHaddocks = do
508
511
tell mempty { wFinals = Map. singleton (packageName package) res }
509
512
510
513
-- | Given a 'PackageName', adds all of the build tasks to build the package, if
511
- -- needed.
514
+ -- needed. First checks if the package name is in the lib map.
512
515
--
513
516
-- 'constructPlan' invokes this on all the target packages, setting
514
517
-- @treatAsDep'@ to False, because those packages are direct build targets.
@@ -517,74 +520,89 @@ addFinal lp package isAllInOne buildHaddocks = do
517
520
-- marked as a dependency, even if it is directly wanted. This makes sense - if
518
521
-- we left out packages that are deps, it would break the --only-dependencies
519
522
-- build plan.
520
- addDep :: MungedPackageName
521
- -> M (Either ConstructPlanException AddDepRes )
523
+ addDep :: MungedPackageName -> M (Either ConstructPlanException AddDepRes )
522
524
addDep mungedName = do
523
- ctx <- ask
524
- m <- get
525
525
let name = encodeCompatPackageName mungedName
526
- case Map. lookup name m of
526
+ libMap <- get
527
+ case Map. lookup name libMap of
527
528
Just res -> do
528
529
planDebug $
529
530
" addDep: Using cached result for " ++ show name ++ " : " ++ show res
530
531
pure res
531
- Nothing -> do
532
- res <- if name `elem` callStack ctx
533
- then do
534
- planDebug $
535
- " addDep: Detected cycle "
536
- <> show name
537
- <> " : "
538
- <> show (callStack ctx)
539
- pure $ Left $ DependencyCycleDetected $ name : callStack ctx
540
- else local (\ ctx' -> ctx' { callStack = name : callStack ctx' }) $ do
541
- let mpackageInfo = Map. lookup name $ combinedMap ctx
532
+ Nothing -> addDep' name
533
+
534
+ -- | Given a 'PackageName', adds all of the build tasks to build the package.
535
+ -- First checks that the package name is not already in the call stack.
536
+ addDep' :: PackageName -> M (Either ConstructPlanException AddDepRes )
537
+ addDep' name = do
538
+ ctx <- ask
539
+ let mpackageInfo = Map. lookup name $ combinedMap ctx
540
+ res <- if name `elem` callStack ctx
541
+ then do
542
+ planDebug $
543
+ " addDep': Detected cycle "
544
+ <> show name
545
+ <> " : "
546
+ <> show (callStack ctx)
547
+ pure $ Left $ DependencyCycleDetected $ name : callStack ctx
548
+ else local (\ ctx' -> ctx' { callStack = name : callStack ctx' }) $ do
549
+ case mpackageInfo of
550
+ -- TODO look up in the package index and see if there's a
551
+ -- recommendation available
552
+ Nothing -> do
542
553
planDebug $
543
- " addDep: Package info for "
554
+ " addDep': No package info for "
544
555
<> show name
545
- <> " : "
546
- <> show mpackageInfo
547
- case mpackageInfo of
548
- -- TODO look up in the package index and see if there's a
549
- -- recommendation available
550
- Nothing -> pure $ Left $ UnknownPackage name
551
- Just (PIOnlyInstalled loc installed) -> do
552
- -- FIXME Slightly hacky, no flags since they likely won't affect
553
- -- executable names. This code does not feel right.
554
- let version = installedVersion installed
555
- askPkgLoc = liftRIO $ do
556
- mrev <- getLatestHackageRevision
557
- YesRequireHackageIndex name version
558
- case mrev of
559
- Nothing -> do
560
- -- this could happen for GHC boot libraries missing from
561
- -- Hackage
562
- prettyWarnL
563
- $ flow " No latest package revision found for"
564
- : style Current (fromString $ packageNameString name) <> " ,"
565
- : flow " dependency callstack:"
566
- : mkNarrativeList
567
- Nothing
568
- False
569
- ( map
570
- (fromString . packageNameString)
571
- (callStack ctx)
572
- :: [StyleDoc ]
573
- )
574
- pure Nothing
575
- Just (_rev, cfKey, treeKey) ->
576
- pure . Just $
577
- PLIHackage (PackageIdentifier name version) cfKey treeKey
578
- tellExecutablesUpstream name askPkgLoc loc Map. empty
579
- pure $ Right $ ADRFound loc installed
580
- Just (PIOnlySource ps) -> do
581
- tellExecutables name ps
582
- installPackage name ps Nothing
583
- Just (PIBoth ps installed) -> do
584
- tellExecutables name ps
585
- installPackage name ps (Just installed)
586
- updateLibMap name res
587
- pure res
556
+ pure $ Left $ UnknownPackage name
557
+ Just packageInfo -> addDep'' name packageInfo
558
+ updateLibMap name res
559
+ pure res
560
+
561
+ -- | Given a 'PackageName' and its 'PackageInfo' from the combined map, adds all
562
+ -- of the build tasks to build the package. Assumes that the head of the call
563
+ -- stack is the current package name.
564
+ addDep'' ::
565
+ PackageName
566
+ -> PackageInfo
567
+ -> M (Either ConstructPlanException AddDepRes )
568
+ addDep'' name packageInfo = do
569
+ planDebug $
570
+ " addDep'': Package info for "
571
+ <> show name
572
+ <> " : "
573
+ <> show packageInfo
574
+ case packageInfo of
575
+ PIOnlyInstalled loc installed -> do
576
+ -- FIXME Slightly hacky, no flags since they likely won't affect
577
+ -- executable names. This code does not feel right.
578
+ let version = installedVersion installed
579
+ askPkgLoc = liftRIO $ do
580
+ mrev <- getLatestHackageRevision YesRequireHackageIndex name version
581
+ case mrev of
582
+ Nothing -> do
583
+ -- This could happen for GHC boot libraries missing from
584
+ -- Hackage.
585
+ cs <- asks (L. tail . callStack)
586
+ prettyWarnL
587
+ $ flow " No latest package revision found for"
588
+ : style Current (fromString $ packageNameString name) <> " ,"
589
+ : flow " dependency callstack:"
590
+ : mkNarrativeList
591
+ Nothing
592
+ False
593
+ (map (fromString . packageNameString) cs :: [StyleDoc ])
594
+ pure Nothing
595
+ Just (_rev, cfKey, treeKey) ->
596
+ pure . Just $
597
+ PLIHackage (PackageIdentifier name version) cfKey treeKey
598
+ tellExecutablesUpstream name askPkgLoc loc Map. empty
599
+ pure $ Right $ ADRFound loc installed
600
+ PIOnlySource ps -> do
601
+ tellExecutables name ps
602
+ installPackage name ps Nothing
603
+ PIBoth ps installed -> do
604
+ tellExecutables name ps
605
+ installPackage name ps (Just installed)
588
606
589
607
-- FIXME what's the purpose of this? Add a Haddock!
590
608
tellExecutables :: PackageName -> PackageSource -> M ()
0 commit comments