From 20188f91890bc9382d989746cb9e5ae4f42fa957 Mon Sep 17 00:00:00 2001 From: Gilbert Date: Fri, 21 Jun 2019 20:52:27 +0800 Subject: [PATCH] Optimize develop workflow and support make run and code hot swapping (#2644) * Optimize develop workflow and support make run and code hot swapping --- .gitignore | 1 + Makefile | 36 ++++++++++++++++++++++++++++++++---- rebar.config | 22 +++++++++++----------- test/run_emqx.escript | 13 +++++++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 test/run_emqx.escript diff --git a/.gitignore b/.gitignore index 16369a576..aaec950d4 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ xrefr erlang.mk *.coverdata etc/emqx.conf.rendered +Mnesia.*/ diff --git a/Makefile b/Makefile index 14790e0e9..bf1da5bc5 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,43 @@ REBAR_GIT_CLONE_OPTIONS += --depth 1 export REBAR_GIT_CLONE_OPTIONS - SUITES_FILES := $(shell find test -name '*_SUITE.erl') CT_SUITES := $(foreach value,$(SUITES_FILES),$(shell val=$$(basename $(value) .erl); echo $${val%_*})) CT_NODE_NAME = emqxct@127.0.0.1 -.PHONY: cover -run: - @echo $(CT_TEST_SUITES) +RUN_NODE_NAME = emqxdebug@127.0.0.1 + +.PHONY: run +run: run_setup + @rebar3 as test get-deps + @rebar3 as test auto --name $(RUN_NODE_NAME) --script test/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]); \ + _ -> \ + 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: @rebar3 compile @@ -89,5 +116,6 @@ gen-clean: .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 diff --git a/rebar.config b/rebar.config index bd017de97..22fbccaf9 100644 --- a/rebar.config +++ b/rebar.config @@ -1,12 +1,12 @@ {deps, - [ {jsx, "2.9.0"} % hex - , {cowboy, "2.6.1"} % hex - , {gproc, "0.8.0"} % hex - , {ekka, "0.5.6"} % hex - , {replayq, "0.1.1"} %hex - , {esockd, "5.5.0"} %hex - , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}} - , {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}} + [{jsx, "2.9.0"}, % hex + {cowboy, "2.6.1"}, % hex + {gproc, "0.8.0"}, % hex + {ekka, "0.5.6"}, % hex + {replayq, "0.1.1"}, %hex + {esockd, "5.5.0"}, %hex + {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}}, + {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}} ]}. {edoc_opts, [{preprocess, true}]}. @@ -29,9 +29,9 @@ {profiles, [{test, [{deps, - [ {meck, "0.8.13"} % hex - , {bbmustache, "1.7.0"} % hex - , {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "v1.1.1"}}} + [{meck, "0.8.13"}, % hex + {bbmustache, "1.7.0"}, % hex + {emqx_ct_helpers, "1.1.3"} % hex ]} ]} ]}. diff --git a/test/run_emqx.escript b/test/run_emqx.escript new file mode 100644 index 000000000..e8d1e2aae --- /dev/null +++ b/test/run_emqx.escript @@ -0,0 +1,13 @@ +#!/usr/bin/env escript + +main(_) -> + start(). + +start() -> + SpecEmqxConfig = fun(_) -> ok end, + start(SpecEmqxConfig). + +start(SpecEmqxConfig) -> + SchemaPath = filename:join(["priv", "emqx.schema"]), + ConfPath = filename:join(["etc", "emqx.conf"]), + emqx_ct_helpers:start_app(emqx, SchemaPath, ConfPath, SpecEmqxConfig).