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

Resolve #6409: Add public multilib test(s) #6802

Merged
merged 1 commit into from
May 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
7 changes: 1 addition & 6 deletions Cabal/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ resolveWithFlags ::
resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
either (Left . fromDepMapUnion) Right $ explore (build mempty dom)
where
extraConstrs = toDepMap
[ Dependency pn ver mainLibSet
| PackageVersionConstraint pn ver <- constrs
]

-- simplify trees by (partially) evaluating all conditions and converting
-- dependencies to dependency maps.
simplifiedTrees :: [CondTree FlagName DependencyMap PDTagged]
Expand All @@ -208,7 +203,7 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
explore (Node flags ts) =
let targetSet = TargetSet $ flip map simplifiedTrees $
-- apply additional constraints to all dependencies
first (`constrainBy` extraConstrs) .
first (`constrainBy` constrs) .
simplifyCondTree (env flags)
deps = overallDependencies enabled targetSet
in case checkDeps (fromDepMap deps) of
Expand Down
25 changes: 12 additions & 13 deletions Cabal/Distribution/Types/DependencyMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module Distribution.Types.DependencyMap (
constrainBy,
) where

import Prelude ()
import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Types.Dependency
import Distribution.Types.PackageName
import Distribution.Types.LibraryName
import Distribution.Types.PackageName
import Distribution.Types.PackageVersionConstraint
import Distribution.Version

