Skip to content

Commit 9b380e2

Browse files
authored
Merge pull request #6907 from phadej/issue-6083-qualified-syntax-dep
Fix #6083: allow depending on public sublibrary with pkg:lib qualified syntax
2 parents 6001bc9 + 6747939 commit 9b380e2

File tree

16 files changed

+104
-82
lines changed

16 files changed

+104
-82
lines changed

cabal-install/Distribution/Client/Dependency.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ import qualified Distribution.PackageDescription as PD
9191
import qualified Distribution.PackageDescription.Configuration as PD
9292
import Distribution.PackageDescription.Configuration
9393
( finalizePD )
94-
import Distribution.Client.PackageUtils
95-
( externalBuildDepends )
9694
import Distribution.Compiler
9795
( CompilerInfo(..) )
9896
import Distribution.System
@@ -890,22 +888,27 @@ showPackageProblem (InvalidDep dep pkgid) =
890888
configuredPackageProblems :: Platform -> CompilerInfo
891889
-> SolverPackage UnresolvedPkgLoc -> [PackageProblem]
892890
configuredPackageProblems platform cinfo
893-
(SolverPackage pkg specifiedFlags stanzas specifiedDeps' _specifiedExeDeps') =
891+
(SolverPackage pkg specifiedFlags stanzas specifiedDeps0 _specifiedExeDeps') =
894892
[ DuplicateFlag flag
895893
| flag <- PD.findDuplicateFlagAssignments specifiedFlags ]
896894
++ [ MissingFlag flag | OnlyInLeft flag <- mergedFlags ]
897895
++ [ ExtraFlag flag | OnlyInRight flag <- mergedFlags ]
898896
++ [ DuplicateDeps pkgs
899897
| pkgs <- CD.nonSetupDeps (fmap (duplicatesBy (comparing packageName))
900-
specifiedDeps) ]
898+
specifiedDeps1) ]
901899
++ [ MissingDep dep | OnlyInLeft dep <- mergedDeps ]
902900
++ [ ExtraDep pkgid | OnlyInRight pkgid <- mergedDeps ]
903901
++ [ InvalidDep dep pkgid | InBoth dep pkgid <- mergedDeps
904902
, not (packageSatisfiesDependency pkgid dep) ]
905903
-- TODO: sanity tests on executable deps
906904
where
907-
specifiedDeps :: ComponentDeps [PackageId]
908-
specifiedDeps = fmap (map solverSrcId) specifiedDeps'
905+
thisPkgName = packageName (packageDescription pkg)
906+
907+
specifiedDeps1 :: ComponentDeps [PackageId]
908+
specifiedDeps1 = fmap (map solverSrcId) specifiedDeps0
909+
910+
specifiedDeps :: [PackageId]
911+
specifiedDeps = CD.flatDeps specifiedDeps1
909912

910913
mergedFlags = mergeBy compare
911914
(sort $ map PD.flagName (PD.genPackageFlags (packageDescription pkg)))
@@ -919,7 +922,7 @@ configuredPackageProblems platform cinfo
919922
dependencyName (Dependency name _ _) = name
920923

921924
mergedDeps :: [MergeResult Dependency PackageId]
922-
mergedDeps = mergeDeps requiredDeps (CD.flatDeps specifiedDeps)
925+
mergedDeps = mergeDeps requiredDeps specifiedDeps
923926

924927
mergeDeps :: [Dependency] -> [PackageId]
925928
-> [MergeResult Dependency PackageId]
@@ -947,7 +950,15 @@ configuredPackageProblems platform cinfo
947950
[]
948951
(packageDescription pkg) of
949952
Right (resolvedPkg, _) ->
950-
externalBuildDepends resolvedPkg compSpec
953+
-- we filter self/internal dependencies. They are still there.
954+
-- This is INCORRECT.
955+
--
956+
-- If we had per-component solver, it would make this unnecessary,
957+
-- but no finalizePDs picks components we are not building, eg. exes.
958+
-- See #3775
959+
--
960+
filter ((/= thisPkgName) . dependencyName)
961+
(PD.enabledBuildDepends resolvedPkg compSpec)
951962
++ maybe [] PD.setupDepends (PD.setupBuildInfo resolvedPkg)
952963
Left _ ->
953964
error "configuredPackageInvalidDeps internal error"

cabal-install/Distribution/Client/PackageUtils.hs

Lines changed: 0 additions & 41 deletions
This file was deleted.

