Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests and fix for #6961 #6964

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 9 additions & 6 deletions cabal-install/Distribution/Solver/Modular/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: pkg-foo pkg-bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = print value
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module InternalLib where

value :: Int
value = 42
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib (value) where

import InternalLib (value)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: pkg-foo pkg-bar
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import InternalLib

main :: IO ()
main = print value
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module InternalLib where

value :: Int
value = 42
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib (value) where

import InternalLib (value)
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Exe/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- issue6961-0 (lib:internal-lib) (first run)
- issue6961-0 (exe:example) (first run)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Exe/exe/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = print value
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Exe/issue6961.cabal
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Exe/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Lib where

value :: Int
value = 42
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Test/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cabal v2-build
Resolving dependencies...
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
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
20 changes: 20 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Test/issue6961.cabal
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6961/Test/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Lib where

value :: Int
value = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = print value