@@ -19,15 +19,14 @@ import Distribution.Compat.Prelude hiding ((<>))
19
19
20
20
import Distribution.Backpack.Id
21
21
22
- import Distribution.Types.Dependency
23
22
import Distribution.Types.ExeDependency
24
23
import Distribution.Types.IncludeRenaming
25
24
import Distribution.Types.ComponentId
26
25
import Distribution.Types.PackageId
27
26
import Distribution.Types.PackageName
27
+ import Distribution.Types.LibDependency
28
28
import Distribution.Types.Mixin
29
29
import Distribution.Types.ComponentName
30
- import Distribution.Types.UnqualComponentName
31
30
import Distribution.Types.ComponentInclude
32
31
import Distribution.Package
33
32
import Distribution.PackageDescription as PD hiding (Flag )
@@ -39,7 +38,6 @@ import Distribution.Utils.LogProgress
39
38
import Distribution.Utils.MapAccum
40
39
41
40
import Control.Monad
42
- import qualified Data.Set as Set
43
41
import qualified Data.Map as Map
44
42
import Distribution.Text
45
43
import Text.PrettyPrint
@@ -85,85 +83,84 @@ dispConfiguredComponent cc =
85
83
| incl <- cc_includes cc
86
84
])
87
85
86
+ -- | This is a mapping that keeps track of package-internal libraries
87
+ -- and executables. Although a component of the key is a general
88
+ -- 'ComponentName', actually only 'CLib', 'CSubLib' and 'CExe' will ever
89
+ -- be here.
88
90
type ConfiguredComponentMap =
89
91
Map PackageName (Map ComponentName (ComponentId , PackageId ))
90
92
93
+ -- Executable map must be different because an executable can
94
+ -- have the same name as a library. Ew.
95
+
96
+ -- | Given some ambient environment of package names that
97
+ -- are "in scope", looks at the 'BuildInfo' to decide
98
+ -- what the packages actually resolve to, and then builds
99
+ -- a 'ConfiguredComponent'.
91
100
toConfiguredComponent
92
101
:: PackageDescription
93
102
-> ComponentId
94
103
-> ConfiguredComponentMap
95
104
-> Component
96
105
-> LogProgress ConfiguredComponent
97
106
toConfiguredComponent pkg_descr this_cid dep_map component = do
98
- lib_deps <-
99
- if newPackageDepsBehaviour pkg_descr
100
- then forM (targetBuildDepends bi) $ \ (Dependency name _) -> do
101
- let keys@ (pn, cn) = fixFakePkgName pkg_descr name
102
- value <- case Map. lookup cn =<< Map. lookup pn dep_map of
103
- Nothing ->
104
- dieProgress $
105
- text " Dependency on unbuildable" <+>
106
- text (showComponentName cn) <+>
107
- text " from" <+> disp pn
108
- Just v -> return v
109
- return (keys, value)
110
- else return old_style_lib_deps
111
-
112
- -- Resolve each @mixins@ into the actual dependency
113
- -- from @lib_deps@.
114
- explicit_includes <- forM (mixins bi) $ \ (Mixin name rns) -> do
115
- let (pkg, cname) = fixFakePkgName pkg_descr name
116
- (cid, pid) <-
117
- case Map. lookup cname =<< Map. lookup pkg dep_map of
118
- Nothing ->
119
- dieProgress $
120
- text " Mix-in refers to non-existent package" <+>
121
- quotes (disp name) $$
122
- text " (did you forget to add the package to build-depends?)"
123
- Just r -> return r
107
+ let reg_lib_deps =
108
+ if newPackageDepsBehaviour pkg_descr
109
+ then
110
+ [ (pn, cn)
111
+ | LibDependency pn mb_ln _ <- targetBuildDepends bi
112
+ , let cn = libraryComponentName mb_ln ]
113
+ else
114
+ -- dep_map contains a mix of internal and external deps.
115
+ -- We want all the public libraries (dep_cn == CLibName)
116
+ -- of all external deps (dep /= pn). Note that this
117
+ -- excludes the public library of the current package:
118
+ -- this is not supported by old-style deps behavior
119
+ -- because it would imply a cyclic dependency for the
120
+ -- library itself.
121
+ [ (pn, cn)
122
+ | (pn, comp_map) <- Map. toList dep_map
123
+ , pn /= packageName pkg_descr
124
+ , (cn, _) <- Map. toList comp_map
125
+ , cn == CLibName ]
126
+
127
+ reg_lib_map , mixin_map :: Map (PackageName , ComponentName ) (IncludeRenaming , Bool )
128
+
129
+ reg_lib_map = Map. fromList $
130
+ reg_lib_deps `zip` repeat (defaultIncludeRenaming, True )
131
+
132
+ mixin_map = Map. fromList
133
+ [ ((pn, cn), (rns, False ))
134
+ | Mixin pn mb_ln rns <- mixins bi
135
+ , let cn = libraryComponentName mb_ln ]
136
+
137
+ lib_deps = Map. toList $ reg_lib_map `Map.union` mixin_map
138
+
139
+ mixin_includes <- forM lib_deps $ \ ((pname, cname), (rns, implicit)) -> do
140
+ (cid, pid) <- case Map. lookup cname =<< Map. lookup pname dep_map of
141
+ Nothing -> dieProgress $
142
+ text " Dependency on unbuildable" <+>
143
+ text (showComponentName cname) <+>
144
+ text " from" <+> disp pname
145
+ Just r -> return r
124
146
return ComponentInclude {
125
147
ci_id = cid,
126
148
ci_pkgid = pid,
127
149
ci_compname = cname,
128
150
ci_renaming = rns,
129
- ci_implicit = False
151
+ ci_implicit = implicit
130
152
}
131
153
132
- -- Any @build-depends@ which is not explicitly mentioned in
133
- -- @backpack-include@ is converted into an "implicit" include.
134
- let used_explicitly = Set. fromList (map ci_id explicit_includes)
135
- implicit_includes
136
- = map (\ ((_, cn), (cid, pid)) -> ComponentInclude {
137
- ci_id = cid,
138
- ci_pkgid = pid,
139
- ci_compname = cn,
140
- ci_renaming = defaultIncludeRenaming,
141
- ci_implicit = True
142
- })
143
- $ filter (flip Set. notMember used_explicitly . fst . snd ) lib_deps
144
-
145
154
return ConfiguredComponent {
146
155
cc_cid = this_cid,
147
156
cc_pkgid = package pkg_descr,
148
157
cc_component = component,
149
158
cc_public = componentName component == CLibName ,
150
159
cc_exe_deps = exe_deps,
151
- cc_includes = explicit_includes ++ implicit_includes
160
+ cc_includes = mixin_includes
152
161
}
153
162
where
154
163
bi = componentBuildInfo component
155
- -- dep_map contains a mix of internal and external deps.
156
- -- We want all the public libraries (dep_cn == CLibName)
157
- -- of all external deps (dep /= pn). Note that this
158
- -- excludes the public library of the current package:
159
- -- this is not supported by old-style deps behavior
160
- -- because it would imply a cyclic dependency for the
161
- -- library itself.
162
- old_style_lib_deps = [ ((pn, cn), e)
163
- | (pn, comp_map) <- Map. toList dep_map
164
- , pn /= packageName pkg_descr
165
- , (cn, e) <- Map. toList comp_map
166
- , cn == CLibName ]
167
164
exe_deps =
168
165
[ exe
169
166
| ExeDependency pn cn _ <- getAllToolDependencies pkg_descr bi
@@ -249,16 +246,3 @@ newPackageDepsBehaviourMinVersion = mkVersion [1,7,1]
249
246
newPackageDepsBehaviour :: PackageDescription -> Bool
250
247
newPackageDepsBehaviour pkg =
251
248
specVersion pkg >= newPackageDepsBehaviourMinVersion
252
-
253
- -- | 'build-depends:' stanzas are currently ambiguous as the external packages
254
- -- and internal libraries are specified the same. For now, we assume internal
255
- -- libraries shadow, and this function disambiguates accordingly, but soon the
256
- -- underlying ambiguity will be addressed.
257
- fixFakePkgName :: PackageDescription -> PackageName -> (PackageName , ComponentName )
258
- fixFakePkgName pkg_descr pn =
259
- if subLibName `elem` internalLibraries
260
- then (packageName pkg_descr, CSubLibName subLibName)
261
- else (pn, CLibName )
262
- where
263
- subLibName = packageNameToUnqualComponentName pn
264
- internalLibraries = mapMaybe libName (allLibraries pkg_descr)
0 commit comments