Commit e2194d25 authored by Francesco Gazzetta's avatar Francesco Gazzetta

Multiple libraries (allow depending on sublibs)

Create a new syntax for depending on any library of any package.
The syntax is

    build-depends: pkgname:{pkgname, sublibname} -any

where the second `pkgname` specifies a dependency on the main unnamed
library.

Closes #4206.
parent 898b284e
...@@ -68,7 +68,7 @@ mkComponentsGraph enabled pkg_descr = ...@@ -68,7 +68,7 @@ mkComponentsGraph enabled pkg_descr =
++ [ if pkgname == packageName pkg_descr ++ [ if pkgname == packageName pkg_descr
then CLibName LMainLibName then CLibName LMainLibName
else CLibName (LSubLibName toolname) else CLibName (LSubLibName toolname)
| Dependency pkgname _ <- targetBuildDepends bi | Dependency pkgname _ _ <- targetBuildDepends bi
, let toolname = packageNameToUnqualComponentName pkgname , let toolname = packageNameToUnqualComponentName pkgname
, toolname `elem` internalPkgDeps ] , toolname `elem` internalPkgDeps ]
where where
......
...@@ -30,6 +30,7 @@ import Distribution.Types.PackageId ...@@ -30,6 +30,7 @@ import Distribution.Types.PackageId
import Distribution.Types.PackageName import Distribution.Types.PackageName
import Distribution.Types.Mixin import Distribution.Types.Mixin
import Distribution.Types.ComponentName import Distribution.Types.ComponentName
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName import Distribution.Types.UnqualComponentName
import Distribution.Types.ComponentInclude import Distribution.Types.ComponentInclude
import Distribution.Package import Distribution.Package
...@@ -165,16 +166,40 @@ toConfiguredComponent ...@@ -165,16 +166,40 @@ toConfiguredComponent
toConfiguredComponent pkg_descr this_cid lib_dep_map exe_dep_map component = do toConfiguredComponent pkg_descr this_cid lib_dep_map exe_dep_map component = do
lib_deps <- lib_deps <-
if newPackageDepsBehaviour pkg_descr if newPackageDepsBehaviour pkg_descr
then forM (targetBuildDepends bi) $ \(Dependency name _) -> do then fmap concat $ forM (targetBuildDepends bi) $ \(Dependency name _ sublibs) -> do
let (pn, cn) = fixFakePkgName pkg_descr name let (pn, cn) = fixFakePkgName pkg_descr name
value <- case Map.lookup cn =<< Map.lookup pn lib_dep_map of pkg <- case Map.lookup pn lib_dep_map of
Nothing ->
dieProgress $
text "Dependency on unbuildable" <+>
text "package" <+> disp pn
Just p -> return p
mainLibraryComponent <-
if sublibs /= Set.singleton LMainLibName
then pure Nothing
-- No sublibraries were specified, so we may be in the
-- legacy case where the package name is used as library
-- name
else Just <$>
case Map.lookup cn pkg of
Nothing -> Nothing ->
dieProgress $ dieProgress $
text "Dependency on unbuildable (i.e. 'buildable: False')" <+> text "Dependency on unbuildable (i.e. 'buildable: False')" <+>
text (showComponentName cn) <+> text (showComponentName cn) <+>
text "from" <+> disp pn text "from" <+> disp pn
Just v -> return v Just v -> return v
return value subLibrariesComponents <- forM (Set.toList sublibs) $ \lib ->
let comp = CLibName lib in
case Map.lookup (CLibName $ LSubLibName $ packageNameToUnqualComponentName name) pkg
<|> Map.lookup comp pkg
of
Nothing ->
dieProgress $
text "Dependency on unbuildable" <+>
text (showLibraryName lib) <+>
text "from" <+> disp pn
Just v -> return v
return (maybeToList mainLibraryComponent ++ subLibrariesComponents)
else return old_style_lib_deps else return old_style_lib_deps
mkConfiguredComponent mkConfiguredComponent
pkg_descr this_cid pkg_descr this_cid
......
...@@ -585,7 +585,7 @@ checkFields pkg = ...@@ -585,7 +585,7 @@ checkFields pkg =
, name `elem` map display knownLanguages ] , name `elem` map display knownLanguages ]
testedWithImpossibleRanges = testedWithImpossibleRanges =
[ Dependency (mkPackageName (display compiler)) vr [ Dependency (mkPackageName (display compiler)) vr Set.empty
| (compiler, vr) <- testedWith pkg | (compiler, vr) <- testedWith pkg
, isNoVersion vr ] , isNoVersion vr ]
...@@ -598,7 +598,7 @@ checkFields pkg = ...@@ -598,7 +598,7 @@ checkFields pkg =
internalLibDeps = internalLibDeps =
[ dep [ dep
| bi <- allBuildInfo pkg | bi <- allBuildInfo pkg
, dep@(Dependency name _) <- targetBuildDepends bi , dep@(Dependency name _ _) <- targetBuildDepends bi
, name `elem` internalLibraries , name `elem` internalLibraries
] ]
...@@ -611,14 +611,14 @@ checkFields pkg = ...@@ -611,14 +611,14 @@ checkFields pkg =
depInternalLibraryWithExtraVersion = depInternalLibraryWithExtraVersion =
[ dep [ dep
| dep@(Dependency _ versionRange) <- internalLibDeps | dep@(Dependency _ versionRange _) <- internalLibDeps
, not $ isAnyVersion versionRange , not $ isAnyVersion versionRange
, packageVersion pkg `withinRange` versionRange , packageVersion pkg `withinRange` versionRange
] ]
depInternalLibraryWithImpossibleVersion = depInternalLibraryWithImpossibleVersion =
[ dep [ dep
| dep@(Dependency _ versionRange) <- internalLibDeps | dep@(Dependency _ versionRange _) <- internalLibDeps
, not $ packageVersion pkg `withinRange` versionRange , not $ packageVersion pkg `withinRange` versionRange
] ]
...@@ -1243,8 +1243,8 @@ checkCabalVersion pkg = ...@@ -1243,8 +1243,8 @@ checkCabalVersion pkg =
++ ". To use this new syntax the package need to specify at least " ++ ". To use this new syntax the package need to specify at least "
++ "'cabal-version: >= 1.6'. Alternatively, if broader compatibility " ++ "'cabal-version: >= 1.6'. Alternatively, if broader compatibility "
++ "is important then use: " ++ commaSep ++ "is important then use: " ++ commaSep
[ display (Dependency name (eliminateWildcardSyntax versionRange)) [ display (Dependency name (eliminateWildcardSyntax versionRange) Set.empty)
| Dependency name versionRange <- depsUsingWildcardSyntax ] | Dependency name versionRange _ <- depsUsingWildcardSyntax ]
-- check use of "build-depends: foo ^>= 1.2.3" syntax -- check use of "build-depends: foo ^>= 1.2.3" syntax
, checkVersion [2,0] (not (null depsUsingMajorBoundSyntax)) $ , checkVersion [2,0] (not (null depsUsingMajorBoundSyntax)) $
...@@ -1255,8 +1255,8 @@ checkCabalVersion pkg = ...@@ -1255,8 +1255,8 @@ checkCabalVersion pkg =
++ ". To use this new syntax the package need to specify at least " ++ ". To use this new syntax the package need to specify at least "
++ "'cabal-version: 2.0'. Alternatively, if broader compatibility " ++ "'cabal-version: 2.0'. Alternatively, if broader compatibility "
++ "is important then use: " ++ commaSep ++ "is important then use: " ++ commaSep
[ display (Dependency name (eliminateMajorBoundSyntax versionRange)) [ display (Dependency name (eliminateMajorBoundSyntax versionRange) Set.empty)
| Dependency name versionRange <- depsUsingMajorBoundSyntax ] | Dependency name versionRange _ <- depsUsingMajorBoundSyntax ]
, checkVersion [2,1] (any (not . null) , checkVersion [2,1] (any (not . null)
(concatMap buildInfoField (concatMap buildInfoField
...@@ -1292,8 +1292,8 @@ checkCabalVersion pkg = ...@@ -1292,8 +1292,8 @@ checkCabalVersion pkg =
++ ". To use this new syntax the package need to specify at least " ++ ". To use this new syntax the package need to specify at least "
++ "'cabal-version: >= 1.6'. Alternatively, if broader compatibility " ++ "'cabal-version: >= 1.6'. Alternatively, if broader compatibility "
++ "is important then use: " ++ commaSep ++ "is important then use: " ++ commaSep
[ display (Dependency name (eliminateWildcardSyntax versionRange)) [ display (Dependency name (eliminateWildcardSyntax versionRange) Set.empty)
| Dependency name versionRange <- testedWithUsingWildcardSyntax ] | Dependency name versionRange _ <- testedWithUsingWildcardSyntax ]
-- check use of "source-repository" section -- check use of "source-repository" section
, checkVersion [1,6] (not (null (sourceRepos pkg))) $ , checkVersion [1,6] (not (null (sourceRepos pkg))) $
...@@ -1367,11 +1367,11 @@ checkCabalVersion pkg = ...@@ -1367,11 +1367,11 @@ checkCabalVersion pkg =
buildInfoField field = map field (allBuildInfo pkg) buildInfoField field = map field (allBuildInfo pkg)
versionRangeExpressions = versionRangeExpressions =
[ dep | dep@(Dependency _ vr) <- allBuildDepends pkg [ dep | dep@(Dependency _ vr _) <- allBuildDepends pkg
, usesNewVersionRangeSyntax vr ] , usesNewVersionRangeSyntax vr ]
testedWithVersionRangeExpressions = testedWithVersionRangeExpressions =
[ Dependency (mkPackageName (display compiler)) vr [ Dependency (mkPackageName (display compiler)) vr Set.empty
| (compiler, vr) <- testedWith pkg | (compiler, vr) <- testedWith pkg
, usesNewVersionRangeSyntax vr ] , usesNewVersionRangeSyntax vr ]
...@@ -1395,16 +1395,16 @@ checkCabalVersion pkg = ...@@ -1395,16 +1395,16 @@ checkCabalVersion pkg =
alg (VersionRangeParensF _) = 3 alg (VersionRangeParensF _) = 3
alg _ = 1 :: Int alg _ = 1 :: Int
depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg depsUsingWildcardSyntax = [ dep | dep@(Dependency _ vr _) <- allBuildDepends pkg
, usesWildcardSyntax vr ] , usesWildcardSyntax vr ]
depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr) <- allBuildDepends pkg depsUsingMajorBoundSyntax = [ dep | dep@(Dependency _ vr _) <- allBuildDepends pkg
, usesMajorBoundSyntax vr ] , usesMajorBoundSyntax vr ]
usesBackpackIncludes = any (not . null . mixins) (allBuildInfo pkg) usesBackpackIncludes = any (not . null . mixins) (allBuildInfo pkg)
testedWithUsingWildcardSyntax = testedWithUsingWildcardSyntax =
[ Dependency (mkPackageName (display compiler)) vr [ Dependency (mkPackageName (display compiler)) vr Set.empty
| (compiler, vr) <- testedWith pkg | (compiler, vr) <- testedWith pkg
, usesWildcardSyntax vr ] , usesWildcardSyntax vr ]
...@@ -1493,7 +1493,7 @@ checkCabalVersion pkg = ...@@ -1493,7 +1493,7 @@ checkCabalVersion pkg =
allModuleNamesAutogen = concatMap autogenModules (allBuildInfo pkg) allModuleNamesAutogen = concatMap autogenModules (allBuildInfo pkg)
displayRawDependency :: Dependency -> String displayRawDependency :: Dependency -> String
displayRawDependency (Dependency pkg vr) = displayRawDependency (Dependency pkg vr _sublibs) =
display pkg ++ " " ++ display vr display pkg ++ " " ++ display vr
...@@ -1545,7 +1545,7 @@ checkPackageVersions pkg = ...@@ -1545,7 +1545,7 @@ checkPackageVersions pkg =
foldr intersectVersionRanges anyVersion baseDeps foldr intersectVersionRanges anyVersion baseDeps
where where
baseDeps = baseDeps =
[ vr | Dependency pname vr <- allBuildDepends pkg' [ vr | Dependency pname vr _ <- allBuildDepends pkg'
, pname == mkPackageName "base" ] , pname == mkPackageName "base" ]
-- Just in case finalizePD fails for any reason, -- Just in case finalizePD fails for any reason,
......
...@@ -65,6 +65,8 @@ import Distribution.Types.DependencyMap ...@@ -65,6 +65,8 @@ import Distribution.Types.DependencyMap
import qualified Data.Map.Strict as Map.Strict import qualified Data.Map.Strict as Map.Strict
import qualified Data.Map.Lazy as Map import qualified Data.Map.Lazy as Map
import Data.Set ( Set )
import qualified Data.Set as Set
import Data.Tree ( Tree(Node) ) import Data.Tree ( Tree(Node) )
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
...@@ -229,7 +231,7 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps = ...@@ -229,7 +231,7 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
mp (Left xs) (Left ys) = mp (Left xs) (Left ys) =
let union = Map.foldrWithKey (Map.Strict.insertWith combine) let union = Map.foldrWithKey (Map.Strict.insertWith combine)
(unDepMapUnion xs) (unDepMapUnion ys) (unDepMapUnion xs) (unDepMapUnion ys)
combine x y = simplifyVersionRange $ unionVersionRanges x y combine x y = (\(vr, cs) -> (simplifyVersionRange vr,cs)) $ unionVersionRanges' x y
in union `seq` Left (DepMapUnion union) in union `seq` Left (DepMapUnion union)
-- `mzero' -- `mzero'
...@@ -307,14 +309,22 @@ extractConditions f gpkg = ...@@ -307,14 +309,22 @@ extractConditions f gpkg =
-- | A map of dependencies that combines version ranges using 'unionVersionRanges'. -- | A map of dependencies that combines version ranges using 'unionVersionRanges'.
newtype DepMapUnion = DepMapUnion { unDepMapUnion :: Map PackageName VersionRange } newtype DepMapUnion = DepMapUnion { unDepMapUnion :: Map PackageName (VersionRange, Set LibraryName) }
-- An union of versions should correspond to an intersection of the components.
-- The intersection may not be necessary.
unionVersionRanges' :: (VersionRange, Set LibraryName)
-> (VersionRange, Set LibraryName)
-> (VersionRange, Set LibraryName)
unionVersionRanges' (vra, csa) (vrb, csb) =
(unionVersionRanges vra vrb, Set.intersection csa csb)
toDepMapUnion :: [Dependency] -> DepMapUnion toDepMapUnion :: [Dependency] -> DepMapUnion
toDepMapUnion ds = toDepMapUnion ds =
DepMapUnion $ Map.fromListWith unionVersionRanges [ (p,vr) | Dependency p vr <- ds ] DepMapUnion $ Map.fromListWith unionVersionRanges' [ (p,(vr,cs)) | Dependency p vr cs <- ds ]
fromDepMapUnion :: DepMapUnion -> [Dependency] fromDepMapUnion :: DepMapUnion -> [Dependency]
fromDepMapUnion m = [ Dependency p vr | (p,vr) <- Map.toList (unDepMapUnion m) ] fromDepMapUnion m = [ Dependency p vr cs | (p,(vr,cs)) <- Map.toList (unDepMapUnion m) ]
freeVars :: CondTree ConfVar c a -> [FlagName] freeVars :: CondTree ConfVar c a -> [FlagName]
freeVars t = [ f | Flag f <- freeVars' t ] freeVars t = [ f | Flag f <- freeVars' t ]
......
...@@ -143,6 +143,8 @@ import Text.PrettyPrint ...@@ -143,6 +143,8 @@ import Text.PrettyPrint
import Distribution.Compat.Environment ( lookupEnv ) import Distribution.Compat.Environment ( lookupEnv )
import Distribution.Compat.Exception ( catchExit, catchIO ) import Distribution.Compat.Exception ( catchExit, catchIO )
import qualified Data.Set as Set
type UseExternalInternalDeps = Bool type UseExternalInternalDeps = Bool
...@@ -874,7 +876,7 @@ dependencySatisfiable ...@@ -874,7 +876,7 @@ dependencySatisfiable
dependencySatisfiable dependencySatisfiable
use_external_internal_deps use_external_internal_deps
exact_config pn installedPackageSet internalPackageSet requiredDepsMap exact_config pn installedPackageSet internalPackageSet requiredDepsMap
d@(Dependency depName vr) (Dependency depName vr sublibs)
| exact_config | exact_config
-- When we're given '--exact-configuration', we assume that all -- When we're given '--exact-configuration', we assume that all
...@@ -889,7 +891,19 @@ dependencySatisfiable ...@@ -889,7 +891,19 @@ dependencySatisfiable
-- Except for internal deps, when we're NOT per-component mode; -- Except for internal deps, when we're NOT per-component mode;
-- those are just True. -- those are just True.
then True then True
else (depName, CLibName LMainLibName) `Map.member` requiredDepsMap else
-- Backward compatibility for the old sublibrary syntax
(sublibs == Set.singleton LMainLibName
&& Map.member
(pn, CLibName $ LSubLibName $ packageNameToUnqualComponentName depName)
requiredDepsMap)
|| all
(\lib ->
(depName, CLibName lib)
`Map.member`
requiredDepsMap)
sublibs
| isInternalDep | isInternalDep
= if use_external_internal_deps = if use_external_internal_deps
...@@ -908,11 +922,11 @@ dependencySatisfiable ...@@ -908,11 +922,11 @@ dependencySatisfiable
isInternalDep = Map.member depName internalPackageSet isInternalDep = Map.member depName internalPackageSet
depSatisfiable = depSatisfiable =
not . null $ PackageIndex.lookupDependency installedPackageSet d not . null $ PackageIndex.lookupDependency installedPackageSet depName vr
internalDepSatisfiable = internalDepSatisfiable =
not . null $ PackageIndex.lookupInternalDependency not . null $ PackageIndex.lookupInternalDependency
installedPackageSet (Dependency pn vr) cn installedPackageSet pn vr cn
where where
cn | pn == depName cn | pn == depName
= Nothing = Nothing
...@@ -1025,8 +1039,8 @@ configureDependencies verbosity use_external_internal_deps ...@@ -1025,8 +1039,8 @@ configureDependencies verbosity use_external_internal_deps
internalPackageSet installedPackageSet requiredDepsMap pkg_descr enableSpec = do internalPackageSet installedPackageSet requiredDepsMap pkg_descr enableSpec = do
let failedDeps :: [FailedDependency] let failedDeps :: [FailedDependency]
allPkgDeps :: [ResolvedDependency] allPkgDeps :: [ResolvedDependency]
(failedDeps, allPkgDeps) = partitionEithers (failedDeps, allPkgDeps) = partitionEithers $ concat
[ (\s -> (dep, s)) <$> status [ fmap (\s -> (dep, s)) <$> status
| dep <- enabledBuildDepends pkg_descr enableSpec | dep <- enabledBuildDepends pkg_descr enableSpec
, let status = selectDependency (package pkg_descr) , let status = selectDependency (package pkg_descr)
internalPackageSet installedPackageSet internalPackageSet installedPackageSet
...@@ -1197,10 +1211,10 @@ selectDependency :: PackageId -- ^ Package id of current package ...@@ -1197,10 +1211,10 @@ selectDependency :: PackageId -- ^ Package id of current package
-> UseExternalInternalDeps -- ^ Are we configuring a -> UseExternalInternalDeps -- ^ Are we configuring a
-- single component? -- single component?
-> Dependency -> Dependency
-> Either FailedDependency DependencyResolution -> [Either FailedDependency DependencyResolution]
selectDependency pkgid internalIndex installedIndex requiredDepsMap selectDependency pkgid internalIndex installedIndex requiredDepsMap
use_external_internal_deps use_external_internal_deps
dep@(Dependency dep_pkgname vr) = (Dependency dep_pkgname vr libs) =
-- If the dependency specification matches anything in the internal package -- If the dependency specification matches anything in the internal package
-- index, then we prefer that match to anything in the second. -- index, then we prefer that match to anything in the second.
-- For example: -- For example:
...@@ -1216,18 +1230,19 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap ...@@ -1216,18 +1230,19 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap
-- even if there is a newer installed library "MyLibrary-0.2". -- even if there is a newer installed library "MyLibrary-0.2".
case Map.lookup dep_pkgname internalIndex of case Map.lookup dep_pkgname internalIndex of
Just cname -> if use_external_internal_deps Just cname -> if use_external_internal_deps
then do_external (Just cname) then do_external (Just cname) <$> Set.toList libs
else do_internal else do_internal
_ -> do_external Nothing _ -> do_external Nothing <$> Set.toList libs
where where
-- It's an internal library, and we're not per-component build -- It's an internal library, and we're not per-component build
do_internal = Right $ InternalDependency do_internal = [Right $ InternalDependency
$ PackageIdentifier dep_pkgname $ packageVersion pkgid $ PackageIdentifier dep_pkgname $ packageVersion pkgid]
-- We have to look it up externally -- We have to look it up externally
do_external is_internal = do do_external :: Maybe (Maybe UnqualComponentName) -> LibraryName -> Either FailedDependency DependencyResolution
ipi <- case Map.lookup (dep_pkgname, CLibName LMainLibName) requiredDepsMap of do_external is_internal lib = do
ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of
-- If we know the exact pkg to use, then use it. -- If we know the exact pkg to use, then use it.
Just pkginstance -> Right pkginstance Just pkginstance -> Right pkginstance
-- Otherwise we just pick an arbitrary instance of the latest version. -- Otherwise we just pick an arbitrary instance of the latest version.
...@@ -1239,14 +1254,14 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap ...@@ -1239,14 +1254,14 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap
-- It's an external package, normal situation -- It's an external package, normal situation
do_external_external = do_external_external =
case PackageIndex.lookupDependency installedIndex dep of case PackageIndex.lookupDependency installedIndex dep_pkgname vr of
[] -> Left (DependencyNotExists dep_pkgname) [] -> Left (DependencyNotExists dep_pkgname)
pkgs -> Right $ head $ snd $ last pkgs pkgs -> Right $ head $ snd $ last pkgs
-- It's an internal library, being looked up externally -- It's an internal library, being looked up externally
do_external_internal mb_uqn = do_external_internal mb_uqn =
case PackageIndex.lookupInternalDependency installedIndex case PackageIndex.lookupInternalDependency installedIndex
(Dependency (packageName pkgid) vr) mb_uqn of (packageName pkgid) vr mb_uqn of
[] -> Left (DependencyMissingInternal dep_pkgname (packageName pkgid)) [] -> Left (DependencyMissingInternal dep_pkgname (packageName pkgid))
pkgs -> Right $ head $ snd $ last pkgs pkgs -> Right $ head $ snd $ last pkgs
......
...@@ -469,11 +469,11 @@ lookupPackageName index name = ...@@ -469,11 +469,11 @@ lookupPackageName index name =
-- --
-- INVARIANT: List of eligible 'IPI.InstalledPackageInfo' is non-empty. -- INVARIANT: List of eligible 'IPI.InstalledPackageInfo' is non-empty.
-- --
lookupDependency :: InstalledPackageIndex -> Dependency lookupDependency :: InstalledPackageIndex -> PackageName -> VersionRange
-> [(Version, [IPI.InstalledPackageInfo])] -> [(Version, [IPI.InstalledPackageInfo])]
lookupDependency index dep = lookupDependency index pn vr =
-- Yes, a little bit of a misnomer here! -- Yes, a little bit of a misnomer here!
lookupInternalDependency index dep Nothing lookupInternalDependency index pn vr Nothing
-- | Does a lookup by source package name and a range of versions. -- | Does a lookup by source package name and a range of versions.
-- --
...@@ -482,10 +482,10 @@ lookupDependency index dep = ...@@ -482,10 +482,10 @@ lookupDependency index dep =
-- --
-- INVARIANT: List of eligible 'IPI.InstalledPackageInfo' is non-empty. -- INVARIANT: List of eligible 'IPI.InstalledPackageInfo' is non-empty.
-- --
lookupInternalDependency :: InstalledPackageIndex -> Dependency lookupInternalDependency :: InstalledPackageIndex -> PackageName -> VersionRange
-> Maybe UnqualComponentName -> Maybe UnqualComponentName
-> [(Version, [IPI.InstalledPackageInfo])] -> [(Version, [IPI.InstalledPackageInfo])]
lookupInternalDependency index (Dependency name versionRange) libn = lookupInternalDependency index name versionRange libn =
case Map.lookup (name, libn) (packageIdIndex index) of case Map.lookup (name, libn) (packageIdIndex index) of
Nothing -> [] Nothing -> []
Just pvers -> [ (ver, pkgs') Just pvers -> [ (ver, pkgs')
......
...@@ -4,6 +4,7 @@ module Distribution.Types.Dependency ...@@ -4,6 +4,7 @@ module Distribution.Types.Dependency
( Dependency(..) ( Dependency(..)
, depPkgName , depPkgName
, depVerRange , depVerRange
, depLibraries
, thisPackageVersion , thisPackageVersion
, notThisPackageVersion , notThisPackageVersion
, simplifyDependency , simplifyDependency
...@@ -20,53 +21,95 @@ import qualified Distribution.Compat.ReadP as Parse ...@@ -20,53 +21,95 @@ import qualified Distribution.Compat.ReadP as Parse
import Distribution.Text import Distribution.Text
import Distribution.Pretty import Distribution.Pretty
import qualified Text.PrettyPrint as PP
import Distribution.Parsec.Class import Distribution.Parsec.Class
import Distribution.Compat.CharParsing (char, spaces)
import Distribution.Compat.Parsing (between, option)
import Distribution.Types.PackageId import Distribution.Types.PackageId
import Distribution.Types.PackageName import Distribution.Types.PackageName
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName
import Text.PrettyPrint ((<+>)) import Text.PrettyPrint ((<+>))
import Data.Set (Set)
import qualified Data.Set as Set
-- | Describes a dependency on a source package (API) -- | Describes a dependency on a source package (API)
-- --
data Dependency = Dependency PackageName VersionRange data Dependency = Dependency
PackageName
VersionRange
(Set LibraryName)
-- ^ The set of libraries required from the package.
-- Only the selected libraries will be built.
-- It does not affect the cabal-install solver yet.
deriving (Generic, Read, Show, Eq, Typeable, Data) deriving (Generic, Read, Show, Eq, Typeable, Data)
depPkgName :: Dependency -> PackageName depPkgName :: Dependency -> PackageName
depPkgName (Dependency pn _) = pn depPkgName (Dependency pn _ _) = pn
depVerRange :: Dependency -> VersionRange depVerRange :: Dependency -> VersionRange
depVerRange (Dependency _ vr) = vr depVerRange (Dependency _ vr _) = vr
depLibraries :: Dependency -> Set LibraryName
depLibraries (Dependency _ _ cs) = cs
instance Binary Dependency instance Binary Dependency
instance NFData Dependency where rnf = genericRnf instance NFData Dependency where rnf = genericRnf
instance Pretty Dependency where instance Pretty Dependency where
pretty (Dependency name ver) = pretty name <+> pretty ver pretty (Dependency name ver sublibs) = pretty name
<+> optionalMonoid
(sublibs /= Set.singleton LMainLibName)
(PP.colon <+> PP.braces prettySublibs)
<+> pretty ver