@@ -1,139 +0,0 @@
1−module Main ( main ) where
2−
3−import Cartel
4−import Control.Monad.Trans ( liftIO )
5−import System.Process ( readProcess )
6−import Data.List ( intercalate )
7−import System.Environment ( getArgs )
8−
9−getVersion :: IO Version
10−getVersion = do
11− v <- readProcess "git" ["log", "-1", "--format=%ci"] ""
12− let [y4,y3,y2,y1,'-',m2,m1,'-',d2,d1] = head (words v)
13− return (read ('[':y4:y3:y2:y1:m2:m1:d2:d1:"]"))
14−
15−getGitVersion :: IO String
16−getGitVersion = do
17− [v] <- fmap lines (readProcess "git" ["describe", "--dirty"] "")
18− return v
19−
20−getAuthors :: IO [NonEmptyString]
21−getAuthors = do
22− buf <- readProcess "sh" ["-c", "git log --pretty=short | git shortlog --numbered --summary"] ""
23− return [ unwords (tail (words l)) | l <- lines buf, not (null l) ]
24−
25−properties :: Betsy IO Properties
26−properties = do
27− v <- liftIO getVersion
28− as <- liftIO getAuthors
29− return $ blank
30− { name = "cabal2nix"
31− , version = v
32− , buildType = Just simple
33− , category = "Distribution"
34− , maintainer = "Peter Simons <simons@cryp.to>"
35− , synopsis = "Convert Cabal files into Nix build instructions."
36− , description = [ "Convert Cabal files into Nix build instructions." ]
37− , license = Just bsd3
38− , licenseFile = "LICENSE"
39− , copyright = "Copyright (c) 2011-2015 by Peter Simons et al"
40− , author = intercalate ", " as
41− , stability = "Experimental"
42− , cabalVersion = Just (1,10)
43− , homepage = "http://github.com/NixOS/cabal2nix/"
44− , bugReports = "http://github.com/NixOS/cabal2nix/issues"
45− , extraSourceFiles = ["README.md"]
46− , testedWith = [(ghc, eq [7,10,2])]
47− }
48−
49−commonBuildOptions :: HasBuildInfo a => [a]
50−commonBuildOptions = hsSourceDirs ["src"] : haskell2010 : commonOptions
51−
52−commonOptions :: HasBuildInfo a => [a]
53−commonOptions = commonGhcOptions : commonBuildDepends
54−
55−commonGhcOptions :: HasBuildInfo a => a
56−commonGhcOptions = ghcOptions ["-Wall"]
57−
58−commonBuildDepends :: HasBuildInfo a => [a]
59−commonBuildDepends =
60− [ buildDepends
61− [ package "base" (lt [5])
62− , unconstrained "aeson"
63− , unconstrained "ansi-wl-pprint"
64− , unconstrained "bytestring"
65− , package "Cabal" (gtEq [1,22,2])
66− , unconstrained "containers"
67− , unconstrained "data-default"
68− , unconstrained "deepseq-generics"
69− , unconstrained "directory"
70− , unconstrained "filepath"
71− , unconstrained "hackage-db"
72− , unconstrained "lens"
73− , unconstrained "monad-par"
74− , unconstrained "monad-par-extras"
75− , unconstrained "mtl"
76− , unconstrained "optparse-applicative"
77− , package "pretty" (gtEq [1,1,2])
78− , unconstrained "process"
79− , unconstrained "pretty-show"
80− , unconstrained "regex-posix"
81− , unconstrained "SHA"
82− , unconstrained "split"
83− , unconstrained "transformers"
84− , unconstrained "utf8-string"
85− ]
86− ]
87−
88−commonTestOptions :: HasBuildInfo a => [a]
89−commonTestOptions = buildDepends
90− [ unconstrained "deepseq"
91− , unconstrained "doctest"
92− , unconstrained "hspec"
93− , unconstrained "QuickCheck"
94− ] : commonBuildOptions
95−
96−mkExecutable :: NonEmptyString -> [ExecutableField] -> Section
97−mkExecutable exe opt = executable exe $ mainIs (exe++".hs") : opt ++ commonBuildOptions
98−
99−mkTest :: NonEmptyString -> [TestSuiteField] -> Section
100−mkTest test opt = testSuite test $ exitcodeFields (test++".hs") ++ opt ++ hsSourceDirs ["test"] : commonTestOptions
101−
102−main :: IO ()
103−main = do
104− args <- getArgs
105− let releaseMode = "--release" `elem` args
106− defaultMainWithHeader (const (return "")) $ do
107− liftIO $ do ('v':gv) <- getGitVersion
108− writeFile "src/Internal/Version.hs" $
109− "module Internal.Version where\n\
110− \version :: String\n\
111− \version = " ++ show gv ++ "\n"
112− libraryModules <- modules "src"
113− liftIO $ writeFile "test/doctest.hs" (mkDoctest libraryModules)
114− props <- properties
115− return ( props
116− , exposedModules libraryModules : commonBuildOptions
117− , [ githubHead "NixOS" "cabal2nix"
118− , mkExecutable "cabal2nix" []
119− , mkExecutable "hackage2nix" [ buildable (not releaseMode)
120− , ghcOptions ["-threaded", "-rtsopts", "-with-rtsopts=-N"]
121− ]
122− , mkTest "spec" []
123− , mkTest "doctest" []
124− ]
125− )
126−
127−mkDoctest :: [NonEmptyString] -> String
128−mkDoctest libraryModules =
129− let paths = [ "src/" ++ map toPath l ++ ".hs" | l <- libraryModules ]
130− toPath '.' = '/'
131− toPath c = c
132− in
133− "module Main ( main ) where\n\
134− \import Test.DocTest\n\
135− \main :: IO ()\n\
136− \main = do\n\
137− \ doctest $ [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\"] ++ " ++ show paths ++ "\n\
138− \ doctest [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\", \"src/cabal2nix.hs\"]\n\
139− \ doctest [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\", \"src/hackage2nix.hs\"]\n"