Makefile 3.6 KB

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