plugin_bootstrap.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. # Bootstrap plugin.
  2. BOOTSTRAP_TARGETS = $(call list_targets,bootstrap)
  3. .PHONY: bootstrap $(BOOTSTRAP_TARGETS)
  4. bootstrap: $(BOOTSTRAP_TARGETS)
  5. bootstrap-app: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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: init
  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 "Add Relx to the list of release dependencies"
  153. $t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
  154. $i "Check that all bootstrapped files exist"
  155. $t test -f $(APP)/Makefile
  156. $t test -f $(APP)/relx.config
  157. $t test -f $(APP)/config/sys.config
  158. $t test -f $(APP)/config/vm.args
  159. ifdef LEGACY
  160. $t test -f $(APP)/src/$(APP).app.src
  161. endif
  162. $t test -f $(APP)/src/$(APP)_app.erl
  163. $t test -f $(APP)/src/$(APP)_sup.erl
  164. $i "Build the application and the release"
  165. $t $(MAKE) -C $(APP) $v
  166. $i "Check that all compiled files exist"
  167. $t test -f $(APP)/ebin/$(APP).app
  168. $t test -f $(APP)/ebin/$(APP)_app.beam
  169. $t test -f $(APP)/ebin/$(APP)_sup.beam
  170. $i "Check that the release was generated"
  171. ifeq ($(PLATFORM),msys2)
  172. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
  173. else
  174. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  175. endif
  176. bootstrap-sp: init
  177. $i "Bootstrap a new OTP application named $(APP)"
  178. $t mkdir $(APP)/
  179. $t cp ../erlang.mk $(APP)/
  180. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  181. $i "Check that all bootstrapped files exist"
  182. $t test -f $(APP)/Makefile
  183. ifdef LEGACY
  184. $t test -f $(APP)/src/$(APP).app.src
  185. endif
  186. $t test -f $(APP)/src/$(APP)_app.erl
  187. $t test -f $(APP)/src/$(APP)_sup.erl
  188. $i "Check that bootstrapped files have no tabs"
  189. ifdef LEGACY
  190. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  191. endif
  192. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  193. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  194. # Everything looks OK, but let's compile the application to make sure.
  195. $i "Build the application"
  196. $t $(MAKE) -C $(APP) $v
  197. $i "Check that all compiled files exist"
  198. $t test -f $(APP)/ebin/$(APP).app
  199. $t test -f $(APP)/ebin/$(APP)_app.beam
  200. $t test -f $(APP)/ebin/$(APP)_sup.beam
  201. $i "Check that the application was compiled correctly"
  202. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  203. ok = application:start($(APP)), \
  204. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  205. {module, $(APP)_app} = code:load_file($(APP)_app), \
  206. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  207. halt()"
  208. bootstrap-tab: init
  209. $i "Bootstrap a new OTP application named $(APP)"
  210. $t mkdir $(APP)/
  211. $t cp ../erlang.mk $(APP)/
  212. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  213. $i "Check that all bootstrapped files exist"
  214. $t test -f $(APP)/Makefile
  215. ifdef LEGACY
  216. $t test -f $(APP)/src/$(APP).app.src
  217. endif
  218. $t test -f $(APP)/src/$(APP)_app.erl
  219. $t test -f $(APP)/src/$(APP)_sup.erl
  220. $i "Check that bootstrapped files have tabs"
  221. ifdef LEGACY
  222. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  223. endif
  224. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  225. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  226. bootstrap-templates: init
  227. $i "Bootstrap a new OTP library named $(APP)"
  228. $t mkdir $(APP)/
  229. $t cp ../erlang.mk $(APP)/
  230. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  231. $i "Check that we can get the list of templates"
  232. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -gt 1
  233. $i "Generate one of each template"
  234. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  235. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
  236. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  237. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  238. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  239. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  240. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  241. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  242. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  243. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  244. # Here we disable warnings because templates contain missing behaviors.
  245. $i "Build the application"
  246. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  247. $i "Check that all compiled files exist"
  248. $t test -f $(APP)/ebin/$(APP).app
  249. $t test -f $(APP)/ebin/my_fsm.beam
  250. $t test -f $(APP)/ebin/my_statem.beam
  251. $t test -f $(APP)/ebin/my_server.beam
  252. $t test -f $(APP)/ebin/my_sup.beam
  253. $t test -f $(APP)/ebin/my_module.beam
  254. $i "Check that all the modules can be loaded"
  255. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  256. ok = application:start($(APP)), \
  257. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_statem, my_sup, my_ws]} \
  258. = application:get_key($(APP), modules), \
  259. [{module, M} = code:load_file(M) || M <- Mods], \
  260. halt()"