|
|
@@ -1,139 +1,62 @@
|
|
|
-## shallow clone for speed
|
|
|
+REBAR_VERSION = 3.13.2-emqx-3
|
|
|
+REBAR = ./rebar3
|
|
|
|
|
|
-REBAR_GIT_CLONE_OPTIONS += --depth 1
|
|
|
-export REBAR_GIT_CLONE_OPTIONS
|
|
|
+PROFILE ?= emqx
|
|
|
+PROFILES := emqx emqx-edge
|
|
|
+PKG_PROFILES := emqx-pkg emqx-edge-pkg
|
|
|
|
|
|
-SUITES_FILES := $(shell find test -name '*_SUITE.erl' | sort)
|
|
|
+export REBAR_GIT_CLONE_OPTIONS=--depth=1
|
|
|
|
|
|
-CT_SUITES := $(foreach value,$(SUITES_FILES),$(shell val=$$(basename $(value) .erl); echo $${val%_*}))
|
|
|
-
|
|
|
-CT_NODE_NAME = emqxct@127.0.0.1
|
|
|
-
|
|
|
-RUN_NODE_NAME = emqxdebug@127.0.0.1
|
|
|
+.PHONY: default
|
|
|
+default: $(REBAR) $(PROFILE)
|
|
|
|
|
|
.PHONY: all
|
|
|
-all: compile
|
|
|
-
|
|
|
-.PHONY: tests
|
|
|
-tests: eunit ct
|
|
|
-
|
|
|
-.PHONY: run
|
|
|
-run: run_setup unlock
|
|
|
- @rebar3 as test get-deps
|
|
|
- @rebar3 as test auto --name $(RUN_NODE_NAME) --script scripts/run_emqx.escript
|
|
|
-
|
|
|
-.PHONY: run_setup
|
|
|
-run_setup:
|
|
|
- @erl -noshell -eval \
|
|
|
- "{ok, [[HOME]]} = init:get_argument(home), \
|
|
|
- FilePath = HOME ++ \"/.config/rebar3/rebar.config\", \
|
|
|
- case file:consult(FilePath) of \
|
|
|
- {ok, Term} -> \
|
|
|
- NewTerm = case lists:keyfind(plugins, 1, Term) of \
|
|
|
- false -> [{plugins, [rebar3_auto]} | Term]; \
|
|
|
- {plugins, OldPlugins} -> \
|
|
|
- NewPlugins0 = OldPlugins -- [rebar3_auto], \
|
|
|
- NewPlugins = [rebar3_auto | NewPlugins0], \
|
|
|
- lists:keyreplace(plugins, 1, Term, {plugins, NewPlugins}) \
|
|
|
- end, \
|
|
|
- ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]); \
|
|
|
- _Enoent -> \
|
|
|
- os:cmd(\"mkdir -p ~/.config/rebar3/ \"), \
|
|
|
- NewTerm=[{plugins, [rebar3_auto]}], \
|
|
|
- ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]) \
|
|
|
- end, \
|
|
|
- halt(0)."
|
|
|
-
|
|
|
-.PHONY: shell
|
|
|
-shell:
|
|
|
- @rebar3 as test auto
|
|
|
-
|
|
|
-compile: unlock
|
|
|
- @rebar3 compile
|
|
|
-
|
|
|
-unlock:
|
|
|
- @rebar3 unlock
|
|
|
-
|
|
|
-clean: distclean
|
|
|
-
|
|
|
-## Cuttlefish escript is built by default when cuttlefish app (as dependency) was built
|
|
|
-CUTTLEFISH_SCRIPT := _build/default/lib/cuttlefish/cuttlefish
|
|
|
-
|
|
|
-.PHONY: cover
|
|
|
-cover:
|
|
|
- @rebar3 cover
|
|
|
-
|
|
|
-.PHONY: coveralls
|
|
|
-coveralls:
|
|
|
- @rebar3 as test coveralls send
|
|
|
-
|
|
|
-.PHONY: xref
|
|
|
-xref:
|
|
|
- @rebar3 xref
|
|
|
-
|
|
|
-.PHONY: dialyzer
|
|
|
-dialyzer:
|
|
|
- @rebar3 dialyzer
|
|
|
-
|
|
|
-.PHONY: proper
|
|
|
-proper:
|
|
|
- @rebar3 proper -d test/props -c
|
|
|
-
|
|
|
-.PHONY: deps
|
|
|
-deps:
|
|
|
- @rebar3 get-deps
|
|
|
-
|
|
|
-.PHONY: eunit
|
|
|
-eunit:
|
|
|
- @rebar3 eunit -v
|
|
|
-
|
|
|
-.PHONY: ct_setup
|
|
|
-ct_setup:
|
|
|
- rebar3 as test compile
|
|
|
- @mkdir -p data
|
|
|
- @if [ ! -f data/loaded_plugins ]; then touch data/loaded_plugins; fi
|
|
|
- @ln -s -f '../../../../etc' _build/test/lib/emqx/
|
|
|
- @ln -s -f '../../../../data' _build/test/lib/emqx/
|
|
|
-
|
|
|
-.PHONY: ct
|
|
|
-ct: ct_setup
|
|
|
- @rebar3 ct -v --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
|
|
|
-
|
|
|
-## Run one single CT with rebar3
|
|
|
-## e.g. make ct-one-suite suite=emqx_bridge
|
|
|
-.PHONY: $(SUITES:%=ct-%)
|
|
|
-$(CT_SUITES:%=ct-%): ct_setup
|
|
|
- @rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(@:ct-%=%)_SUITE --cover
|
|
|
-
|
|
|
-.PHONY: app.config
|
|
|
-app.config: $(CUTTLEFISH_SCRIPT) etc/gen.emqx.conf
|
|
|
- $(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/
|
|
|
-
|
|
|
-$(CUTTLEFISH_SCRIPT):
|
|
|
- @rebar3 get-deps
|
|
|
- @if [ ! -f cuttlefish ]; then make -C _build/default/lib/cuttlefish; fi
|
|
|
-
|
|
|
-bbmustache:
|
|
|
- @git clone https://github.com/soranoba/bbmustache.git && cd bbmustache && ./rebar3 compile && cd ..
|
|
|
+all: $(REBAR) $(PROFILES)
|
|
|
|
|
|
-# This hack is to generate a conf file for testing
|
|
|
-# relx overlay is used for release
|
|
|
-etc/gen.emqx.conf: bbmustache etc/emqx.conf
|
|
|
- @erl -noshell -pa bbmustache/_build/default/lib/bbmustache/ebin -eval \
|
|
|
- "{ok, Temp} = file:read_file('etc/emqx.conf'), \
|
|
|
- {ok, Vars0} = file:consult('vars'), \
|
|
|
- Vars = [{atom_to_list(N), list_to_binary(V)} || {N, V} <- Vars0], \
|
|
|
- Targ = bbmustache:render(Temp, Vars), \
|
|
|
- ok = file:write_file('etc/gen.emqx.conf', Targ), \
|
|
|
- halt(0)."
|
|
|
+.PHONY: ensure-rebar3
|
|
|
+ensure-rebar3:
|
|
|
+ @./ensure-rebar3.sh $(REBAR_VERSION)
|
|
|
|
|
|
-.PHONY: gen-clean
|
|
|
-gen-clean:
|
|
|
- @rm -rf bbmustache
|
|
|
- @rm -f etc/gen.emqx.conf etc/emqx.conf.rendered
|
|
|
+$(REBAR): ensure-rebar3
|
|
|
|
|
|
.PHONY: distclean
|
|
|
-distclean: gen-clean
|
|
|
- @rm -rf Mnesia.*
|
|
|
- @rm -rf _build cover deps logs log data
|
|
|
- @rm -f rebar.lock compile_commands.json cuttlefish erl_crash.dump
|
|
|
+distclean:
|
|
|
+ @rm -rf _build
|
|
|
+
|
|
|
+.PHONY: $(PROFILES)
|
|
|
+$(PROFILES:%=%): $(REBAR)
|
|
|
+ifneq ($(shell echo $(@) |grep edge),)
|
|
|
+ export EMQX_DESC="EMQ X Edge"
|
|
|
+else
|
|
|
+ export EMQX_DESC="EMQ X Broker"
|
|
|
+endif
|
|
|
+ $(REBAR) as $(@) release
|
|
|
+
|
|
|
+.PHONY: $(PROFILES:%=build-%)
|
|
|
+$(PROFILES:%=build-%): $(REBAR)
|
|
|
+ $(REBAR) as $(@:build-%=%) compile
|
|
|
+
|
|
|
+# rebar clean
|
|
|
+.PHONY: clean $(PROFILES:%=clean-%)
|
|
|
+clean: $(PROFILES:%=clean-%) clean-stamps
|
|
|
+$(PROFILES:%=clean-%): $(REBAR)
|
|
|
+ $(REBAR) as $(@:clean-%=%) clean
|
|
|
+
|
|
|
+.PHONY: clean-stamps
|
|
|
+clean-stamps:
|
|
|
+ find -L _build -name '.stamp' -type f | xargs rm -f
|
|
|
+
|
|
|
+.PHONY: deps-all
|
|
|
+deps-all: $(REBAR) $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%)
|
|
|
+
|
|
|
+.PHONY: $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%)
|
|
|
+$(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%): $(REBAR)
|
|
|
+ifneq ($(shell echo $(@) |grep edge),)
|
|
|
+ export EMQX_DESC="EMQ X Edge"
|
|
|
+else
|
|
|
+ export EMQX_DESC="EMQ X Broker"
|
|
|
+endif
|
|
|
+ $(REBAR) as $(@:deps-%=%) get-deps
|
|
|
+
|
|
|
+include packages.mk
|
|
|
+include docker.mk
|