1 module Distribution
.Solver
.Modular
.ConfiguredConversion
6 import Prelude
hiding (pi)
7 import Data
.Either (partitionEithers
)
9 import Distribution
.Package
(UnitId
, packageId
)
11 import qualified Distribution
.Simple
.PackageIndex
as SI
13 import Distribution
.Solver
.Modular
.Configured
14 import Distribution
.Solver
.Modular
.Package
16 import Distribution
.Solver
.Types
.ComponentDeps
(ComponentDeps
)
17 import qualified Distribution
.Solver
.Types
.PackageIndex
as CI
18 import Distribution
.Solver
.Types
.PackagePath
19 import Distribution
.Solver
.Types
.ResolverPackage
20 import Distribution
.Solver
.Types
.SolverId
21 import Distribution
.Solver
.Types
.SolverPackage
22 import Distribution
.Solver
.Types
.InstSolverPackage
23 import Distribution
.Solver
.Types
.SourcePackage
25 -- | Converts from the solver specific result @CP QPN@ into
26 -- a 'ResolverPackage', which can then be converted into
28 convCP
:: SI
.InstalledPackageIndex
->
29 CI
.PackageIndex
(SourcePackage loc
) ->
30 CP QPN
-> ResolverPackage loc
31 convCP iidx sidx
(CP qpi fa es ds
) =
33 Left
pi -> PreExisting
$
35 instSolverPkgIPI
= fromJust $ SI
.lookupUnitId iidx
pi,
36 instSolverPkgLibDeps
= fmap fst ds
',
37 instSolverPkgExeDeps
= fmap snd ds
'
39 Right
pi -> Configured
$
41 solverPkgSource
= srcpkg
,
43 solverPkgStanzas
= es
,
44 solverPkgLibDeps
= fmap fst ds
',
45 solverPkgExeDeps
= fmap snd ds
'
48 srcpkg
= fromMaybe (error "convCP: lookupPackageId failed") $ CI
.lookupPackageId sidx
pi
50 ds
' :: ComponentDeps
([SolverId
] {- lib -}, [SolverId
] {- exe -})
51 ds
' = fmap (partitionEithers
. map convConfId
) ds
53 convPI
:: PI QPN
-> Either UnitId PackageId
54 convPI
(PI _
(I _
(Inst
pi))) = Left
pi
55 convPI
pi = Right
(packageId
(either id id (convConfId
pi)))
57 convConfId
:: PI QPN
-> Either SolverId
{- is lib -} SolverId
{- is exe -}
58 convConfId
(PI
(Q
(PackagePath _ q
) pn
) (I v loc
)) =
60 Inst
pi -> Left
(PreExistingId sourceId
pi)
63 -- NB: the dependencies of the executable are also
64 -- qualified. So the way to tell if this is an executable
65 -- dependency is to make sure the qualifier is pointing
66 -- at the actual thing. Fortunately for us, I was
67 -- silly and didn't allow arbitrarily nested build-tools
68 -- dependencies, so a shallow check works.
69 , pn
== pn
' -> Right
(PlannedId sourceId
)
70 |
otherwise -> Left
(PlannedId sourceId
)
72 sourceId
= PackageIdentifier pn v