plugin_bootstrap.mk 6.8 KB

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