Skip to content

Commit d8671ab

Browse files
committed
fix(cabal-install): use the correct stage for setup deps
1 parent cd40900 commit d8671ab

File tree

2 files changed

+53
-46
lines changed

2 files changed

+53
-46
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,9 +3952,9 @@ setupHsScriptOptions
39523952
, usePackageDB = elabSetupPackageDBStack
39533953
, usePackageIndex = Nothing
39543954
, useDependencies =
3955-
[ (uid, srcid)
3956-
| (WithStage _ (ConfiguredId srcid (Just (CLibName LMainLibName)) uid), _) <-
3957-
elabSetupDependencies elab
3955+
[ (confInstId cid, confSrcId cid)
3956+
-- TODO: we should filter for dependencies on libraries but that should be implicit in elabSetupLibDependencies
3957+
| (WithStage _ cid, _promised) <- elabSetupLibDependencies elab
39583958
]
39593959
, useDependenciesExclusive = True
39603960
, useVersionMacros = elabSetupScriptStyle == SetupCustomExplicitDeps

cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module Distribution.Client.ProjectPlanning.Types
2424
, elabOrderLibDependencies
2525
, elabExeDependencies
2626
, elabOrderExeDependencies
27-
, elabSetupDependencies
27+
, elabSetupLibDependencies
28+
, elabSetupExeDependencies
2829
, elabPkgConfigDependencies
2930
, elabInplaceDependencyBuildCacheFiles
3031
, elabRequiresRegistration
@@ -585,24 +586,28 @@ elabDistDirParams shared elab =
585586
-- use 'elabLibDependencies'. This method is the same as
586587
-- 'nodeNeighbors'.
587588
--
588-
-- NB: this method DOES include setup deps.
589+
-- Note: this method DOES include setup deps.
589590
elabOrderDependencies :: ElaboratedConfiguredPackage -> [WithStage UnitId]
590591
elabOrderDependencies elab =
591592
elabOrderLibDependencies elab ++ elabOrderExeDependencies elab
592593

593-
-- | Like 'elabOrderDependencies', but only returns dependencies on
594-
-- libraries.
594+
-- | The result includes setup dependencies
595595
elabOrderLibDependencies :: ElaboratedConfiguredPackage -> [WithStage UnitId]
596596
elabOrderLibDependencies elab =
597-
case elabPkgOrComp elab of
598-
ElabPackage pkg ->
599-
ordNub [ WithStage (pkgStage pkg) (newSimpleUnitId (confInstId cid))
600-
| cid <- CD.flatDeps (map fst <$> pkgLibDependencies pkg)
601-
]
602-
ElabComponent comp ->
603-
[ WithStage (elabStage elab) c
604-
| c <- compOrderLibDependencies comp
605-
]
597+
ordNub $
598+
[ fmap (newSimpleUnitId . confInstId) dep
599+
| (dep, _promised) <- elabLibDependencies elab ++ elabSetupLibDependencies elab
600+
]
601+
602+
-- | The result includes setup dependencies
603+
elabOrderExeDependencies :: ElaboratedConfiguredPackage -> [WithStage UnitId]
604+
elabOrderExeDependencies elab =
605+
-- Compare with elabOrderLibDependencies. The setup dependencies here do not need
606+
-- any special attention because the stage is already included in pkgExeDependencies.
607+
map (fmap (newSimpleUnitId . confInstId)) $
608+
case elabPkgOrComp elab of
609+
ElabPackage pkg -> CD.flatDeps (pkgExeDependencies pkg)
610+
ElabComponent comp -> compExeDependencies comp
606611

607612
-- | The library dependencies (i.e., the libraries we depend on, NOT
608613
-- the dependencies of the library), NOT including setup dependencies.
@@ -611,28 +616,47 @@ elabLibDependencies :: ElaboratedConfiguredPackage -> [(WithStage ConfiguredId,
611616
elabLibDependencies elab =
612617
case elabPkgOrComp elab of
613618
ElabPackage pkg ->
614-
ordNub [ (WithStage (pkgStage pkg) cid, promised)
615-
| (cid, promised) <- CD.nonSetupDeps (pkgLibDependencies pkg)
616-
]
619+
ordNub [ (WithStage (pkgStage pkg) cid, promised)
620+
| (cid, promised) <- CD.nonSetupDeps (pkgLibDependencies pkg)
621+
]
617622
ElabComponent comp ->
618623
[ (WithStage (elabStage elab) c, promised)
619624
| (c, promised) <- compLibDependencies comp
620625
]
621-
622-
-- | Like 'elabOrderDependencies', but only returns dependencies on
623-
-- executables. (This coincides with 'elabExeDependencies'.)
624-
elabOrderExeDependencies :: ElaboratedConfiguredPackage -> [WithStage UnitId]
625-
elabOrderExeDependencies =
626-
fmap (fmap newSimpleUnitId) . elabExeDependencies
626+
627+
-- | The setup dependencies (the library dependencies of the setup executable;
628+
-- note that it is not legal for setup scripts to have executable
629+
-- dependencies at the moment.)
630+
elabSetupLibDependencies :: ElaboratedConfiguredPackage -> [(WithStage ConfiguredId, Bool)]
631+
elabSetupLibDependencies elab =
632+
case elabPkgOrComp elab of
633+
ElabPackage pkg ->
634+
ordNub [ (WithStage (prevStage (pkgStage pkg)) cid, promised)
635+
| (cid, promised) <- CD.setupDeps (pkgLibDependencies pkg)
636+
]
637+
-- TODO: Custom setups not supported for components yet. When
638+
-- they are, need to do this differently
639+
ElabComponent _ -> []
640+
641+
-- | This would not be allowed actually. See comment on elabSetupLibDependencies.
642+
elabSetupExeDependencies :: ElaboratedConfiguredPackage -> [WithStage ComponentId]
643+
elabSetupExeDependencies elab =
644+
map (fmap confInstId) $
645+
case elabPkgOrComp elab of
646+
ElabPackage pkg -> CD.setupDeps (pkgExeDependencies pkg)
647+
-- TODO: Custom setups not supported for components yet. When
648+
-- they are, need to do this differently
649+
ElabComponent _ -> []
627650

628651
-- | The executable dependencies (i.e., the executables we depend on);
629652
-- these are the executables we must add to the PATH before we invoke
630653
-- the setup script.
631654
elabExeDependencies :: ElaboratedConfiguredPackage -> [WithStage ComponentId]
632-
elabExeDependencies elab = fmap (fmap confInstId) $
633-
case elabPkgOrComp elab of
634-
ElabPackage pkg -> CD.nonSetupDeps (pkgExeDependencies pkg)
635-
ElabComponent comp -> compExeDependencies comp
655+
elabExeDependencies elab =
656+
map (fmap confInstId) $
657+
case elabPkgOrComp elab of
658+
ElabPackage pkg -> CD.nonSetupDeps (pkgExeDependencies pkg)
659+
ElabComponent comp -> compExeDependencies comp
636660

637661
-- | This returns the paths of all the executables we depend on; we
638662
-- must add these paths to PATH before invoking the setup script.
@@ -644,23 +668,6 @@ elabExeDependencyPaths elab =
644668
ElabPackage pkg -> map snd $ CD.nonSetupDeps (pkgExeDependencyPaths pkg)
645669
ElabComponent comp -> map snd (compExeDependencyPaths comp)
646670

647-
-- | The setup dependencies (the library dependencies of the setup executable;
648-
-- note that it is not legal for setup scripts to have executable
649-
-- dependencies at the moment.)
650-
elabSetupDependencies :: ElaboratedConfiguredPackage -> [(WithStage ConfiguredId, Bool)]
651-
elabSetupDependencies elab =
652-
case elabPkgOrComp elab of
653-
-- FIXME: this should be wrong. Setup and its dependencies can be on a different stage. Where did that information go?
654-
ElabPackage pkg ->
655-
ordNub
656-
[ (WithStage (pkgStage pkg) cid, promised)
657-
| (cid, promised) <- CD.setupDeps (pkgLibDependencies pkg)
658-
]
659-
660-
-- TODO: Custom setups not supported for components yet. When
661-
-- they are, need to do this differently
662-
ElabComponent _ -> []
663-
664671
elabPkgConfigDependencies :: ElaboratedConfiguredPackage -> [(PkgconfigName, Maybe PkgconfigVersion)]
665672
elabPkgConfigDependencies ElaboratedConfiguredPackage{elabPkgOrComp = ElabPackage pkg} =
666673
pkgPkgConfigDependencies pkg

0 commit comments

Comments
 (0)