import qualified Data.Map.Lazy as Map
Expand Down Expand Up @@ -45,14 +46,12 @@ fromDepMap m = [ Dependency p vr cs | (p,(vr,cs)) <- Map.toList (unDependencyMap
-- Combines dependencies where the result will only contain keys from the left
-- (first) map. If a key also exists in the right map, both constraints will
-- be intersected.
constrainBy :: DependencyMap -- ^ Input map
-> DependencyMap -- ^ Extra constraints
-> DependencyMap
constrainBy left extra =
DependencyMap $
Map.foldrWithKey tightenConstraint (unDependencyMap left)
(unDependencyMap extra)
where tightenConstraint n c l =
case Map.lookup n l of
Nothing -> l
Just vrcs -> Map.insert n (intersectVersionRangesAndJoinComponents vrcs c) l
constrainBy
:: DependencyMap
-> [PackageVersionConstraint]
-> DependencyMap
constrainBy = foldl' tightenConstraint where
tightenConstraint (DependencyMap l) (PackageVersionConstraint pn vr) = DependencyMap $
case Map.lookup pn l of
Nothing -> l
Just (vr', cs) -> Map.insert pn (intersectVersionRanges vr' vr, cs) l
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ weeder :
# tags
.PHONY : tags
tags :
hasktags -b Cabal/Distribution Cabal/Cabal-described/src Cabal/Language cabal-install/Distribution
hasktags -b Cabal/Distribution Cabal/Cabal-described/src Cabal/Language cabal-install/Distribution cabal-testsuite/src
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Building library 'mylib' instantiated with
Database = Includes2-0.1.0.0-inplace-postgresql:Database.PostgreSQL
for Includes2-0.1.0.0..
Configuring library for Includes2-0.1.0.0..
Warning: The package has an extraneous version range for a dependency on an internal library: Includes2 >=0 && ==0.1.0.0 && ==0.1.0.0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used.
Warning: The package has an extraneous version range for a dependency on an internal library: Includes2 ((>=0 && ==0.1.0.0) && ==0.1.0.0) && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used.
Preprocessing library for Includes2-0.1.0.0..
Building library for Includes2-0.1.0.0..
Configuring executable 'exe' for Includes2-0.1.0.0..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Building library 'privatelib' for d-0.1.0.0..
Warning: p.cabal:6:20: colon specifier is experimental feature (issue #5660)
Configuring library for p-0.1.0.0..
cabal: Encountered missing or private dependencies:
d:{d, privatelib} ==0.1.0.0
d:{privatelib} ==0.1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- pkg-def-0.1.0.0 (lib:publib) (first run)
- pkg-abc-0.1.0.0 (exe:program) (first run)
Warning: pkg-def.cabal:13:27: visibility is experimental feature (issue #5660)
Configuring library 'publib' for pkg-def-0.1.0.0..
Preprocessing library 'publib' for pkg-def-0.1.0.0..
Building library 'publib' for pkg-def-0.1.0.0..
Warning: pkg-abc.cabal:10:15: colon specifier is experimental feature (issue #5660)
Configuring executable 'program' for pkg-abc-0.1.0.0..
Preprocessing executable 'program' for pkg-abc-0.1.0.0..
Building executable 'program' for pkg-abc-0.1.0.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages:
pkg-abc
pkg-def

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude
main = cabalTest $ do
-- https://github.com/haskell/cabal/pull/6047 should make this work for older GHCs too?
skipIf =<< ghcVersionIs (< mkVersion [8,8])

cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-def:publib"

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main (main) where
import PkgDef (defValue)

main :: IO ()
main = print defValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.0
name: pkg-abc
version: 0.1.0.0

executable program
default-language: Haskell2010
main-is: Main.hs
build-depends:
, base
, pkg-def:publib
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 3.0
name: pkg-def
version: 0.1.0.0

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: PkgDef

library publib
default-language: Haskell2010
visibility: public
hs-source-dirs: publib
build-depends: base
exposed-modules: PkgDef

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:publib"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:pkg-def"
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/MultipleLibraries/T6083Pre/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- pkg-abc-0.1.0.0 (lib:pkg-def) (first run)
- pkg-abc-0.1.0.0 (exe:program) (first run)
Warning: pkg-abc.cabal:19:15: colon specifier is experimental feature (issue #5660)
Configuring library 'pkg-def' for pkg-abc-0.1.0.0..
Preprocessing library 'pkg-def' for pkg-abc-0.1.0.0..
Building library 'pkg-def' for pkg-abc-0.1.0.0..
Warning: pkg-abc.cabal:19:15: colon specifier is experimental feature (issue #5660)
Configuring executable 'program' for pkg-abc-0.1.0.0..
Preprocessing executable 'program' for pkg-abc-0.1.0.0..
Building executable 'program' for pkg-abc-0.1.0.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages:
pkg-abc
pkg-def

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

-- https://github.com/haskell/cabal/issues/6083
-- see pkg-abc.cabal
main = cabalTest $ do
-- https://github.com/haskell/cabal/pull/6047 should make this work for older GHCs too?
skipIf =<< ghcVersionIs (< mkVersion [8,8])

cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-abc:pkg-def"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main (main) where
import PkgDef (defValue)

main :: IO ()
main = print defValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.0
name: pkg-abc
version: 0.1.0.0

library pkg-def
default-language: Haskell2010
hs-source-dirs: pkg-def
build-depends: base
exposed-modules: PkgDef

executable program
default-language: Haskell2010
hs-source-dirs: exe
main-is: Main.hs

-- we want that to resolve to pkg-def main library.
build-depends:
, base
, pkg-def:pkg-def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-abc:pkg-def"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 3.0
name: pkg-def
version: 0.1.0.0

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: PkgDef

library publib
default-language: Haskell2010
visibility: public
hs-source-dirs: publib
build-depends: base
exposed-modules: PkgDef

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:publib"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:pkg-def"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- pkg-abc-0.1.0.0 (lib:pkg-def) (first run)
- pkg-abc-0.1.0.0 (exe:program) (first run)
Warning: pkg-abc.cabal:20:15: colon specifier is experimental feature (issue #5660)
Configuring library 'pkg-def' for pkg-abc-0.1.0.0..
Preprocessing library 'pkg-def' for pkg-abc-0.1.0.0..
Building library 'pkg-def' for pkg-abc-0.1.0.0..
Warning: pkg-abc.cabal:20:15: colon specifier is experimental feature (issue #5660)
Configuring executable 'program' for pkg-abc-0.1.0.0..
Preprocessing executable 'program' for pkg-abc-0.1.0.0..
Building executable 'program' for pkg-abc-0.1.0.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages:
pkg-abc
pkg-def

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

-- This is like T6083Pre, but also goes via mixins
--
main = cabalTest $ do
-- https://github.com/haskell/cabal/pull/6047 should make this work for older GHCs too?
skipIf =<< ghcVersionIs (< mkVersion [8,8])

cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-abc:pkg-def"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Main (main) where
import Mixin (defValue)

main :: IO ()
main = print defValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cabal-version: 3.0
name: pkg-abc
version: 0.1.0.0

library pkg-def
default-language: Haskell2010
hs-source-dirs: pkg-def
build-depends: base
exposed-modules: PkgDef

executable program
default-language: Haskell2010
hs-source-dirs: exe
main-is: Main.hs
mixins: pkg-def (PkgDef as Mixin)

-- we want that to resolve to pkg-def main library.
build-depends:
, base
, pkg-def:pkg-def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-abc:pkg-def"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 3.0
name: pkg-def
version: 0.1.0.0

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: PkgDef

library publib
default-language: Haskell2010
visibility: public
hs-source-dirs: publib
build-depends: base
exposed-modules: PkgDef

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:publib"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module PkgDef (defValue) where

defValue :: String
defValue = "pkg-def:pkg-def"