cartel-0.2.0.0: genCabal.hs
-- | This is a Cartel program used to generate the cabal file for
-- Cartel itself.
--
-- You should note in your comments which version of Cartel was used
-- when writing the Cartel program; in this case, I used version
-- 0.1.0.0.
--
-- There's no huge benefit to using Cartel for small programs or
-- libraries; indeed, Cartel itself is small so there's not much
-- benefit to using Cartel here other than for pedagogical and
-- testing purposes. Cartel is most useful for big Cabal files with
-- lots of redundancy and dozens of modules.
module Main (main) where
-- Cartel exports a lot of names; by importing them qualified you
-- don't have to worry about clashing with your own names
import qualified Cartel as A
-- Package Dependencies
--
-- It can be useful to pull these out and define them in
-- top-level values, especially if your Cabal file has many
-- redundancies. That way you can update version numbers in just
-- one place rather than throughout your Cabal file (forgetting to
-- update all these numbers is a major reason I wrote Cartel.)
base :: A.Package
base = A.closedOpen "base" [4,5,0,0] [4,8]
directory :: A.Package
directory = A.closedOpen "directory" [1,1,0,2] [1,3]
filepath :: A.Package
filepath = A.closedOpen "filepath" [1,3,0,0] [1,4]
time :: A.Package
time = A.closedOpen "time" [1,4] [1,5]
testedWith :: [(A.Compiler, A.ConstrTree)]
testedWith =
let ghc v = (A.GHC, A.Leaf (A.Constraint EQ (A.Version v)))
in map ghc [[7,4,1], [7,6,3], [7,8,2]]
-- The global package properties. Build your properties from the
-- default 'properties' record rather than the 'Properties'
-- constructor to help future-proof your code.
properties :: A.Properties
properties = A.properties
{ A.prName = "cartel"
, A.prVersion = A.Version [0,2,0,0]
, A.prCabalVersion = (1, 14)
, A.prBuildType = A.Simple
, A.prLicense = A.BSD3
, A.prLicenseFile = "LICENSE"
, A.prLicenseFiles = []
, A.prExtraSourceFiles =
[ "README.md"
, "genCabal.hs"
, "current-versions.txt"
, "minimum-versions.txt" ]
, A.prTestedWith = testedWith
, A.prCopyright = "2014 Omari Norman"
, A.prAuthor = "Omari Norman"
, A.prMaintainer = "omari@smileystation.com"
, A.prStability = "Experimental"
, A.prHomepage = "http://www.github.com/massysett/cartel"
, A.prBugReports = "omari@smileystation.com"
, A.prSynopsis = "Specify your Cabal files in Haskell"
, A.prDescription =
[ "By specifying Cabal files in Haskell, you have the power"
, "of Haskell at your disposal to eliminate redundancies"
, "and to programatically populate various fields."
, ""
, "See the documentation in the \"Cartel\" module for details."
]
, A.prCategory = "Distribution"
}
-- Definition for the library. It takes a list of modules to export
-- as a parameter; this allows the Main function to use a function
-- to generate the list of modules rather than you having to specify
-- them in a duplicative, error-prone, and boring process.
library
:: [String]
-- ^ List of library modules to export
-> A.Library
library ms = A.Library $
[ A.LibExposedModules ms
, A.LibExposed True
]
++ map A.LibInfo
[ A.BuildDepends [base, directory, filepath, time]
, A.OtherModules ["Paths_cartel"]
, A.Buildable True
, A.GHCOptions ["-Wall"]
, A.DefaultLanguage A.Haskell2010
, A.HsSourceDirs ["lib"]
]
-- Generate the complete Cabal record
cabal
:: [String]
-- ^ List of library modules
-> A.Cabal
cabal mods = A.cabal
{ A.cProperties = properties
, A.cLibrary = Just $ library mods
}
-- To see the result, just run "runhaskell genCabal.hs". The result
-- is printed to standard output.
main :: IO ()
main = do
modulesToExport <- A.modules "lib"
A.render "genCabal.hs" $ cabal modulesToExport