1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.Types
.Library
11 import Distribution
.Compat
.Prelude
14 import Distribution
.ModuleName
15 import Distribution
.Types
.BuildInfo
16 import Distribution
.Types
.LibraryName
17 import Distribution
.Types
.LibraryVisibility
18 import Distribution
.Types
.ModuleReexport
20 import qualified Distribution
.Types
.BuildInfo
.Lens
as L
22 data Library
= Library
23 { libName
:: LibraryName
24 , exposedModules
:: [ModuleName
]
25 , reexportedModules
:: [ModuleReexport
]
26 , signatures
:: [ModuleName
]
27 -- ^ What sigs need implementations?
29 -- ^ Is the lib to be exposed by default? (i.e. whether its modules available in GHCi for example)
30 , libVisibility
:: LibraryVisibility
31 -- ^ Whether this multilib can be used as a dependency for other packages.
32 , libBuildInfo
:: BuildInfo
34 deriving (Generic
, Show, Eq
, Ord
, Read, Typeable
, Data
)
36 instance L
.HasBuildInfo Library
where
37 buildInfo f l
= (\x
-> l
{libBuildInfo
= x
}) <$> f
(libBuildInfo l
)
39 instance Binary Library
40 instance Structured Library
41 instance NFData Library
where rnf
= genericRnf
43 emptyLibrary
:: Library
46 { libName
= LMainLibName
47 , exposedModules
= mempty
48 , reexportedModules
= mempty
51 , libVisibility
= mempty
52 , libBuildInfo
= mempty
55 -- | This instance is not good.
57 -- We need it for 'PackageDescription.Configuration.addBuildableCondition'.
58 -- More correct method would be some kind of "create empty clone".
60 -- More concretely, 'addBuildableCondition' will make `libVisibility = False`
61 -- libraries when `buildable: false`. This may cause problems.
62 instance Monoid Library
where
66 instance Semigroup Library
where
69 { libName
= combineLibraryName
(libName a
) (libName b
)
70 , exposedModules
= combine exposedModules
71 , reexportedModules
= combine reexportedModules
72 , signatures
= combine signatures
73 , libExposed
= libExposed a
&& libExposed b
-- so False propagates
74 , libVisibility
= combine libVisibility
75 , libBuildInfo
= combine libBuildInfo
78 combine field
= field a `mappend` field b
80 -- | Get all the module names from the library (exposed and internal modules)
81 -- which are explicitly listed in the package description which would
82 -- need to be compiled. (This does not include reexports, which
83 -- do not need to be compiled.) This may not include all modules for which
84 -- GHC generated interface files (i.e., implicit modules.)
85 explicitLibModules
:: Library
-> [ModuleName
]
86 explicitLibModules lib
=
88 ++ otherModules
(libBuildInfo lib
)
91 -- | Get all the auto generated module names from the library, exposed or not.
92 -- This are a subset of 'libModules'.
93 libModulesAutogen
:: Library
-> [ModuleName
]
94 libModulesAutogen lib
= autogenModules
(libBuildInfo lib
)
96 -- | Combine 'LibraryName'. in parsing we prefer value coming
97 -- from munged @name@ field over the @lib-name@.
99 -- /Should/ be irrelevant.
100 combineLibraryName
:: LibraryName
-> LibraryName
-> LibraryName
101 combineLibraryName l
@(LSubLibName _
) _
= l
102 combineLibraryName _ l
= l