Sfoglia il codice sorgente

gidl: dispatch to ivory backend

Pat Hickey 9 anni fa
parent
commit
02cd916406
3 ha cambiato i file con 47 aggiunte e 13 eliminazioni
  1. 31 6
      Makefile
  2. 15 7
      src/Gidl.hs
  3. 1 0
      tests/.gitignore

+ 31 - 6
Makefile

@@ -4,23 +4,48 @@ IVORY_REPO ?= ../ivory
 default:
 	cabal build
 
-clean-sandbox:
-	-rm -rf .cabal-sandbox
-	-rm cabal.sandbox.config
-	-rm -rf dist
-
 create-sandbox:
 	cabal sandbox init
 	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
 	cabal install --dependencies-only
 
 test: haskell-backend-test
+test: ivory-backend-test
 
 haskell-backend-test:
-	cabal run gidl -- -b haskell -i tests/example.idl -o tests/gidl-haskell-backend-test -p gidl-haskell-backend-test -n Gidl.Haskell.Test
+	cabal run gidl -- -b haskell \
+		-i tests/example.idl \
+		-o tests/gidl-haskell-backend-test \
+		-p gidl-haskell-backend-test \
+		-n Gidl.Haskell.Test
 	make -C tests/gidl-haskell-backend-test create-sandbox
 	make -C tests/gidl-haskell-backend-test
 	make -C tests/gidl-haskell-backend-test test
 
 haskell-backend-test-clean:
 	-rm -rf tests/gidl-haskell-backend-test
+
+ivory-backend-test:
+	cabal run gidl -- -b ivory \
+		-i tests/example.idl \
+		-o tests/gidl-ivory-backend-test \
+		-p gidl-ivory-backend-test \
+		-n Gidl.Ivory.Test
+	make -C tests/gidl-ivory-backend-test create-sandbox
+	make -C tests/gidl-ivory-backend-test
+	make -C tests/gidl-ivory-backend-test test
+
+ivory-backend-test-clean:
+	-rm -rf tests/gidl-ivory-backend-test
+
+
+clean: ivory-backend-test-clean
+clean: haskell-backend-test-clean
+
+distclean: clean
+	-rm -rf dist
+
+clean-sandbox: distclean
+	-rm -rf .cabal-sandbox
+	-rm cabal.sandbox.config
+

+ 15 - 7
src/Gidl.hs

@@ -12,6 +12,7 @@ import System.Exit
 import Ivory.Artifact
 import Gidl.Parse
 import Gidl.Backend.Haskell
+import Gidl.Backend.Ivory
 
 data OptParser opt = OptParser [String] (opt -> opt)
 instance Monoid (OptParser opt) where
@@ -34,6 +35,7 @@ parseOptions opts args = case getOpt Permute opts args of
 
 data Backend
   = HaskellBackend
+  | IvoryBackend
   deriving (Eq, Show)
 
 data Opts = Opts
@@ -58,8 +60,9 @@ initialOpts = Opts
 setBackend :: String -> OptParser Opts
 setBackend b = case map toUpper b of
   "HASKELL" -> success (\o -> o { backend = HaskellBackend })
+  "IVORY"   -> success (\o -> o { backend = IvoryBackend })
   _         -> invalid ("\"" ++ b ++ "\" is not a valid backend.\n"
-                          ++ "Supported backends: haskell")
+                          ++ "Supported backends: haskell, ivory")
 
 setIdlPath :: String -> OptParser Opts
 setIdlPath p = success (\o -> o { idlpath = p })
@@ -114,10 +117,15 @@ run = do
     Left e -> print e >> exitFailure
     Right (te, ie) ->
       case backend opts of
-        HaskellBackend -> do
-          let as = haskellBackend te ie (packagename opts) (namespace opts)
-          es <- mapM (putArtifact (outpath opts)) as
-          case catMaybes es of
-            [] -> exitSuccess
-            ees -> putStrLn (unlines ees) >> exitFailure
+        HaskellBackend -> artifactBackend opts $
+          haskellBackend te ie (packagename opts) (namespace opts)
+        IvoryBackend -> artifactBackend opts $
+          ivoryBackend te ie (packagename opts) (namespace opts)
 
+  where
+  artifactBackend :: Opts -> [Artifact] -> IO ()
+  artifactBackend opts as = do
+    es <- mapM (putArtifact (outpath opts)) as
+    case catMaybes es of
+      [] -> exitSuccess
+      ees -> putStrLn (unlines ees) >> exitFailure

+ 1 - 0
tests/.gitignore

@@ -1 +1,2 @@
 gidl-haskell-backend-test
+gidl-ivory-backend-test