Haskell.hs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. module Gidl.Backend.Haskell where
  2. import Gidl.Schema
  3. import Gidl.Interface
  4. import Gidl.Backend.Cabal
  5. import Gidl.Backend.Haskell.Types
  6. import Gidl.Backend.Haskell.Test
  7. import Gidl.Backend.Haskell.Interface
  8. import Ivory.Artifact
  9. import Data.Char (isSpace)
  10. import Data.List (nub)
  11. import Text.PrettyPrint.Mainland
  12. haskellBackend :: [Interface] -> String -> String -> [Artifact]
  13. haskellBackend iis pkgname namespace_raw =
  14. [ cabalFileArtifact cf
  15. , makefile
  16. , artifactPath "tests" serializeTestMod
  17. ] ++
  18. [ artifactPath "src" m | m <- sourceMods
  19. ]
  20. where
  21. types = nub [ t | i <- iis, t <- interfaceTypes i]
  22. tmods = [ typeModule False (namespace ++ ["Types"]) t
  23. | t <- types
  24. , isUserDefined t
  25. ]
  26. imods = [ interfaceModule False (namespace ++ ["Interface"]) i
  27. | i <- iis
  28. ]
  29. sourceMods = tmods ++ imods
  30. cf = (defaultCabalFile pkgname cabalmods deps) { tests = [ serializeTest ] }
  31. cabalmods = [ filePathToPackage (artifactFileName m) | m <- sourceMods ]
  32. deps = [ "cereal", "QuickCheck" ]
  33. serializeTest = defaultCabalTest "serialize-test" "SerializeTest.hs"
  34. (pkgname:deps)
  35. serializeTestMod = serializeTestModule namespace iis
  36. namespace = dotwords namespace_raw
  37. dotwords :: String -> [String]
  38. dotwords s = case dropWhile isDot s of
  39. "" -> []
  40. s' -> let (w, s'') = break isDot s' in w : dotwords s''
  41. isDot c = (c == '.') || isSpace c
  42. makefile :: Artifact
  43. makefile = artifactText "Makefile" $
  44. prettyLazyText 1000 $ stack
  45. [ text "default:"
  46. , text "\tcabal build"
  47. , empty
  48. , text "create-sandbox:"
  49. , text "\tcabal sandbox init"
  50. , text "\tcabal install --enable-tests --dependencies-only"
  51. , empty
  52. , text "test:"
  53. , text "\tcabal test"
  54. , empty
  55. ]