plugin_bootstrap.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 "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. bootstrap-sp: init
  175. $i "Bootstrap a new OTP application named $(APP)"
  176. $t mkdir $(APP)/
  177. $t cp ../erlang.mk $(APP)/
  178. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  179. $i "Check that all bootstrapped files exist"
  180. $t test -f $(APP)/Makefile
  181. ifdef LEGACY
  182. $t test -f $(APP)/src/$(APP).app.src
  183. endif
  184. $t test -f $(APP)/src/$(APP)_app.erl
  185. $t test -f $(APP)/src/$(APP)_sup.erl
  186. $i "Check that bootstrapped files have no tabs"
  187. ifdef LEGACY
  188. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  189. endif
  190. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  191. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  192. # Everything looks OK, but let's compile the application to make sure.
  193. $i "Build the application"
  194. $t $(MAKE) -C $(APP) $v
  195. $i "Check that all compiled files exist"
  196. $t test -f $(APP)/ebin/$(APP).app
  197. $t test -f $(APP)/ebin/$(APP)_app.beam
  198. $t test -f $(APP)/ebin/$(APP)_sup.beam
  199. $i "Check that the application was compiled correctly"
  200. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  201. ok = application:start($(APP)), \
  202. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  203. {module, $(APP)_app} = code:load_file($(APP)_app), \
  204. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  205. halt()"
  206. bootstrap-tab: init
  207. $i "Bootstrap a new OTP application named $(APP)"
  208. $t mkdir $(APP)/
  209. $t cp ../erlang.mk $(APP)/
  210. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  211. $i "Check that all bootstrapped files exist"
  212. $t test -f $(APP)/Makefile
  213. ifdef LEGACY
  214. $t test -f $(APP)/src/$(APP).app.src
  215. endif
  216. $t test -f $(APP)/src/$(APP)_app.erl
  217. $t test -f $(APP)/src/$(APP)_sup.erl
  218. $i "Check that bootstrapped files have tabs"
  219. ifdef LEGACY
  220. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  221. endif
  222. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  223. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  224. bootstrap-templates: init
  225. $i "Bootstrap a new OTP library named $(APP)"
  226. $t mkdir $(APP)/
  227. $t cp ../erlang.mk $(APP)/
  228. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  229. $i "Check that we can get the list of templates"
  230. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -gt 1
  231. $i "Generate one of each template"
  232. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  233. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
  234. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  235. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  236. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  237. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  238. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  239. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  240. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  241. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  242. # Here we disable warnings because templates contain missing behaviors.
  243. $i "Build the application"
  244. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  245. $i "Check that all compiled files exist"
  246. $t test -f $(APP)/ebin/$(APP).app
  247. $t test -f $(APP)/ebin/my_fsm.beam
  248. $t test -f $(APP)/ebin/my_statem.beam
  249. $t test -f $(APP)/ebin/my_server.beam
  250. $t test -f $(APP)/ebin/my_sup.beam
  251. $t test -f $(APP)/ebin/my_module.beam
  252. $i "Check that all the modules can be loaded"
  253. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  254. ok = application:start($(APP)), \
  255. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_statem, my_sup, my_ws]} \
  256. = application:get_key($(APP), modules), \
  257. [{module, M} = code:load_file(M) || M <- Mods], \
  258. halt()"