Skip to content

Commit a64244e

Browse files
committed
Include package version in --promised-dependency flag
In the original implementation of promised dependencies I accidentally left over the hard coded `currentCabalId` in the `configureDependencies` function. This led to several errors happening later when the package name and version would be incorrect if you looked at this field (package arguments are not computed using it), it is used when generating cabal macros and something in the haddock options. The solution is to pass the package version in the `--promised-depenency` flag so the format is now ``` NAME-VER[:COMPONENT_NAME]=CID` ``` rather than ``` NAME[:COMPONENT_NAME]=CID ``` Fixes #10166
1 parent 1ff41e8 commit a64244e

File tree

19 files changed

+177
-40
lines changed

19 files changed

+177
-40
lines changed

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ md5CheckGenericPackageDescription proxy = md5Check proxy
3434

3535
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
3636
md5CheckLocalBuildInfo proxy = md5Check proxy
37-
0xb0a61f1d93717a92b2b4ecbe0bc3abd4
37+
0x2c8550e1552f68bf169fafbfcd8f845a

Cabal/src/Distribution/Backpack/Configure.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ configureComponentLocalBuildInfos
7070
-> Flag String -- configIPID
7171
-> Flag ComponentId -- configCID
7272
-> PackageDescription
73-
-> ([PreExistingComponent], [PromisedComponent])
73+
-> ([PreExistingComponent], [ConfiguredPromisedComponent])
7474
-> FlagAssignment -- configConfigurationsFlags
7575
-> [(ModuleName, Module)] -- configInstantiateWith
7676
-> InstalledPackageIndex
@@ -118,7 +118,7 @@ configureComponentLocalBuildInfos
118118
`Map.union` Map.fromListWith
119119
Map.union
120120
[ (pkg, Map.singleton (ann_cname aid) aid)
121-
| PromisedComponent pkg aid <- promisedPkgDeps
121+
| ConfiguredPromisedComponent pkg aid <- promisedPkgDeps
122122
]
123123
graph1 <-
124124
toConfiguredComponents
@@ -151,7 +151,7 @@ configureComponentLocalBuildInfos
151151
, emptyModuleShape
152152
)
153153
)
154-
| PromisedComponent _ aid <- promisedPkgDeps
154+
| ConfiguredPromisedComponent _ aid <- promisedPkgDeps
155155
]
156156
uid_lookup def_uid
157157
| Just pkg <- PackageIndex.lookupUnitId installedPackageSet uid =
@@ -208,7 +208,7 @@ configureComponentLocalBuildInfos
208208
toComponentLocalBuildInfos
209209
:: Compiler
210210
-> InstalledPackageIndex -- FULL set
211-
-> [PromisedComponent]
211+
-> [ConfiguredPromisedComponent]
212212
-> PackageDescription
213213
-> [PreExistingComponent] -- external package deps
214214
-> [ReadyComponent]

Cabal/src/Distribution/Backpack/PreExistingComponent.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- | See <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
22
module Distribution.Backpack.PreExistingComponent
33
( PreExistingComponent (..)
4-
, PromisedComponent (..)
4+
, ConfiguredPromisedComponent (..)
55
, ipiToPreExistingComponent
66
) where
77

@@ -24,12 +24,12 @@ import Distribution.Types.AnnotatedId
2424
-- These components are promised to @configure@ but are not yet built.
2525
--
2626
-- In other words this is 'PreExistingComponent' which doesn't yet exist.
27-
data PromisedComponent = PromisedComponent
27+
data ConfiguredPromisedComponent = ConfiguredPromisedComponent
2828
{ pr_pkgname :: PackageName
2929
, pr_cid :: AnnotatedId ComponentId
3030
}
3131

32-
instance Package PromisedComponent where
32+
instance Package ConfiguredPromisedComponent where
3333
packageId = packageId . pr_cid
3434

3535
-- | Stripped down version of 'LinkedComponent' for things

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ computeLocalBuildConfig cfg comp programDb = do
828828

829829
data PackageInfo = PackageInfo
830830
{ internalPackageSet :: Set LibraryName
831-
, promisedDepsSet :: Map (PackageName, ComponentName) ComponentId
831+
, promisedDepsSet :: Map (PackageName, ComponentName) PromisedComponent
832832
, installedPackageSet :: InstalledPackageIndex
833833
, requiredDepsMap :: Map (PackageName, ComponentName) InstalledPackageInfo
834834
}
@@ -1113,7 +1113,7 @@ finalCheckPackage
11131113
-> LBC.PackageBuildDescr
11141114
-> HookedBuildInfo
11151115
-> PackageInfo
1116-
-> IO ([PreExistingComponent], [PromisedComponent])
1116+
-> IO ([PreExistingComponent], [ConfiguredPromisedComponent])
11171117
finalCheckPackage
11181118
g_pkg_descr
11191119
( LBC.PackageBuildDescr
@@ -1210,7 +1210,7 @@ configureComponents
12101210
:: LBC.LocalBuildConfig
12111211
-> LBC.PackageBuildDescr
12121212
-> PackageInfo
1213-
-> ([PreExistingComponent], [PromisedComponent])
1213+
-> ([PreExistingComponent], [ConfiguredPromisedComponent])
12141214
-> IO LocalBuildInfo
12151215
configureComponents
12161216
lbc@(LBC.LocalBuildConfig{withPrograms = programDb})
@@ -1373,8 +1373,8 @@ configureComponents
13731373

13741374
return lbi
13751375

1376-
mkPromisedDepsSet :: [GivenComponent] -> Map (PackageName, ComponentName) ComponentId
1377-
mkPromisedDepsSet comps = Map.fromList [((pn, CLibName ln), cid) | GivenComponent pn ln cid <- comps]
1376+
mkPromisedDepsSet :: [PromisedComponent] -> Map (PackageName, ComponentName) PromisedComponent
1377+
mkPromisedDepsSet comps = Map.fromList [((packageName pn, CLibName ln), p) | p@(PromisedComponent pn ln _) <- comps]
13781378

13791379
-- | Adds the extra program paths from the flags provided to @configure@ as
13801380
-- well as specified locations for certain known programs and their default
@@ -1477,7 +1477,7 @@ dependencySatisfiable
14771477
-- ^ installed set
14781478
-> Set LibraryName
14791479
-- ^ library components
1480-
-> Map (PackageName, ComponentName) ComponentId
1480+
-> Map (PackageName, ComponentName) PromisedComponent
14811481
-> Map (PackageName, ComponentName) InstalledPackageInfo
14821482
-- ^ required dependencies
14831483
-> (Dependency -> Bool)
@@ -1639,14 +1639,14 @@ configureDependencies
16391639
:: Verbosity
16401640
-> UseExternalInternalDeps
16411641
-> Set LibraryName
1642-
-> Map (PackageName, ComponentName) ComponentId
1642+
-> Map (PackageName, ComponentName) PromisedComponent
16431643
-> InstalledPackageIndex
16441644
-- ^ installed packages
16451645
-> Map (PackageName, ComponentName) InstalledPackageInfo
16461646
-- ^ required deps
16471647
-> PackageDescription
16481648
-> ComponentRequestedSpec
1649-
-> IO ([PreExistingComponent], [PromisedComponent])
1649+
-> IO ([PreExistingComponent], [ConfiguredPromisedComponent])
16501650
configureDependencies
16511651
verbosity
16521652
use_external_internal_deps
@@ -1912,7 +1912,7 @@ data DependencyResolution
19121912
-- we need to build packages in the interactive ghci session, no matter
19131913
-- whether they have been built before.
19141914
-- Building them in the configure phase is then redundant and costs time.
1915-
PromisedDependency PromisedComponent
1915+
PromisedDependency ConfiguredPromisedComponent
19161916
| -- | An internal dependency ('PackageId' should be a library name)
19171917
-- which we are going to have to build. (The
19181918
-- 'PackageId' here is a hack to get a modest amount of
@@ -1925,7 +1925,7 @@ selectDependency
19251925
-- ^ Package id of current package
19261926
-> Set LibraryName
19271927
-- ^ package libraries
1928-
-> Map (PackageName, ComponentName) ComponentId
1928+
-> Map (PackageName, ComponentName) PromisedComponent
19291929
-- ^ Set of components that are promised, i.e. are not installed already. See 'PromisedDependency' for more details.
19301930
-> InstalledPackageIndex
19311931
-- ^ Installed packages
@@ -1977,8 +1977,8 @@ selectDependency
19771977
-- We have to look it up externally
19781978
do_external_external :: LibraryName -> Either FailedDependency DependencyResolution
19791979
do_external_external lib
1980-
| Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1981-
return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid))
1980+
| Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1981+
return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc)))
19821982
do_external_external lib = do
19831983
ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of
19841984
-- If we know the exact pkg to use, then use it.
@@ -1991,8 +1991,8 @@ selectDependency
19911991

19921992
do_external_internal :: LibraryName -> Either FailedDependency DependencyResolution
19931993
do_external_internal lib
1994-
| Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1995-
return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid))
1994+
| Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1995+
return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc)))
19961996
do_external_internal lib = do
19971997
ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of
19981998
-- If we know the exact pkg to use, then use it.

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ import Distribution.Simple.Program.GHC
7575
import Distribution.Simple.Setup.Common (extraCompilationArtifacts)
7676
import Distribution.Simple.Utils
7777
import Distribution.System
78-
import Distribution.Types.ComponentId (ComponentId)
7978
import Distribution.Types.ComponentLocalBuildInfo
79+
import Distribution.Types.GivenComponent
8080
import Distribution.Types.LocalBuildInfo
8181
import Distribution.Types.TargetInfo
8282
import Distribution.Types.UnitId
@@ -672,15 +672,15 @@ getHaskellObjects _implInfo lib lbi clbi pref wanted_obj_ext allow_split_objs
672672
-- and is a hack to avoid passing bogus `-package` arguments to GHC. The assumption being that
673673
-- in 99% of cases we will include the right `-package` so that the C file finds the right headers.
674674
mkGhcOptPackages
675-
:: Map (PackageName, ComponentName) ComponentId
675+
:: Map (PackageName, ComponentName) PromisedComponent
676676
-> ComponentLocalBuildInfo
677677
-> [(OpenUnitId, ModuleRenaming)]
678678
mkGhcOptPackages promisedPkgsMap clbi =
679679
[ i | i@(uid, _) <- componentIncludes clbi, abstractUnitId uid `Set.notMember` promised_cids
680680
]
681681
where
682682
-- Promised deps are going to be simple UnitIds
683-
promised_cids = Set.fromList (map newSimpleUnitId (Map.elems promisedPkgsMap))
683+
promised_cids = Set.fromList (map (newSimpleUnitId . promisedComponentId) (Map.elems promisedPkgsMap))
684684

685685
substTopDir :: FilePath -> IPI.InstalledPackageInfo -> IPI.InstalledPackageInfo
686686
substTopDir topDir ipo =

Cabal/src/Distribution/Simple/Setup/Config.hs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ data ConfigFlags = ConfigFlags
185185
-- dependencies.
186186
, configDependencies :: [GivenComponent]
187187
-- ^ The packages depended on which already exist
188-
, configPromisedDependencies :: [GivenComponent]
188+
, configPromisedDependencies :: [PromisedComponent]
189189
-- ^ The packages depended on which doesn't yet exist (i.e. promised).
190190
-- Promising dependencies enables us to configure components in parallel,
191191
-- and avoids expensive builds if they are not necessary.
@@ -779,13 +779,13 @@ configureOptions showOrParseArgs =
779779
, option
780780
""
781781
["promised-dependency"]
782-
"A list of promised dependencies. E.g., --promised-dependency=\"void=void-0.5.8-177d5cdf20962d0581fe2e4932a6c309\""
782+
"A list of promised dependencies. E.g., --promised-dependency=\"void-0.5.8=void-0.5.8-177d5cdf20962d0581fe2e4932a6c309\""
783783
configPromisedDependencies
784784
(\v flags -> flags{configPromisedDependencies = v})
785785
( reqArg
786-
"NAME[:COMPONENT_NAME]=CID"
787-
(parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecGivenComponent))
788-
(map prettyGivenComponent)
786+
"NAME-VER[:COMPONENT_NAME]=CID"
787+
(parsecToReadE (const "dependency expected") ((\x -> [x]) `fmap` parsecPromisedComponent))
788+
(map prettyPromisedComponent)
789789
)
790790
, option
791791
""
@@ -923,6 +923,29 @@ showProfDetailLevelFlag :: Flag ProfDetailLevel -> [String]
923923
showProfDetailLevelFlag NoFlag = []
924924
showProfDetailLevelFlag (Flag dl) = [showProfDetailLevel dl]
925925

926+
parsecPromisedComponent :: ParsecParser PromisedComponent
927+
parsecPromisedComponent = do
928+
pn <- parsec
929+
ln <- P.option LMainLibName $ do
930+
_ <- P.char ':'
931+
ucn <- parsec
932+
return $
933+
if unUnqualComponentName ucn == unPackageName (pkgName pn)
934+
then LMainLibName
935+
else LSubLibName ucn
936+
_ <- P.char '='
937+
cid <- parsec
938+
return $ PromisedComponent pn ln cid
939+
940+
prettyPromisedComponent :: PromisedComponent -> String
941+
prettyPromisedComponent (PromisedComponent pn cn cid) =
942+
prettyShow pn
943+
++ case cn of
944+
LMainLibName -> ""
945+
LSubLibName n -> ":" ++ prettyShow n
946+
++ "="
947+
++ prettyShow cid
948+
926949
parsecGivenComponent :: ParsecParser GivenComponent
927950
parsecGivenComponent = do
928951
pn <- parsec

Cabal/src/Distribution/Types/GivenComponent.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
module Distribution.Types.GivenComponent
55
( GivenComponent (..)
6+
, PromisedComponent (..)
67
) where
78

89
import Distribution.Compat.Prelude
910

1011
import Distribution.Types.ComponentId
1112
import Distribution.Types.LibraryName
13+
import Distribution.Types.PackageId
1214
import Distribution.Types.PackageName
1315

1416
-- | A 'GivenComponent' represents a library depended on and explicitly
@@ -27,3 +29,20 @@ data GivenComponent = GivenComponent
2729

2830
instance Binary GivenComponent
2931
instance Structured GivenComponent
32+
33+
-- | A 'PromisedComponent' represents a promised library depended on and explicitly
34+
-- specified by the user/client with @--promised-dependency@
35+
--
36+
-- It enables Cabal to know which 'ComponentId' to associate with a library
37+
--
38+
-- @since 3.14.0.0
39+
data PromisedComponent = PromisedComponent
40+
{ promisedComponentPackage :: PackageId
41+
, promisedComponentName :: LibraryName -- --dependency is for libraries
42+
-- only, not for any component
43+
, promisedComponentId :: ComponentId
44+
}
45+
deriving (Generic, Read, Show, Eq, Typeable)
46+
47+
instance Binary PromisedComponent
48+
instance Structured PromisedComponent

Cabal/src/Distribution/Types/LocalBuildConfig.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ module Distribution.Types.LocalBuildConfig
2222
import Distribution.Compat.Prelude
2323
import Prelude ()
2424

25-
import Distribution.Types.ComponentId
2625
import Distribution.Types.ComponentLocalBuildInfo
2726
import Distribution.Types.ComponentRequestedSpec
27+
import Distribution.Types.GivenComponent
2828
import Distribution.Types.PackageDescription
2929
import Distribution.Types.UnitId
3030

@@ -101,7 +101,7 @@ data ComponentBuildDescr = ComponentBuildDescr
101101
-- ^ A map from component name to all matching
102102
-- components. These coincide with 'componentGraph'
103103
-- There may be more than one matching component because of backpack instantiations
104-
, promisedPkgs :: Map (PackageName, ComponentName) ComponentId
104+
, promisedPkgs :: Map (PackageName, ComponentName) PromisedComponent
105105
-- ^ The packages we were promised, but aren't already installed.
106106
-- MP: Perhaps this just needs to be a Set UnitId at this stage.
107107
, installedPkgs :: InstalledPackageIndex

Cabal/src/Distribution/Types/LocalBuildInfo.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import Prelude ()
103103
import Distribution.Types.ComponentId
104104
import Distribution.Types.ComponentLocalBuildInfo
105105
import Distribution.Types.ComponentRequestedSpec
106+
import Distribution.Types.GivenComponent
106107
import qualified Distribution.Types.LocalBuildConfig as LBC
107108
import Distribution.Types.PackageDescription
108109
import Distribution.Types.PackageId
@@ -160,7 +161,7 @@ pattern LocalBuildInfo
160161
-> Maybe (SymbolicPath Pkg File)
161162
-> Graph ComponentLocalBuildInfo
162163
-> Map ComponentName [ComponentLocalBuildInfo]
163-
-> Map (PackageName, ComponentName) ComponentId
164+
-> Map (PackageName, ComponentName) PromisedComponent
164165
-> InstalledPackageIndex
165166
-> PackageDescription
166167
-> ProgramDb

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,7 @@ setupHsConfigureFlags
40174017
]
40184018

40194019
configPromisedDependencies =
4020-
[ cidToGivenComponent cid
4020+
[ cidToPromisedComponent cid
40214021
| (cid, is_internal) <- elabLibDependencies elab
40224022
, is_internal
40234023
]
@@ -4060,6 +4060,15 @@ setupHsConfigureFlags
40604060

40614061
configCoverageFor = determineCoverageFor elab plan
40624062

4063+
cidToPromisedComponent :: ConfiguredId -> PromisedComponent
4064+
cidToPromisedComponent (ConfiguredId srcid mb_cn cid) =
4065+
PromisedComponent srcid ln cid
4066+
where
4067+
ln = case mb_cn of
4068+
Just (CLibName lname) -> lname
4069+
Just _ -> error "non-library dependency"
4070+
Nothing -> LMainLibName
4071+
40634072
setupHsConfigureArgs
40644073
:: ElaboratedConfiguredPackage
40654074
-> [String]

0 commit comments

Comments
 (0)