Skip to content

Commit af24cef

Browse files
committed
Drop version check when resolving package names.
In #4017, hvr reported that when he used --allow-older/--allow-newer, there was an assert failure in toConfiguredComponent. Indeed the problem was that toConfiguredComponent was testing version ranges of build-depends to determine which package to select, but there was no satisfying one (since the build-depends field had not been updated.) After thinking about this for a bit, it seemed a bit bogus for us to be doing another version check at this late phase; we already picked dependencies earlier in the configuration process. So I decided to drop it. To drop it, however, I needed to remove support for a feature (discussed in #4020), which uses version ranges to disambiguate whether or not a dependency is on an external package or an internal package. This feature doesn't seem to be very useful. If someone asks, I'll check on Hackage to see if anyone is using it. Also added some useful extra debug info. Fixes #4020 and #4017 Signed-off-by: Edward Z. Yang <[email protected]>
1 parent 9d25d06 commit af24cef

File tree

11 files changed

+79
-36
lines changed

11 files changed

+79
-36
lines changed

Cabal/Distribution/Backpack/ConfiguredComponent.hs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,16 @@ toConfiguredComponent pkg_descr this_cid
126126
lib_deps exe_deps component
127127
where
128128
bi = componentBuildInfo component
129-
find_it :: PackageName -> VersionRange -> (ComponentId, PackageId)
130-
find_it name reqVer =
131-
fromMaybe (error ("toConfiguredComponent: " ++ display name)) $
132-
lookup_name lib_map <|>
133-
lookup_name external_lib_map
134-
where
135-
lookup_name m =
136-
case Map.lookup name m of
137-
Just (cid, pkgid)
138-
| packageVersion pkgid `withinRange` reqVer
139-
-> Just (cid, pkgid)
140-
_ -> Nothing
129+
find_it :: PackageName -> (ComponentId, PackageId)
130+
find_it name =
131+
fromMaybe (error ("toConfiguredComponent: " ++ display (packageName pkg_descr) ++
132+
" " ++ display name)) $
133+
Map.lookup name lib_map <|>
134+
Map.lookup name external_lib_map
141135
lib_deps
142136
| newPackageDepsBehaviour pkg_descr
143-
= [ (name, find_it name reqVer)
144-
| Dependency name reqVer <- targetBuildDepends bi ]
137+
= [ (name, find_it name)
138+
| Dependency name _ <- targetBuildDepends bi ]
145139
| otherwise
146140
= Map.toList external_lib_map
147141
exe_deps = [ cid

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,14 @@ checkFields pkg =
520520
++ "different versions of the same compiler use multiple entries, "
521521
++ "for example 'tested-with: GHC==6.10.4, GHC==6.12.3' and not "
522522
++ "'tested-with: GHC==6.10.4 && ==6.12.3'."
523+
524+
, check (not (null buildDependsRangeOnInternalLibrary)) $
525+
PackageBuildWarning $
526+
"The package has a version range for a dependency on an "
527+
++ "internal library: "
528+
++ commaSep (map display buildDependsRangeOnInternalLibrary)
529+
++ ". This version range has no semantic meaning and can be "
530+
++ "removed."
523531
]
524532
where
525533
unknownCompilers = [ name | (OtherCompiler name, _) <- testedWith pkg ]
@@ -542,6 +550,17 @@ checkFields pkg =
542550
| (compiler, vr) <- testedWith pkg
543551
, isNoVersion vr ]
544552

553+
internalLibraries =
554+
map (maybe (packageName pkg) mkPackageName . libName)
555+
(allLibraries pkg)
556+
buildDependsRangeOnInternalLibrary =
557+
[ dep
558+
| bi <- allBuildInfo pkg
559+
, dep@(Dependency name versionRange) <- targetBuildDepends bi
560+
, not (isAnyVersion versionRange)
561+
, name `elem` internalLibraries
562+
]
563+
545564

546565
checkLicense :: PackageDescription -> [PackageCheck]
547566
checkLicense pkg =

Cabal/Distribution/Simple/Configure.hs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ dependencySatisfiable
817817
-> Map PackageName InstalledPackageInfo -- ^ required dependencies
818818
-> (Dependency -> Bool)
819819
dependencySatisfiable
820-
exact_config pkg_ver installedPackageSet internalPackageSet requiredDepsMap
821-
d@(Dependency depName verRange)
820+
exact_config _ installedPackageSet internalPackageSet requiredDepsMap
821+
d@(Dependency depName _)
822822
| exact_config =
823823
-- When we're given '--exact-configuration', we assume that all
824824
-- dependencies and flags are exactly specified on the command
@@ -838,17 +838,12 @@ dependencySatisfiable
838838
-- when it actually isn't.
839839
(depName `Map.member` requiredDepsMap) || isInternalDep
840840

