Commit e28348ab authored by Francesco Gazzetta's avatar Francesco Gazzetta

Create the GivenComponent datatype

Before, a 3-tuple was used
parent bf89715d
......@@ -367,6 +367,7 @@ library
Distribution.Types.Version
Distribution.Types.VersionRange
Distribution.Types.VersionInterval
Distribution.Types.GivenComponent
Distribution.Utils.Generic
Distribution.Utils.NubList
Distribution.Utils.ShortText
......
......@@ -88,6 +88,7 @@ import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibType
import Distribution.Types.ForeignLibOption
import Distribution.Types.GivenComponent
import Distribution.Types.Mixin
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Utils
......@@ -1377,7 +1378,7 @@ interpretPackageDbFlags userInstall specificDBs =
-- deps in the end. So we still need to remember which installed packages to
-- pick.
combinedConstraints :: [Dependency] ->
[(PackageName, ComponentName, ComponentId)] ->
[GivenComponent] ->
InstalledPackageIndex ->
Either String ([Dependency],
Map (PackageName, ComponentName) InstalledPackageInfo)
......@@ -1410,7 +1411,7 @@ combinedConstraints constraints dependencies installedPackages = do
Maybe InstalledPackageInfo)]
dependenciesPkgInfo =
[ (pkgname, cname, cid, mpkg)
| (pkgname, cname, cid) <- dependencies
| GivenComponent pkgname cname cid <- dependencies
, let mpkg = PackageIndex.lookupComponentId
installedPackages cid
]
......
......@@ -99,6 +99,7 @@ import Distribution.Verbosity
import Distribution.Utils.NubList
import Distribution.Types.Dependency
import Distribution.Types.ComponentId
import Distribution.Types.GivenComponent
import Distribution.Types.Module
import Distribution.Types.PackageName
import Distribution.Types.UnqualComponentName (unUnqualComponentName)
......@@ -258,7 +259,7 @@ data ConfigFlags = ConfigFlags {
configStripLibs :: Flag Bool, -- ^Enable library stripping
configConstraints :: [Dependency], -- ^Additional constraints for
-- dependencies.
configDependencies :: [(PackageName, ComponentName, ComponentId)],
configDependencies :: [GivenComponent],
-- ^The packages depended on.
configInstantiateWith :: [(ModuleName, Module)],
-- ^ The requested Backpack instantiation. If empty, either this
......@@ -648,8 +649,8 @@ configureOptions showOrParseArgs =
"A list of exact dependencies. E.g., --dependency=\"void=void-0.5.8-177d5cdf20962d0581fe2e4932a6c309\""
configDependencies (\v flags -> flags { configDependencies = v})
(reqArg "NAME[:COMPONENT_NAME]=CID"
(parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecDependency))
(map (\(pn, cn, cid) ->
(parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecGivenComponent))
(map (\(GivenComponent pn cn cid) ->
prettyShow pn
++ case cn of CLibName -> ""
CSubLibName n -> ":" ++ prettyShow n
......@@ -736,8 +737,8 @@ showProfDetailLevelFlag :: Flag ProfDetailLevel -> [String]
showProfDetailLevelFlag NoFlag = []
showProfDetailLevelFlag (Flag dl) = [showProfDetailLevel dl]
parsecDependency :: ParsecParser (PackageName, ComponentName, ComponentId)
parsecDependency = do
parsecGivenComponent :: ParsecParser GivenComponent
parsecGivenComponent = do
pn <- parsec
cn <- P.option CLibName $ do
_ <- P.char ':'
......@@ -747,7 +748,7 @@ parsecDependency = do
else CSubLibName ucn
_ <- P.char '='
cid <- parsec
return (pn, cn, cid)
return $ GivenComponent pn cn cid
installDirsOptions :: [OptionField (InstallDirs (Flag PathTemplate))]
installDirsOptions =
......
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.GivenComponent (
GivenComponent(..)
) where
import Distribution.Compat.Prelude
import Distribution.Types.ComponentId
import Distribution.Types.ComponentName
import Distribution.Types.PackageName
-- | A 'GivenComponent' represents a component depended on and explicitly
-- specified by the user/client with @--dependency@
--
-- It enables Cabal to know which 'ComponentId' to associate with a component
--
-- @since 2.3.0.0
data GivenComponent =
GivenComponent
{ givenComponentPackage :: PackageName
, givenComponentName :: ComponentName
, givenComponentId :: ComponentId }
deriving (Generic, Read, Show, Eq, Typeable)
instance Binary GivenComponent
......@@ -64,6 +64,8 @@ import Distribution.Package
( Package(..), packageName, PackageId )
import Distribution.Types.Dependency
( Dependency(..), thisPackageVersion )
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import qualified Distribution.PackageDescription as PkgDesc
import Distribution.PackageDescription.Parsec
( readGenericPackageDescription )
......@@ -402,7 +404,7 @@ configurePackage verbosity platform comp scriptOptions configFlags
-- depending on the Cabal version we are talking to.
configConstraints = [ thisPackageVersion srcid
| ConfiguredId srcid (Just PkgDesc.CLibName) _uid <- CD.nonSetupDeps deps ],
configDependencies = [ (packageName srcid, PkgDesc.CLibName, uid)
configDependencies = [ GivenComponent (packageName srcid) (PkgDesc.CLibName) uid
| ConfiguredId srcid (Just PkgDesc.CLibName) uid <- CD.nonSetupDeps deps ],
-- Use '--exact-configuration' if supported.
configExactConfiguration = toFlag True,
......
......@@ -143,6 +143,8 @@ import Distribution.Package
, UnitId )
import Distribution.Types.Dependency
( Dependency(..), thisPackageVersion )
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import Distribution.Types.MungedPackageId
import qualified Distribution.PackageDescription as PackageDescription
import Distribution.PackageDescription
......@@ -1245,7 +1247,7 @@ installReadyPackage platform cinfo configFlags
configConstraints = [ thisPackageVersion srcid
| ConfiguredId srcid (Just PackageDescription.CLibName) _ipid
<- CD.nonSetupDeps deps ],
configDependencies = [ (packageName srcid, PackageDescription.CLibName, dep_ipid)
configDependencies = [ GivenComponent (packageName srcid) PackageDescription.CLibName dep_ipid
| ConfiguredId srcid (Just PackageDescription.CLibName) dep_ipid
<- CD.nonSetupDeps deps ],
-- Use '--exact-configuration' if supported.
......
......@@ -112,6 +112,8 @@ import Distribution.Package hiding
(InstalledPackageId, installedPackageId)
import Distribution.Types.AnnotatedId
import Distribution.Types.ComponentName
import Distribution.Types.GivenComponent
(GivenComponent(..))
import Distribution.Types.PkgconfigDependency
import Distribution.Types.UnqualComponentName
import Distribution.System
......@@ -3298,14 +3300,15 @@ setupHsConfigureFlags (ReadyPackage elab@ElaboratedConfiguredPackage{..})
-- NB: This does NOT use InstallPlan.depends, which includes executable
-- dependencies which should NOT be fed in here (also you don't have
-- enough info anyway)
configDependencies = [ (case mb_cn of
-- Special case for internal libraries
Just (CSubLibName uqn)
| packageId elab == srcid
-> mkPackageName (unUnqualComponentName uqn)
_ -> packageName srcid,
CLibName,
cid)
configDependencies = [ GivenComponent
(case mb_cn of
-- Special case for internal libraries
Just (CSubLibName uqn)
| packageId elab == srcid
-> mkPackageName (unUnqualComponentName uqn)
_ -> packageName srcid)
CLibName
cid
| ConfiguredId srcid mb_cn cid <- elabLibDependencies elab ]
configConstraints =
case elabPkgOrComp of
......
......@@ -110,8 +110,13 @@ import Distribution.Simple.InstallDirs
import Distribution.Version
( Version, mkVersion, nullVersion, anyVersion, thisVersion )
import Distribution.Package
( PackageIdentifier, PackageName, packageName, packageVersion )
( PackageIdentifier, PackageName, packageName, mkPackageName
, packageVersion )
import Distribution.Types.Dependency
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import Distribution.Types.UnqualComponentName
( unUnqualComponentName )
import Distribution.PackageDescription
( BuildType(..), RepoKind(..), ComponentName(..) )
import Distribution.System ( Platform )
......@@ -528,9 +533,15 @@ filterConfigureFlags flags cabalLibVersion
-- Cabal < 2.5.0 does not understand --dependency=pkg:COMPONENT=cid
-- (public sublibraries)
configDependencies =
let isMainLib CLibName = True
isMainLib _ = False
in filter (\(_, c, _) -> isMainLib c) $ configDependencies flags
let convertToLegacyInternalDep (GivenComponent _ (CSubLibName cn) cid) =
Just $ GivenComponent
(mkPackageName $ unUnqualComponentName cn)
CLibName
cid
convertToLegacyInternalDep (GivenComponent pn CLibName cid) =
Just $ GivenComponent pn CLibName cid
convertToLegacyInternalDep _ = Nothing
in catMaybes $ convertToLegacyInternalDep <$> configDependencies flags
}
flags_2_1_0 = flags_2_5_0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment