plugin_relx.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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: init
  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 the release was built"
  21. $t test -d $(APP)/_rel
  22. $t test -d $(APP)/_rel/$(APP)_release
  23. $t test -d $(APP)/_rel/$(APP)_release/bin
  24. $t test -d $(APP)/_rel/$(APP)_release/lib
  25. $t test -d $(APP)/_rel/$(APP)_release/releases
  26. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  27. $i "Clean the application"
  28. $t $(MAKE) -C $(APP) clean $v
  29. $i "Check that the release still exists"
  30. $t test -d $(APP)/_rel
  31. $t test -d $(APP)/_rel/$(APP)_release
  32. $t test -d $(APP)/_rel/$(APP)_release/bin
  33. $t test -d $(APP)/_rel/$(APP)_release/lib
  34. $t test -d $(APP)/_rel/$(APP)_release/releases
  35. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  36. $i "Distclean the application"
  37. $t $(MAKE) -C $(APP) distclean $v
  38. $i "Check that the output directory was removed entirely"
  39. $t test ! -d $(APP)/_rel/
  40. relx-apps-with-deps: init
  41. $i "Bootstrap a new release as a multi application repository"
  42. $t mkdir $(APP)/
  43. $t cp ../erlang.mk $(APP)/
  44. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib bootstrap-rel $v
  45. $i "Create a new application my_app"
  46. $t $(MAKE) -C $(APP) new-app in=my_app $v
  47. $i "Include my_app in the release"
  48. $t perl -pi.bak -e 's/$(APP),/$(APP), my_app,/' $(APP)/relx.config
  49. $i "Add Cowlib to the list of dependencies for my_app"
  50. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/apps/my_app/Makefile
  51. ifdef LEGACY
  52. $i "Add Cowlib to the applications key in the my_app.app.src file"
  53. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowlib,\n"}' $(APP)/apps/my_app/src/my_app.app.src
  54. endif
  55. $i "Build the application"
  56. $t $(MAKE) -C $(APP) $v
  57. $i "Check that all compiled files exist"
  58. $t test -f $(APP)/apps/my_app/my_app.d
  59. $t test -f $(APP)/apps/my_app/ebin/my_app.app
  60. $t test -f $(APP)/apps/my_app/ebin/my_app_app.beam
  61. $t test -f $(APP)/apps/my_app/ebin/my_app_sup.beam
  62. $t test -f $(APP)/deps/cowlib/ebin/cowlib.app
  63. $i "Check that Cowlib was included in the release"
  64. $t test -d $(APP)/_rel/test_relx_apps_with_deps_release/lib/cowlib-1.0.2
  65. relx-bare-rel: init
  66. $i "Bootstrap a new release named $(APP)"
  67. $t mkdir $(APP)/
  68. $t cp ../erlang.mk $(APP)/
  69. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  70. $i "Build the release"
  71. $t $(MAKE) -C $(APP) rel $v
  72. $i "Check that the release was built"
  73. $t test -d $(APP)/_rel
  74. $t test -d $(APP)/_rel/$(APP)_release
  75. $t test -d $(APP)/_rel/$(APP)_release/bin
  76. $t test -d $(APP)/_rel/$(APP)_release/lib
  77. $t test -d $(APP)/_rel/$(APP)_release/releases
  78. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  79. relx-post-rel: init
  80. $i "Bootstrap a new release named $(APP)"
  81. $t mkdir $(APP)/
  82. $t cp ../erlang.mk $(APP)/
  83. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  84. $i "Add relx-post-rel target to Makefile"
  85. $t echo "relx-post-rel::" >> $(APP)/Makefile
  86. $t echo " echo test post rel > _rel/$(APP)_release/test_post_rel" >> $(APP)/Makefile
  87. $i "Build the release"
  88. $t $(MAKE) -C $(APP) $v
  89. $i "Check that the release was built"
  90. $t test -d $(APP)/_rel
  91. $t test -d $(APP)/_rel/$(APP)_release
  92. $t test -d $(APP)/_rel/$(APP)_release/bin
  93. $t test -d $(APP)/_rel/$(APP)_release/lib
  94. $t test -d $(APP)/_rel/$(APP)_release/releases
  95. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  96. $t test -f $(APP)/_rel/$(APP)_release/test_post_rel
  97. $t test "test post rel" = "`cat $(APP)/_rel/$(APP)_release/test_post_rel`"
  98. $i "Clean the application"
  99. $t $(MAKE) -C $(APP) clean $v
  100. $i "Check that the release still exists"
  101. $t test -d $(APP)/_rel
  102. $t test -d $(APP)/_rel/$(APP)_release
  103. $t test -d $(APP)/_rel/$(APP)_release/bin
  104. $t test -d $(APP)/_rel/$(APP)_release/lib
  105. $t test -d $(APP)/_rel/$(APP)_release/releases
  106. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  107. $t test -f $(APP)/_rel/$(APP)_release/test_post_rel
  108. $t test "test post rel" = "`cat $(APP)/_rel/$(APP)_release/test_post_rel`"
  109. $i "Distclean the application"
  110. $t $(MAKE) -C $(APP) distclean $v
  111. $i "Check that the output directory was removed entirely"
  112. $t test ! -d $(APP)/_rel/
  113. ifneq ($(PLATFORM),msys2)
  114. # This test is currently disabled on Windows because we are
  115. # running into too many issues preventing the test from
  116. # executing properly and leaving the release running at the end.
  117. relx-relup: init
  118. $i "Bootstrap a new release named $(APP)"
  119. $t mkdir $(APP)/
  120. $t cp ../erlang.mk $(APP)/
  121. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  122. $i "Set the initial application version"
  123. ifeq ($(LEGACY),1)
  124. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  125. else
  126. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  127. endif
  128. $i "Generate a test module"
  129. $t printf "%s\n"\
  130. "-module(test)." \
  131. "-export([test/0])." \
  132. "test() -> old." > $(APP)/src/test.erl
  133. $i "Build the initial release as a tarball"
  134. $t $(MAKE) -C $(APP) $v
  135. $i "Update the test module"
  136. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  137. $i "Bump the application version"
  138. ifeq ($(LEGACY),1)
  139. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  140. else
  141. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  142. endif
  143. $i "Generate a .appup for the application"
  144. $t printf "%s\n" \
  145. "{\"2\","\
  146. " [{\"1\", [{load_module, test}]}],"\
  147. " [{\"1\", [{load_module, test}]}]"\
  148. "}." > $(APP)/ebin/$(APP).appup
  149. $i "Bump the release version"
  150. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  151. $i "Build a new release with a relup as a tarball"
  152. $t $(MAKE) -C $(APP) relup $v
  153. $i "Test that both releases are available"
  154. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  155. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  156. $i "Unpack initial release"
  157. $t mkdir $(APP)/tmp
  158. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  159. ifeq ($(PLATFORM),msys2)
  160. $i "Start initial release"
  161. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install
  162. else
  163. $i "Start initial release and confirm it runs the old code"
  164. endif
  165. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) daemon
  166. $t sleep 1
  167. ifneq ($(PLATFORM),msys2)
  168. # On Windows the script does not have the commands rpc and versions.
  169. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
  170. $i "Check that it's 1 available version"
  171. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  172. endif
  173. $i "Copy the relup tarball to the release directory"
  174. $t mkdir $(APP)/tmp/releases/2
  175. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  176. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  177. ifeq ($(PLATFORM),msys2)
  178. $i "Upgrade the release"
  179. # On Windows the script doesn't seem to change the cwd properly
  180. # which results in the release tarball not being found.
  181. #
  182. # We use --no-permanent to avoid another bug.
  183. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) upgrade --no-permanent "2"
  184. else
  185. $i "Upgrade the release and confirm it runs the new code"
  186. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  187. endif
  188. $t sleep 1
  189. ifneq ($(PLATFORM),msys2)
  190. # On Windows the script does not have the commands rpc and versions.
  191. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = new
  192. $i "Check that it's 2 available versions"
  193. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  194. endif
  195. ifeq ($(PLATFORM),msys2)
  196. $i "Downgrade the release"
  197. # On Windows the script doesn't seem to change the cwd properly
  198. # which results in the release tarball not being found.
  199. #
  200. # We use --no-permanent to avoid another bug.
  201. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) downgrade --no-permanent "1"
  202. else
  203. $i "Downgrade the release and confirm it runs the old code"
  204. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  205. endif
  206. $t sleep 1
  207. ifneq ($(PLATFORM),msys2)
  208. # On Windows the script does not have the commands rpc and versions.
  209. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
  210. endif
  211. $i "Stop the release"
  212. # On Windows this fails with the following reason:
  213. # The service test_relx_relup_release_2 is not an erlsrv controlled service.
  214. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  215. ifeq ($(PLATFORM),msys2)
  216. $t sleep 1
  217. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  218. endif
  219. endif
  220. relx-start-stop: init
  221. $i "Bootstrap a new release named $(APP)"
  222. $t mkdir $(APP)/
  223. $t cp ../erlang.mk $(APP)/
  224. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  225. $i "Build the release"
  226. $t $(MAKE) -C $(APP) $v
  227. $i "Stop the release (in case one is running from a previously aborted run)"
  228. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop || true
  229. ifeq ($(PLATFORM),msys2)
  230. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall || true
  231. endif
  232. $i "Start the release"
  233. ifeq ($(PLATFORM),msys2)
  234. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
  235. endif
  236. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) daemon
  237. $i "Ping the release"
  238. $t $(call wait_for_success,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  239. $i "Stop the release"
  240. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  241. ifeq ($(PLATFORM),msys2)
  242. $t sleep 1
  243. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  244. endif
  245. ifneq ($(PLATFORM),msys2)
  246. # The script will not return false on Windows when the ping fails.
  247. # It sometimes also gets stuck. So we just skip the ping for now.
  248. $i "Check that further pings get no replies"
  249. $t $(call wait_for_failure,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  250. endif
  251. $i "Check that there's no erl_crash.dump file"
  252. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  253. relx-tar: init
  254. $i "Bootstrap a new release named $(APP)"
  255. $t mkdir $(APP)/
  256. $t cp ../erlang.mk $(APP)/
  257. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  258. $i "Build the release without a tarball"
  259. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  260. $i "Check that tarball doesn't exist"
  261. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  262. $i "Build the release as a tarball"
  263. $t $(MAKE) -C $(APP) $v
  264. $i "Check that tarball exists"
  265. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  266. relx-vsn: init
  267. $i "Bootstrap a new release named $(APP)"
  268. $t mkdir $(APP)/
  269. $t cp ../erlang.mk $(APP)/
  270. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  271. $i "Replace the vsn"
  272. $t sed -i.bak s/"\"1\""/"{cmd, \"printf 2\"}"/ $(APP)/relx.config
  273. $i "Build the release"
  274. $t $(MAKE) -C $(APP) $v
  275. $i "Check that the correct release exists"
  276. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  277. $t test -d $(APP)/_rel/$(APP)_release/releases/2