From b0afe4946d48f19e3dffc2a114b1dec6c86dc7a6 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 13 Feb 2024 13:09:32 +0100 Subject: [PATCH] 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 --- .gitignore | 1 + Makefile.in | 4 +++- rebar.config | 2 ++ rel/relive.config | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5c63117ef..fbb2c2135 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ /priv/bin/captcha*sh /priv/sql /rel/ejabberd +/recompile.log /_build /database/ /.rebar diff --git a/Makefile.in b/Makefile.in index 34728f66a..ec6f911eb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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" @@ -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) @@ -377,6 +378,7 @@ uninstall-librel: # relive: + $(EXPLICIT_ELIXIR_COMPILE_DEV) $(RELIVECMD) relivelibdir=$(shell pwd)/$(DEPSDIR) diff --git a/rebar.config b/rebar.config index bacf4a79c..46c904f91 100644 --- a/rebar.config +++ b/rebar.config @@ -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}, @@ -289,6 +290,7 @@ {alias, [{relive, [{shell, "--apps ejabberd \ --config rel/relive.config \ + --eval sync:go(). \ --script rel/relive.escript \ --name ejabberd@localhost"}]} ]}. diff --git a/rel/relive.config b/rel/relive.config index 7e3901fd4..49da88b79 100644 --- a/rel/relive.config +++ b/rel/relive.config @@ -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"}]}].