cabal-install/Distribution/Solver/Modular/IndexConversion.hs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import Distribution.Simple.BuildToolDepends -- from Cabal
1717
import Distribution.Types.ExeDependency -- from Cabal
1818
import Distribution.Types.PkgconfigDependency -- from Cabal
1919
import Distribution.Types.ComponentName -- from Cabal
20-
import Distribution.Types.UnqualComponentName -- from Cabal
2120
import Distribution.Types.CondTree -- from Cabal
2221
import Distribution.Types.MungedPackageId -- from Cabal
2322
import Distribution.Types.MungedPackageName -- from Cabal
@@ -181,19 +180,11 @@ convGPD os arch cinfo constraints strfl solveExes pn
181180
let
182181
fds = flagInfo strfl flags
183182

184-
-- | We have to be careful to filter out dependencies on
185-
-- internal libraries, since they don't refer to real packages
186-
-- and thus cannot actually be solved over. We'll do this
187-
-- by creating a set of package names which are "internal"
188-
-- and dropping them as we convert.
189-
190-
ipns = S.fromList $ [ unqualComponentNameToPackageName nm
191-
| (nm, _) <- sub_libs ]
192183

193184
conv :: Monoid a => Component -> (a -> BuildInfo) -> DependencyReason PN ->
194185
CondTree ConfVar [Dependency] a -> FlaggedDeps PN
195186
conv comp getInfo dr =
196-
convCondTree M.empty dr pkg os arch cinfo pn fds comp getInfo ipns solveExes .
187+
convCondTree M.empty dr pkg os arch cinfo pn fds comp getInfo solveExes .
197188
addBuildableCondition getInfo
198189

199190
initDR = DependencyReason pn M.empty S.empty
@@ -331,41 +322,29 @@ flagInfo (StrongFlags strfl) =
331322
weak m = WeakOrTrivial $ not (strfl || m)
332323
flagType m = if m then Manual else Automatic
333324

