Просмотр исходного кода

Optimize develop workflow and support make run and code hot swapping (#2644)

* Optimize develop workflow and support make run and code hot swapping
Gilbert 6 лет назад
Родитель
Сommit
20188f9189
4 измененных файлов с 57 добавлено и 15 удалено
  1. 1 0
      .gitignore
  2. 32 4
      Makefile
  3. 11 11
      rebar.config
  4. 13 0
      test/run_emqx.escript

+ 1 - 0
.gitignore

@@ -40,3 +40,4 @@ xrefr
 erlang.mk
 *.coverdata
 etc/emqx.conf.rendered
+Mnesia.*/

+ 32 - 4
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

+ 11 - 11
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
             ]}
         ]}
     ]}.

+ 13 - 0
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).