plugin_relx.mk 12 KB

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