From d751bfe997fc444bc9c8652618538c76a568b79b Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Thu, 9 Aug 2018 08:31:36 +0200 Subject: [PATCH] Move CLibName and CSubLibName to a separate type This gives us more type safety when dealing with libraries only --- Cabal/Cabal.cabal | 1 + .../Distribution/Backpack/ComponentsGraph.hs | 4 +- .../Backpack/ConfiguredComponent.hs | 8 +-- Cabal/Distribution/Backpack/ModuleScope.hs | 5 +- Cabal/Distribution/Backpack/ReadyComponent.hs | 5 +- Cabal/Distribution/Backpack/UnifyM.hs | 4 +- Cabal/Distribution/InstalledPackageInfo.hs | 5 +- Cabal/Distribution/PackageDescription.hs | 2 + .../PackageDescription/Configuration.hs | 6 +- Cabal/Distribution/Simple/Build.hs | 2 +- Cabal/Distribution/Simple/BuildTarget.hs | 7 +-- Cabal/Distribution/Simple/Configure.hs | 12 ++-- Cabal/Distribution/Simple/LocalBuildInfo.hs | 5 +- Cabal/Distribution/Simple/Setup.hs | 13 ++-- Cabal/Distribution/Types/ComponentName.hs | 31 ++++----- Cabal/Distribution/Types/GivenComponent.hs | 9 +-- Cabal/Distribution/Types/LibraryName.hs | 63 +++++++++++++++++++ Cabal/Distribution/Types/LocalBuildInfo.hs | 6 +- .../Distribution/Types/PackageDescription.hs | 5 +- .../Types/PackageDescription/Lens.hs | 9 +-- .../Distribution/Client/CmdErrorMessages.hs | 6 +- .../Distribution/Client/CmdInstall.hs | 7 +-- .../Distribution/Client/Configure.hs | 9 ++- .../Distribution/Client/DistDirLayout.hs | 7 ++- cabal-install/Distribution/Client/Install.hs | 16 ++++- .../Distribution/Client/InstallPlan.hs | 2 +- .../Distribution/Client/ProjectBuilding.hs | 15 ++--- .../Distribution/Client/ProjectPlanning.hs | 36 ++++++----- .../Client/ProjectPlanning/Types.hs | 14 ++--- cabal-install/Distribution/Client/Setup.hs | 11 ++-- .../Distribution/Client/TargetSelector.hs | 20 +++--- cabal-install/Distribution/Client/Types.hs | 4 +- .../Solver/Types/ComponentDeps.hs | 5 +- cabal-install/tests/IntegrationTests2.hs | 44 ++++++------- .../Executable/setup-static.test.hs | 2 +- 35 files changed, 242 insertions(+), 158 deletions(-) create mode 100644 Cabal/Distribution/Types/LibraryName.hs diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 458ae697076..3eec84699f9 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -343,6 +343,7 @@ library Distribution.Types.ModuleReexport Distribution.Types.ModuleRenaming Distribution.Types.ComponentName + Distribution.Types.LibraryName Distribution.Types.MungedPackageName Distribution.Types.PackageName Distribution.Types.PkgconfigName diff --git a/Cabal/Distribution/Backpack/ComponentsGraph.hs b/Cabal/Distribution/Backpack/ComponentsGraph.hs index 9b03638355c..bcd30fe0729 100644 --- a/Cabal/Distribution/Backpack/ComponentsGraph.hs +++ b/Cabal/Distribution/Backpack/ComponentsGraph.hs @@ -66,8 +66,8 @@ mkComponentsGraph enabled pkg_descr = (CExeName <$> getAllInternalToolDependencies pkg_descr bi) ++ [ if pkgname == packageName pkg_descr - then CLibName - else CSubLibName toolname + then CLibName LMainLibName + else CLibName (LSubLibName toolname) | Dependency pkgname _ <- targetBuildDepends bi , let toolname = packageNameToUnqualComponentName pkgname , toolname `elem` internalPkgDeps ] diff --git a/Cabal/Distribution/Backpack/ConfiguredComponent.hs b/Cabal/Distribution/Backpack/ConfiguredComponent.hs index dab40667099..1bfd84965ad 100644 --- a/Cabal/Distribution/Backpack/ConfiguredComponent.hs +++ b/Cabal/Distribution/Backpack/ConfiguredComponent.hs @@ -150,7 +150,7 @@ mkConfiguredComponent pkg_descr this_cid lib_deps exe_deps component = do bi = componentBuildInfo component deps_map = Map.fromList [ ((packageName dep, ann_cname dep), dep) | dep <- lib_deps ] - is_public = componentName component == CLibName + is_public = componentName component == CLibName LMainLibName type ConfiguredComponentMap = Map PackageName (Map ComponentName (AnnotatedId ComponentId)) @@ -192,7 +192,7 @@ toConfiguredComponent pkg_descr this_cid lib_dep_map exe_dep_map component = do | (pn, comp_map) <- Map.toList lib_dep_map , pn /= packageName pkg_descr , (cn, e) <- Map.toList comp_map - , cn == CLibName ] + , cn == CLibName LMainLibName ] -- We have to nub here, because 'getAllToolDependencies' may return -- duplicates (see #4986). (NB: This is not needed for lib_deps, -- since those elaborate into includes, for which there explicitly @@ -296,8 +296,8 @@ newPackageDepsBehaviour pkg = fixFakePkgName :: PackageDescription -> PackageName -> (PackageName, ComponentName) fixFakePkgName pkg_descr pn = if subLibName `elem` internalLibraries - then (packageName pkg_descr, CSubLibName subLibName) - else (pn, CLibName) + then (packageName pkg_descr, CLibName (LSubLibName subLibName)) + else (pn, CLibName LMainLibName ) where subLibName = packageNameToUnqualComponentName pn internalLibraries = mapMaybe libName (allLibraries pkg_descr) diff --git a/Cabal/Distribution/Backpack/ModuleScope.hs b/Cabal/Distribution/Backpack/ModuleScope.hs index 8926a61582d..3adf6285600 100644 --- a/Cabal/Distribution/Backpack/ModuleScope.hs +++ b/Cabal/Distribution/Backpack/ModuleScope.hs @@ -23,6 +23,7 @@ import Distribution.ModuleName import Distribution.Types.IncludeRenaming import Distribution.Types.PackageName import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Backpack import Distribution.Backpack.ModSubst @@ -113,8 +114,8 @@ dispComponent pn cn = -- should be clear enough. To do source syntax, we'd -- need to know what the package we're linking is. case cn of - CLibName -> disp pn - CSubLibName ucn -> disp pn <<>> colon <<>> disp ucn + CLibName LMainLibName -> disp pn + CLibName (LSubLibName ucn) -> disp pn <<>> colon <<>> disp ucn -- Case below shouldn't happen _ -> disp pn <+> parens (disp cn) diff --git a/Cabal/Distribution/Backpack/ReadyComponent.hs b/Cabal/Distribution/Backpack/ReadyComponent.hs index db09121775b..90816aef2ea 100644 --- a/Cabal/Distribution/Backpack/ReadyComponent.hs +++ b/Cabal/Distribution/Backpack/ReadyComponent.hs @@ -25,6 +25,7 @@ import Distribution.Types.Component import Distribution.Types.ComponentInclude import Distribution.Types.ComponentId import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Types.PackageId import Distribution.Types.UnitId import Distribution.Compat.Graph (IsNode(..)) @@ -139,8 +140,8 @@ rc_depends rc = ordNub $ computeCompatPackageId (ci_pkgid ci) (case ci_cname ci of - CLibName -> Nothing - CSubLibName uqn -> Just uqn + CLibName LMainLibName -> Nothing + CLibName (LSubLibName uqn) -> Just uqn _ -> error $ display (rc_cid rc) ++ " depends on non-library " ++ display (ci_id ci)) diff --git a/Cabal/Distribution/Backpack/UnifyM.hs b/Cabal/Distribution/Backpack/UnifyM.hs index 97fc3917534..95a0a423431 100644 --- a/Cabal/Distribution/Backpack/UnifyM.hs +++ b/Cabal/Distribution/Backpack/UnifyM.hs @@ -441,8 +441,8 @@ ci_msg ci pn = pkgName (ci_pkgid ci) pp_pn = case ci_cname ci of - CLibName -> disp pn - CSubLibName cn -> disp pn <<>> colon <<>> disp cn + CLibName LMainLibName -> disp pn + CLibName (LSubLibName cn) -> disp pn <<>> colon <<>> disp cn -- Shouldn't happen cn -> disp pn <+> parens (disp cn) diff --git a/Cabal/Distribution/InstalledPackageInfo.hs b/Cabal/Distribution/InstalledPackageInfo.hs index a5c84b23966..2710801e363 100644 --- a/Cabal/Distribution/InstalledPackageInfo.hs +++ b/Cabal/Distribution/InstalledPackageInfo.hs @@ -54,6 +54,7 @@ import Distribution.ModuleName import Distribution.Package hiding (installedPackageId, installedUnitId) import Distribution.ParseUtils import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Utils.Generic (toUTF8BS) import qualified Data.Map as Map @@ -104,8 +105,8 @@ installedPackageId = installedUnitId sourceComponentName :: InstalledPackageInfo -> ComponentName sourceComponentName ipi = case sourceLibName ipi of - Nothing -> CLibName - Just qn -> CSubLibName qn + Nothing -> CLibName LMainLibName + Just qn -> CLibName $ LSubLibName qn -- ----------------------------------------------------------------------------- -- Parsing diff --git a/Cabal/Distribution/PackageDescription.hs b/Cabal/Distribution/PackageDescription.hs index bd3f8141f97..da527106353 100644 --- a/Cabal/Distribution/PackageDescription.hs +++ b/Cabal/Distribution/PackageDescription.hs @@ -86,6 +86,7 @@ module Distribution.PackageDescription ( allBuildDepends, enabledBuildDepends, ComponentName(..), + LibraryName(..), defaultLibName, HookedBuildInfo, emptyHookedBuildInfo, @@ -135,5 +136,6 @@ import Distribution.Types.CondTree import Distribution.Types.Condition import Distribution.Types.PackageDescription import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Types.HookedBuildInfo import Distribution.Types.SourceRepo diff --git a/Cabal/Distribution/PackageDescription/Configuration.hs b/Cabal/Distribution/PackageDescription/Configuration.hs index 896730b378a..59c8cb1cc43 100644 --- a/Cabal/Distribution/PackageDescription/Configuration.hs +++ b/Cabal/Distribution/PackageDescription/Configuration.hs @@ -344,12 +344,14 @@ overallDependencies enabled (TargetSet targets) = mconcat depss -- UGH. The embedded componentName in the 'Component's here is -- BLANK. I don't know whose fault this is but I'll use the tag -- instead. -- ezyang - removeDisabledSections (Lib _) = componentNameRequested enabled CLibName + removeDisabledSections (Lib _) = componentNameRequested + enabled + (CLibName LMainLibName) removeDisabledSections (SubComp t c) -- Do NOT use componentName = componentNameRequested enabled $ case c of - CLib _ -> CSubLibName t + CLib _ -> CLibName (LSubLibName t) CFLib _ -> CFLibName t CExe _ -> CExeName t CTest _ -> CTestName t diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index ef4ed6b7348..2131552c7b0 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -470,7 +470,7 @@ testSuiteLibV09AsLibAndExe pkg_descr , componentInternalDeps = componentInternalDeps clbi , componentIsIndefinite_ = False , componentExeDeps = componentExeDeps clbi - , componentLocalName = CSubLibName (testName test) + , componentLocalName = CLibName $ LSubLibName $ testName test , componentIsPublic = False , componentIncludes = componentIncludes clbi , componentUnitId = componentUnitId clbi diff --git a/Cabal/Distribution/Simple/BuildTarget.hs b/Cabal/Distribution/Simple/BuildTarget.hs index 0a210db5521..7fc3583c6e1 100644 --- a/Cabal/Distribution/Simple/BuildTarget.hs +++ b/Cabal/Distribution/Simple/BuildTarget.hs @@ -502,8 +502,8 @@ pkgComponentInfo pkg = , let bi = componentBuildInfo c ] componentStringName :: Package pkg => pkg -> ComponentName -> ComponentStringName -componentStringName pkg CLibName = prettyShow (packageName pkg) -componentStringName _ (CSubLibName name) = unUnqualComponentName name +componentStringName pkg (CLibName LMainLibName ) = prettyShow (packageName pkg) +componentStringName _ (CLibName (LSubLibName name)) = unUnqualComponentName name componentStringName _ (CFLibName name) = unUnqualComponentName name componentStringName _ (CExeName name) = unUnqualComponentName name componentStringName _ (CTestName name) = unUnqualComponentName name @@ -555,8 +555,7 @@ data ComponentKind = LibKind | FLibKind | ExeKind | TestKind | BenchKind deriving (Eq, Ord, Show) componentKind :: ComponentName -> ComponentKind -componentKind CLibName = LibKind -componentKind (CSubLibName _) = LibKind +componentKind (CLibName _) = LibKind componentKind (CFLibName _) = FLibKind componentKind (CExeName _) = ExeKind componentKind (CTestName _) = TestKind diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 8aa7017e1cb..80699950804 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -889,7 +889,7 @@ dependencySatisfiable -- Except for internal deps, when we're NOT per-component mode; -- those are just True. then True - else (depName, CLibName) `Map.member` requiredDepsMap + else (depName, CLibName LMainLibName) `Map.member` requiredDepsMap | isInternalDep = if use_external_internal_deps @@ -1227,7 +1227,7 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap -- We have to look it up externally do_external is_internal = do - ipi <- case Map.lookup (dep_pkgname, CLibName) requiredDepsMap of + ipi <- case Map.lookup (dep_pkgname, CLibName LMainLibName) requiredDepsMap of -- If we know the exact pkg to use, then use it. Just pkginstance -> Right pkginstance -- Otherwise we just pick an arbitrary instance of the latest version. @@ -1410,8 +1410,8 @@ combinedConstraints constraints dependencies installedPackages = do dependenciesPkgInfo :: [(PackageName, ComponentName, ComponentId, Maybe InstalledPackageInfo)] dependenciesPkgInfo = - [ (pkgname, cname, cid, mpkg) - | GivenComponent pkgname cname cid <- dependencies + [ (pkgname, CLibName lname, cid, mpkg) + | GivenComponent pkgname lname cid <- dependencies , let mpkg = PackageIndex.lookupComponentId installedPackages cid ] @@ -1427,8 +1427,8 @@ combinedConstraints constraints dependencies installedPackages = do hsep [ text "--dependency=" <<>> quotes (pretty pkgname - <<>> case cname of CLibName -> "" - CSubLibName n -> ":" <<>> pretty n + <<>> case cname of CLibName LMainLibName -> "" + CLibName (LSubLibName n) -> ":" <<>> pretty n _ -> ":" <<>> pretty cname <<>> char '=' <<>> pretty cid) diff --git a/Cabal/Distribution/Simple/LocalBuildInfo.hs b/Cabal/Distribution/Simple/LocalBuildInfo.hs index 8258955c81c..70b0a276946 100644 --- a/Cabal/Distribution/Simple/LocalBuildInfo.hs +++ b/Cabal/Distribution/Simple/LocalBuildInfo.hs @@ -29,6 +29,7 @@ module Distribution.Simple.LocalBuildInfo ( -- * Buildable package components Component(..), ComponentName(..), + LibraryName(..), defaultLibName, showComponentName, componentNameString, @@ -108,11 +109,11 @@ componentBuildDir :: LocalBuildInfo -> ComponentLocalBuildInfo -> FilePath componentBuildDir lbi clbi = buildDir lbi case componentLocalName clbi of - CLibName -> + CLibName LMainLibName -> if prettyShow (componentUnitId clbi) == prettyShow (componentComponentId clbi) then "" else prettyShow (componentUnitId clbi) - CSubLibName s -> + CLibName (LSubLibName s) -> if prettyShow (componentUnitId clbi) == prettyShow (componentComponentId clbi) then unUnqualComponentName s else prettyShow (componentUnitId clbi) diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 88a1dfef8a9..997bd8f661f 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -652,9 +652,8 @@ configureOptions showOrParseArgs = (parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecGivenComponent)) (map (\(GivenComponent pn cn cid) -> prettyShow pn - ++ case cn of CLibName -> "" - CSubLibName n -> ":" ++ prettyShow n - _ -> ":" ++ prettyShow cn + ++ case cn of LMainLibName -> "" + LSubLibName n -> ":" ++ prettyShow n ++ "=" ++ prettyShow cid))) ,option "" ["instantiate-with"] @@ -740,15 +739,15 @@ showProfDetailLevelFlag (Flag dl) = [showProfDetailLevel dl] parsecGivenComponent :: ParsecParser GivenComponent parsecGivenComponent = do pn <- parsec - cn <- P.option CLibName $ do + ln <- P.option LMainLibName $ do _ <- P.char ':' ucn <- parsec return $ if unUnqualComponentName ucn == unPackageName pn - then CLibName - else CSubLibName ucn + then LMainLibName + else LSubLibName ucn _ <- P.char '=' cid <- parsec - return $ GivenComponent pn cn cid + return $ GivenComponent pn ln cid installDirsOptions :: [OptionField (InstallDirs (Flag PathTemplate))] installDirsOptions = diff --git a/Cabal/Distribution/Types/ComponentName.hs b/Cabal/Distribution/Types/ComponentName.hs index 444b8ca2e7f..36ed298bfc7 100644 --- a/Cabal/Distribution/Types/ComponentName.hs +++ b/Cabal/Distribution/Types/ComponentName.hs @@ -3,7 +3,6 @@ module Distribution.Types.ComponentName ( ComponentName(..), - defaultLibName, libraryComponentName, showComponentName, componentNameStanza, @@ -16,14 +15,14 @@ import Distribution.Compat.Prelude import qualified Distribution.Compat.ReadP as Parse import Distribution.Compat.ReadP ((<++)) import Distribution.Types.UnqualComponentName +import Distribution.Types.LibraryName import Distribution.Pretty import Distribution.Text import Text.PrettyPrint as Disp -- Libraries live in a separate namespace, so must distinguish -data ComponentName = CLibName - | CSubLibName UnqualComponentName +data ComponentName = CLibName LibraryName | CFLibName UnqualComponentName | CExeName UnqualComponentName | CTestName UnqualComponentName @@ -34,39 +33,32 @@ instance Binary ComponentName -- Build-target-ish syntax instance Pretty ComponentName where - pretty CLibName = Disp.text "lib" - pretty (CSubLibName str) = Disp.text "lib:" <<>> pretty str + pretty (CLibName lib) = pretty lib pretty (CFLibName str) = Disp.text "flib:" <<>> pretty str pretty (CExeName str) = Disp.text "exe:" <<>> pretty str pretty (CTestName str) = Disp.text "test:" <<>> pretty str pretty (CBenchName str) = Disp.text "bench:" <<>> pretty str instance Text ComponentName where - parse = parseComposite <++ parseSingle + parse = parseComposite <++ parseLib where - parseSingle = Parse.string "lib" >> return CLibName + parseLib = CLibName <$> parse parseComposite = do - ctor <- Parse.choice [ Parse.string "lib:" >> return CSubLibName - , Parse.string "flib:" >> return CFLibName + ctor <- Parse.choice [ Parse.string "flib:" >> return CFLibName , Parse.string "exe:" >> return CExeName , Parse.string "bench:" >> return CBenchName , Parse.string "test:" >> return CTestName ] ctor <$> parse -defaultLibName :: ComponentName -defaultLibName = CLibName - showComponentName :: ComponentName -> String -showComponentName CLibName = "library" -showComponentName (CSubLibName name) = "library '" ++ display name ++ "'" +showComponentName (CLibName lib) = showLibraryName lib showComponentName (CFLibName name) = "foreign library '" ++ display name ++ "'" showComponentName (CExeName name) = "executable '" ++ display name ++ "'" showComponentName (CTestName name) = "test suite '" ++ display name ++ "'" showComponentName (CBenchName name) = "benchmark '" ++ display name ++ "'" componentNameStanza :: ComponentName -> String -componentNameStanza CLibName = "library" -componentNameStanza (CSubLibName name) = "library " ++ display name +componentNameStanza (CLibName lib) = libraryNameStanza lib componentNameStanza (CFLibName name) = "foreign-library " ++ display name componentNameStanza (CExeName name) = "executable " ++ display name componentNameStanza (CTestName name) = "test-suite " ++ display name @@ -77,8 +69,7 @@ componentNameStanza (CBenchName name) = "benchmark " ++ display name -- @Nothing@ if the 'ComponentName' was for the public -- library. componentNameString :: ComponentName -> Maybe UnqualComponentName -componentNameString CLibName = Nothing -componentNameString (CSubLibName n) = Just n +componentNameString (CLibName lib) = libraryNameString lib componentNameString (CFLibName n) = Just n componentNameString (CExeName n) = Just n componentNameString (CTestName n) = Just n @@ -87,5 +78,5 @@ componentNameString (CBenchName n) = Just n -- | Convert the 'UnqualComponentName' of a library into a -- 'ComponentName'. libraryComponentName :: Maybe UnqualComponentName -> ComponentName -libraryComponentName Nothing = CLibName -libraryComponentName (Just n) = CSubLibName n +libraryComponentName Nothing = CLibName LMainLibName +libraryComponentName (Just n) = CLibName $ LSubLibName n diff --git a/Cabal/Distribution/Types/GivenComponent.hs b/Cabal/Distribution/Types/GivenComponent.hs index 93274a13418..ebbbf6d98eb 100644 --- a/Cabal/Distribution/Types/GivenComponent.hs +++ b/Cabal/Distribution/Types/GivenComponent.hs @@ -7,19 +7,20 @@ module Distribution.Types.GivenComponent ( import Distribution.Compat.Prelude import Distribution.Types.ComponentId -import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Types.PackageName --- | A 'GivenComponent' represents a component depended on and explicitly +-- | A 'GivenComponent' represents a library depended on and explicitly -- specified by the user/client with @--dependency@ -- --- It enables Cabal to know which 'ComponentId' to associate with a component +-- It enables Cabal to know which 'ComponentId' to associate with a library -- -- @since 2.3.0.0 data GivenComponent = GivenComponent { givenComponentPackage :: PackageName - , givenComponentName :: ComponentName + , givenComponentName :: LibraryName -- --dependency is for libraries + -- only, not for any component , givenComponentId :: ComponentId } deriving (Generic, Read, Show, Eq, Typeable) diff --git a/Cabal/Distribution/Types/LibraryName.hs b/Cabal/Distribution/Types/LibraryName.hs new file mode 100644 index 00000000000..63a1d849712 --- /dev/null +++ b/Cabal/Distribution/Types/LibraryName.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} + +module Distribution.Types.LibraryName ( + LibraryName(..), + defaultLibName, + maybeToLibraryName, + showLibraryName, + libraryNameStanza, + libraryNameString, + ) where + +import Prelude () +import Distribution.Compat.Prelude + +import qualified Distribution.Compat.ReadP as Parse +import Distribution.Compat.ReadP ((<++)) +import Distribution.Types.UnqualComponentName +import Distribution.Pretty +import Distribution.Text + +import Text.PrettyPrint as Disp + +data LibraryName = LMainLibName + | LSubLibName UnqualComponentName + deriving (Eq, Generic, Ord, Read, Show, Typeable) + +instance Binary LibraryName + +-- Build-target-ish syntax +instance Pretty LibraryName where + pretty LMainLibName = Disp.text "lib" + pretty (LSubLibName str) = Disp.text "lib:" <<>> pretty str + +instance Text LibraryName where + parse = parseComposite <++ parseSingle + where + parseSingle = Parse.string "lib" >> return LMainLibName + parseComposite = do + ctor <- Parse.string "lib:" >> return LSubLibName + ctor <$> parse + +defaultLibName :: LibraryName +defaultLibName = LMainLibName + +showLibraryName :: LibraryName -> String +showLibraryName LMainLibName = "library" +showLibraryName (LSubLibName name) = "library '" ++ display name ++ "'" + +libraryNameStanza :: LibraryName -> String +libraryNameStanza LMainLibName = "library" +libraryNameStanza (LSubLibName name) = "library " ++ display name + +libraryNameString :: LibraryName -> Maybe UnqualComponentName +libraryNameString LMainLibName = Nothing +libraryNameString (LSubLibName n) = Just n + +-- | Convert the 'UnqualComponentName' of a library into a +-- 'LibraryName'. +maybeToLibraryName :: Maybe UnqualComponentName -> LibraryName +maybeToLibraryName Nothing = LMainLibName +maybeToLibraryName (Just n) = LSubLibName n + diff --git a/Cabal/Distribution/Types/LocalBuildInfo.hs b/Cabal/Distribution/Types/LocalBuildInfo.hs index 8e79f73d856..0d586030c6e 100644 --- a/Cabal/Distribution/Types/LocalBuildInfo.hs +++ b/Cabal/Distribution/Types/LocalBuildInfo.hs @@ -176,7 +176,7 @@ instance Binary LocalBuildInfo -- on the package ID. localComponentId :: LocalBuildInfo -> ComponentId localComponentId lbi = - case componentNameCLBIs lbi CLibName of + case componentNameCLBIs lbi (CLibName LMainLibName) of [LibComponentLocalBuildInfo { componentComponentId = cid }] -> cid _ -> mkComponentId (display (localPackage lbi)) @@ -191,7 +191,7 @@ localPackage lbi = package (localPkgDescr lbi) -- the package ID. localUnitId :: LocalBuildInfo -> UnitId localUnitId lbi = - case componentNameCLBIs lbi CLibName of + case componentNameCLBIs lbi (CLibName LMainLibName) of [LibComponentLocalBuildInfo { componentUnitId = uid }] -> uid _ -> mkLegacyUnitId $ localPackage lbi @@ -201,7 +201,7 @@ localUnitId lbi = -- on the package ID. localCompatPackageKey :: LocalBuildInfo -> String localCompatPackageKey lbi = - case componentNameCLBIs lbi CLibName of + case componentNameCLBIs lbi (CLibName LMainLibName) of [LibComponentLocalBuildInfo { componentCompatPackageKey = pk }] -> pk _ -> display (localPackage lbi) diff --git a/Cabal/Distribution/Types/PackageDescription.hs b/Cabal/Distribution/Types/PackageDescription.hs index 0a6f519fce7..e1ec1b6a0ce 100644 --- a/Cabal/Distribution/Types/PackageDescription.hs +++ b/Cabal/Distribution/Types/PackageDescription.hs @@ -77,6 +77,7 @@ import Distribution.Types.ComponentRequestedSpec import Distribution.Types.Dependency import Distribution.Types.PackageId import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Types.PackageName import Distribution.Types.UnqualComponentName import Distribution.Types.SetupBuildInfo @@ -449,8 +450,8 @@ enabledComponents :: PackageDescription -> ComponentRequestedSpec -> [Component] enabledComponents pkg enabled = filter (componentEnabled enabled) $ pkgBuildableComponents pkg lookupComponent :: PackageDescription -> ComponentName -> Maybe Component -lookupComponent pkg CLibName = fmap CLib (library pkg) -lookupComponent pkg (CSubLibName name) = +lookupComponent pkg (CLibName LMainLibName) = fmap CLib (library pkg) +lookupComponent pkg (CLibName (LSubLibName name)) = fmap CLib $ find ((Just name ==) . libName) (subLibraries pkg) lookupComponent pkg (CFLibName name) = fmap CFLib $ find ((name ==) . foreignLibName) (foreignLibs pkg) diff --git a/Cabal/Distribution/Types/PackageDescription/Lens.hs b/Cabal/Distribution/Types/PackageDescription/Lens.hs index a5dbab3c05f..bcff4358934 100644 --- a/Cabal/Distribution/Types/PackageDescription/Lens.hs +++ b/Cabal/Distribution/Types/PackageDescription/Lens.hs @@ -23,6 +23,7 @@ import Distribution.Types.ForeignLib (ForeignLib, foreignLibModules) import Distribution.Types.ForeignLib.Lens (foreignLibName, foreignLibBuildInfo) import Distribution.Types.Library (Library, explicitLibModules) import Distribution.Types.Library.Lens (libName, libBuildInfo) +import Distribution.Types.LibraryName (LibraryName(..)) import Distribution.Types.PackageDescription (PackageDescription) import Distribution.Types.PackageId (PackageIdentifier) import Distribution.Types.SetupBuildInfo (SetupBuildInfo) @@ -158,8 +159,8 @@ extraDocFiles f s = fmap (\x -> s { T.extraDocFiles = x }) (f (T.extraDocFiles s -- | @since 2.4 componentModules :: Monoid r => ComponentName -> Getting r PackageDescription [ModuleName] componentModules cname = case cname of - CLibName -> library . traverse . getting explicitLibModules - CSubLibName name -> + CLibName LMainLibName -> library . traverse . getting explicitLibModules + CLibName (LSubLibName name) -> componentModules' name subLibraries (libName . non "") explicitLibModules CFLibName name -> componentModules' name foreignLibs foreignLibName foreignLibModules @@ -194,9 +195,9 @@ componentModules cname = case cname of -- | @since 2.4 componentBuildInfo :: ComponentName -> Traversal' PackageDescription BuildInfo componentBuildInfo cname = case cname of - CLibName -> + CLibName LMainLibName -> library . traverse . libBuildInfo - CSubLibName name -> + CLibName (LSubLibName name) -> componentBuildInfo' name subLibraries (libName . non "") libBuildInfo CFLibName name -> componentBuildInfo' name foreignLibs foreignLibName foreignLibBuildInfo diff --git a/cabal-install/Distribution/Client/CmdErrorMessages.hs b/cabal-install/Distribution/Client/CmdErrorMessages.hs index f11057d029b..3aedaa5b23a 100644 --- a/cabal-install/Distribution/Client/CmdErrorMessages.hs +++ b/cabal-install/Distribution/Client/CmdErrorMessages.hs @@ -15,6 +15,8 @@ import Distribution.Package ( packageId, PackageName, packageName ) import Distribution.Types.ComponentName ( showComponentName ) +import Distribution.Types.LibraryName + ( LibraryName(..) ) import Distribution.Solver.Types.OptionalStanza ( OptionalStanza(..) ) import Distribution.Text @@ -165,8 +167,8 @@ targetSelectorFilter TargetComponent{} = Nothing targetSelectorFilter TargetComponentUnknown{} = Nothing renderComponentName :: PackageName -> ComponentName -> String -renderComponentName pkgname CLibName = "library " ++ display pkgname -renderComponentName _ (CSubLibName name) = "library " ++ display name +renderComponentName pkgname (CLibName LMainLibName) = "library " ++ display pkgname +renderComponentName _ (CLibName (LSubLibName name)) = "library " ++ display name renderComponentName _ (CFLibName name) = "foreign library " ++ display name renderComponentName _ (CExeName name) = "executable " ++ display name renderComponentName _ (CTestName name) = "test suite " ++ display name diff --git a/cabal-install/Distribution/Client/CmdInstall.hs b/cabal-install/Distribution/Client/CmdInstall.hs index f3c354497fc..dcb735de25f 100644 --- a/cabal-install/Distribution/Client/CmdInstall.hs +++ b/cabal-install/Distribution/Client/CmdInstall.hs @@ -614,10 +614,9 @@ entriesForLibraryComponents :: TargetsMap -> [GhcEnvironmentFileEntry] entriesForLibraryComponents = Map.foldrWithKey' (\k v -> mappend (go k v)) [] where hasLib :: (ComponentTarget, [TargetSelector]) -> Bool - hasLib (ComponentTarget CLibName _, _) = True - hasLib (ComponentTarget (CSubLibName _) _, _) = True - hasLib _ = False - + hasLib (ComponentTarget (CLibName _) _, _) = True + hasLib _ = False + go :: UnitId -> [(ComponentTarget, [TargetSelector])] -> [GhcEnvironmentFileEntry] go unitId targets | any hasLib targets = [GhcEnvFilePackageId unitId] diff --git a/cabal-install/Distribution/Client/Configure.hs b/cabal-install/Distribution/Client/Configure.hs index 949c1c04735..7bc870b1fef 100644 --- a/cabal-install/Distribution/Client/Configure.hs +++ b/cabal-install/Distribution/Client/Configure.hs @@ -256,7 +256,8 @@ configureSetupScript packageDBs -- Return the setup dependencies computed by the solver ReadyPackage cpkg <- mpkg return [ ( cid, srcid ) - | ConfiguredId srcid (Just PkgDesc.CLibName) cid <- CD.setupDeps (confPkgDeps cpkg) + | ConfiguredId srcid (Just (PkgDesc.CLibName PkgDesc.LMainLibName)) cid + <- CD.setupDeps (confPkgDeps cpkg) ] -- | Warn if any constraints or preferences name packages that are not in the @@ -403,9 +404,11 @@ configurePackage verbosity platform comp scriptOptions configFlags -- deps. In the end only one set gets passed to Setup.hs configure, -- depending on the Cabal version we are talking to. configConstraints = [ thisPackageVersion srcid - | ConfiguredId srcid (Just PkgDesc.CLibName) _uid <- CD.nonSetupDeps deps ], + | ConfiguredId srcid (Just (PkgDesc.CLibName PkgDesc.LMainLibName)) _uid + <- CD.nonSetupDeps deps ], configDependencies = [ GivenComponent (packageName srcid) cname uid - | ConfiguredId srcid (Just cname) uid <- CD.nonSetupDeps deps ], + | ConfiguredId srcid (Just (PkgDesc.CLibName cname)) uid + <- CD.nonSetupDeps deps ], -- Use '--exact-configuration' if supported. configExactConfiguration = toFlag True, configVerbosity = toFlag verbosity, diff --git a/cabal-install/Distribution/Client/DistDirLayout.hs b/cabal-install/Distribution/Client/DistDirLayout.hs index a1cfc354a50..2c9e1ad376e 100644 --- a/cabal-install/Distribution/Client/DistDirLayout.hs +++ b/cabal-install/Distribution/Client/DistDirLayout.hs @@ -36,6 +36,7 @@ import Distribution.Text import Distribution.Pretty ( prettyShow ) import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.System @@ -199,8 +200,8 @@ defaultDistDirLayout projectRoot mdistDirectory = display (distParamPackageId params) (case distParamComponentName params of Nothing -> "" - Just CLibName -> "" - Just (CSubLibName name) -> "l" display name + Just (CLibName LMainLibName) -> "" + Just (CLibName (LSubLibName name)) -> "l" display name Just (CFLibName name) -> "f" display name Just (CExeName name) -> "x" display name Just (CTestName name) -> "t" display name @@ -282,4 +283,4 @@ mkCabalDirLayout cabalDir mstoreDir mlogDir = cabalStoreDirLayout = defaultStoreDirLayout (fromMaybe (cabalDir "store") mstoreDir) cabalLogsDirectory = fromMaybe (cabalDir "logs") mlogDir - cabalWorldFile = cabalDir "world" \ No newline at end of file + cabalWorldFile = cabalDir "world" diff --git a/cabal-install/Distribution/Client/Install.hs b/cabal-install/Distribution/Client/Install.hs index 5d6555f4637..77bb0328f02 100644 --- a/cabal-install/Distribution/Client/Install.hs +++ b/cabal-install/Distribution/Client/Install.hs @@ -727,7 +727,12 @@ printPlan dryRun verbosity plan sourcePkgDb = case plan of revDepGraphEdges :: [(PackageId, PackageId)] revDepGraphEdges = [ (rpid, packageId cpkg) | (ReadyPackage cpkg, _) <- plan - , ConfiguredId rpid (Just PackageDescription.CLibName) _ + , ConfiguredId + rpid + (Just + (PackageDescription.CLibName + PackageDescription.LMainLibName)) + _ <- CD.flatDeps (confPkgDeps cpkg) ] revDeps :: Map.Map PackageId [PackageId] @@ -1244,10 +1249,15 @@ installReadyPackage platform cinfo configFlags -- In the end only one set gets passed to Setup.hs configure, depending on -- the Cabal version we are talking to. configConstraints = [ thisPackageVersion srcid - | ConfiguredId srcid (Just PackageDescription.CLibName) _ipid + | ConfiguredId + srcid + (Just + (PackageDescription.CLibName + PackageDescription.LMainLibName)) + _ipid <- CD.nonSetupDeps deps ], configDependencies = [ GivenComponent (packageName srcid) cname dep_ipid - | ConfiguredId srcid (Just cname) dep_ipid + | ConfiguredId srcid (Just (PackageDescription.CLibName cname)) dep_ipid <- CD.nonSetupDeps deps ], -- Use '--exact-configuration' if supported. configExactConfiguration = toFlag True, diff --git a/cabal-install/Distribution/Client/InstallPlan.hs b/cabal-install/Distribution/Client/InstallPlan.hs index e6df0246956..0408103150d 100644 --- a/cabal-install/Distribution/Client/InstallPlan.hs +++ b/cabal-install/Distribution/Client/InstallPlan.hs @@ -527,7 +527,7 @@ configureInstallPlan configFlags solverPlan = Cabal.NoFlag Cabal.NoFlag (packageId spkg) - PD.CLibName + (PD.CLibName PD.LMainLibName) (Just (map confInstId (CD.libraryDeps deps), solverPkgFlags spkg)), confPkgSource = solverPkgSource spkg, diff --git a/cabal-install/Distribution/Client/ProjectBuilding.hs b/cabal-install/Distribution/Client/ProjectBuilding.hs index 702b04fb823..646caef9935 100644 --- a/cabal-install/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/Distribution/Client/ProjectBuilding.hs @@ -81,7 +81,8 @@ import Distribution.Simple.Program import qualified Distribution.Simple.Setup as Cabal import Distribution.Simple.Command (CommandUI) import qualified Distribution.Simple.Register as Cabal -import Distribution.Simple.LocalBuildInfo (ComponentName(..)) +import Distribution.Simple.LocalBuildInfo + ( ComponentName(..), LibraryName(..) ) import Distribution.Simple.Compiler ( Compiler, compilerId, PackageDB(..) ) @@ -1135,12 +1136,12 @@ hasValidHaddockTargets ElaboratedConfiguredPackage{..} componentHasHaddocks :: ComponentTarget -> Bool componentHasHaddocks (ComponentTarget name _) = case name of - CLibName -> hasHaddocks - CSubLibName _ -> elabHaddockInternal && hasHaddocks - CFLibName _ -> elabHaddockForeignLibs && hasHaddocks - CExeName _ -> elabHaddockExecutables && hasHaddocks - CTestName _ -> elabHaddockTestSuites && hasHaddocks - CBenchName _ -> elabHaddockBenchmarks && hasHaddocks + CLibName LMainLibName -> hasHaddocks + CLibName (LSubLibName _) -> elabHaddockInternal && hasHaddocks + CFLibName _ -> elabHaddockForeignLibs && hasHaddocks + CExeName _ -> elabHaddockExecutables && hasHaddocks + CTestName _ -> elabHaddockTestSuites && hasHaddocks + CBenchName _ -> elabHaddockBenchmarks && hasHaddocks where hasHaddocks = not (null (elabPkgDescription ^. componentModules name)) diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index 4ac9dea89e8..32ebbc230b5 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -112,6 +112,7 @@ import Distribution.Package hiding (InstalledPackageId, installedPackageId) import Distribution.Types.AnnotatedId import Distribution.Types.ComponentName +import Distribution.Types.LibraryName import Distribution.Types.GivenComponent (GivenComponent(..)) import Distribution.Types.PkgconfigDependency @@ -261,8 +262,7 @@ sanityCheckElaboratedComponent ElaboratedConfiguredPackage{..} assert (elabBuildStyle == BuildInplaceOnly || case compComponentName of Nothing -> True - Just CLibName -> True - Just (CSubLibName _) -> True + Just (CLibName _) -> True Just (CExeName _) -> True -- This is interesting: there's no way to declare a dependency -- on a foreign library at the moment, but you may still want @@ -1355,7 +1355,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB -- supported in per-package mode. If this is the case, we should -- give an error when this occurs. checkPerPackageOk comps reasons = do - let is_sublib (CSubLibName _) = True + let is_sublib (CLibName (LSubLibName _)) = True is_sublib _ = False when (any (matchElabPkg is_sublib) comps) $ dieProgress $ @@ -1583,7 +1583,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB -- returns at most one result. elaborateLibSolverId :: (SolverId -> [ElaboratedPlanPackage]) -> SolverId -> [ElaboratedPlanPackage] - elaborateLibSolverId mapDep = filter (matchPlanPkg (== CLibName)) . mapDep + elaborateLibSolverId mapDep = filter (matchPlanPkg (== (CLibName LMainLibName))) . mapDep -- | Given an 'ElaboratedPlanPackage', return the path to where the -- executable that this package represents would be installed. @@ -1627,7 +1627,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB elabModuleShape = modShape } - modShape = case find (matchElabPkg (== CLibName)) comps of + modShape = case find (matchElabPkg (== (CLibName LMainLibName))) comps of Nothing -> emptyModuleShape Just e -> Ty.elabModuleShape e @@ -1667,10 +1667,9 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB | Graph.N _ cn _ <- fromMaybe [] mb_closure ] where mb_closure = Graph.revClosure compGraph [ k | k <- Graph.keys compGraph, is_lib k ] - is_lib CLibName = True - -- NB: this case should not occur, because sub-libraries + -- NB: the sublib case should not occur, because sub-libraries -- are not supported without per-component builds - is_lib (CSubLibName _) = True + is_lib (CLibName _) = True is_lib _ = False buildComponentDeps f @@ -2005,8 +2004,8 @@ matchPlanPkg p = InstallPlan.foldPlanPackage (p . ipiComponentName) (matchElabPk ipiComponentName :: IPI.InstalledPackageInfo -> ComponentName ipiComponentName ipkg = case IPI.sourceLibName ipkg of - Nothing -> CLibName - Just n -> (CSubLibName n) + Nothing -> CLibName LMainLibName + Just n -> CLibName (LSubLibName n) -- | Given a 'ElaboratedConfiguredPackage', report if it matches a -- 'ComponentName'. @@ -2335,7 +2334,7 @@ availableInstalledTargets :: IPI.InstalledPackageInfo AvailableTarget (UnitId, ComponentName))] availableInstalledTargets ipkg = let unitid = installedUnitId ipkg - cname = CLibName + cname = CLibName LMainLibName status = TargetBuildable (unitid, cname) TargetRequestedByDefault target = AvailableTarget (packageId ipkg) cname status False fake = False @@ -2441,7 +2440,7 @@ availableSourceTargets elab = compComponentName elabComponent == Just cname ElabPackage _ -> case componentName component of - CLibName -> True + CLibName (LMainLibName) -> True CExeName _ -> True --TODO: what about sub-libs and foreign libs? _ -> False @@ -2818,7 +2817,7 @@ pruneInstallPlanPass2 pkgs = } where libTargetsRequiredForRevDeps = - [ ComponentTarget Cabal.defaultLibName WholeComponent + [ ComponentTarget (CLibName Cabal.defaultLibName) WholeComponent | installedUnitId elab `Set.member` hasReverseLibDeps ] exeTargetsRequiredForRevDeps = @@ -3129,7 +3128,7 @@ setupHsScriptOptions (ReadyPackage elab@ElaboratedConfiguredPackage{..}) usePackageDB = elabSetupPackageDBStack, usePackageIndex = Nothing, useDependencies = [ (uid, srcid) - | ConfiguredId srcid (Just CLibName) uid + | ConfiguredId srcid (Just (CLibName LMainLibName)) uid <- elabSetupDependencies elab ], useDependenciesExclusive = True, useVersionMacros = elabSetupScriptStyle == SetupCustomExplicitDeps, @@ -3290,9 +3289,14 @@ setupHsConfigureFlags (ReadyPackage elab@ElaboratedConfiguredPackage{..}) -- enough info anyway) configDependencies = [ GivenComponent (packageName srcid) - (fromMaybe CLibName mb_cn) + ln cid - | ConfiguredId srcid mb_cn cid <- elabLibDependencies elab ] + | ConfiguredId srcid mb_cn cid <- elabLibDependencies elab + , let ln = case mb_cn + of Just (CLibName lname) -> lname + Just _ -> error "non-library dependency" + Nothing -> LMainLibName + ] configConstraints = case elabPkgOrComp of ElabPackage _ -> diff --git a/cabal-install/Distribution/Client/ProjectPlanning/Types.hs b/cabal-install/Distribution/Client/ProjectPlanning/Types.hs index 4583f2ae2fc..37a86661885 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning/Types.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning/Types.hs @@ -87,7 +87,8 @@ import Distribution.Simple.Build.PathsModule (pkgPathEnvVar) import qualified Distribution.Simple.BuildTarget as Cabal import Distribution.Simple.Program import Distribution.ModuleName (ModuleName) -import Distribution.Simple.LocalBuildInfo (ComponentName(..)) +import Distribution.Simple.LocalBuildInfo + ( ComponentName(..), LibraryName(..) ) import qualified Distribution.Simple.InstallDirs as InstallDirs import Distribution.Simple.InstallDirs (PathTemplate) import Distribution.Simple.Setup (HaddockTarget) @@ -371,8 +372,7 @@ elabRequiresRegistration elab = -- single file is_lib_target (ComponentTarget cn WholeComponent) = is_lib cn is_lib_target _ = False - is_lib CLibName = True - is_lib (CSubLibName _) = True + is_lib (CLibName _) = True is_lib _ = False -- | Construct the environment needed for the data files to work. @@ -443,7 +443,7 @@ instance Binary ElaboratedPackageOrComponent elabComponentName :: ElaboratedConfiguredPackage -> Maybe ComponentName elabComponentName elab = case elabPkgOrComp elab of - ElabPackage _ -> Just CLibName -- there could be more, but default this + ElabPackage _ -> Just $ CLibName LMainLibName -- there could be more, but default this ElabComponent comp -> compComponentName comp -- | A user-friendly descriptor for an 'ElaboratedConfiguredPackage'. @@ -455,7 +455,7 @@ elabConfiguredName verbosity elab ElabComponent comp -> case compComponentName comp of Nothing -> "setup from " - Just CLibName -> "" + Just (CLibName LMainLibName) -> "" Just cname -> display cname ++ " from ") ++ display (packageId elab) | otherwise @@ -759,8 +759,8 @@ isExeComponentTarget (ComponentTarget (CExeName _) _ ) = True isExeComponentTarget _ = False isSubLibComponentTarget :: ComponentTarget -> Bool -isSubLibComponentTarget (ComponentTarget (CSubLibName _) _) = True -isSubLibComponentTarget _ = False +isSubLibComponentTarget (ComponentTarget (CLibName (LSubLibName _)) _) = True +isSubLibComponentTarget _ = False --------------------------- -- Setup.hs script policy diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 155c6453246..202c549cd5c 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -118,7 +118,7 @@ import Distribution.Types.GivenComponent import Distribution.Types.UnqualComponentName ( unUnqualComponentName ) import Distribution.PackageDescription - ( BuildType(..), RepoKind(..), ComponentName(..) ) + ( BuildType(..), RepoKind(..), LibraryName(..) ) import Distribution.System ( Platform ) import Distribution.Text ( Text(..), display ) @@ -533,14 +533,13 @@ filterConfigureFlags flags cabalLibVersion -- Cabal < 2.5.0 does not understand --dependency=pkg:COMPONENT=cid -- (public sublibraries) configDependencies = - let convertToLegacyInternalDep (GivenComponent _ (CSubLibName cn) cid) = + let convertToLegacyInternalDep (GivenComponent _ (LSubLibName cn) cid) = Just $ GivenComponent (mkPackageName $ unUnqualComponentName cn) - CLibName + LMainLibName cid - convertToLegacyInternalDep (GivenComponent pn CLibName cid) = - Just $ GivenComponent pn CLibName cid - convertToLegacyInternalDep _ = Nothing + convertToLegacyInternalDep (GivenComponent pn LMainLibName cid) = + Just $ GivenComponent pn LMainLibName cid in catMaybes $ convertToLegacyInternalDep <$> configDependencies flags } diff --git a/cabal-install/Distribution/Client/TargetSelector.hs b/cabal-install/Distribution/Client/TargetSelector.hs index 64abafb7361..31f7d3ba54b 100644 --- a/cabal-install/Distribution/Client/TargetSelector.hs +++ b/cabal-install/Distribution/Client/TargetSelector.hs @@ -61,7 +61,7 @@ import Distribution.Solver.Types.SourcePackage import Distribution.ModuleName ( ModuleName, toFilePath ) import Distribution.Simple.LocalBuildInfo - ( Component(..), ComponentName(..) + ( Component(..), ComponentName(..), LibraryName(..) , pkgComponents, componentName, componentBuildInfo ) import Distribution.Types.ForeignLib @@ -552,8 +552,7 @@ resolveTargetSelector knowntargets@KnownTargets{..} mfilter targetStrStatus = go (TargetPackageNamed _ (Just filter')) = kfilter == filter' go (TargetAllPackages (Just filter')) = kfilter == filter' go (TargetComponent _ cname _) - | CLibName <- cname = kfilter == LibKind - | CSubLibName _ <- cname = kfilter == LibKind + | CLibName _ <- cname = kfilter == LibKind | CFLibName _ <- cname = kfilter == FLibKind | CExeName _ <- cname = kfilter == ExeKind | CTestName _ <- cname = kfilter == TestKind @@ -1183,7 +1182,7 @@ syntaxForm2PackageModule ps = KnownPackageName pn -> do m <- matchModuleNameUnknown str2 -- We assume the primary library component of the package: - return (TargetComponentUnknown pn (Right CLibName) (ModuleTarget m)) + return (TargetComponentUnknown pn (Right $ CLibName LMainLibName) (ModuleTarget m)) where render (TargetComponent p _c (ModuleTarget m)) = [TargetStringFileStatus2 (dispP p) noFileStatus (dispM m)] @@ -1228,7 +1227,7 @@ syntaxForm2PackageFile ps = KnownPackageName pn -> let filepath = str2 in -- We assume the primary library component of the package: - return (TargetComponentUnknown pn (Right CLibName) (FileTarget filepath)) + return (TargetComponentUnknown pn (Right $ CLibName LMainLibName) (FileTarget filepath)) where render (TargetComponent p _c (FileTarget f)) = [TargetStringFileStatus2 (dispP p) noFileStatus f] @@ -1799,8 +1798,8 @@ collectKnownComponentInfo pkg = componentStringName :: PackageName -> ComponentName -> ComponentStringName -componentStringName pkgname CLibName = display pkgname -componentStringName _ (CSubLibName name) = unUnqualComponentName name +componentStringName pkgname (CLibName LMainLibName) = display pkgname +componentStringName _ (CLibName (LSubLibName name)) = unUnqualComponentName name componentStringName _ (CFLibName name) = unUnqualComponentName name componentStringName _ (CExeName name) = unUnqualComponentName name componentStringName _ (CTestName name) = unUnqualComponentName name @@ -1859,8 +1858,7 @@ guardToken tokens msg s -- componentKind :: ComponentName -> ComponentKind -componentKind CLibName = LibKind -componentKind (CSubLibName _) = LibKind +componentKind (CLibName _) = LibKind componentKind (CFLibName _) = FLibKind componentKind (CExeName _) = ExeKind componentKind (CTestName _) = TestKind @@ -2390,8 +2388,8 @@ mkComponentName pkgname ckind ucname = case ckind of LibKind | packageNameToUnqualComponentName pkgname == ucname - -> CLibName - | otherwise -> CSubLibName ucname + -> CLibName LMainLibName + | otherwise -> CLibName $ LSubLibName ucname FLibKind -> CFLibName ucname ExeKind -> CExeName ucname TestKind -> CTestName ucname diff --git a/cabal-install/Distribution/Client/Types.hs b/cabal-install/Distribution/Client/Types.hs index b87597d63b1..4217ee5d8ae 100644 --- a/cabal-install/Distribution/Client/Types.hs +++ b/cabal-install/Distribution/Client/Types.hs @@ -46,6 +46,8 @@ import Distribution.Types.PackageName ( PackageName, mkPackageName ) import Distribution.Types.ComponentName ( ComponentName(..) ) +import Distribution.Types.LibraryName + ( LibraryName(..) ) import Distribution.Types.SourceRepo ( SourceRepo ) @@ -129,7 +131,7 @@ data ConfiguredPackage loc = ConfiguredPackage { -- 'ElaboratedPackage' and 'ElaboratedComponent'. -- instance HasConfiguredId (ConfiguredPackage loc) where - configuredId pkg = ConfiguredId (packageId pkg) (Just CLibName) (confPkgId pkg) + configuredId pkg = ConfiguredId (packageId pkg) (Just (CLibName LMainLibName)) (confPkgId pkg) -- 'ConfiguredPackage' is the legacy codepath, we are guaranteed -- to never have a nontrivial 'UnitId' diff --git a/cabal-install/Distribution/Solver/Types/ComponentDeps.hs b/cabal-install/Distribution/Solver/Types/ComponentDeps.hs index 63df935b08a..db21a1352c8 100644 --- a/cabal-install/Distribution/Solver/Types/ComponentDeps.hs +++ b/cabal-install/Distribution/Solver/Types/ComponentDeps.hs @@ -44,6 +44,7 @@ import qualified Data.Map as Map import Data.Foldable (fold) import qualified Distribution.Types.ComponentName as CN +import qualified Distribution.Types.LibraryName as LN {------------------------------------------------------------------------------- Types @@ -90,8 +91,8 @@ instance Traversable ComponentDeps where instance Binary a => Binary (ComponentDeps a) componentNameToComponent :: CN.ComponentName -> Component -componentNameToComponent (CN.CLibName) = ComponentLib -componentNameToComponent (CN.CSubLibName s) = ComponentSubLib s +componentNameToComponent (CN.CLibName LN.LMainLibName ) = ComponentLib +componentNameToComponent (CN.CLibName (LN.LSubLibName s)) = ComponentSubLib s componentNameToComponent (CN.CFLibName s) = ComponentFLib s componentNameToComponent (CN.CExeName s) = ComponentExe s componentNameToComponent (CN.CTestName s) = ComponentTest s diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index 2b79a1c18a7..5fc081051a5 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -216,8 +216,8 @@ testTargetSelectors reportSubCase = do do Right ts <- readTargetSelectors' [ "p", "lib:p", "p:lib:p", ":pkg:p:lib:p" , "lib:q", "q:lib:q", ":pkg:q:lib:q" ] - ts @?= replicate 4 (TargetComponent "p-0.1" CLibName WholeComponent) - ++ replicate 3 (TargetComponent "q-0.1" CLibName WholeComponent) + ts @?= replicate 4 (TargetComponent "p-0.1" (CLibName LMainLibName) WholeComponent) + ++ replicate 3 (TargetComponent "q-0.1" (CLibName LMainLibName) WholeComponent) reportSubCase "module" do Right ts <- readTargetSelectors' @@ -226,8 +226,8 @@ testTargetSelectors reportSubCase = do , "pexe:PMain" -- p:P or q:QQ would be ambiguous here , "qexe:QMain" -- package p vs component p ] - ts @?= replicate 4 (TargetComponent "p-0.1" CLibName (ModuleTarget "P")) - ++ replicate 4 (TargetComponent "q-0.1" CLibName (ModuleTarget "QQ")) + ts @?= replicate 4 (TargetComponent "p-0.1" (CLibName LMainLibName) (ModuleTarget "P")) + ++ replicate 4 (TargetComponent "q-0.1" (CLibName LMainLibName) (ModuleTarget "QQ")) ++ [ TargetComponent "p-0.1" (CExeName "pexe") (ModuleTarget "PMain") , TargetComponent "q-0.1" (CExeName "qexe") (ModuleTarget "QMain") ] @@ -239,8 +239,8 @@ testTargetSelectors reportSubCase = do , "q/QQ.hs", "q:QQ.lhs", "lib:q:QQ.hsc", "q:q:QQ.hsc", ":pkg:q:lib:q:file:QQ.y" ] - ts @?= replicate 5 (TargetComponent "p-0.1" CLibName (FileTarget "P")) - ++ replicate 5 (TargetComponent "q-0.1" CLibName (FileTarget "QQ")) + ts @?= replicate 5 (TargetComponent "p-0.1" (CLibName LMainLibName) (FileTarget "P")) + ++ replicate 5 (TargetComponent "q-0.1" (CLibName LMainLibName) (FileTarget "QQ")) -- Note there's a bit of an inconsistency here: for the single-part -- syntax the target has to point to a file that exists, whereas for -- all the other forms we don't require that. @@ -624,7 +624,7 @@ testTargetProblemsBuild config reportSubCase = do TargetDisabledBySolver True , AvailableTarget "p-0.1" (CExeName "buildable-false") TargetNotBuildable True - , AvailableTarget "p-0.1" CLibName + , AvailableTarget "p-0.1" (CLibName LMainLibName) TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) @@ -645,7 +645,7 @@ testTargetProblemsBuild config reportSubCase = do CmdBuild.selectComponentTarget CmdBuild.TargetProblemCommon [ mkTargetPackage "p-0.1" ] - [ ("p-0.1-inplace", CLibName) + [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-a-benchmark", CBenchName "a-benchmark") , ("p-0.1-inplace-a-testsuite", CTestName "a-testsuite") , ("p-0.1-inplace-an-exe", CExeName "an-exe") @@ -667,7 +667,7 @@ testTargetProblemsBuild config reportSubCase = do CmdBuild.selectComponentTarget CmdBuild.TargetProblemCommon [ mkTargetPackage "p-0.1" ] - [ ("p-0.1-inplace", CLibName) + [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-an-exe", CExeName "an-exe") , ("p-0.1-inplace-libp", CFLibName "libp") ] @@ -699,9 +699,9 @@ testTargetProblemsRepl config reportSubCase = do CmdRepl.selectComponentTarget CmdRepl.TargetProblemCommon [ ( flip CmdRepl.TargetProblemMatchesMultiple - [ AvailableTarget "p-0.1" CLibName + [ AvailableTarget "p-0.1" (CLibName LMainLibName) (TargetBuildable () TargetRequestedByDefault) True - , AvailableTarget "q-0.1" CLibName + , AvailableTarget "q-0.1" (CLibName LMainLibName) (TargetBuildable () TargetRequestedByDefault) True ] , mkTargetAllPackages ) @@ -758,7 +758,7 @@ testTargetProblemsRepl config reportSubCase = do CmdRepl.selectComponentTarget CmdRepl.TargetProblemCommon [ ( flip CmdRepl.TargetProblemNoneEnabled - [ AvailableTarget "p-0.1" CLibName TargetNotBuildable True ] + [ AvailableTarget "p-0.1" (CLibName LMainLibName) TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) ] @@ -805,7 +805,7 @@ testTargetProblemsRepl config reportSubCase = do CmdRepl.selectComponentTarget CmdRepl.TargetProblemCommon [ TargetPackage TargetExplicitNamed ["p-0.1"] Nothing ] - [ ("p-0.1-inplace", CLibName) ] + [ ("p-0.1-inplace", (CLibName LMainLibName)) ] -- When we select the package with an explicit filter then we get those -- components even though we did not explicitly enable tests/benchmarks assertProjectDistinctTargets @@ -960,8 +960,8 @@ testTargetProblemsTest config reportSubCase = do CmdTest.selectComponentTarget CmdTest.TargetProblemCommon $ [ ( const (CmdTest.TargetProblemComponentNotTest - "p-0.1" CLibName) - , mkTargetComponent "p-0.1" CLibName ) + "p-0.1" (CLibName LMainLibName)) + , mkTargetComponent "p-0.1" (CLibName LMainLibName) ) , ( const (CmdTest.TargetProblemComponentNotTest "p-0.1" (CExeName "an-exe")) @@ -981,7 +981,7 @@ testTargetProblemsTest config reportSubCase = do | (cname, modname) <- [ (CTestName "a-testsuite", "TestModule") , (CBenchName "a-benchmark", "BenchModule") , (CExeName "an-exe", "ExeModule") - , (CLibName, "P") + , ((CLibName LMainLibName), "P") ] ] ++ [ ( const (CmdTest.TargetProblemIsSubComponent @@ -1067,8 +1067,8 @@ testTargetProblemsBench config reportSubCase = do CmdBench.selectComponentTarget CmdBench.TargetProblemCommon $ [ ( const (CmdBench.TargetProblemComponentNotBenchmark - "p-0.1" CLibName) - , mkTargetComponent "p-0.1" CLibName ) + "p-0.1" (CLibName LMainLibName)) + , mkTargetComponent "p-0.1" (CLibName LMainLibName) ) , ( const (CmdBench.TargetProblemComponentNotBenchmark "p-0.1" (CExeName "an-exe")) @@ -1088,7 +1088,7 @@ testTargetProblemsBench config reportSubCase = do | (cname, modname) <- [ (CTestName "a-testsuite", "TestModule") , (CBenchName "a-benchmark", "BenchModule") , (CExeName "an-exe", "ExeModule") - , (CLibName, "P") + , ((CLibName LMainLibName), "P") ] ] ++ [ ( const (CmdBench.TargetProblemIsSubComponent @@ -1119,7 +1119,7 @@ testTargetProblemsHaddock config reportSubCase = do TargetDisabledBySolver True , AvailableTarget "p-0.1" (CExeName "buildable-false") TargetNotBuildable True - , AvailableTarget "p-0.1" CLibName + , AvailableTarget "p-0.1" (CLibName LMainLibName) TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) @@ -1146,7 +1146,7 @@ testTargetProblemsHaddock config reportSubCase = do CmdHaddock.selectComponentTarget CmdHaddock.TargetProblemCommon [ mkTargetPackage "p-0.1" ] - [ ("p-0.1-inplace", CLibName) + [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-a-benchmark", CBenchName "a-benchmark") , ("p-0.1-inplace-a-testsuite", CTestName "a-testsuite") , ("p-0.1-inplace-an-exe", CExeName "an-exe") @@ -1163,7 +1163,7 @@ testTargetProblemsHaddock config reportSubCase = do CmdHaddock.selectComponentTarget CmdHaddock.TargetProblemCommon [ mkTargetPackage "p-0.1" ] - [ ("p-0.1-inplace", CLibName) ] + [ ("p-0.1-inplace", (CLibName LMainLibName)) ] reportSubCase "requested component kinds" -- When we selecting the package with an explicit filter then it does not diff --git a/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs b/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs index f3e9d1979fc..a2a48e62ec6 100644 --- a/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs +++ b/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs @@ -29,7 +29,7 @@ main = setupAndCabalTest $ do lbi <- liftIO $ getPersistBuildConfig dist_dir let pkg_descr = localPkgDescr lbi compiler_id = compilerId (compiler lbi) - cname = CSubLibName $ mkUnqualComponentName "foo-internal" + cname = CLibName $ LSubLibName $ mkUnqualComponentName "foo-internal" [target] = componentNameTargets' pkg_descr lbi cname uid = componentUnitId (targetCLBI target) InstallDirs{libdir=dir,dynlibdir=dyndir} =