Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ## shallow clone for speed
  2. REBAR_GIT_CLONE_OPTIONS += --depth 1
  3. export REBAR_GIT_CLONE_OPTIONS
  4. SUITES_FILES := $(shell find test -name '*_SUITE.erl')
  5. CT_SUITES := $(foreach value,$(SUITES_FILES),$(shell val=$$(basename $(value) .erl); echo $${val%_*}))
  6. CT_NODE_NAME = emqxct@127.0.0.1
  7. RUN_NODE_NAME = emqxdebug@127.0.0.1
  8. .PHONY: all
  9. all: compile
  10. .PHONY: tests
  11. tests: eunit ct proper
  12. .PHONY: proper
  13. proper:
  14. @rebar3 proper
  15. .PHONY: run
  16. run: run_setup unlock
  17. @rebar3 as test get-deps
  18. @rebar3 as test auto --name $(RUN_NODE_NAME) --script scripts/run_emqx.escript
  19. .PHONY: run_setup
  20. run_setup:
  21. @erl -noshell -eval \
  22. "{ok, [[HOME]]} = init:get_argument(home), \
  23. FilePath = HOME ++ \"/.config/rebar3/rebar.config\", \
  24. case file:consult(FilePath) of \
  25. {ok, Term} -> \
  26. NewTerm = case lists:keyfind(plugins, 1, Term) of \
  27. false -> [{plugins, [rebar3_auto]} | Term]; \
  28. {plugins, OldPlugins} -> \
  29. NewPlugins0 = OldPlugins -- [rebar3_auto], \
  30. NewPlugins = [rebar3_auto | NewPlugins0], \
  31. lists:keyreplace(plugins, 1, Term, {plugins, NewPlugins}) \
  32. end, \
  33. ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]); \
  34. _Enoent -> \
  35. os:cmd(\"mkdir -p ~/.config/rebar3/ \"), \
  36. NewTerm=[{plugins, [rebar3_auto]}], \
  37. ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]) \
  38. end, \
  39. halt(0)."
  40. .PHONY: shell
  41. shell:
  42. @rebar3 as test auto
  43. compile: unlock
  44. @rebar3 compile
  45. unlock:
  46. @rebar3 unlock
  47. clean: distclean
  48. ## Cuttlefish escript is built by default when cuttlefish app (as dependency) was built
  49. CUTTLEFISH_SCRIPT := _build/default/lib/cuttlefish/cuttlefish
  50. .PHONY: cover
  51. cover:
  52. @rebar3 cover
  53. .PHONY: coveralls
  54. coveralls:
  55. @rebar3 coveralls send
  56. .PHONY: xref
  57. xref:
  58. @rebar3 xref
  59. .PHONY: deps
  60. deps:
  61. @rebar3 get-deps
  62. .PHONY: eunit
  63. eunit:
  64. @rebar3 eunit -v
  65. .PHONY: ct_setup
  66. ct_setup:
  67. rebar3 as test compile
  68. @mkdir -p data
  69. @if [ ! -f data/loaded_plugins ]; then touch data/loaded_plugins; fi
  70. @ln -s -f '../../../../etc' _build/test/lib/emqx/
  71. @ln -s -f '../../../../data' _build/test/lib/emqx/
  72. .PHONY: ct
  73. ct: ct_setup
  74. @rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
  75. ## Run one single CT with rebar3
  76. ## e.g. make ct-one-suite suite=emqx_bridge
  77. .PHONY: $(SUITES:%=ct-%)
  78. $(CT_SUITES:%=ct-%): ct_setup
  79. @rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(@:ct-%=%)_SUITE
  80. .PHONY: app.config
  81. app.config: $(CUTTLEFISH_SCRIPT) etc/gen.emqx.conf
  82. $(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/
  83. $(CUTTLEFISH_SCRIPT):
  84. @rebar3 get-deps
  85. @if [ ! -f cuttlefish ]; then make -C _build/default/lib/cuttlefish; fi
  86. bbmustache:
  87. @git clone https://github.com/soranoba/bbmustache.git && cd bbmustache && ./rebar3 compile && cd ..
  88. # This hack is to generate a conf file for testing
  89. # relx overlay is used for release
  90. etc/gen.emqx.conf: bbmustache etc/emqx.conf
  91. @erl -noshell -pa bbmustache/_build/default/lib/bbmustache/ebin -eval \
  92. "{ok, Temp} = file:read_file('etc/emqx.conf'), \
  93. {ok, Vars0} = file:consult('vars'), \
  94. Vars = [{atom_to_list(N), list_to_binary(V)} || {N, V} <- Vars0], \
  95. Targ = bbmustache:render(Temp, Vars), \
  96. ok = file:write_file('etc/gen.emqx.conf', Targ), \
  97. halt(0)."
  98. .PHONY: gen-clean
  99. gen-clean:
  100. @rm -rf bbmustache
  101. @rm -f etc/gen.emqx.conf etc/emqx.conf.rendered
  102. .PHONY: distclean
  103. distclean: gen-clean
  104. @rm -rf Mnesia.*
  105. @rm -rf _build cover deps logs log data
  106. @rm -f rebar.lock compile_commands.json cuttlefish erl_crash.dump