never executed always true always false
1 {-# LANGUAGE DeriveGeneric #-}
2 module Distribution.Client.Types.ConfiguredId (
3 InstalledPackageId,
4 ConfiguredId (..),
5 annotatedIdToConfiguredId,
6 HasConfiguredId (..),
7 ) where
8
9 import Distribution.Client.Compat.Prelude
10 import Prelude ()
11
12 import Distribution.InstalledPackageInfo (InstalledPackageInfo, sourceComponentName, installedComponentId)
13 import Distribution.Package (Package (..))
14 import Distribution.Types.AnnotatedId (AnnotatedId (..))
15 import Distribution.Types.ComponentId (ComponentId)
16 import Distribution.Types.ComponentName (ComponentName)
17 import Distribution.Types.PackageId (PackageId)
18
19 -------------------------------------------------------------------------------
20 -- InstalledPackageId
21 -------------------------------------------------------------------------------
22
23 -- | Within Cabal the library we no longer have a @InstalledPackageId@ type.
24 -- That's because it deals with the compilers' notion of a registered library,
25 -- and those really are libraries not packages. Those are now named units.
26 --
27 -- The package management layer does however deal with installed packages, as
28 -- whole packages not just as libraries. So we do still need a type for
29 -- installed package ids. At the moment however we track instaled packages via
30 -- their primary library, which is a unit id. In future this may change
31 -- slightly and we may distinguish these two types and have an explicit
32 -- conversion when we register units with the compiler.
33 --
34 type InstalledPackageId = ComponentId
35
36 -------------------------------------------------------------------------------
37 -- ConfiguredId
38 -------------------------------------------------------------------------------
39
40 -- | A ConfiguredId is a package ID for a configured package.
41 --
42 -- Once we configure a source package we know its UnitId. It is still
43 -- however useful in lots of places to also know the source ID for the package.
44 -- We therefore bundle the two.
45 --
46 -- An already installed package of course is also "configured" (all its
47 -- configuration parameters and dependencies have been specified).
48 data ConfiguredId = ConfiguredId {
49 confSrcId :: PackageId
50 , confCompName :: Maybe ComponentName
51 , confInstId :: ComponentId
52 }
53 deriving (Eq, Ord, Generic)
54
55 annotatedIdToConfiguredId :: AnnotatedId ComponentId -> ConfiguredId
56 annotatedIdToConfiguredId aid = ConfiguredId {
57 confSrcId = ann_pid aid,
58 confCompName = Just (ann_cname aid),
59 confInstId = ann_id aid
60 }
61
62 instance Binary ConfiguredId
63 instance Structured ConfiguredId
64
65 instance Show ConfiguredId where
66 show cid = show (confInstId cid)
67
68 instance Package ConfiguredId where
69 packageId = confSrcId
70
71 -------------------------------------------------------------------------------
72 -- HasConfiguredId class
73 -------------------------------------------------------------------------------
74
75 class HasConfiguredId a where
76 configuredId :: a -> ConfiguredId
77
78 -- NB: This instance is slightly dangerous, in that you'll lose
79 -- information about the specific UnitId you depended on.
80 instance HasConfiguredId InstalledPackageInfo where
81 configuredId ipkg = ConfiguredId (packageId ipkg)
82 (Just (sourceComponentName ipkg))
83 (installedComponentId ipkg)