core_plugins.mk 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # Core: External plugins.
  2. CORE_PLUGINS_CASES = all early early-local local one templates templates-apps-only test
  3. CORE_PLUGINS_TARGETS = $(addprefix core-plugins-,$(CORE_PLUGINS_CASES))
  4. .PHONY: core-plugins $(CORE_PLUGINS_TARGETS)
  5. core-plugins: $(CORE_PLUGINS_TARGETS)
  6. core-plugins-all: build clean
  7. $i "Bootstrap a new OTP library named $(APP)"
  8. $t mkdir $(APP)/
  9. $t cp ../erlang.mk $(APP)/
  10. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  11. $i "Create a local git repository with two plugins"
  12. $t mkdir -p $(APP)/plugin_dep/mk
  13. $t echo "plugin1: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin1.mk
  14. $t echo "plugin2: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin2.mk
  15. $t echo "THIS := \$$(dir \$$(realpath \$$(lastword \$$(MAKEFILE_LIST))))" > $(APP)/plugin_dep/plugins.mk
  16. $t printf "%s\n" "include \$$(THIS)/mk/plugin1.mk" >> $(APP)/plugin_dep/plugins.mk
  17. $t printf "%s\n" "include \$$(THIS)/mk/plugin2.mk" >> $(APP)/plugin_dep/plugins.mk
  18. # We check that overriding THIS doesn't cause an error.
  19. $t echo "THIS :=" >> $(APP)/plugin_dep/plugins.mk
  20. $t cd $(APP)/plugin_dep && \
  21. git init -q && \
  22. git config user.email "testsuite@erlang.mk" && \
  23. git config user.name "test suite" && \
  24. git add . && \
  25. git commit -q --no-gpg-sign -m "Tests"
  26. $i "Add dependency and plugins to the Makefile"
  27. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = plugin_dep\ndep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master\nDEP_PLUGINS = plugin_dep\n"}' $(APP)/Makefile
  28. $i "Run 'make plugin1' and check that it prints plugin1"
  29. $t test -n "`$(MAKE) -C $(APP) plugin1 | grep plugin1`"
  30. $i "Run 'make plugin2' and check that it prints plugin2"
  31. $t test -n "`$(MAKE) -C $(APP) plugin2 | grep plugin2`"
  32. core-plugins-early: build clean
  33. $i "Bootstrap a new OTP library named $(APP)"
  34. $t mkdir $(APP)/
  35. $t cp ../erlang.mk $(APP)/
  36. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  37. $i "Write external plugin adddep_plugin"
  38. $t mkdir $(APP)/adddep_plugin
  39. $t echo -e "DEPS += cowlib" >> $(APP)/adddep_plugin/early-plugins.mk
  40. $i "Inject external plugin dependencies into $(APP)"
  41. $t echo 'DEPS = ranch' >>$(APP)/Makefile.tmp
  42. $t echo 'BUILD_DEPS = adddep_plugin' >>$(APP)/Makefile.tmp
  43. $t echo 'DEP_EARLY_PLUGINS = adddep_plugin' >>$(APP)/Makefile.tmp
  44. $t echo 'dep_adddep_plugin = cp adddep_plugin' >>$(APP)/Makefile.tmp
  45. $t cat $(APP)/Makefile >>$(APP)/Makefile.tmp
  46. $t mv $(APP)/Makefile.tmp $(APP)/Makefile
  47. $i "Build the application"
  48. $t $(MAKE) -C $(APP) $v
  49. $i "Check that all dependencies were fetched"
  50. $t test -e $(APP)/deps/cowlib
  51. $t test -e $(APP)/deps/ranch
  52. core-plugins-early-local: build clean
  53. $i "Bootstrap a new OTP library named $(APP)"
  54. $t mkdir $(APP)/
  55. $t cp ../erlang.mk $(APP)/
  56. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  57. $i "Create two internal plugin makefiles"
  58. $t mkdir -p $(APP)/mk
  59. $t echo "plugin1: ; @echo \$$@" > $(APP)/mk/plugin1.mk
  60. $t echo "plugin2: ; @echo \$$@" > $(APP)/early-plugins.mk
  61. $i "Add dependency and plugins to the Makefile"
  62. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEP_EARLY_PLUGINS = \$$(PROJECT) \$$(PROJECT)/mk/plugin1.mk\n"}' $(APP)/Makefile
  63. $i "Run 'make plugin1' and check that it prints plugin1"
  64. $t $(MAKE) --no-print-directory -C $(APP) plugin1 | grep -qw plugin1
  65. $i "Run 'make plugin2' and check that it prints plugin2"
  66. $t $(MAKE) --no-print-directory -C $(APP) plugin2 | grep -qw plugin2
  67. core-plugins-local: build clean
  68. $i "Bootstrap a new OTP library named $(APP)"
  69. $t mkdir $(APP)/
  70. $t cp ../erlang.mk $(APP)/
  71. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  72. $i "Create two internal plugin makefiles"
  73. $t mkdir -p $(APP)/mk
  74. $t echo "plugin1: ; @echo \$$@" > $(APP)/mk/plugin1.mk
  75. $t echo "plugin2: ; @echo \$$@" > $(APP)/plugins.mk
  76. $i "Add dependency and plugins to the Makefile"
  77. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEP_PLUGINS = \$$(PROJECT) \$$(PROJECT)/mk/plugin1.mk\n"}' $(APP)/Makefile
  78. $i "Run 'make plugin1' and check that it prints plugin1"
  79. $t $(MAKE) --no-print-directory -C $(APP) plugin1 | grep -qw plugin1
  80. $i "Run 'make plugin2' and check that it prints plugin2"
  81. $t $(MAKE) --no-print-directory -C $(APP) plugin2 | grep -qw plugin2
  82. core-plugins-one: build clean
  83. $i "Bootstrap a new OTP library named $(APP)"
  84. $t mkdir $(APP)/
  85. $t cp ../erlang.mk $(APP)/
  86. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  87. $i "Create a local git repository with two plugins"
  88. $t mkdir -p $(APP)/plugin_dep/mk
  89. $t echo "plugin1: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin1.mk
  90. $t echo "plugin2: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin2.mk
  91. $t echo "THIS := \$$(dir \$$(realpath \$$(lastword \$$(MAKEFILE_LIST))))" > $(APP)/plugin_dep/plugins.mk
  92. $t printf "%s\n" "include \$$(THIS)/mk/plugin1.mk" >> $(APP)/plugin_dep/plugins.mk
  93. $t printf "%s\n" "include \$$(THIS)/mk/plugin2.mk" >> $(APP)/plugin_dep/plugins.mk
  94. # We check that overriding THIS doesn't cause an error.
  95. $t echo "THIS :=" >> $(APP)/plugin_dep/plugins.mk
  96. $t cd $(APP)/plugin_dep && \
  97. git init -q && \
  98. git config user.email "testsuite@erlang.mk" && \
  99. git config user.name "test suite" && \
  100. git add . && \
  101. git commit -q --no-gpg-sign -m "Tests"
  102. $i "Add dependency and plugins to the Makefile"
  103. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = plugin_dep\ndep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master\nDEP_PLUGINS = plugin_dep/mk/plugin1.mk\n"}' $(APP)/Makefile
  104. $i "Run 'make plugin1' and check that it prints plugin1"
  105. $t $(MAKE) --no-print-directory -C $(APP) plugin1 | grep -qw plugin1
  106. $i "Run 'make plugin2' and confirm the target doesn't exist"
  107. $t ! $(MAKE) --no-print-directory -C $(APP) plugin2
  108. core-plugins-templates: build clean
  109. $i "Bootstrap a new OTP library named $(APP)"
  110. $t mkdir $(APP)/
  111. $t cp ../erlang.mk $(APP)/
  112. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  113. $i "Create a local git repository with a plugin containing a template"
  114. $t mkdir -p $(APP)/plugin_dep
  115. $t printf "%s\n" \
  116. "define tpl_test_mk" \
  117. "-module(test_mk)." \
  118. "endef" > $(APP)/plugin_dep/plugins.mk
  119. $t cd $(APP)/plugin_dep && \
  120. git init -q && \
  121. git config user.email "testsuite@erlang.mk" && \
  122. git config user.name "test suite" && \
  123. git add . && \
  124. git commit -q --no-gpg-sign -m "Tests"
  125. $i "Add dependency and plugins to the Makefile"
  126. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = plugin_dep\ndep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master\nDEP_PLUGINS = plugin_dep\n"}' $(APP)/Makefile
  127. $i "Run 'make list-templates' and check that it prints test_mk"
  128. $t $(MAKE) --no-print-directory -C $(APP) list-templates | grep -qw test_mk
  129. $i "Create a new file using the template"
  130. $t $(MAKE) --no-print-directory -C $(APP) new t=test_mk n=test_mk $v
  131. $i "Confirm the file exists"
  132. $t test -f $(APP)/src/test_mk.erl
  133. $i "Build the application"
  134. $t $(MAKE) -C $(APP) $v
  135. $i "Check that the file was compiled correctly"
  136. $t test -f $(APP)/ebin/test_mk.beam
  137. core-plugins-templates-apps-only: build clean
  138. $i "Create a multi application repository with no root application"
  139. $t mkdir $(APP)/
  140. $t cp ../erlang.mk $(APP)/
  141. $t echo "include erlang.mk" > $(APP)/Makefile
  142. $i "Create a new application my_app"
  143. $t $(MAKE) -C $(APP) new-app in=my_app $v
  144. $i "Create a local git repository with a plugin containing a template"
  145. $t mkdir -p $(APP)/plugin_dep
  146. $t printf "%s\n" \
  147. "define tpl_test_mk" \
  148. "-module(test_mk)." \
  149. "endef" > $(APP)/plugin_dep/plugins.mk
  150. $t cd $(APP)/plugin_dep && \
  151. git init -q && \
  152. git config user.email "testsuite@erlang.mk" && \
  153. git config user.name "test suite" && \
  154. git add . && \
  155. git commit -q --no-gpg-sign -m "Tests"
  156. $i "Add dependency and plugins to the Makefile"
  157. $t printf "%s\n" \
  158. "DEPS = plugin_dep" \
  159. "dep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master" \
  160. "DEP_PLUGINS = plugin_dep" \
  161. "include erlang.mk" > $(APP)/Makefile
  162. $i "Create a new file using the template in the my_app application"
  163. $t $(MAKE) --no-print-directory -C $(APP) new t=test_mk n=test_mk in=my_app $v
  164. $i "Confirm the file exists"
  165. $t test -f $(APP)/apps/my_app/src/test_mk.erl
  166. $i "Build the application"
  167. $t $(MAKE) -C $(APP) $v
  168. $i "Check that the file was compiled correctly"
  169. $t test -f $(APP)/apps/my_app/ebin/test_mk.beam
  170. core-plugins-test: build clean
  171. $i "Bootstrap a new OTP library named $(APP)"
  172. $t mkdir $(APP)/
  173. $t cp ../erlang.mk $(APP)/
  174. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  175. $i "Write external plugin touch_plugin"
  176. $t mkdir $(APP)/touch_plugin
  177. $t echo -e "app::" >> $(APP)/touch_plugin/plugins.mk
  178. $t echo -e "\ttouch markerfile" >> $(APP)/touch_plugin/plugins.mk
  179. $t echo -e "test-build:: app" >> $(APP)/touch_plugin/plugins.mk
  180. $t echo -e "clean::" >> $(APP)/touch_plugin/plugins.mk
  181. $t echo -e "\trm -f markerfile" >> $(APP)/touch_plugin/plugins.mk
  182. $i "Inject external plugin dependencies into $(APP)"
  183. $t echo 'BUILD_DEPS = touch_plugin' >>$(APP)/Makefile.tmp
  184. $t echo 'DEP_PLUGINS = touch_plugin' >>$(APP)/Makefile.tmp
  185. $t echo 'dep_touch_plugin = cp touch_plugin' >>$(APP)/Makefile.tmp
  186. $t cat $(APP)/Makefile >>$(APP)/Makefile.tmp
  187. $t mv $(APP)/Makefile.tmp $(APP)/Makefile
  188. $i "Build the application"
  189. $t $(MAKE) -C $(APP) $v
  190. $i "Check that the application was compiled correctly"
  191. $t test -e $(APP)/markerfile
  192. $i "Clean the application"
  193. $t $(MAKE) -C $(APP) clean $v
  194. $i "Check that the application was cleaned correctly"
  195. $t test ! -e $(APP)/markerfile
  196. $i "Run tests"
  197. $t $(MAKE) -C $(APP) tests $v
  198. $i "Check that the application was compiled correctly"
  199. $t test -e $(APP)/markerfile