From 5fd73de1a9bf07e47dc57bf77a21889a582dd145 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 14 Jul 2020 22:16:08 +0300 Subject: [PATCH] Fix #6961. Depending on a private component from the same package is fine. --- cabal-install/Distribution/Solver/Modular/Index.hs | 5 +++-- cabal-install/Distribution/Solver/Modular/Validate.hs | 6 ++++-- .../PackageTests/Regression/T6961/Test/cabal.out | 10 ++++------ .../PackageTests/Regression/T6961/Test/cabal.test.hs | 4 +--- .../PackageTests/Regression/T6961/Test/issue6961.cabal | 2 +- 5 files changed, 13 insertions(+), 14 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..690e5dcc549 100644 --- a/cabal-install/Distribution/Solver/Modular/Validate.hs +++ b/cabal-install/Distribution/Solver/Modular/Validate.hs @@ -543,7 +543,7 @@ extendRequiredComponents available = foldM extendSingle extendSingle :: Map QPN ComponentDependencyReasons -> LDep QPN -> Either Conflict (Map QPN ComponentDependencyReasons) - extendSingle required (LDep dr (Dep (PkgComponent qpn comp) _)) = + extendSingle required (LDep dr@(DependencyReason drQpn _ _) (Dep (PkgComponent qpn comp) _)) = let compDeps = M.findWithDefault M.empty qpn required success = Right $ M.insertWith M.union qpn (M.insert comp dr compDeps) required in -- Only check for the existence of the component if its package has @@ -554,7 +554,9 @@ extendRequiredComponents available = foldM extendSingle Nothing -> Left $ mkConflict qpn comp dr PackageRequiresMissingComponent Just compInfo - | compIsVisible compInfo == IsVisible False -> + | compIsVisible compInfo == IsVisible False + , drQpn /= 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