Ivory.hs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module Gidl.Backend.Ivory where
  2. import Gidl.Types
  3. import Gidl.Interface
  4. import Gidl.Backend.Cabal
  5. import Gidl.Backend.Ivory.Types
  6. import Gidl.Backend.Ivory.Interface
  7. import Ivory.Artifact
  8. import Data.Char (isSpace)
  9. import Text.PrettyPrint.Mainland
  10. ivoryBackend :: TypeEnv -> InterfaceEnv -> String -> String -> [Artifact]
  11. ivoryBackend (TypeEnv te) (InterfaceEnv ie) pkgname namespace_raw =
  12. [ cabalFileArtifact cf
  13. , makefile
  14. ] ++
  15. [ artifactPath "src" m | m <- sourceMods
  16. ]
  17. where
  18. userDefinedTypes = [ t | (_,t) <- te, isUserDefined t ]
  19. tmods = [ typeModule (namespace ++ ["Types"]) t
  20. | t <- userDefinedTypes ]
  21. imods =[ interfaceModule (namespace ++ ["Interface"]) i
  22. | (_iname, i) <- ie
  23. ]
  24. sourceMods = tmods ++ imods ++ [ typeUmbrella namespace userDefinedTypes ]
  25. cf = (defaultCabalFile pkgname cabalmods deps)
  26. cabalmods = [ filePathToPackage (artifactFileName m) | m <- sourceMods ]
  27. deps = words "ivory ivory-stdlib ivory-serialize"
  28. namespace = dotwords namespace_raw
  29. dotwords :: String -> [String]
  30. dotwords s = case dropWhile isDot s of
  31. "" -> []
  32. s' -> let (w, s'') = break isDot s' in w : dotwords s''
  33. isDot c = (c == '.') || isSpace c
  34. makefile :: Artifact
  35. makefile = artifactText "Makefile" $
  36. prettyLazyText 80 $ stack
  37. [ text "IVORY_REPO ?= ../../../ivory"
  38. , empty
  39. , text "default:"
  40. , text "\tcabal build"
  41. , empty
  42. , text "create-sandbox:"
  43. , text "\tcabal sandbox init"
  44. , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory"
  45. , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-artifact"
  46. , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-serialize"
  47. , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-stdlib"
  48. , text "\tcabal install --enable-tests --dependencies-only"
  49. , empty
  50. , text "test:"
  51. , text "\tcabal test"
  52. , empty
  53. ]