1 {-# LANGUAGE DeriveFunctor #-}
2 module Distribution
.Solver
.Modular
.Package
6 , PackageIdentifier
(..)
7 , PackageName
, mkPackageName
, unPackageName
8 , PkgconfigName
, mkPkgconfigName
, unPkgconfigName
22 import Distribution
.Package
-- from Cabal
23 import Distribution
.Text
(display
)
25 import Distribution
.Solver
.Modular
.Version
26 import Distribution
.Solver
.Types
.PackagePath
31 -- | Unpacking a package name.
35 -- | Package version. A package name plus a version number.
38 -- | Qualified package version.
39 type QPV
= Qualified PV
41 -- | Package id. Currently just a black-box string.
44 -- | Location. Info about whether a package is installed or not, and where
45 -- exactly it is located. For installed packages, uniquely identifies the
46 -- package instance via its 'PId'.
48 -- TODO: More information is needed about the repo.
49 data Loc
= Inst PId | InRepo
50 deriving (Eq
, Ord
, Show)
52 -- | Instance. A version number and a location.
54 deriving (Eq
, Ord
, Show)
56 -- | String representation of an instance.
58 showI
(I v InRepo
) = showVer v
59 showI
(I v
(Inst uid
)) = showVer v
++ "/installed" ++ shortId uid
61 -- A hack to extract the beginning of the package ABI hash
62 shortId
= snip
(splitAt 4) (++ "...")
63 . snip
((\ (x
, y
) -> (reverse x
, y
)) . break (=='-') . reverse) ('-':)
65 snip p f xs
= case p xs
of
66 (ys
, zs
) -> (if L
.null zs
then id else f
) ys
68 -- | Package instance. A package name and an instance.
69 data PI qpn
= PI qpn I
70 deriving (Eq
, Ord
, Show, Functor
)
72 -- | String representation of a package instance.
73 showPI
:: PI QPN
-> String
74 showPI
(PI qpn i
) = showQPN qpn
++ "-" ++ showI i
77 instI
(I _
(Inst _
)) = True
80 -- | Is the package in the primary group of packages. This is used to
81 -- determine (1) if we should try to establish stanza preferences
82 -- for this goal, and (2) whether or not a user specified @--constraint@
83 -- should apply to this dependency (grep 'primaryPP' to see the
84 -- use sites). In particular this does not include packages pulled in
87 primaryPP
:: PackagePath
-> Bool
88 primaryPP
(PackagePath _ns q
) = go q
95 -- | Create artificial parents for each of the package names, making
96 -- them all independent.
97 makeIndependent
:: [PN
] -> [QPN
]
98 makeIndependent ps
= [ Q pp pn |
(pn
, i
) <- zip ps
[0::Int ..]
99 , let pp
= PackagePath
(Independent i
) Unqualified