plugin_bootstrap.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. # Bootstrap plugin.
  2. BOOTSTRAP_TARGETS = $(call list_targets,bootstrap)
  3. .PHONY: bootstrap $(BOOTSTRAP_TARGETS)
  4. bootstrap: $(BOOTSTRAP_TARGETS)
  5. bootstrap-app: build clean
  6. $i "Bootstrap a new OTP application named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  10. $i "Check that all bootstrapped files exist"
  11. $t test -f $(APP)/Makefile
  12. ifdef LEGACY
  13. $t test -f $(APP)/src/$(APP).app.src
  14. endif
  15. $t test -f $(APP)/src/$(APP)_app.erl
  16. $t test -f $(APP)/src/$(APP)_sup.erl
  17. $i "Build the application"
  18. $t $(MAKE) -C $(APP) $v
  19. $i "Check that all compiled files exist"
  20. $t test -f $(APP)/ebin/$(APP).app
  21. $t test -f $(APP)/ebin/$(APP)_app.beam
  22. $t test -f $(APP)/ebin/$(APP)_sup.beam
  23. $i "Check that the application was compiled correctly"
  24. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  25. ok = application:start($(APP)), \
  26. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  27. {module, $(APP)_app} = code:load_file($(APP)_app), \
  28. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  29. halt()"
  30. bootstrap-invalid-app-name-dash: build clean
  31. $i "Try to bootstrap a new OTP application named test_$@"
  32. $t mkdir test_$@/
  33. $t cp ../erlang.mk test_$@/
  34. $t ! $(MAKE) -C test_$@ -f erlang.mk bootstrap $v
  35. bootstrap-invalid-app-name-uppercase: build clean
  36. $i "Try to bootstrap a new OTP application named $(APP)_HELLO"
  37. $t mkdir $(APP)_HELLO/
  38. $t cp ../erlang.mk $(APP)_HELLO/
  39. $t ! $(MAKE) -C $(APP)_HELLO -f erlang.mk bootstrap $v
  40. bootstrap-invalid-lib-name-dash: build clean
  41. $i "Try to bootstrap a new OTP library named test_$@"
  42. $t mkdir test_$@/
  43. $t cp ../erlang.mk test_$@/
  44. $t ! $(MAKE) -C test_$@ -f erlang.mk bootstrap-lib $v
  45. bootstrap-invalid-lib-name-uppercase: build clean
  46. $i "Try to bootstrap a new OTP library named $(APP)_HELLO"
  47. $t mkdir $(APP)_HELLO/
  48. $t cp ../erlang.mk $(APP)_HELLO/
  49. $t ! $(MAKE) -C $(APP)_HELLO -f erlang.mk bootstrap-lib $v
  50. bootstrap-invalid-new-app-name-dash: build clean
  51. $i "Bootstrap a new OTP library named $(APP)"
  52. $t mkdir $(APP)/
  53. $t cp ../erlang.mk $(APP)/
  54. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  55. $i "Try to create a new application my-app"
  56. $t ! $(MAKE) -C $(APP) new-app in=my-app $v
  57. bootstrap-invalid-new-app-name-uppercase: build clean
  58. $i "Bootstrap a new OTP library named $(APP)"
  59. $t mkdir $(APP)/
  60. $t cp ../erlang.mk $(APP)/
  61. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  62. $i "Try to create a new application My_app"
  63. $t ! $(MAKE) -C $(APP) new-app in=My_app $v
  64. bootstrap-invalid-new-lib-name-dash: build clean
  65. $i "Bootstrap a new OTP library named $(APP)"
  66. $t mkdir $(APP)/
  67. $t cp ../erlang.mk $(APP)/
  68. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  69. $i "Try to create a new library my-lib"
  70. $t ! $(MAKE) -C $(APP) new-lib in=my-lib $v
  71. bootstrap-invalid-new-lib-name-uppercase: build clean
  72. $i "Bootstrap a new OTP library named $(APP)"
  73. $t mkdir $(APP)/
  74. $t cp ../erlang.mk $(APP)/
  75. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  76. $i "Try to create a new library My_lib"
  77. $t ! $(MAKE) -C $(APP) new-lib in=My_lib $v
  78. bootstrap-lib: build clean
  79. $i "Bootstrap a new OTP library named $(APP)"
  80. $t mkdir $(APP)/
  81. $t cp ../erlang.mk $(APP)/
  82. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  83. $i "Check that all bootstrapped files exist"
  84. $t test -f $(APP)/Makefile
  85. ifdef LEGACY
  86. $t test -f $(APP)/src/$(APP).app.src
  87. endif
  88. $i "Build the application"
  89. $t $(MAKE) -C $(APP) $v
  90. $i "Check that all compiled files exist"
  91. $t test -f $(APP)/ebin/$(APP).app
  92. $i "Check that the application was compiled correctly"
  93. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  94. ok = application:start($(APP)), \
  95. {ok, []} = application:get_key($(APP), modules), \
  96. halt()"
  97. bootstrap-new-app-sp: build clean
  98. $i "Bootstrap a new OTP application named $(APP)"
  99. $t mkdir $(APP)/
  100. $t cp ../erlang.mk $(APP)/
  101. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  102. $i "Create a new application my_app"
  103. $t $(MAKE) -C $(APP) new-app in=my_app $v
  104. $i "Check that SP is included in the new Makefile"
  105. $t grep -q "SP = 2" $(APP)/apps/my_app/Makefile
  106. $i "Check that bootstrapped files have no tabs"
  107. ifdef LEGACY
  108. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app.app.src`"
  109. endif
  110. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app_app.erl`"
  111. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app_sup.erl`"
  112. # Everything looks OK, but let's compile the application to make sure.
  113. $i "Build the application"
  114. $t $(MAKE) -C $(APP) $v
  115. $i "Check that all compiled files exist"
  116. $t test -f $(APP)/ebin/$(APP).app
  117. $t test -f $(APP)/ebin/$(APP)_app.beam
  118. $t test -f $(APP)/ebin/$(APP)_sup.beam
  119. $t test -f $(APP)/apps/my_app/ebin/my_app.app
  120. $t test -f $(APP)/apps/my_app/ebin/my_app_app.beam
  121. $t test -f $(APP)/apps/my_app/ebin/my_app_sup.beam
  122. bootstrap-new-app-sp-override: build clean
  123. $i "Bootstrap a new OTP application named $(APP)"
  124. $t mkdir $(APP)/
  125. $t cp ../erlang.mk $(APP)/
  126. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  127. $i "Create a new application my_app"
  128. $t $(MAKE) -C $(APP) new-app in=my_app SP=8 $v
  129. $i "Check that the SP we provided is included in the new Makefile"
  130. $t grep -q "SP = 8" $(APP)/apps/my_app/Makefile
  131. $i "Check that bootstrapped files have no tabs"
  132. ifdef LEGACY
  133. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app.app.src`"
  134. endif
  135. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app_app.erl`"
  136. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/apps/my_app/src/my_app_sup.erl`"
  137. # Everything looks OK, but let's compile the application to make sure.
  138. $i "Build the application"
  139. $t $(MAKE) -C $(APP) $v
  140. $i "Check that all compiled files exist"
  141. $t test -f $(APP)/ebin/$(APP).app
  142. $t test -f $(APP)/ebin/$(APP)_app.beam
  143. $t test -f $(APP)/ebin/$(APP)_sup.beam
  144. $t test -f $(APP)/apps/my_app/ebin/my_app.app
  145. $t test -f $(APP)/apps/my_app/ebin/my_app_app.beam
  146. $t test -f $(APP)/apps/my_app/ebin/my_app_sup.beam
  147. bootstrap-rel: build clean
  148. $i "Bootstrap a new release-enabled OTP application 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 "Check that all bootstrapped files exist"
  153. $t test -f $(APP)/Makefile
  154. $t test -f $(APP)/relx.config
  155. $t test -f $(APP)/config/sys.config
  156. $t test -f $(APP)/config/vm.args
  157. ifdef LEGACY
  158. $t test -f $(APP)/src/$(APP).app.src
  159. endif
  160. $t test -f $(APP)/src/$(APP)_app.erl
  161. $t test -f $(APP)/src/$(APP)_sup.erl
  162. $i "Build the application and the release"
  163. $t $(MAKE) -C $(APP) $v
  164. $i "Check that all compiled files exist"
  165. $t test -f $(APP)/ebin/$(APP).app
  166. $t test -f $(APP)/ebin/$(APP)_app.beam
  167. $t test -f $(APP)/ebin/$(APP)_sup.beam
  168. $i "Check that the release was generated"
  169. ifeq ($(PLATFORM),msys2)
  170. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
  171. else
  172. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  173. endif
  174. $i "Check that the release can be started and stopped"
  175. ifeq ($(PLATFORM),msys2)
  176. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  177. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
  178. $t sleep 1
  179. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
  180. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  181. else
  182. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  183. $t sleep 1
  184. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  185. endif
  186. $i "Check that there's no erl_crash.dump file"
  187. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  188. bootstrap-sp: build clean
  189. $i "Bootstrap a new OTP application named $(APP)"
  190. $t mkdir $(APP)/
  191. $t cp ../erlang.mk $(APP)/
  192. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  193. $i "Check that all bootstrapped files exist"
  194. $t test -f $(APP)/Makefile
  195. ifdef LEGACY
  196. $t test -f $(APP)/src/$(APP).app.src
  197. endif
  198. $t test -f $(APP)/src/$(APP)_app.erl
  199. $t test -f $(APP)/src/$(APP)_sup.erl
  200. $i "Check that bootstrapped files have no tabs"
  201. ifdef LEGACY
  202. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  203. endif
  204. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  205. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  206. # Everything looks OK, but let's compile the application to make sure.
  207. $i "Build the application"
  208. $t $(MAKE) -C $(APP) $v
  209. $i "Check that all compiled files exist"
  210. $t test -f $(APP)/ebin/$(APP).app
  211. $t test -f $(APP)/ebin/$(APP)_app.beam
  212. $t test -f $(APP)/ebin/$(APP)_sup.beam
  213. $i "Check that the application was compiled correctly"
  214. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  215. ok = application:start($(APP)), \
  216. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  217. {module, $(APP)_app} = code:load_file($(APP)_app), \
  218. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  219. halt()"
  220. bootstrap-tab: build clean
  221. $i "Bootstrap a new OTP application named $(APP)"
  222. $t mkdir $(APP)/
  223. $t cp ../erlang.mk $(APP)/
  224. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  225. $i "Check that all bootstrapped files exist"
  226. $t test -f $(APP)/Makefile
  227. ifdef LEGACY
  228. $t test -f $(APP)/src/$(APP).app.src
  229. endif
  230. $t test -f $(APP)/src/$(APP)_app.erl
  231. $t test -f $(APP)/src/$(APP)_sup.erl
  232. $i "Check that bootstrapped files have tabs"
  233. ifdef LEGACY
  234. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  235. endif
  236. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  237. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  238. bootstrap-templates: build clean
  239. $i "Bootstrap a new OTP library named $(APP)"
  240. $t mkdir $(APP)/
  241. $t cp ../erlang.mk $(APP)/
  242. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  243. $i "Check that we can get the list of templates"
  244. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -gt 1
  245. $i "Generate one of each template"
  246. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  247. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
  248. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  249. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  250. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  251. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  252. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  253. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  254. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  255. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  256. # Here we disable warnings because templates contain missing behaviors.
  257. $i "Build the application"
  258. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  259. $i "Check that all compiled files exist"
  260. $t test -f $(APP)/ebin/$(APP).app
  261. $t test -f $(APP)/ebin/my_fsm.beam
  262. $t test -f $(APP)/ebin/my_statem.beam
  263. $t test -f $(APP)/ebin/my_server.beam
  264. $t test -f $(APP)/ebin/my_sup.beam
  265. $t test -f $(APP)/ebin/my_module.beam
  266. $i "Check that all the modules can be loaded"
  267. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  268. ok = application:start($(APP)), \
  269. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_statem, my_sup, my_ws]} \
  270. = application:get_key($(APP), modules), \
  271. [{module, M} = code:load_file(M) || M <- Mods], \
  272. halt()"