plugin_relx.mk 15 KB

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