Skip to content

Commit

Permalink
Fix #6961. Depending on a private component from the same package is …
Browse files Browse the repository at this point in the history
…fine.
  • Loading branch information
phadej committed Jul 14, 2020
1 parent f953054 commit 5fd73de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
5 changes: 3 additions & 2 deletions cabal-install/Distribution/Solver/Modular/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Solver/Modular/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out
Original file line number Diff line number Diff line change
@@ -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-<GHCVER> -O1
In order, the following would be built:
- issue6961-0 (lib:internal-lib) (first run)
- issue6961-0 (test:example) (first run)
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5fd73de

Please sign in to comment.