1module Main ( main ) where
4import Control.Monad.Trans ( liftIO )
5import System.Process ( readProcess )
6import Data.List ( intercalate )
7import System.Environment ( getArgs )
9getVersion :: IO Version
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:"]"))
15getGitVersion :: IO String
17 [v] <- fmap lines (readProcess "git" ["describe", "--dirty"] "")
20getAuthors :: IO [NonEmptyString]
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) ]
25properties :: Betsy IO Properties
27 v <- liftIO getVersion
28 as <- liftIO getAuthors
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." ]
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,1])]
49commonBuildOptions :: HasBuildInfo a => [a]
50commonBuildOptions = hsSourceDirs ["src"] : haskell2010 : commonOptions
52commonOptions :: HasBuildInfo a => [a]
53commonOptions = commonGhcOptions : commonBuildDepends
55commonGhcOptions :: HasBuildInfo a => a
56commonGhcOptions = ghcOptions ["-Wall"]
58commonBuildDepends :: HasBuildInfo a => [a]
61 [ package "base" (lt [5])
62 , unconstrained "aeson"
63 , unconstrained "bytestring"
64 , package "Cabal" (gtEq [1,22,2])
65 , unconstrained "containers"
66 , unconstrained "deepseq-generics"
67 , unconstrained "directory"
68 , unconstrained "filepath"
69 , unconstrained "hackage-db"
70 , unconstrained "lens"
71 , unconstrained "monad-par"
72 , unconstrained "monad-par-extras"
74 , package "pretty" (gtEq [1,1,2])
75 , unconstrained "process"
76 , unconstrained "regex-posix"
78 , unconstrained "split"
79 , unconstrained "transformers"
80 , unconstrained "utf8-string"
84commonTestOptions :: HasBuildInfo a => [a]
85commonTestOptions = buildDepends
86 [ unconstrained "deepseq"
87 , unconstrained "doctest"
88 , unconstrained "hspec"
89 , unconstrained "QuickCheck"
90 ] : commonBuildOptions
92mkExecutable :: NonEmptyString -> [ExecutableField] -> Section
93mkExecutable exe opt = executable exe $ mainIs (exe++".hs") : opt ++ commonBuildOptions
95mkTest :: NonEmptyString -> [TestSuiteField] -> Section
96mkTest test opt = testSuite test $ exitcodeFields (test++".hs") ++ opt ++ hsSourceDirs ["test"] : commonTestOptions
101 let releaseMode = "--release" `elem` args
102 defaultMainWithHeader (const (return "")) $ do
103 liftIO $ do ('v':gv) <- getGitVersion
104 writeFile "src/Cabal2Nix/Version.hs" $
105 "module Cabal2Nix.Version where\n\
106 \version :: String\n\
107 \version = " ++ show gv ++ "\n"
108 libraryModules <- modules "src"
109 liftIO $ writeFile "test/doctest.hs" (mkDoctest libraryModules)
112 , exposedModules libraryModules : commonBuildOptions
113 , [ githubHead "NixOS" "cabal2nix"
114 , mkExecutable "cabal2nix" []
115 , mkExecutable "hackage2nix" [ buildable (not releaseMode)
116 , ghcOptions ["-threaded", "-rtsopts", "-with-rtsopts=-N"]
119 , mkTest "doctest" []
123mkDoctest :: [NonEmptyString] -> String
124mkDoctest libraryModules =
125 let paths = [ "src/" ++ map toPath l ++ ".hs" | l <- libraryModules ]
129 "module Main ( main ) where\n\
130 \import Test.DocTest\n\
133 \ doctest $ [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\"] ++ " ++ show paths ++ "\n\
134 \ doctest [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\", \"src/cabal2nix.hs\"]\n\
135 \ doctest [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\", \"src/hackage2nix.hs\"]\n"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list