forked from jfischoff/wreq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
64 lines (58 loc) · 2.49 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- I don't know who originally wrote this, but I picked it up from
-- Edward Kmett's folds package.
{-# OPTIONS_GHC -Wall #-}
module Main (main) where
import Data.List (nub)
import Data.Version (showVersion)
import Distribution.Package
(PackageName(PackageName), Package, PackageId, InstalledPackageId,
packageVersion, packageName)
import Distribution.PackageDescription (PackageDescription(), TestSuite(..))
import Distribution.Simple
(defaultMainWithHooks, UserHooks(..), simpleUserHooks)
import Distribution.Simple.BuildPaths (autogenModulesDir)
import Distribution.Simple.LocalBuildInfo
(withLibLBI, withTestLBI, LocalBuildInfo(),
ComponentLocalBuildInfo(componentPackageDeps))
import Distribution.Simple.Setup
(BuildFlags(buildVerbosity), Flag(..), fromFlag,
HaddockFlags(haddockDistPref))
import Distribution.Simple.Utils
(rewriteFile, createDirectoryIfMissingVerbose, copyFiles)
import Distribution.Text (display)
import Distribution.Verbosity (Verbosity, normal)
import System.FilePath ((</>))
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ buildHook = \pkg lbi hooks flags -> do
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags
, postHaddock = \args flags pkg lbi -> do
copyFiles normal (haddockOutputDir flags pkg) []
postHaddock simpleUserHooks args flags pkg lbi
}
haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath
haddockOutputDir flags pkg = destDir where
baseDir = case haddockDistPref flags of
NoFlag -> "."
Flag x -> x
destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)
generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo
-> IO ()
generateBuildModule verbosity pkg lbi = do
let dir = autogenModulesDir lbi
createDirectoryIfMissingVerbose verbosity True dir
withLibLBI pkg lbi $ \_ libcfg -> do
withTestLBI pkg lbi $ \suite suitecfg -> do
rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
[ "module Build_" ++ testName suite ++ " where"
, "deps :: [String]"
, "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
]
where
formatdeps = map (formatone . snd)
formatone p = case packageName p of
PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo
-> [(InstalledPackageId, PackageId)]
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys