@@ -7,6 +7,7 @@ import Prelude ()
7
7
8
8
import qualified Data.List as L
9
9
import qualified Data.Map.Strict as M
10
+ import qualified Distribution.Compat.NonEmptySet as NonEmptySet
10
11
import qualified Data.Set as S
11
12
12
13
import qualified Distribution.InstalledPackageInfo as IPI
@@ -25,6 +26,7 @@ import Distribution.PackageDescription.Configuration
25
26
import qualified Distribution.Simple.PackageIndex as SI
26
27
import Distribution.System
27
28
import Distribution.Types.ForeignLib
29
+ import Distribution.Types.LibraryVisibility
28
30
29
31
import Distribution.Solver.Types.ComponentDeps
30
32
( Component (.. ), componentNameToComponent )
@@ -92,11 +94,18 @@ convIP :: SI.InstalledPackageIndex -> IPI.InstalledPackageInfo -> (PN, I, PInfo)
92
94
convIP idx ipi =
93
95
case traverse (convIPId (DependencyReason pn M. empty S. empty) comp idx) (IPI. depends ipi) of
94
96
Nothing -> (pn, i, PInfo [] M. empty M. empty (Just Broken ))
95
- Just fds -> ( pn
96
- , i
97
- , PInfo fds (M. singleton ExposedLib (IsBuildable True )) M. empty Nothing )
97
+ Just fds -> ( pn, i, PInfo fds components M. empty Nothing )
98
98
where
99
+ -- TODO: Handle sub-libraries and visibility.
100
+ components =
101
+ M. singleton (ExposedLib LMainLibName )
102
+ ComponentInfo {
103
+ compIsVisible = IsVisible True
104
+ , compIsBuildable = IsBuildable True
105
+ }
106
+
99
107
(pn, i) = convId ipi
108
+
100
109
-- 'sourceLibName' is unreliable, but for now we only really use this for
101
110
-- primary libs anyways
102
111
comp = componentNameToComponent $ CLibName $ IPI. sourceLibName ipi
@@ -140,7 +149,8 @@ convIPId dr comp idx ipid =
140
149
case SI. lookupUnitId idx ipid of
141
150
Nothing -> Nothing
142
151
Just ipi -> let (pn, i) = convId ipi
143
- in Just (D. Simple (LDep dr (Dep (PkgComponent pn ExposedLib ) (Fixed i))) comp)
152
+ name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
153
+ in Just (D. Simple (LDep dr (Dep (PkgComponent pn name) (Fixed i))) comp)
144
154
-- NB: something we pick up from the
145
155
-- InstalledPackageIndex is NEVER an executable
146
156
@@ -213,34 +223,52 @@ convGPD os arch cinfo constraints strfl solveExes pn
213
223
Just ver -> Just (UnsupportedSpecVer ver)
214
224
Nothing -> Nothing
215
225
216
- components :: Map ExposedComponent IsBuildable
217
- components = M. fromList $ libComps ++ exeComps
226
+ components :: Map ExposedComponent ComponentInfo
227
+ components = M. fromList $ libComps ++ subLibComps ++ exeComps
218
228
where
219
- libComps = [ (ExposedLib , IsBuildable $ isBuildable libBuildInfo lib)
229
+ libComps = [ (ExposedLib LMainLibName , libToComponentInfo lib)
220
230
| lib <- maybeToList mlib ]
221
- exeComps = [ (ExposedExe name, IsBuildable $ isBuildable buildInfo exe)
231
+ subLibComps = [ (ExposedLib (LSubLibName name), libToComponentInfo lib)
232
+ | (name, lib) <- sub_libs ]
233
+ exeComps = [ ( ExposedExe name
234
+ , ComponentInfo {
235
+ compIsVisible = IsVisible True
236
+ , compIsBuildable = IsBuildable $ testCondition (buildable . buildInfo) exe /= Just False
237
+ }
238
+ )
222
239
| (name, exe) <- exes ]
223
- isBuildable = isBuildableComponent os arch cinfo constraints
240
+
241
+ libToComponentInfo lib =
242
+ ComponentInfo {
243
+ compIsVisible = IsVisible $ testCondition (isPrivate . libVisibility) lib /= Just True
244
+ , compIsBuildable = IsBuildable $ testCondition (buildable . libBuildInfo) lib /= Just False
245
+ }
246
+
247
+ testCondition = testConditionForComponent os arch cinfo constraints
248
+
249
+ isPrivate LibraryVisibilityPrivate = True
250
+ isPrivate LibraryVisibilityPublic = False
224
251
225
252
in PInfo flagged_deps components fds fr
226
253
227
- -- | Returns true if the component is buildable in the given environment.
228
- -- This function can give false-positives. For example, it only considers flags
229
- -- that are set by unqualified flag constraints, and it doesn't check whether
230
- -- the intra-package dependencies of a component are buildable. It is also
231
- -- possible for the solver to later assign a value to an automatic flag that
232
- -- makes the component unbuildable.
233
- isBuildableComponent :: OS
234
- -> Arch
235
- -> CompilerInfo
236
- -> [LabeledPackageConstraint ]
237
- -> (a -> BuildInfo )
238
- -> CondTree ConfVar [Dependency ] a
239
- -> Bool
240
- isBuildableComponent os arch cinfo constraints getInfo tree =
241
- case simplifyCondition $ extractCondition (buildable . getInfo) tree of
242
- Lit False -> False
243
- _ -> True
254
+ -- | Applies the given predicate (for example, testing buildability or
255
+ -- visibility) to the given component and environment. Values are combined with
256
+ -- AND. This function returns 'Nothing' when the result cannot be determined
257
+ -- before dependency solving. Additionally, this function only considers flags
258
+ -- that are set by unqualified flag constraints, and it doesn't check the
259
+ -- intra-package dependencies of a component.
260
+ testConditionForComponent :: OS
261
+ -> Arch
262
+ -> CompilerInfo
263
+ -> [LabeledPackageConstraint ]
264
+ -> (a -> Bool )
265
+ -> CondTree ConfVar [Dependency ] a
266
+ -> Maybe Bool
267
+ testConditionForComponent os arch cinfo constraints p tree =
268
+ case simplifyCondition $ extractCondition p tree of
269
+ Lit True -> Just True
270
+ Lit False -> Just False
271
+ _ -> Nothing
244
272
where
245
273
flagAssignment :: [(FlagName , Bool )]
246
274
flagAssignment =
@@ -332,8 +360,10 @@ convCondTree flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes@(Solv
332
360
-- duplicates could grow exponentially from the leaves to the root
333
361
-- of the tree.
334
362
mergeSimpleDeps $
335
- L. map (\ d -> D. Simple (convLibDep dr d) comp)
336
- (mapMaybe (filterIPNs ipns) ds) -- unconditional package dependencies
363
+ [ D. Simple singleDep comp
364
+ | dep <- mapMaybe (filterIPNs ipns) ds
365
+ , singleDep <- convLibDeps dr dep ] -- unconditional package dependencies
366
+
337
367
++ L. map (\ e -> D. Simple (LDep dr (Ext e)) comp) (allExtensions bi) -- unconditional extension dependencies
338
368
++ L. map (\ l -> D. Simple (LDep dr (Lang l)) comp) (allLanguages bi) -- unconditional language dependencies
339
369
++ L. map (\ (PkgconfigDependency pkn vr) -> D. Simple (LDep dr (Pkg pkn vr)) comp) (pkgconfigDepends bi) -- unconditional pkg-config dependencies
@@ -537,9 +567,12 @@ unionDRs :: DependencyReason pn -> DependencyReason pn -> DependencyReason pn
537
567
unionDRs (DependencyReason pn' fs1 ss1) (DependencyReason _ fs2 ss2) =
538
568
DependencyReason pn' (M. union fs1 fs2) (S. union ss1 ss2)
539
569
540
- -- | Convert a Cabal dependency on a library to a solver-specific dependency.
541
- convLibDep :: DependencyReason PN -> Dependency -> LDep PN
542
- convLibDep dr (Dependency pn vr _) = LDep dr $ Dep (PkgComponent pn ExposedLib ) (Constrained vr)
570
+ -- | Convert a Cabal dependency on a set of library components (from a single
571
+ -- package) to solver-specific dependencies.
572
+ convLibDeps :: DependencyReason PN -> Dependency -> [LDep PN ]
573
+ convLibDeps dr (Dependency pn vr libs) =
574
+ [ LDep dr $ Dep (PkgComponent pn (ExposedLib lib)) (Constrained vr)
575
+ | lib <- NonEmptySet. toList libs ]
543
576
544
577
-- | Convert a Cabal dependency on an executable (build-tools) to a solver-specific dependency.
545
578
convExeDep :: DependencyReason PN -> ExeDependency -> LDep PN
@@ -548,5 +581,6 @@ convExeDep dr (ExeDependency pn exe vr) = LDep dr $ Dep (PkgComponent pn (Expose
548
581
-- | Convert setup dependencies
549
582
convSetupBuildInfo :: PN -> SetupBuildInfo -> FlaggedDeps PN
550
583
convSetupBuildInfo pn nfo =
551
- L. map (\ d -> D. Simple (convLibDep (DependencyReason pn M. empty S. empty) d) ComponentSetup )
552
- (setupDepends nfo)
584
+ [ D. Simple singleDep ComponentSetup
585
+ | dep <- setupDepends nfo
586
+ , singleDep <- convLibDeps (DependencyReason pn M. empty S. empty) dep ]
0 commit comments