plugin_relx.mk 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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-bare-rel: build clean
  43. $i "Bootstrap a new release named $(APP)"
  44. $t mkdir $(APP)/
  45. $t cp ../erlang.mk $(APP)/
  46. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  47. $i "Build the release"
  48. $t $(MAKE) -C $(APP) rel $v
  49. $i "Check that relx was downloaded"
  50. $t test -f $(APP)/.erlang.mk/relx
  51. $i "Check that the release was built"
  52. $t test -d $(APP)/_rel
  53. $t test -d $(APP)/_rel/$(APP)_release
  54. $t test -d $(APP)/_rel/$(APP)_release/bin
  55. $t test -d $(APP)/_rel/$(APP)_release/lib
  56. $t test -d $(APP)/_rel/$(APP)_release/releases
  57. $t test -d $(APP)/_rel/$(APP)_release/releases/1
  58. relx-relup: build clean
  59. $i "Bootstrap a new release named $(APP)"
  60. $t mkdir $(APP)/
  61. $t cp ../erlang.mk $(APP)/
  62. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  63. $i "Set the initial application version"
  64. ifeq ($(LEGACY),1)
  65. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  66. else
  67. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  68. endif
  69. $i "Generate a test module"
  70. $t printf "%s\n"\
  71. "-module(test)." \
  72. "-export([test/0])." \
  73. "test() -> old." > $(APP)/src/test.erl
  74. $i "Build the initial release as a tarball"
  75. $t $(MAKE) -C $(APP) $v
  76. $i "Update the test module"
  77. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  78. $i "Bump the application version"
  79. ifeq ($(LEGACY),1)
  80. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  81. else
  82. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  83. endif
  84. $i "Generate a .appup for the application"
  85. $t printf "%s\n" \
  86. "{\"2\","\
  87. " [{\"1\", [{load_module, test}]}],"\
  88. " [{\"1\", [{load_module, test}]}]"\
  89. "}." > $(APP)/ebin/$(APP).appup
  90. $i "Bump the release version"
  91. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  92. $i "Build a new release with a relup as a tarball"
  93. $t $(MAKE) -C $(APP) relup $v
  94. $i "Test that both releases are available"
  95. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  96. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  97. $i "Unpack initial release"
  98. $t mkdir $(APP)/tmp
  99. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  100. $i "Start initial release and confirm it runs the old code"
  101. ifeq ($(PLATFORM),msys2)
  102. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install $v
  103. endif
  104. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) start $v
  105. $t sleep 1
  106. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  107. $i "Check that it's 1 available version"
  108. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  109. $i "Copy the relup tarball to the release directory"
  110. $t mkdir $(APP)/tmp/releases/2
  111. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  112. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  113. $i "Upgrade the release and confirm it runs the new code"
  114. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  115. $t sleep 1
  116. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = new
  117. $i "Check that it's 2 available versions"
  118. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  119. $i "Downgrade the release and confirm it runs the old code"
  120. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  121. $t sleep 1
  122. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
  123. $i "Stop the release"
  124. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  125. ifeq ($(PLATFORM),msys2)
  126. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall $v
  127. endif
  128. relx-start-stop: build clean
  129. $i "Bootstrap a new release named $(APP)"
  130. $t mkdir $(APP)/
  131. $t cp ../erlang.mk $(APP)/
  132. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  133. $i "Build the release"
  134. $t $(MAKE) -C $(APP) $v
  135. $i "Start the release"
  136. ifeq ($(PLATFORM),msys2)
  137. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  138. endif
  139. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start $v
  140. $t sleep 1
  141. $i "Ping the release"
  142. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  143. $i "Stop the release"
  144. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop $v
  145. ifeq ($(PLATFORM),msys2)
  146. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  147. endif
  148. $i "Check that further pings get no replies"
  149. $t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping $v
  150. relx-tar: build clean
  151. $i "Bootstrap a new release named $(APP)"
  152. $t mkdir $(APP)/
  153. $t cp ../erlang.mk $(APP)/
  154. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  155. $i "Build the release without a tarball"
  156. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  157. $i "Check that tarball doesn't exist"
  158. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  159. $i "Build the release as a tarball"
  160. $t $(MAKE) -C $(APP) $v
  161. $i "Check that tarball exists"
  162. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  163. relx-vsn: build clean
  164. $i "Bootstrap a new release named $(APP)"
  165. $t mkdir $(APP)/
  166. $t cp ../erlang.mk $(APP)/
  167. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  168. $i "Replace the vsn"
  169. $t sed -i.bak s/"\"1\""/"{cmd, \"echo -n 2\"}"/ $(APP)/relx.config
  170. $i "Build the release"
  171. $t $(MAKE) -C $(APP) $v
  172. $i "Check that the correct release exists"
  173. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  174. $t test -d $(APP)/_rel/$(APP)_release/releases/2