Skip to content

Commit 8fc8b9b

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 30d2a38 commit 8fc8b9b

File tree

19 files changed

+178
-41
lines changed

19 files changed

+178
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ md5CheckGenericPackageDescription proxy = md5Check proxy
3939
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
4040
md5CheckLocalBuildInfo proxy = md5Check proxy
4141
#if MIN_VERSION_base(4,19,0)
42-
0xc68e9c0758c4bf2d72fe82b3d55cee34
42+
0x041c4f233ad92ae5c3fc4e0384f993ff
4343
#else
44-
0xcf7e7bbcaec504d745fe086eec1786ff
44+
0x26e4eb4ac4691ca0432e8622eb5a5016
4545
#endif

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})
@@ -1371,8 +1371,8 @@ configureComponents
13711371

13721372
return lbi
13731373

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

13771377
-- | Adds the extra program paths from the flags provided to @configure@ as
13781378
-- well as specified locations for certain known programs and their default
@@ -1475,7 +1475,7 @@ dependencySatisfiable
14751475
-- ^ installed set
14761476
-> Set LibraryName
14771477
-- ^ library components
1478-
-> Map (PackageName, ComponentName) ComponentId
1478+
-> Map (PackageName, ComponentName) PromisedComponent
14791479
-> Map (PackageName, ComponentName) InstalledPackageInfo
14801480
-- ^ required dependencies
14811481
-> (Dependency -> Bool)
@@ -1637,14 +1637,14 @@ configureDependencies
16371637
:: Verbosity
16381638
-> UseExternalInternalDeps
16391639
-> Set LibraryName
1640-
-> Map (PackageName, ComponentName) ComponentId
1640+
-> Map (PackageName, ComponentName) PromisedComponent
16411641
-> InstalledPackageIndex
16421642
-- ^ installed packages
16431643
-> Map (PackageName, ComponentName) InstalledPackageInfo
16441644
-- ^ required deps
16451645
-> PackageDescription
16461646
-> ComponentRequestedSpec
1647-
-> IO ([PreExistingComponent], [PromisedComponent])
1647+
-> IO ([PreExistingComponent], [ConfiguredPromisedComponent])
16481648
configureDependencies
16491649
verbosity
16501650
use_external_internal_deps
@@ -1910,7 +1910,7 @@ data DependencyResolution
19101910
-- we need to build packages in the interactive ghci session, no matter
19111911
-- whether they have been built before.
19121912
-- Building them in the configure phase is then redundant and costs time.
1913-
PromisedDependency PromisedComponent
1913+
PromisedDependency ConfiguredPromisedComponent
19141914
| -- | An internal dependency ('PackageId' should be a library name)
19151915
-- which we are going to have to build. (The
19161916
-- 'PackageId' here is a hack to get a modest amount of
@@ -1923,7 +1923,7 @@ selectDependency
19231923
-- ^ Package id of current package
19241924
-> Set LibraryName
19251925
-- ^ package libraries
1926-
-> Map (PackageName, ComponentName) ComponentId
1926+
-> Map (PackageName, ComponentName) PromisedComponent
19271927
-- ^ Set of components that are promised, i.e. are not installed already. See 'PromisedDependency' for more details.
19281928
-> InstalledPackageIndex
19291929
-- ^ Installed packages
@@ -1975,8 +1975,8 @@ selectDependency
19751975
-- We have to look it up externally
19761976
do_external_external :: LibraryName -> Either FailedDependency DependencyResolution
19771977
do_external_external lib
1978-
| Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1979-
return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid))
1978+
| Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1979+
return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc)))
19801980
do_external_external lib = do
19811981
ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of
19821982
-- If we know the exact pkg to use, then use it.
@@ -1989,8 +1989,8 @@ selectDependency
19891989

19901990
do_external_internal :: LibraryName -> Either FailedDependency DependencyResolution
19911991
do_external_internal lib
1992-
| Just cid <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1993-
return $ PromisedDependency (PromisedComponent dep_pkgname (AnnotatedId currentCabalId (CLibName lib) cid))
1992+
| Just pc <- Map.lookup (dep_pkgname, CLibName lib) promisedIndex =
1993+
return $ PromisedDependency (ConfiguredPromisedComponent dep_pkgname (AnnotatedId (promisedComponentPackage pc) (CLibName lib) (promisedComponentId pc)))
19941994
do_external_internal lib = do
19951995
ipi <- case Map.lookup (dep_pkgname, CLibName lib) requiredDepsMap of
19961996
-- 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.1.1=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
]
@@ -4058,6 +4058,15 @@ setupHsConfigureFlags
40584058
Just _ -> error "non-library dependency"
40594059
Nothing -> LMainLibName
40604060

4061+
cidToPromisedComponent :: ConfiguredId -> PromisedComponent
4062+
cidToPromisedComponent (ConfiguredId srcid mb_cn cid) =
4063+
PromisedComponent srcid ln cid
4064+
where
4065+
ln = case mb_cn of
4066+
Just (CLibName lname) -> lname
4067+
Just _ -> error "non-library dependency"
4068+
Nothing -> LMainLibName
4069+
40614070
configCoverageFor = determineCoverageFor elabPkgSourceId plan
40624071

40634072
setupHsConfigureArgs

0 commit comments

Comments
 (0)