123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- {-# 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
- , executables :: [CabalExe]
- , tests :: [CabalTest]
- } deriving (Eq, Show)
- data CabalTest =
- CabalTest
- { test_name :: String
- , test_type :: String
- , test_hs_source_dirs :: [String]
- , test_main_is :: String
- , test_build_depends :: [String]
- } deriving (Eq, Show)
- data CabalExe =
- CabalExe
- { exe_name :: String
- , exe_hs_source_dirs :: [String]
- , exe_main_is :: String
- , exe_build_depends :: [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"
- , executables = []
- , tests = []
- }
- defaultCabalExe :: String -> String -> [String] -> CabalExe
- defaultCabalExe name_ main_ build_depends_ = CabalExe
- { exe_name = name_
- , exe_hs_source_dirs = ["tests"]
- , exe_main_is = main_
- , exe_build_depends = "base >= 4.7" : build_depends_
- }
- defaultCabalTest :: String -> String -> [String] -> CabalTest
- defaultCabalTest name_ main_ build_depends_ = CabalTest
- { test_name = name_
- , test_type = "exitcode-stdio-1.0"
- , test_hs_source_dirs = ["tests"]
- , test_main_is = main_
- , test_build_depends = "base >= 4.7" : build_depends_
- }
- cabalFileArtifact :: CabalFile -> Artifact
- cabalFileArtifact CabalFile{..} = artifactText (name ++ ".cabal") $
- prettyLazyText 1000 $ 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
- ]
- , stack [ empty </> cabalExeDoc e | e <- executables ]
- , stack [ empty </> cabalTestDoc t | t <- tests ]
- ]
- cabalExeDoc :: CabalExe -> Doc
- cabalExeDoc CabalExe{..} =
- text "executable" <+> text exe_name </> indent 2 (stack
- [ text "main-is:" <+> text exe_main_is
- , text "hs-source-dirs:" <+> sep (punctuate comma (map text exe_hs_source_dirs))
- , text "build-depends:" <+> align (stack (punctuate comma (map text exe_build_depends)))
- , text "default-language: Haskell2010"
- , text "ghc-options: -Wall"
- ])
- cabalTestDoc :: CabalTest -> Doc
- cabalTestDoc CabalTest{..} =
- text "Test-Suite" <+> text test_name </> indent 2 (stack
- [ text "type:" <+> text test_type
- , text "hs-source-dirs:" <+> sep (punctuate comma (map text test_hs_source_dirs))
- , text "main-is:" <+> text test_main_is
- , text "build-depends:" <+> align (stack (punctuate comma (map text test_build_depends)))
- ])
- filePathToPackage :: String -> String
- filePathToPackage ('.':'h':'s':[]) = []
- filePathToPackage ('/':as) = '.' : filePathToPackage as
- filePathToPackage (a:as) = a : filePathToPackage as
- filePathToPackage [] = []
|