334-
-- | Internal package names, which should not be interpreted as true
335-
-- dependencies.
336-
type IPNs = S.Set PN
337-
338-
-- | Convenience function to delete a 'Dependency' if it's
339-
-- for a 'PN' that isn't actually real.
340-
filterIPNs :: IPNs -> Dependency -> Maybe Dependency
341-
filterIPNs ipns d@(Dependency pn _ _)
342-
| S.notMember pn ipns = Just d
343-
| otherwise = Nothing
344-
345325
-- | Convert condition trees to flagged dependencies. Mutually
346326
-- recursive with 'convBranch'. See 'convBranch' for an explanation
347327
-- of all arguments preceding the input 'CondTree'.
348328
convCondTree :: Map FlagName Bool -> DependencyReason PN -> PackageDescription -> OS -> Arch -> CompilerInfo -> PN -> FlagInfo ->
349329
Component ->
350330
(a -> BuildInfo) ->
351-
IPNs ->
352331
SolveExecutables ->
353332
CondTree ConfVar [Dependency] a -> FlaggedDeps PN
354-
convCondTree flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes@(SolveExecutables solveExes') (CondNode info ds branches) =
333+
convCondTree flags dr pkg os arch cinfo pn fds comp getInfo solveExes@(SolveExecutables solveExes') (CondNode info ds branches) =
355334
-- Merge all library and build-tool dependencies at every level in
356335
-- the tree of flagged dependencies. Otherwise 'extractCommon'
357336
-- could create duplicate dependencies, and the number of
358337
-- duplicates could grow exponentially from the leaves to the root
359338
-- of the tree.
360339
mergeSimpleDeps $
361340
[ D.Simple singleDep comp
362-
| dep <- mapMaybe (filterIPNs ipns) ds
341+
| dep <- ds
363342
, singleDep <- convLibDeps dr dep ] -- unconditional package dependencies
364343

365344
++ L.map (\e -> D.Simple (LDep dr (Ext e)) comp) (allExtensions bi) -- unconditional extension dependencies
366345
++ L.map (\l -> D.Simple (LDep dr (Lang l)) comp) (allLanguages bi) -- unconditional language dependencies
367346
++ L.map (\(PkgconfigDependency pkn vr) -> D.Simple (LDep dr (Pkg pkn vr)) comp) (pkgconfigDepends bi) -- unconditional pkg-config dependencies
368-
++ concatMap (convBranch flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes) branches
347+
++ concatMap (convBranch flags dr pkg os arch cinfo pn fds comp getInfo solveExes) branches
369348
-- build-tools dependencies
370349
-- NB: Only include these dependencies if SolveExecutables
371350
-- is True. It might be false in the legacy solver
@@ -481,14 +460,13 @@ convBranch :: Map FlagName Bool
481460
-> FlagInfo
482461
-> Component
483462
-> (a -> BuildInfo)
484-
-> IPNs
485463
-> SolveExecutables
486464
-> CondBranch ConfVar [Dependency] a
487465
-> FlaggedDeps PN
488-
convBranch flags dr pkg os arch cinfo pn fds comp getInfo ipns solveExes (CondBranch c' t' mf') =
466+
convBranch flags dr pkg os arch cinfo pn fds comp getInfo solveExes (CondBranch c' t' mf') =
489467
go c'
490-
(\flags' dr' -> convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo ipns solveExes t')
491-
(\flags' dr' -> maybe [] (convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo ipns solveExes) mf')
468+
(\flags' dr' -> convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo solveExes t')
469+
(\flags' dr' -> maybe [] (convCondTree flags' dr' pkg os arch cinfo pn fds comp getInfo solveExes) mf')
492470
flags dr
493471
where
494472
go :: Condition ConfVar

cabal-install/cabal-install.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ executable cabal
225225
Distribution.Client.NixStyleOptions
226226
Distribution.Client.Outdated
227227
Distribution.Client.PackageHash
228-
Distribution.Client.PackageUtils
229228
Distribution.Client.ParseUtils
230229
Distribution.Client.ProjectBuilding
231230
Distribution.Client.ProjectBuilding.Types

cabal-install/cabal-install.cabal.dev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ library cabal-lib-client
217217
Distribution.Client.NixStyleOptions
218218
Distribution.Client.Outdated
219219
Distribution.Client.PackageHash
220-
Distribution.Client.PackageUtils
221220
Distribution.Client.ParseUtils
222221
Distribution.Client.ProjectBuilding
223222
Distribution.Client.ProjectBuilding.Types

cabal-install/cabal-install.cabal.prod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ executable cabal
225225
Distribution.Client.NixStyleOptions
226226
Distribution.Client.Outdated
227227
Distribution.Client.PackageHash
228-
Distribution.Client.PackageUtils
229228
Distribution.Client.ParseUtils
230229
Distribution.Client.ProjectBuilding
231230
Distribution.Client.ProjectBuilding.Types

cabal-install/cabal-install.cabal.zinza

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ Version: 3.3.0.0
161161
Distribution.Client.NixStyleOptions
162162
Distribution.Client.Outdated
163163
Distribution.Client.PackageHash
164-
Distribution.Client.PackageUtils
165164
Distribution.Client.ParseUtils
166165
Distribution.Client.ProjectBuilding
167166
Distribution.Client.ProjectBuilding.Types
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# cabal v2-run
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- pkg-def-0.1.0.0 (lib) (first run)
6+
- pkg-abc-0.1.0.0 (exe:program) (first run)
7+
Warning: pkg-def.cabal:13:27: visibility is experimental feature (issue #5660)
8+
Configuring library for pkg-def-0.1.0.0..
9+
Preprocessing library for pkg-def-0.1.0.0..
10+
Building library for pkg-def-0.1.0.0..
11+
Warning: pkg-abc.cabal:19:15: colon specifier is experimental feature (issue #5660)
12+
Configuring executable 'program' for pkg-abc-0.1.0.0..
13+
Warning: The package has an extraneous version range for a dependency on an internal library: pkg-def >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used.
14+
Preprocessing executable 'program' for pkg-abc-0.1.0.0..
15+
Building executable 'program' for pkg-abc-0.1.0.0..
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages:
2+
pkg-abc
3+
pkg-def
4+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
-- https://github.com/haskell/cabal/issues/6083
4+
-- see pkg-abc.cabal
5+
main = cabalTest $
6+
cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-def:pkg-def"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Main (main) where
2+
import PkgDef (defValue)
3+
4+
main :: IO ()
5+
main = print defValue
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cabal-version: 3.4
2+
name: pkg-abc
3+
version: 0.1.0.0
4+
5+
library pkg-def
6+
default-language: Haskell2010
7+
hs-source-dirs: pkg-def
8+
build-depends: base
9+
exposed-modules: PkgDef
10+
11+
executable program
12+
default-language: Haskell2010
13+
hs-source-dirs: exe
14+
main-is: Main.hs
15+
16+
-- we want that to resolve to pkg-def main library.
17+
build-depends:
18+
, base
19+
, pkg-def:pkg-def
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module PkgDef (defValue) where
2+
3+
defValue :: String
4+
defValue = "pkg-abc:pkg-def"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cabal-version: 3.0
2+
name: pkg-def
3+
version: 0.1.0.0
4+
5+
library
6+
default-language: Haskell2010
7+
hs-source-dirs: src
8+
build-depends: base
9+
exposed-modules: PkgDef
10+
11+
library publib
12+
default-language: Haskell2010
13+
visibility: public
14+
hs-source-dirs: publib
15+
build-depends: base
16+
exposed-modules: PkgDef
17+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module PkgDef (defValue) where
2+
3+
defValue :: String
4+
defValue = "pkg-def:publib"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module PkgDef (defValue) where
2+
3+
defValue :: String
4+
defValue = "pkg-def:pkg-def"

0 commit comments

Comments
 (0)