diff --git a/cabal-install/Distribution/Solver/Modular/Index.hs b/cabal-install/Distribution/Solver/Modular/Index.hs index c1a8c0be412..2f28d12de85 100644 --- a/cabal-install/Distribution/Solver/Modular/Index.hs +++ b/cabal-install/Distribution/Solver/Modular/Index.hs @@ -42,14 +42,15 @@ data ComponentInfo = ComponentInfo { compIsVisible :: IsVisible , compIsBuildable :: IsBuildable } + deriving Show -- | Whether a component is visible in the current environment. newtype IsVisible = IsVisible Bool - deriving Eq + deriving (Eq, Show) -- | Whether a component is made unbuildable by a "buildable: False" field. newtype IsBuildable = IsBuildable Bool - deriving Eq + deriving (Eq, Show) mkIndex :: [(PN, I, PInfo)] -> Index mkIndex xs = M.map M.fromList (groupMap (L.map (\ (pn, i, pi) -> (pn, (i, pi))) xs)) diff --git a/cabal-install/Distribution/Solver/Modular/Validate.hs b/cabal-install/Distribution/Solver/Modular/Validate.hs index 9c20c9bc321..b809e4fbbda 100644 --- a/cabal-install/Distribution/Solver/Modular/Validate.hs +++ b/cabal-install/Distribution/Solver/Modular/Validate.hs @@ -230,7 +230,7 @@ validate = cata go let newDeps :: Either Conflict (PPreAssignment, Map QPN ComponentDependencyReasons) newDeps = do nppa <- mnppa - rComps' <- extendRequiredComponents aComps rComps newactives + rComps' <- extendRequiredComponents qpn aComps rComps newactives checkComponentsInNewPackage (M.findWithDefault M.empty qpn rComps) qpn comps return (nppa, rComps') in case newDeps of @@ -265,7 +265,7 @@ validate = cata go -- We now try to get the new active dependencies we might learn about because -- we have chosen a new flag. let newactives = extractNewDeps (F qfn) b npfa psa qdeps - mNewRequiredComps = extendRequiredComponents aComps rComps newactives + mNewRequiredComps = extendRequiredComponents qpn aComps rComps newactives -- As in the package case, we try to extend the partial assignment. let mnppa = extend extSupported langSupported pkgPresent newactives ppa case liftM2 (,) mnppa mNewRequiredComps of @@ -295,7 +295,7 @@ validate = cata go -- We now try to get the new active dependencies we might learn about because -- we have chosen a new flag. let newactives = extractNewDeps (S qsn) b pfa npsa qdeps - mNewRequiredComps = extendRequiredComponents aComps rComps newactives + mNewRequiredComps = extendRequiredComponents qpn aComps rComps newactives -- As in the package case, we try to extend the partial assignment. let mnppa = extend extSupported langSupported pkgPresent newactives ppa case liftM2 (,) mnppa mNewRequiredComps of @@ -534,11 +534,12 @@ createConflictSetForVersionConflict pkg -- known component dependencies. It returns a failure when a new dependency -- requires a component that is missing, private, or unbuildable in a previously -- chosen package. -extendRequiredComponents :: Map QPN (Map ExposedComponent ComponentInfo) +extendRequiredComponents :: QPN -- ^ package we extend + -> Map QPN (Map ExposedComponent ComponentInfo) -> Map QPN ComponentDependencyReasons -> [LDep QPN] -> Either Conflict (Map QPN ComponentDependencyReasons) -extendRequiredComponents available = foldM extendSingle +extendRequiredComponents eqpn available = foldM extendSingle where extendSingle :: Map QPN ComponentDependencyReasons -> LDep QPN @@ -554,7 +555,9 @@ extendRequiredComponents available = foldM extendSingle Nothing -> Left $ mkConflict qpn comp dr PackageRequiresMissingComponent Just compInfo - | compIsVisible compInfo == IsVisible False -> + | compIsVisible compInfo == IsVisible False + , eqpn /= qpn -- package components can depend on other components + -> Left $ mkConflict qpn comp dr PackageRequiresPrivateComponent | compIsBuildable compInfo == IsBuildable False -> Left $ mkConflict qpn comp dr PackageRequiresUnbuildableComponent diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.out b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.out new file mode 100644 index 00000000000..a063ee92cb8 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.out @@ -0,0 +1,7 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - pkg-foo-0 (lib:internal-lib) (first run) + - pkg-foo-0 (lib) (first run) + - pkg-bar-0 (exe:example) (first run) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.project b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.project new file mode 100644 index 00000000000..56221084a1f --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.project @@ -0,0 +1 @@ +packages: pkg-foo pkg-bar diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.test.hs new file mode 100644 index 00000000000..915337859f5 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.test.hs @@ -0,0 +1,3 @@ +import Test.Cabal.Prelude +main = cabalTest $ + cabal "v2-build" ["all", "--dry-run", "--enable-tests"] diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/exe/Main.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/exe/Main.hs new file mode 100644 index 00000000000..5edf24437d0 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/exe/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = print value diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/pkg-bar.cabal b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/pkg-bar.cabal new file mode 100644 index 00000000000..a8c855e8fbc --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/pkg-bar.cabal @@ -0,0 +1,13 @@ +cabal-version: 2.0 +name: pkg-bar +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +executable example + default-language: Haskell2010 + hs-source-dirs: exe + main-is: Main.hs + build-depends: base, pkg-foo diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/internal/InternalLib.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/internal/InternalLib.hs new file mode 100644 index 00000000000..b925bcad362 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/internal/InternalLib.hs @@ -0,0 +1,4 @@ +module InternalLib where + +value :: Int +value = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/pkg-foo.cabal b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/pkg-foo.cabal new file mode 100644 index 00000000000..d22f7a32a6b --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/pkg-foo.cabal @@ -0,0 +1,19 @@ +cabal-version: 2.0 +name: pkg-foo +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +library + default-language: Haskell2010 + hs-source-dirs: src + build-depends: base <5, internal-lib + exposed-modules: Lib + +library internal-lib + default-language: Haskell2010 + hs-source-dirs: internal + build-depends: base <5 + exposed-modules: InternalLib diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/src/Lib.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/src/Lib.hs new file mode 100644 index 00000000000..c7683f97b49 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/src/Lib.hs @@ -0,0 +1,3 @@ +module Lib (value) where + +import InternalLib (value) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.out b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.out new file mode 100644 index 00000000000..aa10de2a405 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.out @@ -0,0 +1,8 @@ +# cabal v2-build +Resolving dependencies... +cabal: Could not resolve dependencies: +[__0] trying: pkg-bar-0 (user goal) +[__1] next goal: pkg-foo (user goal) +[__1] rejecting: pkg-foo-0 (library 'internal-lib' is private, but it is required by pkg-bar) +[__1] fail (backjumping, conflict set: pkg-bar, pkg-foo) +After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: pkg-bar (2), pkg-foo (2) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.project b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.project new file mode 100644 index 00000000000..56221084a1f --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.project @@ -0,0 +1 @@ +packages: pkg-foo pkg-bar diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.test.hs new file mode 100644 index 00000000000..6b4ad601b07 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude +main = cabalTest $ + -- we try to depend on private component from outside, + -- so this should fail. + fails $ cabal "v2-build" ["all", "--dry-run", "--enable-tests"] diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/exe/Main.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/exe/Main.hs new file mode 100644 index 00000000000..cfae2b73f2a --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/exe/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import InternalLib + +main :: IO () +main = print value diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/pkg-bar.cabal b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/pkg-bar.cabal new file mode 100644 index 00000000000..2895fd54b2c --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/pkg-bar.cabal @@ -0,0 +1,13 @@ +cabal-version: 3.0 +name: pkg-bar +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +executable example + default-language: Haskell2010 + hs-source-dirs: exe + main-is: Main.hs + build-depends: base, pkg-foo:internal-lib diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/internal/InternalLib.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/internal/InternalLib.hs new file mode 100644 index 00000000000..b925bcad362 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/internal/InternalLib.hs @@ -0,0 +1,4 @@ +module InternalLib where + +value :: Int +value = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/pkg-foo.cabal b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/pkg-foo.cabal new file mode 100644 index 00000000000..d22f7a32a6b --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/pkg-foo.cabal @@ -0,0 +1,19 @@ +cabal-version: 2.0 +name: pkg-foo +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +library + default-language: Haskell2010 + hs-source-dirs: src + build-depends: base <5, internal-lib + exposed-modules: Lib + +library internal-lib + default-language: Haskell2010 + hs-source-dirs: internal + build-depends: base <5 + exposed-modules: InternalLib diff --git a/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/src/Lib.hs b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/src/Lib.hs new file mode 100644 index 00000000000..c7683f97b49 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/src/Lib.hs @@ -0,0 +1,3 @@ +module Lib (value) where + +import InternalLib (value) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.out b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.out new file mode 100644 index 00000000000..bde31817cf4 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.out @@ -0,0 +1,6 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - issue6961-0 (lib:internal-lib) (first run) + - issue6961-0 (exe:example) (first run) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.project b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.test.hs new file mode 100644 index 00000000000..915337859f5 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.test.hs @@ -0,0 +1,3 @@ +import Test.Cabal.Prelude +main = cabalTest $ + cabal "v2-build" ["all", "--dry-run", "--enable-tests"] diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/exe/Main.hs b/cabal-testsuite/PackageTests/Regression/T6961/Exe/exe/Main.hs new file mode 100644 index 00000000000..5edf24437d0 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/exe/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = print value diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/issue6961.cabal b/cabal-testsuite/PackageTests/Regression/T6961/Exe/issue6961.cabal new file mode 100644 index 00000000000..c2e3faf69f1 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/issue6961.cabal @@ -0,0 +1,19 @@ +cabal-version: 2.0 +name: issue6961 +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +library internal-lib + default-language: Haskell2010 + hs-source-dirs: src + build-depends: base <5 + exposed-modules: Lib + +executable example + default-language: Haskell2010 + hs-source-dirs: exe + main-is: Main.hs + build-depends: base, internal-lib diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Exe/src/Lib.hs b/cabal-testsuite/PackageTests/Regression/T6961/Exe/src/Lib.hs new file mode 100644 index 00000000000..e4dce2beed1 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Exe/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +value :: Int +value = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out new file mode 100644 index 00000000000..8f28d66058a --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out @@ -0,0 +1,6 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - issue6961-0 (lib:internal-lib) (first run) + - issue6961-0 (test:example) (first run) diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.project b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs new file mode 100644 index 00000000000..915337859f5 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs @@ -0,0 +1,3 @@ +import Test.Cabal.Prelude +main = cabalTest $ + cabal "v2-build" ["all", "--dry-run", "--enable-tests"] diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal b/cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal new file mode 100644 index 00000000000..490ec5f55f9 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal @@ -0,0 +1,20 @@ +cabal-version: 2.0 +name: issue6961 +version: 0 +build-type: Simple + +synopsis: This should work +category: Test + +library internal-lib + default-language: Haskell2010 + hs-source-dirs: src + build-depends: base <5 + exposed-modules: Lib + +test-suite example + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: tests + main-is: Main.hs + build-depends: base, internal-lib diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/src/Lib.hs b/cabal-testsuite/PackageTests/Regression/T6961/Test/src/Lib.hs new file mode 100644 index 00000000000..e4dce2beed1 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +value :: Int +value = 42 diff --git a/cabal-testsuite/PackageTests/Regression/T6961/Test/tests/Main.hs b/cabal-testsuite/PackageTests/Regression/T6961/Test/tests/Main.hs new file mode 100644 index 00000000000..5edf24437d0 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/tests/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = print value