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