ci: add elixir support to `dev` / `make quickrun` scripts

This commit is contained in:
Thales Macedo Garitezi 2023-05-26 14:46:02 -03:00
parent fe81e9521a
commit 475c86640d
3 changed files with 82 additions and 17 deletions

View File

@ -159,6 +159,10 @@ compile: $(PROFILES:%=compile-%)
$(PROFILES:%=compile-%): $(PROFILES:%=compile-%):
@$(BUILD) $(@:compile-%=%) apps @$(BUILD) $(@:compile-%=%) apps
.PHONY: $(PROFILES:%=compile-%-elixir)
$(PROFILES:%=compile-%-elixir):
@env IS_ELIXIR=yes $(BUILD) $(@:compile-%-elixir=%) apps
## Not calling rebar3 clean because ## Not calling rebar3 clean because
## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
## 2. it's slow ## 2. it's slow

16
build
View File

@ -145,6 +145,16 @@ just_compile() {
make_docs make_docs
} }
just_compile_elixir() {
./scripts/pre-compile.sh "$PROFILE"
rm -f rebar.lock
# shellcheck disable=SC1010
env MIX_ENV="$PROFILE" mix do local.hex --if-missing --force, \
local.rebar rebar3 "${PWD}/rebar3" --if-missing --force, \
deps.get
env MIX_ENV="$PROFILE" mix compile
}
make_rel() { make_rel() {
local release_or_tar="${1}" local release_or_tar="${1}"
just_compile just_compile
@ -395,7 +405,11 @@ log "building artifact=$ARTIFACT for profile=$PROFILE"
case "$ARTIFACT" in case "$ARTIFACT" in
apps) apps)
just_compile if [ "${IS_ELIXIR:-}" = "yes" ]; then
just_compile_elixir
else
just_compile
fi
;; ;;
doc|docs) doc|docs)
make_docs make_docs

79
dev
View File

@ -2,6 +2,10 @@
set -euo pipefail set -euo pipefail
if [ -n "${DEBUG:-}" ]; then
set -x
fi
UNAME="$(uname -s)" UNAME="$(uname -s)"
PROJ_ROOT="$(git rev-parse --show-toplevel)" PROJ_ROOT="$(git rev-parse --show-toplevel)"
@ -123,6 +127,14 @@ case "${PROFILE}" in
ee|emqx-enterprise) ee|emqx-enterprise)
PROFILE='emqx-enterprise' PROFILE='emqx-enterprise'
;; ;;
ce-ex|emqx-elixir)
export IS_ELIXIR=yes
PROFILE='emqx'
;;
ee-ex|emqx-enterprise-elixir)
export IS_ELIXIR=yes
PROFILE='emqx-enterprise'
;;
*) *)
echo "Unknown profile $PROFILE" echo "Unknown profile $PROFILE"
exit 1 exit 1
@ -131,10 +143,10 @@ esac
export PROFILE export PROFILE
case "${PROFILE}" in case "${PROFILE}" in
emqx) emqx|emqx-elixir)
export SCHEMA_MOD='emqx_conf_schema' export SCHEMA_MOD='emqx_conf_schema'
;; ;;
emqx-enterprise) emqx-enterprise|emqx-enterprise-elixir)
export SCHEMA_MOD='emqx_enterprise_schema' export SCHEMA_MOD='emqx_enterprise_schema'
;; ;;
esac esac
@ -177,6 +189,17 @@ prepare_erl_libs() {
erl_libs="${app}" erl_libs="${app}"
fi fi
done done
if [ "${IS_ELIXIR:-}" = "yes" ]; then
local elixir_libs_root_dir
elixir_libs_root_dir=$(realpath "$(elixir -e ':code.lib_dir(:elixir) |> IO.puts()')"/..)
for app in "${elixir_libs_root_dir}"/*; do
if [ -n "$erl_libs" ]; then
erl_libs="${erl_libs}${sep}${app}"
else
erl_libs="${app}"
fi
done
fi
export ERL_LIBS="$erl_libs" export ERL_LIBS="$erl_libs"
} }
@ -342,21 +365,45 @@ boot() {
append_args_file append_args_file
APPS="$(apps_to_load)" APPS="$(apps_to_load)"
BOOT_SEQUENCE=" if [ "${IS_ELIXIR:-}" = "yes" ]; then
Apps=[${APPS}], BOOT_SEQUENCE='
ok=lists:foreach(fun application:load/1, Apps), apps = System.get_env("APPS") |> String.split(",") |> Enum.map(&String.to_atom/1)
io:format(user, \"~nLoaded: ~p~n\", [Apps]), Enum.each(apps, &Application.load/1)
{ok, _} = application:ensure_all_started(emqx_machine). IO.inspect(apps, label: :loaded, limit: :infinity)
" {:ok, _} = Application.ensure_all_started(:emqx_machine)
'
if [ -n "${EPMD_ARGS:-}" ]; then
EPMD_ARGS_ELIXIR="--erl $EPMD_ARGS"
else
EPMD_ARGS_ELIXIR=""
fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
erl -name "$EMQX_NODE_NAME" \ env APPS="$APPS" iex \
$EPMD_ARGS \ --name "$EMQX_NODE_NAME" \
-proto_dist ekka \ $EPMD_ARGS_ELIXIR \
-args_file "$ARGS_FILE" \ --erl '-user Elixir.IEx.CLI' \
-config "$CONF_FILE" \ --erl '-proto_dist ekka' \
-s emqx_restricted_shell set_prompt_func \ --vm-args "$ARGS_FILE" \
-eval "$BOOT_SEQUENCE" --erl-config "$CONF_FILE" \
-e "$BOOT_SEQUENCE"
else
BOOT_SEQUENCE="
Apps=[${APPS}],
ok=lists:foreach(fun application:load/1, Apps),
io:format(user, \"~nLoaded: ~p~n\", [Apps]),
{ok, _} = application:ensure_all_started(emqx_machine).
"
# shellcheck disable=SC2086
erl -name "$EMQX_NODE_NAME" \
$EPMD_ARGS \
-proto_dist ekka \
-args_file "$ARGS_FILE" \
-config "$CONF_FILE" \
-s emqx_restricted_shell set_prompt_func \
-eval "$BOOT_SEQUENCE"
fi
} }
# Generate a random id # Generate a random id