Skip to content

Commit

Permalink
Inline mkConfiguredComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Mar 14, 2017
1 parent fc7657a commit 929d16a
Showing 1 changed file with 24 additions and 42 deletions.
66 changes: 24 additions & 42 deletions Cabal/Distribution/Backpack/ConfiguredComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,36 @@ dispConfiguredComponent cc =
| incl <- cc_includes cc
])

-- | Construct a 'ConfiguredComponent', given that the 'ComponentId'
-- and library/executable dependencies are known. The primary
-- work this does is handling implicit @backpack-include@ fields.
mkConfiguredComponent
type ConfiguredComponentMap =
Map PackageName (Map ComponentName (ComponentId, PackageId))

toConfiguredComponent
:: PackageDescription
-> ComponentId
-> [((PackageName, ComponentName), (ComponentId, PackageId))]
-> [(ComponentId, PackageId)]
-> ConfiguredComponentMap
-> Component
-> LogProgress ConfiguredComponent
mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do
toConfiguredComponent pkg_descr this_cid dep_map component = do
lib_deps <-
if newPackageDepsBehaviour pkg_descr
then forM (targetBuildDepends bi) $ \(Dependency name _) -> do
let keys@(pn, cn) = fixFakePkgName pkg_descr name
value <- case Map.lookup cn =<< Map.lookup pn dep_map of
Nothing ->
dieProgress $
text "Dependency on unbuildable" <+>
text (showComponentName cn) <+>
text "from" <+> disp pn
Just v -> return v
return (keys, value)
else return old_style_lib_deps

-- Resolve each @mixins@ into the actual dependency
-- from @lib_deps@.
explicit_includes <- forM (mixins bi) $ \(Mixin name rns) -> do
let keys@(_, cname) = fixFakePkgName pkg_decr name
let (pkg, cname) = fixFakePkgName pkg_descr name
(cid, pid) <-
case Map.lookup keys deps_map of
case Map.lookup cname =<< Map.lookup pkg dep_map of
Nothing ->
dieProgress $
text "Mix-in refers to non-existent package" <+>
Expand Down Expand Up @@ -131,43 +144,12 @@ mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do

return ConfiguredComponent {
cc_cid = this_cid,
cc_pkgid = package pkg_decr,
cc_pkgid = package pkg_descr,
cc_component = component,
cc_public = is_public,
cc_public = componentName component == CLibName,
cc_exe_deps = exe_deps,
cc_includes = explicit_includes ++ implicit_includes
}
where
bi = componentBuildInfo component
deps_map = Map.fromList lib_deps
is_public = componentName component == CLibName

type ConfiguredComponentMap =
Map PackageName (Map ComponentName (ComponentId, PackageId))

toConfiguredComponent
:: PackageDescription
-> ComponentId
-> ConfiguredComponentMap
-> Component
-> LogProgress ConfiguredComponent
toConfiguredComponent pkg_descr this_cid dep_map component = do
lib_deps <-
if newPackageDepsBehaviour pkg_descr
then forM (targetBuildDepends bi) $ \(Dependency name _) -> do
let keys@(pn, cn) = fixFakePkgName pkg_descr name
value <- case Map.lookup cn =<< Map.lookup pn dep_map of
Nothing ->
dieProgress $
text "Dependency on unbuildable" <+>
text (showComponentName cn) <+>
text "from" <+> disp pn
Just v -> return v
return (keys, value)
else return old_style_lib_deps
mkConfiguredComponent
pkg_descr this_cid
lib_deps exe_deps component
where
bi = componentBuildInfo component
-- dep_map contains a mix of internal and external deps.
Expand Down

0 comments on commit 929d16a

Please sign in to comment.