plugin_bootstrap.mk 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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: 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-lib-name: build clean
  36. $i "Try to bootstrap a new OTP library named test_$@"
  37. $t mkdir test_$@/
  38. $t cp ../erlang.mk test_$@/
  39. $t ! $(MAKE) -C test_$@ -f erlang.mk bootstrap-lib $v
  40. bootstrap-invalid-new-app-name: build clean
  41. $i "Bootstrap a new OTP library named $(APP)"
  42. $t mkdir $(APP)/
  43. $t cp ../erlang.mk $(APP)/
  44. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  45. $i "Try to create a new application my-app"
  46. $t ! $(MAKE) -C $(APP) new-app in=my-app $v
  47. bootstrap-invalid-new-lib-name: build clean
  48. $i "Bootstrap a new OTP library named $(APP)"
  49. $t mkdir $(APP)/
  50. $t cp ../erlang.mk $(APP)/
  51. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  52. $i "Try to create a new library my-lib"
  53. $t ! $(MAKE) -C $(APP) new-lib in=my-lib $v
  54. bootstrap-lib: build clean
  55. $i "Bootstrap a new OTP library named $(APP)"
  56. $t mkdir $(APP)/
  57. $t cp ../erlang.mk $(APP)/
  58. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  59. $i "Check that all bootstrapped files exist"
  60. $t test -f $(APP)/Makefile
  61. ifdef LEGACY
  62. $t test -f $(APP)/src/$(APP).app.src
  63. endif
  64. $i "Build the application"
  65. $t $(MAKE) -C $(APP) $v
  66. $i "Check that all compiled files exist"
  67. $t test -f $(APP)/ebin/$(APP).app
  68. $i "Check that the application was compiled correctly"
  69. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  70. ok = application:start($(APP)), \
  71. {ok, []} = application:get_key($(APP), modules), \
  72. halt()"
  73. bootstrap-rel: build clean
  74. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  75. $t mkdir $(APP)/
  76. $t cp ../erlang.mk $(APP)/
  77. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  78. $i "Check that all bootstrapped files exist"
  79. $t test -f $(APP)/Makefile
  80. $t test -f $(APP)/relx.config
  81. $t test -f $(APP)/rel/sys.config
  82. $t test -f $(APP)/rel/vm.args
  83. ifdef LEGACY
  84. $t test -f $(APP)/src/$(APP).app.src
  85. endif
  86. $t test -f $(APP)/src/$(APP)_app.erl
  87. $t test -f $(APP)/src/$(APP)_sup.erl
  88. $i "Build the application and the release"
  89. $t $(MAKE) -C $(APP) $v
  90. $i "Check that all compiled files exist"
  91. $t test -f $(APP)/ebin/$(APP).app
  92. $t test -f $(APP)/ebin/$(APP)_app.beam
  93. $t test -f $(APP)/ebin/$(APP)_sup.beam
  94. $i "Check that the release was generated"
  95. ifeq ($(PLATFORM),msys2)
  96. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
  97. else
  98. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  99. endif
  100. $i "Check that the release can be started and stopped"
  101. ifeq ($(PLATFORM),msys2)
  102. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  103. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
  104. $t sleep 1
  105. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
  106. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  107. else
  108. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  109. $t sleep 1
  110. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  111. endif
  112. $i "Check that there's no erl_crash.dump file"
  113. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  114. bootstrap-sp: build clean
  115. $i "Bootstrap a new OTP application named $(APP)"
  116. $t mkdir $(APP)/
  117. $t cp ../erlang.mk $(APP)/
  118. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  119. $i "Check that all bootstrapped files exist"
  120. $t test -f $(APP)/Makefile
  121. ifdef LEGACY
  122. $t test -f $(APP)/src/$(APP).app.src
  123. endif
  124. $t test -f $(APP)/src/$(APP)_app.erl
  125. $t test -f $(APP)/src/$(APP)_sup.erl
  126. $i "Check that bootstrapped files have no tabs"
  127. ifdef LEGACY
  128. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  129. endif
  130. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  131. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  132. # Everything looks OK, but let's compile the application to make sure.
  133. $i "Build the application"
  134. $t $(MAKE) -C $(APP) $v
  135. $i "Check that all compiled files exist"
  136. $t test -f $(APP)/ebin/$(APP).app
  137. $t test -f $(APP)/ebin/$(APP)_app.beam
  138. $t test -f $(APP)/ebin/$(APP)_sup.beam
  139. $i "Check that the application was compiled correctly"
  140. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  141. ok = application:start($(APP)), \
  142. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  143. {module, $(APP)_app} = code:load_file($(APP)_app), \
  144. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  145. halt()"
  146. bootstrap-tab: build clean
  147. $i "Bootstrap a new OTP application named $(APP)"
  148. $t mkdir $(APP)/
  149. $t cp ../erlang.mk $(APP)/
  150. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  151. $i "Check that all bootstrapped files exist"
  152. $t test -f $(APP)/Makefile
  153. ifdef LEGACY
  154. $t test -f $(APP)/src/$(APP).app.src
  155. endif
  156. $t test -f $(APP)/src/$(APP)_app.erl
  157. $t test -f $(APP)/src/$(APP)_sup.erl
  158. $i "Check that bootstrapped files have tabs"
  159. ifdef LEGACY
  160. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  161. endif
  162. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  163. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  164. bootstrap-templates: build clean
  165. $i "Bootstrap a new OTP library named $(APP)"
  166. $t mkdir $(APP)/
  167. $t cp ../erlang.mk $(APP)/
  168. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  169. $i "Check that we can get the list of templates"
  170. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -gt 1
  171. $i "Generate one of each template"
  172. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  173. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_statem n=my_statem
  174. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  175. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  176. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  177. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  178. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  179. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  180. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  181. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  182. # Here we disable warnings because templates contain missing behaviors.
  183. $i "Build the application"
  184. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  185. $i "Check that all compiled files exist"
  186. $t test -f $(APP)/ebin/$(APP).app
  187. $t test -f $(APP)/ebin/my_fsm.beam
  188. $t test -f $(APP)/ebin/my_statem.beam
  189. $t test -f $(APP)/ebin/my_server.beam
  190. $t test -f $(APP)/ebin/my_sup.beam
  191. $t test -f $(APP)/ebin/my_module.beam
  192. $i "Check that all the modules can be loaded"
  193. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  194. ok = application:start($(APP)), \
  195. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_statem, my_sup, my_ws]} \
  196. = application:get_key($(APP), modules), \
  197. [{module, M} = code:load_file(M) || M <- Mods], \
  198. halt()"