Ivory.hs 1.9 KB

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