Makefile 3.8 KB

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