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 "ansi-wl-pprint"
64 , unconstrained "bytestring"
65 , package "Cabal" (gtEq [1,22,2])
66 , unconstrained "containers"
67 , unconstrained "deepseq-generics"
68 , unconstrained "directory"
69 , unconstrained "filepath"
70 , unconstrained "hackage-db"
71 , unconstrained "lens"
72 , unconstrained "monad-par"
73 , unconstrained "monad-par-extras"
75 , unconstrained "optparse-applicative"
76 , package "pretty" (gtEq [1,1,2])
77 , unconstrained "process"
78 , unconstrained "regex-posix"
80 , unconstrained "split"
81 , unconstrained "transformers"
82 , unconstrained "utf8-string"
86commonTestOptions :: HasBuildInfo a => [a]
87commonTestOptions = buildDepends
88 [ unconstrained "deepseq"
89 , unconstrained "doctest"
90 , unconstrained "hspec"
91 , unconstrained "QuickCheck"
92 ] : commonBuildOptions
94mkExecutable :: NonEmptyString -> [ExecutableField] -> Section
95mkExecutable exe opt = executable exe $ mainIs (exe++".hs") : opt ++ commonBuildOptions
97mkTest :: NonEmptyString -> [TestSuiteField] -> Section
98mkTest test opt = testSuite test $ exitcodeFields (test++".hs") ++ opt ++ hsSourceDirs ["test"] : commonTestOptions
103 let releaseMode = "--release" `elem` args
104 defaultMainWithHeader (const (return "")) $ do
105 liftIO $ do ('v':gv) <- getGitVersion
106 writeFile "src/Cabal2Nix/Version.hs" $
107 "module Cabal2Nix.Version where\n\
108 \version :: String\n\
109 \version = " ++ show gv ++ "\n"
110 libraryModules <- modules "src"
111 liftIO $ writeFile "test/doctest.hs" (mkDoctest libraryModules)
114 , exposedModules libraryModules : commonBuildOptions
115 , [ githubHead "NixOS" "cabal2nix"
116 , mkExecutable "cabal2nix" []
117 , mkExecutable "hackage2nix" [ buildable (not releaseMode)
118 , ghcOptions ["-threaded", "-rtsopts", "-with-rtsopts=-N"]
121 , mkTest "doctest" []
125mkDoctest :: [NonEmptyString] -> String
126mkDoctest libraryModules =
127 let paths = [ "src/" ++ map toPath l ++ ".hs" | l <- libraryModules ]
131 "module Main ( main ) where\n\
132 \import Test.DocTest\n\
135 \ doctest $ [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\"] ++ " ++ show paths ++ "\n\
136 \ doctest [\"-isrc\", \"-optP-include\", \"-optPdist/build/autogen/cabal_macros.h\", \"src/cabal2nix.hs\"]\n\
137 \ 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