plugin_bootstrap.mk 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 $(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 $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  86. endif
  87. $i "Check that there's no erl_crash.dump file"
  88. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  89. bootstrap-sp: build clean
  90. $i "Bootstrap a new OTP application named $(APP)"
  91. $t mkdir $(APP)/
  92. $t cp ../erlang.mk $(APP)/
  93. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
  94. $i "Check that all bootstrapped files exist"
  95. $t test -f $(APP)/Makefile
  96. ifdef LEGACY
  97. $t test -f $(APP)/src/$(APP).app.src
  98. endif
  99. $t test -f $(APP)/src/$(APP)_app.erl
  100. $t test -f $(APP)/src/$(APP)_sup.erl
  101. $i "Check that bootstrapped files have no tabs"
  102. ifdef LEGACY
  103. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  104. endif
  105. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  106. $t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  107. # Everything looks OK, but let's compile the application to make sure.
  108. $i "Build the application"
  109. $t $(MAKE) -C $(APP) $v
  110. $i "Check that all compiled files exist"
  111. $t test -f $(APP)/ebin/$(APP).app
  112. $t test -f $(APP)/ebin/$(APP)_app.beam
  113. $t test -f $(APP)/ebin/$(APP)_sup.beam
  114. $i "Check that the application was compiled correctly"
  115. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  116. ok = application:start($(APP)), \
  117. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  118. {module, $(APP)_app} = code:load_file($(APP)_app), \
  119. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  120. halt()"
  121. bootstrap-tab: build clean
  122. $i "Bootstrap a new OTP application named $(APP)"
  123. $t mkdir $(APP)/
  124. $t cp ../erlang.mk $(APP)/
  125. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  126. $i "Check that all bootstrapped files exist"
  127. $t test -f $(APP)/Makefile
  128. ifdef LEGACY
  129. $t test -f $(APP)/src/$(APP).app.src
  130. endif
  131. $t test -f $(APP)/src/$(APP)_app.erl
  132. $t test -f $(APP)/src/$(APP)_sup.erl
  133. $i "Check that bootstrapped files have tabs"
  134. ifdef LEGACY
  135. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
  136. endif
  137. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
  138. $t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
  139. bootstrap-templates: build clean
  140. $i "Bootstrap a new OTP library named $(APP)"
  141. $t mkdir $(APP)/
  142. $t cp ../erlang.mk $(APP)/
  143. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  144. $i "Check that we can get the list of templates"
  145. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  146. $i "Generate one of each template"
  147. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  148. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  149. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  150. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  151. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  152. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  153. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  154. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  155. $t $(MAKE) -C $(APP) --no-print-directory new t=module n=my_module
  156. # Here we disable warnings because templates contain missing behaviors.
  157. $i "Build the application"
  158. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  159. $i "Check that all compiled files exist"
  160. $t test -f $(APP)/ebin/$(APP).app
  161. $t test -f $(APP)/ebin/my_fsm.beam
  162. $t test -f $(APP)/ebin/my_server.beam
  163. $t test -f $(APP)/ebin/my_sup.beam
  164. $t test -f $(APP)/ebin/my_module.beam
  165. $i "Check that all the modules can be loaded"
  166. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  167. ok = application:start($(APP)), \
  168. {ok, Mods = [my_fsm, my_http, my_loop, my_module, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  169. = application:get_key($(APP), modules), \
  170. [{module, M} = code:load_file(M) || M <- Mods], \
  171. halt()"