Commit dee975fe authored by tibbe's avatar tibbe
Browse files

Implement 'configure' and preprocessing for benchmarks

parent aaf0681f
......@@ -82,7 +82,7 @@ import Distribution.PackageDescription as PD
( PackageDescription(..), specVersion, GenericPackageDescription(..)
, Library(..), hasLibs, Executable(..), BuildInfo(..), allExtensions
, HookedBuildInfo, updatePackageDescription, allBuildInfo
, FlagName(..), TestSuite(..) )
, FlagName(..), TestSuite(..), Benchmark(..) )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription, mapTreeData )
import Distribution.PackageDescription.Check
......@@ -326,7 +326,11 @@ configure (pkg_descr0, pbi) cfg
enableTest t = t { testEnabled = fromFlag (configTests cfg) }
flaggedTests = map (\(n, t) -> (n, mapTreeData enableTest t))
(condTestSuites pkg_descr0)
pkg_descr0'' = pkg_descr0 { condTestSuites = flaggedTests }
enableBenchmark bm = bm { benchmarkEnabled = fromFlag (configBenchmarks cfg) }
flaggedBenchmarks = map (\(n, bm) -> (n, mapTreeData enableBenchmark bm))
(condBenchmarks pkg_descr0)
pkg_descr0'' = pkg_descr0 { condTestSuites = flaggedTests
, condBenchmarks = flaggedBenchmarks }
(pkg_descr0', flags) <-
case finalizePackageDescription
......@@ -469,6 +473,8 @@ configure (pkg_descr0, pbi) cfg
configExe exe = (exeName exe, configComponent (buildInfo exe))
configTest test = (testName test,
configComponent(testBuildInfo test))
configBenchmark bm = (benchmarkName bm,
configComponent(benchmarkBuildInfo bm))
configComponent bi = ComponentLocalBuildInfo {
componentPackageDeps =
if newPackageDepsBehaviour pkg_descr'
......@@ -490,7 +496,8 @@ configure (pkg_descr0, pbi) cfg
mapMaybe exeDepToComp (buildTools bi)
++ mapMaybe libDepToComp (targetBuildDepends bi)
where
bi = foldComponent libBuildInfo buildInfo testBuildInfo component
bi = foldComponent libBuildInfo buildInfo testBuildInfo
benchmarkBuildInfo component
exeDepToComp (Dependency (PackageName name) _) =
CExe `fmap` find ((==) name . exeName)
(executables pkg_descr')
......@@ -503,13 +510,15 @@ configure (pkg_descr0, pbi) cfg
where (g, lkup, _) = graphFromEdges
$ allComponentsBy pkg_descr'
$ \c -> (c, key c, map key (ipDeps c))
key = foldComponent (const "library") exeName testName
key = foldComponent (const "library") exeName
testName benchmarkName
-- check for cycles in the dependency graph
buildOrder <- forM sccs $ \scc -> case scc of
AcyclicSCC (c,_,_) -> return (foldComponent (const CLibName)
(CExeName . exeName)
(CTestName . testName)
(CBenchName . benchmarkName)
c)
CyclicSCC vs ->
die $ "Found cycle in intrapackage dependency graph:\n "
......@@ -530,6 +539,7 @@ configure (pkg_descr0, pbi) cfg
libraryConfig = configLib `fmap` library pkg_descr',
executableConfigs = configExe `fmap` executables pkg_descr',
testSuiteConfigs = configTest `fmap` testSuites pkg_descr',
benchmarkConfigs = configBenchmark `fmap` benchmarks pkg_descr',
compBuildOrder = buildOrder,
installedPkgs = packageDependsIndex,
pkgDescrFile = Nothing,
......
......@@ -75,7 +75,7 @@ import Distribution.Simple.Program (ProgramConfiguration)
import Distribution.PackageDescription
( PackageDescription(..), withLib, Library(libBuildInfo), withExe
, Executable(exeName, buildInfo), withTest, TestSuite(..)
, BuildInfo(buildable) )
, BuildInfo(buildable), Benchmark(..) )
import Distribution.Package
( PackageId, Package(..), InstalledPackageId(..) )
import Distribution.Simple.Compiler
......@@ -117,6 +117,7 @@ data LocalBuildInfo = LocalBuildInfo {
-- ^ All the components to build, ordered by topological sort
-- over the intrapackage dependency graph
testSuiteConfigs :: [(String, ComponentLocalBuildInfo)],
benchmarkConfigs :: [(String, ComponentLocalBuildInfo)],
installedPkgs :: PackageIndex,
-- ^ All the info about the installed packages that the
-- current package depends on (directly or indirectly).
......@@ -161,14 +162,16 @@ inplacePackageId pkgid = InstalledPackageId (display pkgid ++ "-inplace")
-- -----------------------------------------------------------------------------
-- Buildable components
data Component = CLib Library
| CExe Executable
| CTest TestSuite
data Component = CLib Library
| CExe Executable
| CTest TestSuite
| CBench Benchmark
deriving (Show, Eq, Read)
data ComponentName = CLibName -- currently only a single lib
| CExeName String
| CTestName String
data ComponentName = CLibName -- currently only a single lib
| CExeName String
| CTestName String
| CBenchName String
deriving (Show, Eq, Read)
data ComponentLocalBuildInfo = ComponentLocalBuildInfo {
......@@ -183,11 +186,13 @@ data ComponentLocalBuildInfo = ComponentLocalBuildInfo {
foldComponent :: (Library -> a)
-> (Executable -> a)
-> (TestSuite -> a)
-> (Benchmark -> a)
-> Component
-> a
foldComponent f _ _ (CLib lib) = f lib
foldComponent _ f _ (CExe exe) = f exe
foldComponent _ _ f (CTest tst) = f tst
foldComponent f _ _ _ (CLib lib) = f lib
foldComponent _ f _ _ (CExe exe) = f exe
foldComponent _ _ f _ (CTest tst) = f tst
foldComponent _ _ _ f (CBench bch) = f bch
-- | Obtains all components (libs, exes, or test suites), transformed by the
-- given function. Useful for gathering dependencies with component context.
......@@ -268,8 +273,18 @@ withComponentsLBI pkg_descr lbi f = mapM_ compF (compBuildOrder lbi)
missingtest = "internal error: component list includes a test suite "
++ name ++ " but the package contains no such test suite."
compF (CBenchName name) =
case find (\bch -> benchmarkName bch == name) (benchmarks pkg_descr) of
Nothing -> die missingbench
Just bch -> case lookup name (benchmarkConfigs lbi) of
Nothing -> die (missingBenchConf name)
Just clbi -> f (CBench bch) clbi
where
missingbench = "internal error: component list includes a benchmark "
++ name ++ " but the package contains no such benchmark."
missingLibConf :: String
missingExeConf, missingTestConf :: String -> String
missingExeConf, missingTestConf, missingBenchConf :: String -> String
missingLibConf = "internal error: the package contains a library "
++ "but there is no corresponding configuration data"
......@@ -277,6 +292,8 @@ missingExeConf name = "internal error: the package contains an executable "
++ name ++ " but there is no corresponding configuration data"
missingTestConf name = "internal error: the package contains a test suite "
++ name ++ " but there is no corresponding configuration data"
missingBenchConf name = "internal error: the package contains a benchmark "
++ name ++ " but there is no corresponding configuration data"
-- -----------------------------------------------------------------------------
......
......@@ -66,7 +66,8 @@ import Distribution.PackageDescription as PD
, Executable(..)
, Library(..), libModules
, TestSuite(..), testModules
, TestSuiteInterface(..) )
, TestSuiteInterface(..)
, Benchmark(..), benchmarkModules, BenchmarkInterface(..) )
import qualified Distribution.InstalledPackageInfo as Installed
( InstalledPackageInfo_(..) )
import qualified Distribution.Simple.PackageIndex as PackageIndex
......@@ -209,6 +210,14 @@ preprocessComponent pd comp lbi isSrcDist verbosity handlers = case comp of
preProcessTest test (stubFilePath test) testDir
TestSuiteUnsupported tt -> die $ "No support for preprocessing test "
++ "suite type " ++ display tt
CBench bm@Benchmark{ benchmarkName = nm } -> do
setupMessage verbosity ("Preprocessing benchmark '" ++ nm ++ "' for") (packageId pd)
case benchmarkInterface bm of
BenchmarkExeV10 _ f ->
preProcessBench bm f $ buildDir lbi </> benchmarkName bm
</> benchmarkName bm ++ "-tmp"
BenchmarkUnsupported tt -> die $ "No support for preprocessing benchmark "
++ "type " ++ display tt
where
builtinSuffixes
| NHC == compilerFlavor (compiler lbi) = ["hs", "lhs", "gc"]
......@@ -216,15 +225,18 @@ preprocessComponent pd comp lbi isSrcDist verbosity handlers = case comp of
localHandlers bi = [(ext, h bi lbi) | (ext, h) <- handlers]
pre dirs dir lhndlrs fp =
preprocessFile dirs dir isSrcDist fp verbosity builtinSuffixes lhndlrs
preProcessTest test exePath testDir = do
let bi = testBuildInfo test
biHandlers = localHandlers bi
preProcessTest test = preProcessComponent (testBuildInfo test)
(testModules test)
preProcessBench bm = preProcessComponent (benchmarkBuildInfo bm)
(benchmarkModules bm)
preProcessComponent bi modules exePath dir = do
let biHandlers = localHandlers bi
sourceDirs = hsSourceDirs bi ++ [ autogenModulesDir lbi ]
sequence_ [ preprocessFile sourceDirs (buildDir lbi) isSrcDist
(ModuleName.toFilePath modu) verbosity builtinSuffixes
biHandlers
| modu <- testModules test ]
preprocessFile (testDir : (hsSourceDirs bi)) testDir isSrcDist
| modu <- modules ]
preprocessFile (dir : (hsSourceDirs bi)) dir isSrcDist
(dropExtensions $ exePath) verbosity
builtinSuffixes biHandlers
......
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