plugin_relx.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 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: 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 "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: init
  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: init
  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. ifneq ($(PLATFORM),msys2)
  120. # This test is currently disabled on Windows because we are
  121. # running into too many issues preventing the test from
  122. # executing properly and leaving the release running at the end.
  123. relx-relup: init
  124. $i "Bootstrap a new release named $(APP)"
  125. $t mkdir $(APP)/
  126. $t cp ../erlang.mk $(APP)/
  127. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  128. $i "Set the initial application version"
  129. ifeq ($(LEGACY),1)
  130. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  131. else
  132. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  133. endif
  134. $i "Generate a test module"
  135. $t printf "%s\n"\
  136. "-module(test)." \
  137. "-export([test/0])." \
  138. "test() -> old." > $(APP)/src/test.erl
  139. $i "Build the initial release as a tarball"
  140. $t $(MAKE) -C $(APP) $v
  141. $i "Update the test module"
  142. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  143. $i "Bump the application version"
  144. ifeq ($(LEGACY),1)
  145. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  146. else
  147. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  148. endif
  149. $i "Generate a .appup for the application"
  150. $t printf "%s\n" \
  151. "{\"2\","\
  152. " [{\"1\", [{load_module, test}]}],"\
  153. " [{\"1\", [{load_module, test}]}]"\
  154. "}." > $(APP)/ebin/$(APP).appup
  155. $i "Bump the release version"
  156. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  157. $i "Build a new release with a relup as a tarball"
  158. $t $(MAKE) -C $(APP) relup $v
  159. $i "Test that both releases are available"
  160. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  161. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  162. $i "Unpack initial release"
  163. $t mkdir $(APP)/tmp
  164. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  165. ifeq ($(PLATFORM),msys2)
  166. $i "Start initial release"
  167. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install
  168. else
  169. $i "Start initial release and confirm it runs the old code"
  170. endif
  171. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) start
  172. $t sleep 1
  173. ifneq ($(PLATFORM),msys2)
  174. # On Windows the script does not have the commands rpcterms and versions.
  175. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  176. $i "Check that it's 1 available version"
  177. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  178. endif
  179. $i "Copy the relup tarball to the release directory"
  180. $t mkdir $(APP)/tmp/releases/2
  181. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  182. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  183. ifeq ($(PLATFORM),msys2)
  184. $i "Upgrade the release"
  185. # On Windows the script doesn't seem to change the cwd properly
  186. # which results in the release tarball not being found.
  187. #
  188. # We use --no-permanent to avoid another bug.
  189. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) upgrade --no-permanent "2"
  190. else
  191. $i "Upgrade the release and confirm it runs the new code"
  192. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  193. endif
  194. $t sleep 1
  195. ifneq ($(PLATFORM),msys2)
  196. # On Windows the script does not have the commands rpcterms and versions.
  197. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = new
  198. $i "Check that it's 2 available versions"
  199. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  200. endif
  201. ifeq ($(PLATFORM),msys2)
  202. $i "Downgrade the release"
  203. # On Windows the script doesn't seem to change the cwd properly
  204. # which results in the release tarball not being found.
  205. #
  206. # We use --no-permanent to avoid another bug.
  207. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) downgrade --no-permanent "1"
  208. else
  209. $i "Downgrade the release and confirm it runs the old code"
  210. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  211. endif
  212. $t sleep 1
  213. ifneq ($(PLATFORM),msys2)
  214. # On Windows the script does not have the commands rpcterms and versions.
  215. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  216. endif
  217. $i "Stop the release"
  218. # On Windows this fails with the following reason:
  219. # The service test_relx_relup_release_2 is not an erlsrv controlled service.
  220. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  221. ifeq ($(PLATFORM),msys2)
  222. $t sleep 1
  223. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  224. endif
  225. endif
  226. relx-start-stop: init
  227. $i "Bootstrap a new release named $(APP)"
  228. $t mkdir $(APP)/
  229. $t cp ../erlang.mk $(APP)/
  230. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  231. $i "Build the release"
  232. $t $(MAKE) -C $(APP) $v
  233. $i "Stop the release (in case one is running from a previously aborted run)"
  234. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop || true
  235. ifeq ($(PLATFORM),msys2)
  236. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall || true
  237. endif
  238. $i "Start the release"
  239. ifeq ($(PLATFORM),msys2)
  240. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
  241. endif
  242. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start
  243. $i "Ping the release"
  244. $t $(call wait_for_success,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  245. $i "Stop the release"
  246. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  247. ifeq ($(PLATFORM),msys2)
  248. $t sleep 1
  249. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  250. endif
  251. ifneq ($(PLATFORM),msys2)
  252. # The script will not return false on Windows when the ping fails.
  253. # It sometimes also gets stuck. So we just skip the ping for now.
  254. $i "Check that further pings get no replies"
  255. $t $(call wait_for_failure,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  256. endif
  257. $i "Check that there's no erl_crash.dump file"
  258. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  259. relx-tar: init
  260. $i "Bootstrap a new release named $(APP)"
  261. $t mkdir $(APP)/
  262. $t cp ../erlang.mk $(APP)/
  263. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  264. $i "Build the release without a tarball"
  265. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  266. $i "Check that tarball doesn't exist"
  267. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  268. $i "Build the release as a tarball"
  269. $t $(MAKE) -C $(APP) $v
  270. $i "Check that tarball exists"
  271. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  272. relx-vsn: init
  273. $i "Bootstrap a new release named $(APP)"
  274. $t mkdir $(APP)/
  275. $t cp ../erlang.mk $(APP)/
  276. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  277. $i "Replace the vsn"
  278. $t sed -i.bak s/"\"1\""/"{cmd, \"printf 2\"}"/ $(APP)/relx.config
  279. $i "Build the release"
  280. $t $(MAKE) -C $(APP) $v
  281. $i "Check that the correct release exists"
  282. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  283. $t test -d $(APP)/_rel/$(APP)_release/releases/2