plugin_relx.mk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. relx-rel-with-script: init
  114. $i "Bootstrap a new release named $(APP)"
  115. $t mkdir $(APP)/
  116. $t cp ../erlang.mk $(APP)/
  117. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  118. $i "Create a relx.config.script file"
  119. $t printf "%s\n" \
  120. "{release, {App, _Ver}, Apps} = lists:keyfind(release, 1, CONFIG)," \
  121. "lists:keyreplace(release, 1, CONFIG, {release, {App, \"ONE\"}, Apps})." \
  122. > $(APP)/relx.config.script
  123. $i "Build the release"
  124. $t $(MAKE) -C $(APP) $v
  125. $i "Check that the release was built"
  126. $t test -d $(APP)/_rel
  127. $t test -d $(APP)/_rel/$(APP)_release
  128. $t test -d $(APP)/_rel/$(APP)_release/bin
  129. $t test -d $(APP)/_rel/$(APP)_release/lib
  130. $t test -d $(APP)/_rel/$(APP)_release/releases
  131. $t test -d $(APP)/_rel/$(APP)_release/releases/ONE
  132. $i "Clean the application"
  133. $t $(MAKE) -C $(APP) clean $v
  134. $i "Check that the release still exists"
  135. $t test -d $(APP)/_rel
  136. $t test -d $(APP)/_rel/$(APP)_release
  137. $t test -d $(APP)/_rel/$(APP)_release/bin
  138. $t test -d $(APP)/_rel/$(APP)_release/lib
  139. $t test -d $(APP)/_rel/$(APP)_release/releases
  140. $t test -d $(APP)/_rel/$(APP)_release/releases/ONE
  141. $i "Distclean the application"
  142. $t $(MAKE) -C $(APP) distclean $v
  143. $i "Check that the output directory was removed entirely"
  144. $t test ! -d $(APP)/_rel/
  145. define relx-rel-with-only-script-relx.config.script.erl
  146. endef
  147. relx-rel-with-script-only: init
  148. $i "Bootstrap a new release named $(APP)"
  149. $t mkdir $(APP)/
  150. $t cp ../erlang.mk $(APP)/
  151. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  152. $i "Delete relx.config and create a relx.config.script file"
  153. $t rm -f $(APP)/relx.config
  154. $t printf "%s\n" \
  155. "CONFIG = [], %% Assert that config is empty." \
  156. "[" \
  157. " {release, {$(APP)_release, \"ONE\"}, [$(APP), sasl, runtime_tools]}," \
  158. " {dev_mode, false}," \
  159. " {include_erts, true}," \
  160. " {extended_start_script, true}," \
  161. " {sys_config, \"config/sys.config\"}," \
  162. " {vm_args, \"config/vm.args\"}" \
  163. "| CONFIG]." \
  164. > $(APP)/relx.config.script
  165. $i "Build the release"
  166. $t $(MAKE) -C $(APP) $v
  167. $i "Check that the release was built"
  168. $t test -d $(APP)/_rel
  169. $t test -d $(APP)/_rel/$(APP)_release
  170. $t test -d $(APP)/_rel/$(APP)_release/bin
  171. $t test -d $(APP)/_rel/$(APP)_release/lib
  172. $t test -d $(APP)/_rel/$(APP)_release/releases
  173. $t test -d $(APP)/_rel/$(APP)_release/releases/ONE
  174. $i "Clean the application"
  175. $t $(MAKE) -C $(APP) clean $v
  176. $i "Check that the release still exists"
  177. $t test -d $(APP)/_rel
  178. $t test -d $(APP)/_rel/$(APP)_release
  179. $t test -d $(APP)/_rel/$(APP)_release/bin
  180. $t test -d $(APP)/_rel/$(APP)_release/lib
  181. $t test -d $(APP)/_rel/$(APP)_release/releases
  182. $t test -d $(APP)/_rel/$(APP)_release/releases/ONE
  183. $i "Distclean the application"
  184. $t $(MAKE) -C $(APP) distclean $v
  185. $i "Check that the output directory was removed entirely"
  186. $t test ! -d $(APP)/_rel/
  187. ifneq ($(PLATFORM),msys2)
  188. # This test is currently disabled on Windows because we are
  189. # running into too many issues preventing the test from
  190. # executing properly and leaving the release running at the end.
  191. relx-relup: init
  192. $i "Bootstrap a new release named $(APP)"
  193. $t mkdir $(APP)/
  194. $t cp ../erlang.mk $(APP)/
  195. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  196. $i "Set the initial application version"
  197. ifeq ($(LEGACY),1)
  198. $t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
  199. else
  200. $t echo "PROJECT_VERSION = 1" >> $(APP)/Makefile
  201. endif
  202. $i "Generate a test module"
  203. $t printf "%s\n"\
  204. "-module(test)." \
  205. "-export([test/0])." \
  206. "test() -> old." > $(APP)/src/test.erl
  207. $i "Build the initial release as a tarball"
  208. $t $(MAKE) -C $(APP) $v
  209. $i "Update the test module"
  210. $t sed -i.bak s/"test() -> old."/"test() -> new."/ $(APP)/src/test.erl
  211. $i "Bump the application version"
  212. ifeq ($(LEGACY),1)
  213. $t sed -i.bak s/"{vsn, \"1\"}"/"{vsn, \"2\"}"/ $(APP)/src/$(APP).app.src
  214. else
  215. $t sed -i.bak s/"PROJECT_VERSION = 1"/"PROJECT_VERSION = 2"/ $(APP)/Makefile
  216. endif
  217. $i "Generate a .appup for the application"
  218. $t printf "%s\n" \
  219. "{\"2\","\
  220. " [{\"1\", [{load_module, test}]}],"\
  221. " [{\"1\", [{load_module, test}]}]"\
  222. "}." > $(APP)/ebin/$(APP).appup
  223. $i "Bump the release version"
  224. $t sed -i.bak s/"1"/"2"/ $(APP)/relx.config
  225. $i "Build a new release with a relup as a tarball"
  226. $t $(MAKE) -C $(APP) relup $v
  227. $i "Test that both releases are available"
  228. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  229. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz
  230. $i "Unpack initial release"
  231. $t mkdir $(APP)/tmp
  232. $t tar -xzf $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz -C $(APP)/tmp
  233. ifeq ($(PLATFORM),msys2)
  234. $i "Start initial release"
  235. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) install
  236. else
  237. $i "Start initial release and confirm it runs the old code"
  238. endif
  239. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) daemon
  240. $t sleep 1
  241. ifneq ($(PLATFORM),msys2)
  242. # On Windows the script does not have the commands rpc and versions.
  243. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
  244. $i "Check that it's 1 available version"
  245. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
  246. endif
  247. $i "Copy the relup tarball to the release directory"
  248. $t mkdir $(APP)/tmp/releases/2
  249. $t cp $(APP)/_rel/$(APP)_release/$(APP)_release-2.tar.gz $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  250. $t test -f $(APP)/tmp/releases/2/$(APP)_release.tar.gz
  251. ifeq ($(PLATFORM),msys2)
  252. $i "Upgrade the release"
  253. # On Windows the script doesn't seem to change the cwd properly
  254. # which results in the release tarball not being found.
  255. #
  256. # We use --no-permanent to avoid another bug.
  257. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) upgrade --no-permanent "2"
  258. else
  259. $i "Upgrade the release and confirm it runs the new code"
  260. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) upgrade "2"
  261. endif
  262. $t sleep 1
  263. ifneq ($(PLATFORM),msys2)
  264. # On Windows the script does not have the commands rpc and versions.
  265. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = new
  266. $i "Check that it's 2 available versions"
  267. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
  268. endif
  269. ifeq ($(PLATFORM),msys2)
  270. $i "Downgrade the release"
  271. # On Windows the script doesn't seem to change the cwd properly
  272. # which results in the release tarball not being found.
  273. #
  274. # We use --no-permanent to avoid another bug.
  275. $t cd $(APP)/tmp && ./bin/$(APP)_release$(RELX_REL_EXT) downgrade --no-permanent "1"
  276. else
  277. $i "Downgrade the release and confirm it runs the old code"
  278. $t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) downgrade "1"
  279. endif
  280. $t sleep 1
  281. ifneq ($(PLATFORM),msys2)
  282. # On Windows the script does not have the commands rpc and versions.
  283. $t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
  284. endif
  285. $i "Stop the release"
  286. # On Windows this fails with the following reason:
  287. # The service test_relx_relup_release_2 is not an erlsrv controlled service.
  288. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  289. ifeq ($(PLATFORM),msys2)
  290. $t sleep 1
  291. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  292. endif
  293. endif
  294. relx-start-stop: init
  295. $i "Bootstrap a new release named $(APP)"
  296. $t mkdir $(APP)/
  297. $t cp ../erlang.mk $(APP)/
  298. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  299. $i "Build the release"
  300. $t $(MAKE) -C $(APP) $v
  301. $i "Stop the release (in case one is running from a previously aborted run)"
  302. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop || true
  303. ifeq ($(PLATFORM),msys2)
  304. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall || true
  305. endif
  306. $i "Start the release"
  307. ifeq ($(PLATFORM),msys2)
  308. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
  309. endif
  310. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) daemon
  311. $i "Ping the release"
  312. $t $(call wait_for_success,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  313. $i "Stop the release"
  314. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
  315. ifeq ($(PLATFORM),msys2)
  316. $t sleep 1
  317. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
  318. endif
  319. ifneq ($(PLATFORM),msys2)
  320. # The script will not return false on Windows when the ping fails.
  321. # It sometimes also gets stuck. So we just skip the ping for now.
  322. $i "Check that further pings get no replies"
  323. $t $(call wait_for_failure,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
  324. endif
  325. $i "Check that there's no erl_crash.dump file"
  326. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  327. relx-tar: init
  328. $i "Bootstrap a new release named $(APP)"
  329. $t mkdir $(APP)/
  330. $t cp ../erlang.mk $(APP)/
  331. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  332. $i "Build the release without a tarball"
  333. $t $(MAKE) -C $(APP) RELX_TAR=0 $v
  334. $i "Check that tarball doesn't exist"
  335. $t test ! -e $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  336. $i "Build the release as a tarball"
  337. $t $(MAKE) -C $(APP) $v
  338. $i "Check that tarball exists"
  339. $t test -f $(APP)/_rel/$(APP)_release/$(APP)_release-1.tar.gz
  340. relx-vsn-cmd: init
  341. $i "Bootstrap a new release named $(APP)"
  342. $t mkdir $(APP)/
  343. $t cp ../erlang.mk $(APP)/
  344. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  345. $i "Replace the vsn"
  346. $t sed -i.bak s/"\"1\""/"{cmd, \"printf 2\"}"/ $(APP)/relx.config
  347. $i "Build the release"
  348. $t $(MAKE) -C $(APP) $v
  349. $i "Check that the correct release exists"
  350. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  351. $t test -d $(APP)/_rel/$(APP)_release/releases/2
  352. relx-vsn-git-long: init
  353. $i "Bootstrap a new release named $(APP)"
  354. $t mkdir $(APP)/
  355. $t cp ../erlang.mk $(APP)/
  356. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  357. $i "Replace the vsn"
  358. $t sed -i.bak s/"\"1\""/"{git, long}"/ $(APP)/relx.config
  359. $i "Build the release"
  360. $t $(MAKE) -C $(APP) $v
  361. $i "Check that the correct release exists"
  362. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  363. $t test -d $(APP)/_rel/$(APP)_release/releases/$(shell git rev-parse HEAD)
  364. relx-vsn-git-short: init
  365. $i "Bootstrap a new release named $(APP)"
  366. $t mkdir $(APP)/
  367. $t cp ../erlang.mk $(APP)/
  368. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  369. $i "Replace the vsn"
  370. $t sed -i.bak s/"\"1\""/"{git, short}"/ $(APP)/relx.config
  371. $i "Build the release"
  372. $t $(MAKE) -C $(APP) $v
  373. $i "Check that the correct release exists"
  374. $t ! test -d $(APP)/_rel/$(APP)_release/releases/1
  375. $t test -d $(APP)/_rel/$(APP)_release/releases/$(shell git rev-parse --short HEAD)