Commit 4dd5093e authored by Oleg Grenrus's avatar Oleg Grenrus Committed by GitHub

Merge pull request #6967 from phadej/backport-issue-6961-fix

Backport issue 6961 fix
parents 5b28d47b ec34e611
......@@ -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))
......
......@@ -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
......
# 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)
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
module Main where
import Lib
main :: IO ()
main = print value
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
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
# 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)
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"]
module Main where
import InternalLib
main :: IO ()
main = print value
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
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
# 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)
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
module Main where
import Lib
main :: IO ()
main = print value
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
# 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)
import Test.Cabal.Prelude
main = cabalTest $
cabal "v2-build" ["all", "--dry-run", "--enable-tests"]
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
module Main where
import Lib
main :: IO ()
main = print value
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment