Browse Source

Use my new cabal dependency snippets.

Jamey Sharp 9 years ago
parent
commit
59b930ba21
7 changed files with 90 additions and 60 deletions
  1. 1 19
      Makefile
  2. 4 0
      Makefile.deps
  3. 34 0
      Makefile.sandbox
  4. 23 4
      src/Gidl/Backend/Ivory.hs
  5. 26 4
      src/Gidl/Backend/Tower.hs
  6. 1 13
      support/ivory/Makefile
  7. 1 20
      support/tower/Makefile

+ 1 - 19
Makefile

@@ -1,15 +1,6 @@
-
 SCARGOT_REPO ?= ../s-cargot
 IVORY_REPO ?= ../ivory
-
-default:
-	cabal build
-
-create-sandbox:
-	cabal sandbox init
-	cabal sandbox add-source $(SCARGOT_REPO)
-	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
-	cabal install --dependencies-only
+include Makefile.sandbox
 
 test: haskell-backend-test
 test: ivory-backend-test
@@ -73,15 +64,6 @@ rpc-backend-test:
 rpc-backend-test-clean:
 	-rm -rf tests/gidl-ivory-backend-test
 
-
 clean: ivory-backend-test-clean
 clean: tower-backend-test-clean
 clean: haskell-backend-test-clean
-
-distclean: clean
-	-rm -rf dist
-
-clean-sandbox: distclean
-	-rm -rf .cabal-sandbox
-	-rm cabal.sandbox.config
-

+ 4 - 0
Makefile.deps

@@ -0,0 +1,4 @@
+$(call add-cabal-package-source, \
+  $(SCARGOT_REPO) \
+  $(IVORY_REPO)/ivory-artifact \
+)

+ 34 - 0
Makefile.sandbox

@@ -0,0 +1,34 @@
+default:
+	cabal build
+
+test:
+
+define add-cabal-package-source-once
+ifeq ($(findstring $(1) ,$(CABAL_PACKAGE_SOURCES) ),)
+CABAL_PACKAGE_SOURCES += $(1)
+-include $(1)/Makefile.deps
+endif
+endef
+
+add-cabal-package-source = $(foreach package,$(1),$(eval $(call add-cabal-package-source-once,$(package))))
+
+include Makefile.deps
+
+create-sandbox:
+	cabal sandbox init
+	echo "tests: True" >> cabal.sandbox.config
+ifneq ($(strip $(CABAL_PACKAGE_SOURCES)),)
+	cabal sandbox add-source $(CABAL_PACKAGE_SOURCES)
+endif
+	cabal install --dependencies-only
+
+clean:
+
+distclean: clean
+	-rm -rf dist
+
+clean-sandbox: distclean
+	-rm -rf cabal.sandbox.config
+	-rm -rf .cabal-sandbox
+
+.PHONY: default test create-sandbox clean distclean clean-sandbox

+ 23 - 4
src/Gidl/Backend/Ivory.hs

@@ -17,20 +17,39 @@ import Gidl.Backend.Ivory.Schema
 ivoryBackend :: [Interface] -> String -> String -> [Artifact]
 ivoryBackend iis pkgname namespace_raw =
   [ cabalFileArtifact cf
-  , artifactPath "tests" $ codegenTest namespace
   , makefile
+  , artifactCabalFile P.getDataDir "Makefile.sandbox"
+  , depsfile
+  , artifactPath "tests" $ codegenTest namespace
   ] ++ map (artifactPath "src") sources
   where
   sources = ivorySources iis namespace
   namespace = dotwords namespace_raw
 
-  cf = (defaultCabalFile pkgname cabalmods deps) { executables = [ cg_exe ] }
+  cf = (defaultCabalFile pkgname cabalmods cabalDeps) { executables = [ cg_exe ] }
   cg_exe = defaultCabalExe (pkgname ++ "-gen") "CodeGen.hs"
-              (deps ++ (words "ivory-backend-c") ++ [pkgname])
+              (cabalDeps ++ cabalExeDeps ++ [pkgname])
   cabalmods = map (filePathToPackage . artifactFileName) sources
-  deps = words "ivory ivory-stdlib ivory-serialize"
+  (makeDeps, cabalDeps) = unzip ivoryDeps
+  (makeExeDeps, cabalExeDeps) = unzip ivoryTestDeps
+
+  sandwich a b c = a ++ c ++ b
+  depsfile = artifactString "Makefile.deps" $ unlines $
+    sandwich ["$(call add-cabal-package-source, \\"] [")"] $
+    map (sandwich "  " " \\") $
+    makeDeps ++ makeExeDeps
 
+ivoryDeps :: [(String, String)]
+ivoryDeps =
+  [ ("$(IVORY_REPO)/ivory", "ivory")
+  , ("$(IVORY_REPO)/ivory-serialize", "ivory-serialize")
+  , ("$(IVORY_REPO)/ivory-stdlib", "ivory-stdlib")
+  ]
 
+ivoryTestDeps :: [(String, String)]
+ivoryTestDeps =
+  [ ("$(IVORY_REPO)/ivory-backend-c", "ivory-backend-c")
+  ]
 
 ivorySources :: [Interface] -> [String] -> [Artifact]
 ivorySources iis namespace =

+ 26 - 4
src/Gidl/Backend/Tower.hs

@@ -19,6 +19,8 @@ towerBackend :: [Interface] -> String -> String -> [Artifact]
 towerBackend iis pkgname namespace_raw =
   [ cabalFileArtifact cf
   , makefile
+  , artifactCabalFile P.getDataDir "Makefile.sandbox"
+  , depsfile
   , defaultconf
   , artifactPath "tests" (codegenTest iis namespace)
   ] ++ map (artifactPath "src") sources
@@ -33,12 +35,32 @@ towerBackend iis pkgname namespace_raw =
 
   isources = ivorySources iis (namespace ++ ["Ivory"])
 
-  cf = (defaultCabalFile pkgname cabalmods deps) { executables = [ cg_exe ] }
+  cf = (defaultCabalFile pkgname cabalmods cabalDeps) { executables = [ cg_exe ] }
   cabalmods = map (filePathToPackage . artifactFileName) sources
-  deps = words "ivory ivory-stdlib ivory-serialize tower"
+  (makeDeps, cabalDeps) = unzip towerDeps
+  (makeExeDeps, cabalExeDeps) = unzip towerTestDeps
   cg_exe = defaultCabalExe (pkgname ++ "-gen") "CodeGen.hs"
-            (deps ++ (words "tower-config tower-freertos-stm32") ++ [pkgname])
-
+            (cabalDeps ++ cabalExeDeps ++ [pkgname])
+
+  sandwich a b c = a ++ c ++ b
+  depsfile = artifactString "Makefile.deps" $ unlines $
+    sandwich ["$(call add-cabal-package-source, \\"] [")"] $
+    map (sandwich "  " " \\") $
+    makeDeps ++ makeExeDeps
+
+towerDeps :: [(String, String)]
+towerDeps =
+  [ ("$(IVORY_REPO)/ivory", "ivory")
+  , ("$(IVORY_REPO)/ivory-serialize", "ivory-serialize")
+  , ("$(IVORY_REPO)/ivory-stdlib", "ivory-stdlib")
+  , ("$(TOWER_REPO)/tower", "tower")
+  ]
+
+towerTestDeps :: [(String, String)]
+towerTestDeps =
+  [ ("$(TOWER_REPO)/tower-config", "tower-config")
+  , ("$(BSP_REPO)/tower-freertos-stm32", "tower-freertos-stm32")
+  ]
 
 towerSources :: [Interface] -> [String] -> [Artifact]
 towerSources iis namespace = towerInterfaces

+ 1 - 13
support/ivory/Makefile

@@ -1,17 +1,5 @@
 IVORY_REPO ?= ../../../ivory
-
-default:
-	cabal build
-
-create-sandbox:
-	cabal sandbox init
-	cabal sandbox add-source $(IVORY_REPO)/ivory
-	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
-	cabal sandbox add-source $(IVORY_REPO)/ivory-serialize
-	cabal sandbox add-source $(IVORY_REPO)/ivory-stdlib
-	cabal sandbox add-source $(IVORY_REPO)/ivory-opts
-	cabal sandbox add-source $(IVORY_REPO)/ivory-backend-c
-	cabal install --enable-tests --dependencies-only
+include Makefile.sandbox
 
 test:
 	cabal run -- --src-dir=codegen-out

+ 1 - 20
support/tower/Makefile

@@ -1,26 +1,7 @@
 IVORY_REPO ?= ../../../ivory
 TOWER_REPO ?= ../../../tower
 BSP_REPO ?= ../../../ivory-tower-stm32
-
-default:
-	cabal build
-
-create-sandbox:
-	cabal sandbox init
-	cabal sandbox add-source $(IVORY_REPO)/ivory
-	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
-	cabal sandbox add-source $(IVORY_REPO)/ivory-serialize
-	cabal sandbox add-source $(IVORY_REPO)/ivory-stdlib
-	cabal sandbox add-source $(IVORY_REPO)/ivory-opts
-	cabal sandbox add-source $(IVORY_REPO)/ivory-hw
-	cabal sandbox add-source $(IVORY_REPO)/ivory-backend-c
-	cabal sandbox add-source $(TOWER_REPO)/tower-config
-	cabal sandbox add-source $(TOWER_REPO)/tower
-	cabal sandbox add-source $(BSP_REPO)/ivory-freertos-bindings
-	cabal sandbox add-source $(BSP_REPO)/tower-freertos-stm32
-	cabal sandbox add-source $(BSP_REPO)/ivory-bsp-stm32
-	cabal sandbox add-source $(BSP_REPO)/ivory-bsp-tests
-	cabal install --enable-tests --dependencies-only
+include Makefile.sandbox
 
 test:
 	cabal run -- --src-dir=codegen-out