From 1d2acbbe88ec777e3b2bebf2157fa57a58f9bc57 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 14 Jul 2020 21:26:31 +0300 Subject: [PATCH 1/2] Add tests for #6961 --- .../Regression/T6961/DepExternal/cabal.out | 7 +++++++ .../T6961/DepExternal/cabal.project | 1 + .../T6961/DepExternal/cabal.test.hs | 3 +++ .../T6961/DepExternal/pkg-bar/exe/Main.hs | 6 ++++++ .../T6961/DepExternal/pkg-bar/pkg-bar.cabal | 13 ++++++++++++ .../pkg-foo/internal/InternalLib.hs | 4 ++++ .../T6961/DepExternal/pkg-foo/pkg-foo.cabal | 19 ++++++++++++++++++ .../T6961/DepExternal/pkg-foo/src/Lib.hs | 3 +++ .../Regression/T6961/DepInternal/cabal.out | 8 ++++++++ .../T6961/DepInternal/cabal.project | 1 + .../T6961/DepInternal/cabal.test.hs | 5 +++++ .../T6961/DepInternal/pkg-bar/exe/Main.hs | 6 ++++++ .../T6961/DepInternal/pkg-bar/pkg-bar.cabal | 13 ++++++++++++ .../pkg-foo/internal/InternalLib.hs | 4 ++++ .../T6961/DepInternal/pkg-foo/pkg-foo.cabal | 19 ++++++++++++++++++ .../T6961/DepInternal/pkg-foo/src/Lib.hs | 3 +++ .../Regression/T6961/Exe/cabal.out | 6 ++++++ .../Regression/T6961/Exe/cabal.project | 1 + .../Regression/T6961/Exe/cabal.test.hs | 3 +++ .../Regression/T6961/Exe/exe/Main.hs | 6 ++++++ .../Regression/T6961/Exe/issue6961.cabal | 19 ++++++++++++++++++ .../Regression/T6961/Exe/src/Lib.hs | 4 ++++ .../Regression/T6961/Test/cabal.out | 8 ++++++++ .../Regression/T6961/Test/cabal.project | 1 + .../Regression/T6961/Test/cabal.test.hs | 5 +++++ .../Regression/T6961/Test/issue6961.cabal | 20 +++++++++++++++++++ .../Regression/T6961/Test/src/Lib.hs | 4 ++++ .../Regression/T6961/Test/tests/Main.hs | 6 ++++++ 28 files changed, 198 insertions(+) create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/exe/Main.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-bar/pkg-bar.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/internal/InternalLib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/pkg-foo.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepExternal/pkg-foo/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/exe/Main.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-bar/pkg-bar.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/internal/InternalLib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/pkg-foo.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/DepInternal/pkg-foo/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/exe/Main.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/issue6961.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Exe/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T6961/Test/tests/Main.hs 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..96820cffdc9 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out @@ -0,0 +1,8 @@ +# cabal v2-build +Resolving dependencies... +cabal: Could not resolve dependencies: +[__0] trying: issue6961-0 (user goal) +[__1] rejecting: issue6961:!test (constraint from config file, command line flag, or user target requires opposite flag selection) +[__1] rejecting: issue6961:*test (requires library 'internal-lib' from issue6961, but the component is private) +[__1] fail (backjumping, conflict set: issue6961, issue6961:test) +After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: issue6961 (3), issue6961:test (3) 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..a0c89658e3a --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude +main = cabalTest $ + -- fails, but it shouldn't. + -- https://github.com/haskell/cabal/issues/6961 + fails $ 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..f2fff29c5e5 --- /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: exe + 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 From f374a1e90053534c769c9af69ccf6202fe390cbb Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 14 Jul 2020 22:16:08 +0300 Subject: [PATCH 2/2] Fix #6961. Depending on a private component from the same package is fine. --- .../Distribution/Solver/Modular/Index.hs | 5 +++-- .../Distribution/Solver/Modular/Validate.hs | 15 +++++++++------ .../PackageTests/Regression/T6961/Test/cabal.out | 10 ++++------ .../Regression/T6961/Test/cabal.test.hs | 4 +--- .../Regression/T6961/Test/issue6961.cabal | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) 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/Test/cabal.out b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out index 96820cffdc9..8f28d66058a 100644 --- a/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out @@ -1,8 +1,6 @@ # cabal v2-build Resolving dependencies... -cabal: Could not resolve dependencies: -[__0] trying: issue6961-0 (user goal) -[__1] rejecting: issue6961:!test (constraint from config file, command line flag, or user target requires opposite flag selection) -[__1] rejecting: issue6961:*test (requires library 'internal-lib' from issue6961, but the component is private) -[__1] fail (backjumping, conflict set: issue6961, issue6961:test) -After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: issue6961 (3), issue6961:test (3) +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.test.hs b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs index a0c89658e3a..915337859f5 100644 --- a/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.test.hs @@ -1,5 +1,3 @@ import Test.Cabal.Prelude main = cabalTest $ - -- fails, but it shouldn't. - -- https://github.com/haskell/cabal/issues/6961 - fails $ cabal "v2-build" ["all", "--dry-run", "--enable-tests"] + 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 index f2fff29c5e5..490ec5f55f9 100644 --- a/cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal +++ b/cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal @@ -15,6 +15,6 @@ library internal-lib test-suite example type: exitcode-stdio-1.0 default-language: Haskell2010 - hs-source-dirs: exe + hs-source-dirs: tests main-is: Main.hs build-depends: base, internal-lib