plugin_relx.mk 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. # Relx plugin.
  2. #
  3. # Sleeps when interacting with relx script are necessary after start and upgrade
  4. # as both of those interactions are not synchronized.
  5. RELX_TARGETS = $(call list_targets,relx)
  6. .PHONY: relx $(RELX_TARGETS)
  7. ifeq ($(PLATFORM),msys2)
  8. RELX_REL_EXT = .cmd
  9. else
  10. RELX_REL_EXT =
  11. endif
  12. relx: $(RELX_TARGETS)
  13. relx-rel: build clean
  14. $i "Bootstrap a new release named $(APP)"
  15. $t mkdir $(APP)/
  16. $t cp ../erlang.mk $(APP)/
  17. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  18. $i "Build the release"
  19. $t $(MAKE) -C $(APP) $v
  20. $i "Check that relx was downloaded"
  21. $t test -f $(APP)/.erlang.mk/relx
  22. $i "Check that the release was built"
  23. $t test -d $(APP)/_rel
  24. $t test -d $(APP)/_rel/$(APP)_release
  25. $t test -d $(APP)/_rel/$(APP)_release/bin
  26. $t test -d $(APP)/_rel/$(APP)_release/lib
  27. $t test -d $(APP)/_rel/$(APP)_release/releases
  28. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  29. $i "Clean the application"
  30. $t $(MAKE) -C $(APP) clean $v
  31. $i "Check that the release still exists"
  32. $t test -d $(APP)/_rel
  33. $t test -d $(APP)/_rel/$(APP)_release
  34. $t test -d $(APP)/_rel/$(APP)_release/bin
  35. $t test -d $(APP)/_rel/$(APP)_release/lib
  36. $t test -d $(APP)/_rel/$(APP)_release/releases
  37. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  38. $i "Distclean the application"
  39. $t $(MAKE) -C $(APP) distclean $v
  40. $i "Check that the output directory was removed entirely"
  41. $t test ! -d $(APP)/_rel/
  42. relx-apps-with-deps: build clean
  43. $i "Bootstrap a new release as a multi application repository"
  44. $t mkdir $(APP)/
  45. $t cp ../erlang.mk $(APP)/
  46. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib bootstrap-rel $v
  47. $i "Create a new application my_app"
  48. $t $(MAKE) -C $(APP) new-app in=my_app $v
  49. $i "Include my_app in the release"
  50. $t perl -pi.bak -e 's/$(APP),/$(APP), my_app,/' $(APP)/relx.config
  51. $i "Add Cowlib to the list of dependencies for my_app"
  52. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/apps/my_app/Makefile
  53. ifdef LEGACY
  54. $i "Add Cowlib to the applications key in the my_app.app.src file"
  55. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowlib,\n"}' $(APP)/apps/my_app/src/my_app.app.src
  56. endif
  57. $i "Build the application"
  58. $t $(MAKE) -C $(APP) $v
  59. $i "Check that all compiled files exist"
  60. $t test -f $(APP)/apps/my_app/my_app.d
  61. $t test -f $(APP)/apps/my_app/ebin/my_app.app
  62. $t test -f $(APP)/apps/my_app/ebin/my_app_app.beam
  63. $t test -f $(APP)/apps/my_app/ebin/my_app_sup.beam
  64. $t test -f $(APP)/deps/cowlib/ebin/cowlib.app
  65. $i "Check that Cowlib was included in the release"
  66. $t test -d $(APP)/_rel/test_relx_apps_with_deps_release/lib/cowlib-1.0.2
  67. relx-bare-rel: build clean
  68. $i "Bootstrap a new release named $(APP)"
  69. $t mkdir $(APP)/
  70. $t cp ../erlang.mk $(APP)/
  71. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  72. $i "Build the release"
  73. $t $(MAKE) -C $(APP) rel $v
  74. $i "Check that relx was downloaded"
  75. $t test -f $(APP)/.erlang.mk/relx
  76. $i "Check that the release was built"
  77. $t test -d $(APP)/_rel
  78. $t test -d $(APP)/_rel/$(APP)_release
  79. $t test -d $(APP)/_rel/$(APP)_release/bin
  80. $t test -d $(APP)/_rel/$(APP)_release/lib
  81. $t test -d $(APP)/_rel/$(APP)_release/releases
  82. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  83. relx-post-rel: build clean
  84. $i "Bootstrap a new release named $(APP)"
  85. $t mkdir $(APP)/
  86. $t cp ../erlang.mk $(APP)/
  87. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  88. $i "Add relx-post-rel target to Makefile"
  89. $t echo "relx-post-rel::" >> $(APP)/Makefile
  90. $t echo " echo test post rel > _rel/$(APP)_release/test_post_rel" >> $(APP)/Makefile
  91. $i "Build the release"
  92. $t $(MAKE) -C $(APP) $v
  93. $i "Check that relx was downloaded"
  94. $t test -f $(APP)/.erlang.mk/relx
  95. $i "Check that the release was built"
  96. $t test -d $(APP)/_rel
  97. $t test -d $(APP)/_rel/$(APP)_release
  98. $t test -d $(APP)/_rel/$(APP)_release/bin
  99. $t test -d $(APP)/_rel/$(APP)_release/lib
  100. $t test -d $(APP)/_rel/$(APP)_release/releases
  101. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  102. $t test -f $(APP)/_rel/$(APP)_release/test_post_rel
  103. $t test "test post rel" = "`cat $(APP)/_rel/$(APP)_release/test_post_rel`"
  104. $i "Clean the application"
  105. $t $(MAKE) -C $(APP) clean $v
  106. $i "Check that the release still exists"
  107. $t test -d $(APP)/_rel
  108. $t test -d $(APP)/_rel/$(APP)_release
  109. $t test -d $(APP)/_rel/$(APP)_release/bin
  110. $t test -d $(APP)/_rel/$(APP)_release/lib
  111. $t test -d $(APP)/_rel/$(APP)_release/releases
  112. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  113. $t test -f $(APP)/_rel/$(APP)_release/test_post_rel
  114. $t test "test post rel" = "`cat $(APP)/_rel/$(APP)_release/test_post_rel`"
  115. $i "Distclean the application"
  116. $t $(MAKE) -C $(APP) distclean $v
  117. $i "Check that the output directory was removed entirely"
  118. $t test ! -d $(APP)/_rel/
  119. relx-relup: build clean
  120. $i "Bootstrap a new release named $(APP)"
  121. $t mkdir $(APP)/
  122. $t cp ../erlang.mk $(APP)/
  123. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  124. $i "Set the initial application version"
  125. ifeq ($(LEGACY),1)
  126. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  127. else
  128. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  129. endif
  130. $i "Generate a test module"
  131. $t printf "%s\n"\
  132. "-module(test)." \
  133. "-export([test/0])." \
  134. "test() -> old." > $(APP)/src/test.erl
  135. $i "Build the initial release as a tarball"
  136. $t $(MAKE) -C $(APP) $v
  137. $i "Update the test module"
  138. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  139. $i "Bump the application version"
  140. ifeq ($(LEGACY),1)
  141. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  142. else
  143. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  144. endif
  145. $i "Generate a .appup for the application"
  146. $t printf "%s\n" \
  147. "{\"2\","\
  148. " [{\"1\", [{load_module, test}]}],"\
  149. " [{\"1\", [{load_module, test}]}]"\
  150. "}." > $(APP)/ebin/$(APP).appup
  151. $i "Bump the release version"
  152. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  153. $i "Build a new release with a relup as a tarball"
  154. $t $(MAKE) -C $(APP) relup $v
  155. $i "Test that both releases are available"
  156. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  157. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  158. $i "Unpack initial release"
  159. $t mkdir $(APP)/tmp
  160. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  161. $i "Start initial release and confirm it runs the old code"
  162. ifeq ($(PLATFORM),msys2)
  163. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install $v
  164. endif
  165. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) start $v
  166. $t sleep 1
  167. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  168. $i "Check that it's 1 available version"
  169. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  170. $i "Copy the relup tarball to the release directory"
  171. $t mkdir $(APP)/tmp/releases/2
  172. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  173. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  174. $i "Upgrade the release and confirm it runs the new code"
  175. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  176. $t sleep 1
  177. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = new
  178. $i "Check that it's 2 available versions"
  179. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  180. $i "Downgrade the release and confirm it runs the old code"
  181. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  182. $t sleep 1
  183. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  184. $i "Stop the release"
  185. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  186. ifeq ($(PLATFORM),msys2)
  187. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall $v
  188. endif
  189. relx-start-stop: build clean
  190. $i "Bootstrap a new release named $(APP)"
  191. $t mkdir $(APP)/
  192. $t cp ../erlang.mk $(APP)/
  193. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  194. $i "Build the release"
  195. $t $(MAKE) -C $(APP) $v
  196. $i "Start the release"
  197. ifeq ($(PLATFORM),msys2)
  198. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  199. endif
  200. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start $v
  201. $t sleep 1
  202. $i "Ping the release"
  203. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  204. $i "Stop the release"
  205. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  206. ifeq ($(PLATFORM),msys2)
  207. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  208. endif
  209. $i "Check that further pings get no replies"
  210. $t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  211. relx-tar: build clean
  212. $i "Bootstrap a new release named $(APP)"
  213. $t mkdir $(APP)/
  214. $t cp ../erlang.mk $(APP)/
  215. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  216. $i "Build the release without a tarball"
  217. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  218. $i "Check that tarball doesn't exist"
  219. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  220. $i "Build the release as a tarball"
  221. $t $(MAKE) -C $(APP) $v
  222. $i "Check that tarball exists"
  223. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  224. relx-vsn: build clean
  225. $i "Bootstrap a new release named $(APP)"
  226. $t mkdir $(APP)/
  227. $t cp ../erlang.mk $(APP)/
  228. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  229. $i "Replace the vsn"
  230. $t sed -i.bak s/"\"1\""/"{cmd, \"printf 2\"}"/ $(APP)/relx.config
  231. $i "Build the release"
  232. $t $(MAKE) -C $(APP) $v
  233. $i "Check that the correct release exists"
  234. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  235. $t test -d $(APP)/_rel/$(APP)_release/releases/2