|
@@ -0,0 +1,58 @@
|
|
|
|
+{-# LANGUAGE RecordWildCards #-}
|
|
|
|
+
|
|
|
|
+module Gidl.Backend.Cabal where
|
|
|
|
+
|
|
|
|
+import Ivory.Artifact
|
|
|
|
+import Text.PrettyPrint.Mainland
|
|
|
|
+
|
|
|
|
+data CabalFile =
|
|
|
|
+ CabalFile
|
|
|
|
+ { name :: String
|
|
|
|
+ , version :: String
|
|
|
|
+ , author :: String
|
|
|
|
+ , exposed_modules :: [String]
|
|
|
|
+ , build_depends :: [String]
|
|
|
|
+ , hs_source_dirs :: [String]
|
|
|
|
+ , default_language :: String
|
|
|
|
+ , ghc_options :: String
|
|
|
|
+ } deriving (Eq, Show)
|
|
|
|
+
|
|
|
|
+defaultCabalFile :: String -> [String] -> [String] -> CabalFile
|
|
|
|
+defaultCabalFile name_ exposed_modules_ build_depends_ = CabalFile
|
|
|
|
+ { name = name_
|
|
|
|
+ , version = "0.1.0.0"
|
|
|
|
+ , author = "Generated by Gidl"
|
|
|
|
+ , exposed_modules = exposed_modules_
|
|
|
|
+ , build_depends = "base >= 4.7" : build_depends_
|
|
|
|
+ , hs_source_dirs = ["src"]
|
|
|
|
+ , default_language = "Haskell2010"
|
|
|
|
+ , ghc_options = "-Wall"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+cabalFileArtifact :: CabalFile -> Artifact
|
|
|
|
+cabalFileArtifact CabalFile{..} = artifactText (name ++ ".cabal") $
|
|
|
|
+ prettyLazyText 80 $ stack
|
|
|
|
+ [ text "name:" <+> text name
|
|
|
|
+ , text "version:" <+> text version
|
|
|
|
+ , text "author:" <+> text author
|
|
|
|
+ , text "build-type: Simple"
|
|
|
|
+ , text "cabal-version: >=1.10"
|
|
|
|
+ , empty
|
|
|
|
+ , text "library"
|
|
|
|
+ , indent 2 $ stack
|
|
|
|
+ [ text "exposed-modules:" <+>
|
|
|
|
+ align (stack (punctuate comma (map text exposed_modules)))
|
|
|
|
+ , text "build-depends:" <+>
|
|
|
|
+ align (stack (punctuate comma (map text build_depends)))
|
|
|
|
+ , text "hs-source-dirs:" <+> sep (punctuate comma (map text hs_source_dirs))
|
|
|
|
+ , text "default-language:" <+> text default_language
|
|
|
|
+ , text "ghc-options:" <+> text ghc_options
|
|
|
|
+ ]
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+filePathToPackage :: String -> String
|
|
|
|
+filePathToPackage ('.':'h':'s':[]) = []
|
|
|
|
+filePathToPackage ('/':as) = '.' : filePathToPackage as
|
|
|
|
+filePathToPackage (a:as) = a : filePathToPackage as
|
|
|
|
+filePathToPackage [] = []
|
|
|
|
+
|