plugin_bootstrap.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Bootstrap plugin.
  2. BOOTSTRAP_CASES = app lib rel 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. $t test -f $(APP)/src/$(APP).app.src
  18. $t test -f $(APP)/src/$(APP)_app.erl
  19. $t test -f $(APP)/src/$(APP)_sup.erl
  20. $i "Build the application"
  21. $t $(MAKE) -C $(APP) $v
  22. $i "Check that all compiled files exist"
  23. $t test -f $(APP)/ebin/$(APP).app
  24. $t test -f $(APP)/ebin/$(APP)_app.beam
  25. $t test -f $(APP)/ebin/$(APP)_sup.beam
  26. $i "Check that the application was compiled correctly"
  27. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  28. ok = application:start($(APP)), \
  29. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  30. {module, $(APP)_app} = code:load_file($(APP)_app), \
  31. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  32. halt()"
  33. bootstrap-lib: build clean-bootstrap-lib
  34. $i "Bootstrap a new OTP library named $(APP)"
  35. $t mkdir $(APP)/
  36. $t cp ../erlang.mk $(APP)/
  37. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  38. $i "Check that all bootstrapped files exist"
  39. $t test -f $(APP)/Makefile
  40. $t test -f $(APP)/src/$(APP).app.src
  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-bootstrap-rel
  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. $t test -f $(APP)/src/$(APP).app.src
  61. $t test -f $(APP)/src/$(APP)_app.erl
  62. $t test -f $(APP)/src/$(APP)_sup.erl
  63. $i "Build the application and the release"
  64. $t $(MAKE) -C $(APP) $v
  65. $i "Check that all compiled files exist"
  66. $t test -f $(APP)/ebin/$(APP).app
  67. $t test -f $(APP)/ebin/$(APP)_app.beam
  68. $t test -f $(APP)/ebin/$(APP)_sup.beam
  69. $i "Check that the release was generated"
  70. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  71. $i "Check that the release can be started and stopped"
  72. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  73. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  74. $i "Check that there's no erl_crash.dump file"
  75. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  76. bootstrap-templates: build clean-bootstrap-templates
  77. $i "Bootstrap a new OTP library named $(APP)"
  78. $t mkdir $(APP)/
  79. $t cp ../erlang.mk $(APP)/
  80. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  81. $i "Check that we can get the list of templates"
  82. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  83. $i "Generate one of each template"
  84. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  85. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  86. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  87. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  88. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  89. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  90. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  91. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  92. # Here we disable warnings because templates contain missing behaviors.
  93. $i "Build the application"
  94. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  95. $i "Check that all compiled files exist"
  96. $t test -f $(APP)/ebin/$(APP).app
  97. $t test -f $(APP)/ebin/my_fsm.beam
  98. $t test -f $(APP)/ebin/my_server.beam
  99. $t test -f $(APP)/ebin/my_sup.beam
  100. $i "Check that all the modules can be loaded"
  101. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  102. ok = application:start($(APP)), \
  103. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  104. = application:get_key($(APP), modules), \
  105. [{module, M} = code:load_file(M) || M <- Mods], \
  106. halt()"