841-
| isInternalDep
842-
, pkg_ver `withinRange` verRange =
843-
-- If a 'PackageName' is defined by an internal component,
844-
-- and the user didn't specify a version range which is
845-
-- incompatible with the package version, the dep is
846-
-- satisfiable (and we are going to use the internal
847-
-- dependency.) Note that this doesn't mean we are
848-
-- actually going to SUCCEED when we configure the package,
849-
-- if UseExternalInternalDeps is True. NB: if
850-
-- the version bound fails we want to fall through to the
851-
-- next case.
841+
| isInternalDep =
842+
-- If a 'PackageName' is defined by an internal component, the
843+
-- dep is satisfiable (and we are going to use the internal
844+
-- dependency.) Note that this doesn't mean we are actually
845+
-- going to SUCCEED when we configure the package, if
846+
-- UseExternalInternalDeps is True.
852847
True
853848

854849
| otherwise =
@@ -1164,13 +1159,11 @@ selectDependency pkgid internalIndex installedIndex requiredDepsMap
11641159
--
11651160
-- We want "build-depends: MyLibrary" always to match the internal library
11661161
-- even if there is a newer installed library "MyLibrary-0.2".
1167-
-- However, "build-depends: MyLibrary >= 0.2" should match the installed one.
11681162
case Map.lookup dep_pkgname internalIndex of
1169-
Just cname | packageVersion pkgid `withinRange` vr
1170-
-> if use_external_internal_deps
1171-
then do_external (Just cname)
1172-
else do_internal
1173-
_ -> do_external Nothing
1163+
Just cname -> if use_external_internal_deps
1164+
then do_external (Just cname)
1165+
else do_internal
1166+
_ -> do_external Nothing
11741167
where
11751168
do_internal = Right (InternalDependency dep
11761169
(PackageIdentifier dep_pkgname (packageVersion pkgid)))

Cabal/changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
or greater, respectively).
9999
* New `Distribution.Utils.ShortText.ShortText` type for representing
100100
short text strings compactly (#3898)
101+
* Cabal no longer supports using a version bound to disambiguate
102+
between an internal and external package (#4020). This should
103+
not affect many people, as this mode of use already did not
104+
work with the dependency solver.
101105

102106
1.24.0.0 Ryan Thomas <[email protected]> March 2016
103107
* Support GHC 8.

Cabal/tests/PackageTests/Tests.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ tests config = do
120120
-- with the same name and LATER version
121121
tc "BuildDeps/InternalLibrary3" $ internal_lib_test "internal"
122122

123-
-- Test that an explicit dependency constraint which doesn't
124-
-- match the internal library causes us to use external library
125-
tc "BuildDeps/InternalLibrary4" $ internal_lib_test "installed"
123+
-- On old versions of Cabal, an explicit dependency constraint which
124+
-- doesn't match the internal library causes us to use external
125+
-- library. We got rid of this functionality in 1.25; now, we always
126+
-- use internal, and just emit an error if you check.
127+
tcs "BuildDeps/InternalLibrary4" "external" $ internal_lib_test "internal"
128+
129+
-- On a previous buggy version of my patch, the test above passed only
130+
-- because the installed library caused Cabal to think that the
131+
-- dependency was fulfilled. Make sure we ignore the dependency
132+
-- entirely.
133+
tcs "BuildDeps/InternalLibrary4" "ignore" $ cabal_build []
126134

127135
-- Test "old build-dep behavior", where we should get the
128136
-- same package dependencies on all targets if cabal-version

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,8 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
10961096
-> LogProgress [ElaboratedConfiguredPackage]
10971097
elaborateSolverToComponents mapDep spkg@(SolverPackage _ _ _ deps0 exe_deps0)
10981098
| Right g <- toComponentsGraph (elabEnabledSpec elab0) pd = do
1099+
infoProgress $ hang (text "Component graph for" <+> disp pkgid <<>> colon)
1100+
4 (dispComponentsGraph g)
10991101
(_, comps) <- mapAccumM buildComponent
11001102
((Map.empty, Map.empty), Map.empty, Map.empty)
11011103
(map fst g)

cabal-install/cabal-install.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ Extra-Source-Files:
139139
tests/IntegrationTests/new-build/T3978/cabal.project
140140
tests/IntegrationTests/new-build/T3978/p/p.cabal
141141
tests/IntegrationTests/new-build/T3978/q/q.cabal
142+
tests/IntegrationTests/new-build/T4017.sh
143+
tests/IntegrationTests/new-build/T4017/cabal.project
144+
tests/IntegrationTests/new-build/T4017/p/p.cabal
145+
tests/IntegrationTests/new-build/T4017/q/q.cabal
142146
tests/IntegrationTests/new-build/executable/Main.hs
143147
tests/IntegrationTests/new-build/executable/Setup.hs
144148
tests/IntegrationTests/new-build/executable/Test.hs
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ./common.sh
2+
cd T4017
3+
cabal new-build q
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: p q
2+
allow-older: p:base
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: p
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
library
7+
build-depends: base >= 99999
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: q
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
library
7+
build-depends: p

0 commit comments

Comments
 (0)