plugin_bootstrap.mk 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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-rel: build clean
  98. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  99. $t mkdir $(APP)/
  100. $t cp ../erlang.mk $(APP)/
  101. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  102. $i "Check that all bootstrapped files exist"
  103. $t test -f $(APP)/Makefile
  104. $t test -f $(APP)/relx.config
  105. $t test -f $(APP)/rel/sys.config
  106. $t test -f $(APP)/rel/vm.args
  107. ifdef LEGACY
  108. $t test -f $(APP)/src/$(APP).app.src
  109. endif
  110. $t test -f $(APP)/src/$(APP)_app.erl
  111. $t test -f $(APP)/src/$(APP)_sup.erl
  112. $i "Build the application and the release"
  113. $t $(MAKE) -C $(APP) $v
  114. $i "Check that all compiled files exist"
  115. $t test -f $(APP)/ebin/$(APP).app
  116. $t test -f $(APP)/ebin/$(APP)_app.beam
  117. $t test -f $(APP)/ebin/$(APP)_sup.beam
  118. $i "Check that the release was generated"
  119. ifeq ($(PLATFORM),msys2)
  120. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
  121. else
  122. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  123. endif
  124. $i "Check that the release can be started and stopped"
  125. ifeq ($(PLATFORM),msys2)
  126. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  127. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
  128. $t sleep 1
  129. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
  130. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  131. else
  132. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  133. $t sleep 1
  134. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  135. endif
  136. $i "Check that there's no erl_crash.dump file"
  137. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  138. bootstrap-sp: build clean
  139. $i "Bootstrap a new OTP application named $(APP)"
  140. $t mkdir $(APP)/
  141. $t cp ../erlang.mk $(APP)/
  142. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  143. $i "Check that all bootstrapped files exist"
  144. $t test -f $(APP)/Makefile
  145. ifdef LEGACY
  146. $t test -f $(APP)/src/$(APP).app.src
  147. endif
  148. $t test -f $(APP)/src/$(APP)_app.erl
  149. $t test -f $(APP)/src/$(APP)_sup.erl
  150. $i "Check that bootstrapped files have no tabs"
  151. ifdef LEGACY
  152. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  153. endif
  154. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  155. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  156. # Everything looks OK, but let's compile the application to make sure.
  157. $i "Build the application"
  158. $t $(MAKE) -C $(APP) $v
  159. $i "Check that all compiled files exist"
  160. $t test -f $(APP)/ebin/$(APP).app
  161. $t test -f $(APP)/ebin/$(APP)_app.beam
  162. $t test -f $(APP)/ebin/$(APP)_sup.beam
  163. $i "Check that the application was compiled correctly"
  164. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  165. ok = application:start($(APP)), \
  166. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  167. {module, $(APP)_app} = code:load_file($(APP)_app), \
  168. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  169. halt()"
  170. bootstrap-tab: build clean
  171. $i "Bootstrap a new OTP application named $(APP)"
  172. $t mkdir $(APP)/
  173. $t cp ../erlang.mk $(APP)/
  174. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  175. $i "Check that all bootstrapped files exist"
  176. $t test -f $(APP)/Makefile
  177. ifdef LEGACY
  178. $t test -f $(APP)/src/$(APP).app.src
  179. endif
  180. $t test -f $(APP)/src/$(APP)_app.erl
  181. $t test -f $(APP)/src/$(APP)_sup.erl
  182. $i "Check that bootstrapped files have tabs"
  183. ifdef LEGACY
  184. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  185. endif
  186. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  187. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  188. bootstrap-templates: build clean
  189. $i "Bootstrap a new OTP library named $(APP)"
  190. $t mkdir $(APP)/
  191. $t cp ../erlang.mk $(APP)/
  192. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  193. $i "Check that we can get the list of templates"
  194. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -gt 1
  195. $i "Generate one of each template"
  196. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  197. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
  198. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  199. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  200. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  201. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  202. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  203. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  204. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  205. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  206. # Here we disable warnings because templates contain missing behaviors.
  207. $i "Build the application"
  208. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  209. $i "Check that all compiled files exist"
  210. $t test -f $(APP)/ebin/$(APP).app
  211. $t test -f $(APP)/ebin/my_fsm.beam
  212. $t test -f $(APP)/ebin/my_statem.beam
  213. $t test -f $(APP)/ebin/my_server.beam
  214. $t test -f $(APP)/ebin/my_sup.beam
  215. $t test -f $(APP)/ebin/my_module.beam
  216. $i "Check that all the modules can be loaded"
  217. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  218. ok = application:start($(APP)), \
  219. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_statem, my_sup, my_ws]} \
  220. = application:get_key($(APP), modules), \
  221. [{module, M} = code:load_file(M) || M <- Mods], \
  222. halt()"