Commit 25df01d0 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by GitHub
Browse files

Merge pull request #3783 from ezyang/pr/T3775

Add support for executables to DSL, and failing test for #3775
parents 798470a7 c7fdf9d0
......@@ -121,9 +121,7 @@ convGPD os arch cinfo strfl pi
-- by creating a set of package names which are "internal"
-- and dropping them as we convert.
ipns = S.fromList $ [ PackageName nm
| (nm, _) <- sub_libs ] ++
[ PackageName nm
| (nm, _) <- exes ]
| (nm, _) <- sub_libs ]
conv :: Mon.Monoid a => Component -> (a -> BuildInfo) ->
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
......
......@@ -4,6 +4,7 @@ module UnitTests.Distribution.Solver.Modular.DSL (
ExampleDependency(..)
, Dependencies(..)
, ExTest(..)
, ExExe(..)
, ExPreference(..)
, ExampleDb
, ExampleVersionRange
......@@ -21,6 +22,8 @@ module UnitTests.Distribution.Solver.Modular.DSL (
, withSetupDeps
, withTest
, withTests
, withExe
, withExes
, runProgress
) where
......@@ -110,6 +113,7 @@ type ExamplePkgVersion = Int
type ExamplePkgHash = String -- for example "installed" packages
type ExampleFlagName = String
type ExampleTestName = String
type ExampleExeName = String
type ExampleVersionRange = C.VersionRange
data Dependencies = NotBuildable | Buildable [ExampleDependency]
......@@ -143,6 +147,8 @@ data ExampleDependency =
data ExTest = ExTest ExampleTestName [ExampleDependency]
data ExExe = ExExe ExampleExeName [ExampleDependency]
exFlag :: ExampleFlagName -> [ExampleDependency] -> [ExampleDependency]
-> ExampleDependency
exFlag n t e = ExFlag n (Buildable t) (Buildable e)
......@@ -194,6 +200,15 @@ withTests ex tests =
| ExTest name deps <- tests]
in ex { exAvDeps = exAvDeps ex <> testCDs }
withExe :: ExampleAvailable -> ExExe -> ExampleAvailable
withExe ex exe = withExes ex [exe]
withExes :: ExampleAvailable -> [ExExe] -> ExampleAvailable
withExes ex exes =
let exeCDs = CD.fromList [(CD.ComponentExe name, deps)
| ExExe name deps <- exes]
in ex { exAvDeps = exAvDeps ex <> exeCDs }
-- | An installed package in 'ExampleDb'; construct me with 'exInst'.
data ExampleInstalled = ExInst {
exInstName :: ExamplePkgName
......@@ -230,6 +245,7 @@ exAvSrcPkg :: ExampleAvailable -> UnresolvedSourcePackage
exAvSrcPkg ex =
let (libraryDeps, exts, mlang, pcpkgs, exes) = splitTopLevel (CD.libraryDeps (exAvDeps ex))
testSuites = [(name, deps) | (CD.ComponentTest name, deps) <- CD.toList (exAvDeps ex)]
executables = [(name, deps) | (CD.ComponentExe name, deps) <- CD.toList (exAvDeps ex)]
in SourcePackage {
packageInfoId = exAvPkgId ex
, packageSource = LocalTarballPackage "<<path>>"
......@@ -249,13 +265,19 @@ exAvSrcPkg ex =
}
}
, C.genPackageFlags = nub $ concatMap extractFlags $
CD.libraryDeps (exAvDeps ex) ++ concatMap snd testSuites
CD.libraryDeps (exAvDeps ex)
++ concatMap snd testSuites
++ concatMap snd executables
, C.condLibrary = Just (mkCondTree
(extsLib exts <> langLib mlang <> pcpkgLib pcpkgs <> buildtoolsLib exes)
disableLib
(Buildable libraryDeps))
, C.condSubLibraries = []
, C.condExecutables = []
, C.condExecutables =
-- Executables not presently disableable. We can't
-- error in the disable case
let mkTree = mkCondTree mempty disableExe . Buildable
in map (\(t, deps) -> (t, mkTree deps)) executables
, C.condTestSuites =
let mkTree = mkCondTree mempty disableTest . Buildable
in map (\(t, deps) -> (t, mkTree deps)) testSuites
......@@ -395,6 +417,10 @@ exAvSrcPkg ex =
disableTest test =
test { C.testBuildInfo = (C.testBuildInfo test) { C.buildable = False }}
disableExe :: C.Executable -> C.Executable
disableExe exe =
exe { C.buildInfo = (C.buildInfo exe) { C.buildable = False }}
-- A 'C.Library' with just the given pkgconfig-depends in its 'BuildInfo'
pcpkgLib :: [(ExamplePkgName, ExamplePkgVersion)] -> C.Library
pcpkgLib ds = mempty { C.libBuildInfo = mempty { C.pkgconfigDepends = [mkDirect (n, (Just v)) | (n,v) <- ds] } }
......
{-# LANGUAGE RecordWildCards #-}
-- | This is a set of unit tests for the dependency solver,
-- which uses the solver DSL ("UnitTests.Distribution.Solver.Modular.DSL")
-- to more conveniently create package databases to run the solver tests on.
module UnitTests.Distribution.Solver.Modular.Solver (tests)
where
......@@ -163,6 +166,7 @@ tests = [
, runTest $ mkTest dbBuildTools3 "bt3" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1), ("alex", 1), ("alex", 2)])
, runTest $ mkTest dbBuildTools4 "bt4" ["B"] (solverSuccess [("A", 1), ("A", 2), ("B", 1), ("alex", 1)])
, runTest $ mkTest dbBuildTools5 "bt5" ["A"] (solverSuccess [("A", 1), ("alex", 1), ("happy", 1)])
, runTest $ mkTest dbBuildTools6 "bt6" ["B"] (solverSuccess [("A", 2), ("B", 2), ("warp", 1)])
]
-- Tests for the contents of the solver's log
, testGroup "Solver log" [
......@@ -1141,3 +1145,14 @@ dbBuildTools5 = [
Right $ exAv "happy" 1 [ExBuildToolAny "alex"],
Right $ exAv "A" 1 [ExBuildToolAny "happy"]
]
-- Test that build-depends on library/executable package works.
-- Extracted from https://github.com/haskell/cabal/issues/3775
dbBuildTools6 :: ExampleDb
dbBuildTools6 = [
Right $ exAv "warp" 1 [],
-- NB: the warp build-depends refers to the package, not the internal
-- executable!
Right $ exAv "A" 2 [ExFix "warp" 1] `withExe` ExExe "warp" [ExAny "A"],
Right $ exAv "B" 2 [ExAny "A", ExAny "warp"]
]
Supports Markdown
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