plugin_bootstrap.mk 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # Bootstrap plugin.
  2. BOOTSTRAP_CASES = app lib rel sp tab templates
  3. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  4. .PHONY: bootstrap $(BOOTSTRAP_TARGETS)
  5. bootstrap: $(BOOTSTRAP_TARGETS)
  6. bootstrap-app: build clean
  7. $i "Bootstrap a new OTP application named $(APP)"
  8. $t mkdir $(APP)/
  9. $t cp ../erlang.mk $(APP)/
  10. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  11. $i "Check that all bootstrapped files exist"
  12. $t test -f $(APP)/Makefile
  13. ifdef LEGACY
  14. $t test -f $(APP)/src/$(APP).app.src
  15. endif
  16. $t test -f $(APP)/src/$(APP)_app.erl
  17. $t test -f $(APP)/src/$(APP)_sup.erl
  18. $i "Build the application"
  19. $t $(MAKE) -C $(APP) $v
  20. $i "Check that all compiled files exist"
  21. $t test -f $(APP)/ebin/$(APP).app
  22. $t test -f $(APP)/ebin/$(APP)_app.beam
  23. $t test -f $(APP)/ebin/$(APP)_sup.beam
  24. $i "Check that the application was compiled correctly"
  25. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  26. ok = application:start($(APP)), \
  27. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  28. {module, $(APP)_app} = code:load_file($(APP)_app), \
  29. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  30. halt()"
  31. bootstrap-lib: build clean
  32. $i "Bootstrap a new OTP library named $(APP)"
  33. $t mkdir $(APP)/
  34. $t cp ../erlang.mk $(APP)/
  35. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  36. $i "Check that all bootstrapped files exist"
  37. $t test -f $(APP)/Makefile
  38. ifdef LEGACY
  39. $t test -f $(APP)/src/$(APP).app.src
  40. endif
  41. $i "Build the application"
  42. $t $(MAKE) -C $(APP) $v
  43. $i "Check that all compiled files exist"
  44. $t test -f $(APP)/ebin/$(APP).app
  45. $i "Check that the application was compiled correctly"
  46. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  47. ok = application:start($(APP)), \
  48. {ok, []} = application:get_key($(APP), modules), \
  49. halt()"
  50. bootstrap-rel: build clean
  51. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  52. $t mkdir $(APP)/
  53. $t cp ../erlang.mk $(APP)/
  54. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  55. $i "Check that all bootstrapped files exist"
  56. $t test -f $(APP)/Makefile
  57. $t test -f $(APP)/relx.config
  58. $t test -f $(APP)/rel/sys.config
  59. $t test -f $(APP)/rel/vm.args
  60. ifdef LEGACY
  61. $t test -f $(APP)/src/$(APP).app.src
  62. endif
  63. $t test -f $(APP)/src/$(APP)_app.erl
  64. $t test -f $(APP)/src/$(APP)_sup.erl
  65. $i "Build the application and the release"
  66. $t $(MAKE) -C $(APP) $v
  67. $i "Check that all compiled files exist"
  68. $t test -f $(APP)/ebin/$(APP).app
  69. $t test -f $(APP)/ebin/$(APP)_app.beam
  70. $t test -f $(APP)/ebin/$(APP)_sup.beam
  71. $i "Check that the release was generated"
  72. ifeq ($(PLATFORM),msys2)
  73. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
  74. else
  75. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  76. endif
  77. $i "Check that the release can be started and stopped"
  78. ifeq ($(PLATFORM),msys2)
  79. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
  80. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
  81. $t sleep 1
  82. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
  83. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
  84. else
  85. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  86. $t sleep 1
  87. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  88. endif
  89. $i "Check that there's no erl_crash.dump file"
  90. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  91. bootstrap-sp: build clean
  92. $i "Bootstrap a new OTP application named $(APP)"
  93. $t mkdir $(APP)/
  94. $t cp ../erlang.mk $(APP)/
  95. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  96. $i "Check that all bootstrapped files exist"
  97. $t test -f $(APP)/Makefile
  98. ifdef LEGACY
  99. $t test -f $(APP)/src/$(APP).app.src
  100. endif
  101. $t test -f $(APP)/src/$(APP)_app.erl
  102. $t test -f $(APP)/src/$(APP)_sup.erl
  103. $i "Check that bootstrapped files have no tabs"
  104. ifdef LEGACY
  105. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  106. endif
  107. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  108. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  109. # Everything looks OK, but let's compile the application to make sure.
  110. $i "Build the application"
  111. $t $(MAKE) -C $(APP) $v
  112. $i "Check that all compiled files exist"
  113. $t test -f $(APP)/ebin/$(APP).app
  114. $t test -f $(APP)/ebin/$(APP)_app.beam
  115. $t test -f $(APP)/ebin/$(APP)_sup.beam
  116. $i "Check that the application was compiled correctly"
  117. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  118. ok = application:start($(APP)), \
  119. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  120. {module, $(APP)_app} = code:load_file($(APP)_app), \
  121. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  122. halt()"
  123. bootstrap-tab: build clean
  124. $i "Bootstrap a new OTP application named $(APP)"
  125. $t mkdir $(APP)/
  126. $t cp ../erlang.mk $(APP)/
  127. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  128. $i "Check that all bootstrapped files exist"
  129. $t test -f $(APP)/Makefile
  130. ifdef LEGACY
  131. $t test -f $(APP)/src/$(APP).app.src
  132. endif
  133. $t test -f $(APP)/src/$(APP)_app.erl
  134. $t test -f $(APP)/src/$(APP)_sup.erl
  135. $i "Check that bootstrapped files have tabs"
  136. ifdef LEGACY
  137. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  138. endif
  139. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  140. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  141. bootstrap-templates: build clean
  142. $i "Bootstrap a new OTP library named $(APP)"
  143. $t mkdir $(APP)/
  144. $t cp ../erlang.mk $(APP)/
  145. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  146. $i "Check that we can get the list of templates"
  147. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  148. $i "Generate one of each template"
  149. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  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_server.beam
  165. $t test -f $(APP)/ebin/my_sup.beam
  166. $t test -f $(APP)/ebin/my_module.beam
  167. $i "Check that all the modules can be loaded"
  168. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  169. ok = application:start($(APP)), \
  170. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  171. = application:get_key($(APP), modules), \
  172. [{module, M} = code:load_file(M) || M <- Mods], \
  173. halt()"