Skip to content

Commit

Permalink
Add Sync tool to "make relive" with Rebar3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
badlop committed Apr 30, 2024
1 parent 5c6a399 commit b0afe49
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/priv/bin/captcha*sh
/priv/sql
/rel/ejabberd
/recompile.log
/_build
/database/
/.rebar
Expand Down
4 changes: 3 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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=":$(ELIXIR_LIBDIR_RAW)"
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
endif
ifeq "$(REBAR_VER)" "3"
Expand All @@ -170,7 +171,7 @@ endif
CLEANARG=--all
REBARREL=$(REBAR) as prod tar
REBARDEV=$(REBAR) as dev release
RELIVECMD=$(REBAR) relive
RELIVECMD=$(REBAR) as dev relive
REL_LIB_DIR = _build/dev/rel/ejabberd/lib
COPY_REL_TARGET = dev
GET_DEPS_TRANSLATIONS=$(REBAR) as translations $(GET_DEPS)
Expand Down Expand Up @@ -377,6 +378,7 @@ uninstall-librel:
#

relive:
$(EXPLICIT_ELIXIR_COMPILE_DEV)
$(RELIVECMD)

relivelibdir=$(shell pwd)/$(DEPSDIR)
Expand Down
2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
{copy, "ejabberdctl.cfg.example", "conf/ejabberdctl.cfg"},
{copy, "ejabberd.yml.example", "conf/ejabberd.yml"}]}]}]},
{dev, [{post_hooks, [{release, "rel/setup-dev.sh rebar3"}]},
{deps, [{if_version_above, "20", sync}]},
{relx, [{debug_info, keep},
{dev_mode, true},
{include_erts, true},
Expand All @@ -289,6 +290,7 @@

{alias, [{relive, [{shell, "--apps ejabberd \
--config rel/relive.config \
--eval sync:go(). \
--script rel/relive.escript \
--name ejabberd@localhost"}]}
]}.
Expand Down
1 change: 1 addition & 0 deletions rel/relive.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[{mnesia, [{dir, "_build/relive/database"}]},
{sync,[{src_dirs, {replace, [{"ejabberd/src", []}]}}]},
{ejabberd, [{config, "_build/relive/conf/ejabberd.yml"},
{log_path, "_build/relive/logs/ejabberd.log"}]}].

0 comments on commit b0afe49

Please sign in to comment.