Add Sync tool to "make relive" with Rebar3

How to use:
- Compile ejabberd with Rebar3
- Start ejabberd with "make relive"
- Edit some ejabberd source code file
- Save the file, and Sync will compile and reload it automatically

I've added src_dirs option so Sync doesn't act on dependencies,
which would produce many garbage log lines.
However, now it only works if the parent directory is named "ejabberd"

Sync requires at least Erlang/OTP 21, which introduced the
new try-catch syntax to retrieve the stacktrace
https://www.erlang.org/patches/otp-21.0

References:
https://hex.pm/packages/sync
https://github.com/rustyio/sync
This commit is contained in:
Badlop 2024-02-13 13:09:32 +01:00
parent 5c6a399f5b
commit b0afe4946d
4 changed files with 7 additions and 1 deletions

1
.gitignore vendored
View File

@ -34,6 +34,7 @@
/priv/bin/captcha*sh /priv/bin/captcha*sh
/priv/sql /priv/sql
/rel/ejabberd /rel/ejabberd
/recompile.log
/_build /_build
/database/ /database/
/.rebar /.rebar

View File

@ -150,6 +150,7 @@ ifeq ($(REBAR_ENABLE_ELIXIR),true)
ELIXIR_LIBDIR_RAW=$(shell elixir -e "IO.puts(:filename.dirname(:code.lib_dir(:elixir)))" -e ":erlang.halt") ELIXIR_LIBDIR_RAW=$(shell elixir -e "IO.puts(:filename.dirname(:code.lib_dir(:elixir)))" -e ":erlang.halt")
ELIXIR_LIBDIR=":$(ELIXIR_LIBDIR_RAW)" ELIXIR_LIBDIR=":$(ELIXIR_LIBDIR_RAW)"
EXPLICIT_ELIXIR_COMPILE=MIX_ENV=default mix compile.elixir EXPLICIT_ELIXIR_COMPILE=MIX_ENV=default mix compile.elixir
EXPLICIT_ELIXIR_COMPILE_DEV=MIX_ENV=dev mix compile.elixir
PREPARE_ELIXIR_SCRIPTS=$(MKDIR_P) rel/overlays; cp $(ELIXIR_LIBDIR_RAW)/../bin/iex rel/overlays/; cp $(ELIXIR_LIBDIR_RAW)/../bin/elixir rel/overlays/; sed -i 's|ERTS_BIN=$$|ERTS_BIN=$$SCRIPT_PATH/../../erts-{{erts_vsn}}/bin/|' rel/overlays/elixir PREPARE_ELIXIR_SCRIPTS=$(MKDIR_P) rel/overlays; cp $(ELIXIR_LIBDIR_RAW)/../bin/iex rel/overlays/; cp $(ELIXIR_LIBDIR_RAW)/../bin/elixir rel/overlays/; sed -i 's|ERTS_BIN=$$|ERTS_BIN=$$SCRIPT_PATH/../../erts-{{erts_vsn}}/bin/|' rel/overlays/elixir
endif endif
ifeq "$(REBAR_VER)" "3" ifeq "$(REBAR_VER)" "3"
@ -170,7 +171,7 @@ endif
CLEANARG=--all CLEANARG=--all
REBARREL=$(REBAR) as prod tar REBARREL=$(REBAR) as prod tar
REBARDEV=$(REBAR) as dev release REBARDEV=$(REBAR) as dev release
RELIVECMD=$(REBAR) relive RELIVECMD=$(REBAR) as dev relive
REL_LIB_DIR = _build/dev/rel/ejabberd/lib REL_LIB_DIR = _build/dev/rel/ejabberd/lib
COPY_REL_TARGET = dev COPY_REL_TARGET = dev
GET_DEPS_TRANSLATIONS=$(REBAR) as translations $(GET_DEPS) GET_DEPS_TRANSLATIONS=$(REBAR) as translations $(GET_DEPS)
@ -377,6 +378,7 @@ uninstall-librel:
# #
relive: relive:
$(EXPLICIT_ELIXIR_COMPILE_DEV)
$(RELIVECMD) $(RELIVECMD)
relivelibdir=$(shell pwd)/$(DEPSDIR) relivelibdir=$(shell pwd)/$(DEPSDIR)

View File

@ -274,6 +274,7 @@
{copy, "ejabberdctl.cfg.example", "conf/ejabberdctl.cfg"}, {copy, "ejabberdctl.cfg.example", "conf/ejabberdctl.cfg"},
{copy, "ejabberd.yml.example", "conf/ejabberd.yml"}]}]}]}, {copy, "ejabberd.yml.example", "conf/ejabberd.yml"}]}]}]},
{dev, [{post_hooks, [{release, "rel/setup-dev.sh rebar3"}]}, {dev, [{post_hooks, [{release, "rel/setup-dev.sh rebar3"}]},
{deps, [{if_version_above, "20", sync}]},
{relx, [{debug_info, keep}, {relx, [{debug_info, keep},
{dev_mode, true}, {dev_mode, true},
{include_erts, true}, {include_erts, true},
@ -289,6 +290,7 @@
{alias, [{relive, [{shell, "--apps ejabberd \ {alias, [{relive, [{shell, "--apps ejabberd \
--config rel/relive.config \ --config rel/relive.config \
--eval sync:go(). \
--script rel/relive.escript \ --script rel/relive.escript \
--name ejabberd@localhost"}]} --name ejabberd@localhost"}]}
]}. ]}.

View File

@ -1,3 +1,4 @@
[{mnesia, [{dir, "_build/relive/database"}]}, [{mnesia, [{dir, "_build/relive/database"}]},
{sync,[{src_dirs, {replace, [{"ejabberd/src", []}]}}]},
{ejabberd, [{config, "_build/relive/conf/ejabberd.yml"}, {ejabberd, [{config, "_build/relive/conf/ejabberd.yml"},
{log_path, "_build/relive/logs/ejabberd.log"}]}]. {log_path, "_build/relive/logs/ejabberd.log"}]}].