@@ -22,15 +22,14 @@ import Distribution.Compat.Prelude hiding ((<>))
22
22
import Distribution.Backpack.Id
23
23
24
24
import Distribution.Types.AnnotatedId
25
- import Distribution.Types.Dependency
25
+ import Distribution.Types.LibDependency
26
26
import Distribution.Types.ExeDependency
27
27
import Distribution.Types.IncludeRenaming
28
28
import Distribution.Types.ComponentId
29
29
import Distribution.Types.PackageId
30
30
import Distribution.Types.PackageName
31
31
import Distribution.Types.Mixin
32
32
import Distribution.Types.ComponentName
33
- import Distribution.Types.UnqualComponentName
34
33
import Distribution.Types.ComponentInclude
35
34
import Distribution.Package
36
35
import Distribution.PackageDescription as PD hiding (Flag )
@@ -43,7 +42,6 @@ import Distribution.Utils.MapAccum
43
42
import Distribution.Utils.Generic
44
43
45
44
import Control.Monad
46
- import qualified Data.Set as Set
47
45
import qualified Data.Map as Map
48
46
import Distribution.Text
49
47
import Text.PrettyPrint
@@ -96,59 +94,72 @@ dispConfiguredComponent cc =
96
94
| incl <- cc_includes cc
97
95
])
98
96
97
+ -- | This is a mapping that keeps track of package-internal libraries
98
+ -- and executables. Although a component of the key is a general
99
+ -- 'ComponentName', actually only 'CLib', 'CSubLib' and 'CExe' will ever
100
+ -- be here.
99
101
type ConfiguredComponentMap =
100
102
Map PackageName (Map ComponentName (AnnotatedId ComponentId ))
101
103
104
+ -- Executable map must be different because an executable can
105
+ -- have the same name as a library. Ew.
106
+
107
+ -- | Given some ambient environment of package names that
108
+ -- are "in scope", looks at the 'BuildInfo' to decide
109
+ -- what the packages actually resolve to, and then builds
110
+ -- a 'ConfiguredComponent'.
102
111
toConfiguredComponent
103
112
:: PackageDescription
104
113
-> ComponentId
105
114
-> ConfiguredComponentMap
106
115
-> Component
107
116
-> LogProgress ConfiguredComponent
108
117
toConfiguredComponent pkg_descr this_cid dep_map component = do
109
- lib_deps <-
110
- if newPackageDepsBehaviour pkg_descr
111
- then forM (targetBuildDepends bi) $ \ (Dependency name _) -> do
112
- let (pn, cn) = fixFakePkgName pkg_descr name
113
- value <- case Map. lookup cn =<< Map. lookup pn dep_map of
114
- Nothing ->
115
- dieProgress $
116
- text " Dependency on unbuildable" <+>
117
- text (showComponentName cn) <+>
118
- text " from" <+> disp pn
119
- Just v -> return v
120
- return value
121
- else return old_style_lib_deps
118
+ let reg_lib_deps =
119
+ if newPackageDepsBehaviour pkg_descr
120
+ then
121
+ [ (pn, cn)
122
+ | LibDependency pn mb_ln _ <- targetBuildDepends bi
123
+ , let cn = libraryComponentName mb_ln ]
124
+ else
125
+ -- dep_map contains a mix of internal and external deps.
126
+ -- We want all the public libraries (dep_cn == CLibName)
127
+ -- of all external deps (dep /= pn). Note that this
128
+ -- excludes the public library of the current package:
129
+ -- this is not supported by old-style deps behavior
130
+ -- because it would imply a cyclic dependency for the
131
+ -- library itself.
132
+ [ (pn, cn)
133
+ | (pn, comp_map) <- Map. toList dep_map
134
+ , pn /= packageName pkg_descr
135
+ , (cn, _) <- Map. toList comp_map
136
+ , cn == CLibName ]
137
+
138
+ reg_lib_map , mixin_map :: Map (PackageName , ComponentName ) (IncludeRenaming , Bool )
139
+
140
+ reg_lib_map = Map. fromList $
141
+ reg_lib_deps `zip` repeat (defaultIncludeRenaming, True )
142
+
143
+ mixin_map = Map. fromList
144
+ [ ((pn, cn), (rns, False ))
145
+ | Mixin pn mb_ln rns <- mixins bi
146
+ , let cn = libraryComponentName mb_ln ]
122
147
123
- -- Resolve each @mixins@ into the actual dependency
124
- -- from @lib_deps@.
125
- explicit_includes <- forM (mixins bi) $ \ (Mixin name rns) -> do
126
- let (pkg, cname) = fixFakePkgName pkg_descr name
127
- aid <-
128
- case Map. lookup cname =<< Map. lookup pkg dep_map of
129
- Nothing ->
130
- dieProgress $
131
- text " Mix-in refers to non-existent package" <+>
132
- quotes (disp name) $$
133
- text " (did you forget to add the package to build-depends?)"
134
- Just r -> return r
148
+ lib_deps = Map. toList $ reg_lib_map `Map.union` mixin_map
149
+
150
+ mixin_includes <- forM lib_deps $ \ ((pname, cname), (rns, implicit)) -> do
151
+ aid <- case Map. lookup cname =<< Map. lookup pname dep_map of
152
+ Nothing -> dieProgress $
153
+ text " Dependency on unbuildable" <+>
154
+ text (showComponentName cname) <+>
155
+ text " from" <+> disp pname
156
+ Just r -> return r
135
157
return ComponentInclude {
136
158
ci_ann_id = aid,
137
159
ci_renaming = rns,
138
- ci_implicit = False
160
+ ci_implicit = implicit
139
161
}
140
162
141
- -- Any @build-depends@ which is not explicitly mentioned in
142
- -- @backpack-include@ is converted into an "implicit" include.
143
- let used_explicitly = Set. fromList (map ci_id explicit_includes)
144
- implicit_includes
145
- = map (\ aid -> ComponentInclude {
146
- ci_ann_id = aid,
147
- ci_renaming = defaultIncludeRenaming,
148
- ci_implicit = True
149
- })
150
- $ filter (flip Set. notMember used_explicitly . ann_id) lib_deps
151
-
152
163
return ConfiguredComponent {
153
164
cc_ann_id = AnnotatedId {
154
165
ann_id = this_cid,
@@ -158,22 +169,10 @@ toConfiguredComponent pkg_descr this_cid dep_map component = do
158
169
cc_component = component,
159
170
cc_public = componentName component == CLibName ,
160
171
cc_exe_deps = exe_deps,
161
- cc_includes = explicit_includes ++ implicit_includes
172
+ cc_includes = mixin_includes
162
173
}
163
174
where
164
175
bi = componentBuildInfo component
165
- -- dep_map contains a mix of internal and external deps.
166
- -- We want all the public libraries (dep_cn == CLibName)
167
- -- of all external deps (dep /= pn). Note that this
168
- -- excludes the public library of the current package:
169
- -- this is not supported by old-style deps behavior
170
- -- because it would imply a cyclic dependency for the
171
- -- library itself.
172
- old_style_lib_deps = [ e
173
- | (pn, comp_map) <- Map. toList dep_map
174
- , pn /= packageName pkg_descr
175
- , (cn, e) <- Map. toList comp_map
176
- , cn == CLibName ]
177
176
-- We have to nub here, because 'getAllToolDependencies' may return
178
177
-- duplicates (see #4986). (NB: This is not needed for lib_deps,
179
178
-- since those elaborate into includes, for which there explicitly
@@ -264,16 +263,3 @@ newPackageDepsBehaviourMinVersion = mkVersion [1,7,1]
264
263
newPackageDepsBehaviour :: PackageDescription -> Bool
265
264
newPackageDepsBehaviour pkg =
266
265
specVersion pkg >= newPackageDepsBehaviourMinVersion
267
-
268
- -- | 'build-depends:' stanzas are currently ambiguous as the external packages
269
- -- and internal libraries are specified the same. For now, we assume internal
270
- -- libraries shadow, and this function disambiguates accordingly, but soon the
271
- -- underlying ambiguity will be addressed.
272
- fixFakePkgName :: PackageDescription -> PackageName -> (PackageName , ComponentName )
273
- fixFakePkgName pkg_descr pn =
274
- if subLibName `elem` internalLibraries
275
- then (packageName pkg_descr, CSubLibName subLibName)
276
- else (pn, CLibName )
277
- where
278
- subLibName = packageNameToUnqualComponentName pn
279
- internalLibraries = mapMaybe libName (allLibraries pkg_descr)
0 commit comments