plugin_bootstrap.mk 6.9 KB

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