Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (39 sloc) 1.959 kB
0b91a14 @ekmett Setup.lhs
authored
1 #!/usr/bin/runhaskell
70f39f5 @ekmett updated doctest and travis config to match lens
authored
2 \begin{code}
3 {-# OPTIONS_GHC -Wall #-}
4 module Main (main) where
0b91a14 @ekmett Setup.lhs
authored
5
70f39f5 @ekmett updated doctest and travis config to match lens
authored
6 import Data.List ( nub )
7 import Data.Version ( showVersion )
8 import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
9 import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
10 import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
11 import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
12 import Distribution.Simple.BuildPaths ( autogenModulesDir )
13 import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
14 import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
15 import Distribution.Verbosity ( Verbosity )
16 import System.FilePath ( (</>) )
0b91a14 @ekmett Setup.lhs
authored
17
70f39f5 @ekmett updated doctest and travis config to match lens
authored
18 main :: IO ()
19 main = defaultMainWithHooks simpleUserHooks
20 { buildHook = \pkg lbi hooks flags -> do
21 generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
22 buildHook simpleUserHooks pkg lbi hooks flags
23 }
24
25 generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
26 generateBuildModule verbosity pkg lbi = do
27 let dir = autogenModulesDir lbi
28 createDirectoryIfMissingVerbose verbosity True dir
29 withLibLBI pkg lbi $ \_ libcfg -> do
30 withTestLBI pkg lbi $ \suite suitecfg -> do
31 rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
32 [ "module Build_" ++ testName suite ++ " where"
33 , "deps :: [String]"
34 , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
35 ]
36 where
37 formatdeps = map (formatone . snd)
38 formatone p = case packageName p of
39 PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
40
41 testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
42 testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
43
44 \end{code}
Something went wrong with that request. Please try again.