From 929d16a43881e7ece865ec83a5b8cd9bd2a9df53 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 13 Mar 2017 16:45:14 -0400 Subject: [PATCH] Inline `mkConfiguredComponent` --- .../Backpack/ConfiguredComponent.hs | 66 +++++++------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/Cabal/Distribution/Backpack/ConfiguredComponent.hs b/Cabal/Distribution/Backpack/ConfiguredComponent.hs index 0c0da1b6d62..4709f45f241 100644 --- a/Cabal/Distribution/Backpack/ConfiguredComponent.hs +++ b/Cabal/Distribution/Backpack/ConfiguredComponent.hs @@ -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" <+> @@ -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.