Skip to content

Commit

Permalink
Cleanup mix.exs and rabbitmq_cli Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoguin committed Dec 18, 2024
1 parent 0090a7b commit c22a46b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
48 changes: 15 additions & 33 deletions deps/rabbitmq_cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DEP_PLUGINS = rabbit_common/mk/rabbitmq-build.mk
VERBOSE_TEST ?= true
MAX_CASES ?= 1

# We are still using Mix for testing.
MIX_TEST_OPTS ?= ""
MIX_TEST = ERL_COMPILER_OPTIONS=deterministic MIX_ENV=test mix do compile --warnings-as-errors, test --max-cases=$(MAX_CASES) --warnings-as-errors

Expand Down Expand Up @@ -62,33 +63,15 @@ ESCRIPT_EMU_ARGS += -hidden
escript-zip::
$(verbose) $(ESCRIPT_ZIP) $(ESCRIPT_ZIP_FILE) $(ELIXIR_LIBS)/*


# rabbitmq-mix.mk is generated during the creation of the RabbitMQ
# source archive. It sets some environment variables to allow
# rabbitmq_cli to build offline, using the bundled sources only.
-include rabbitmq-mix.mk

ACTUAL_ESCRIPTS = $(ESCRIPT_FILE)

LINKED_ESCRIPTS = escript/rabbitmq-plugins \
escript/rabbitmq-diagnostics \
escript/rabbitmq-queues \
escript/rabbitmq-streams \
escript/vmware-rabbitmq \
escript/rabbitmq-upgrade
escript/rabbitmq-diagnostics \
escript/rabbitmq-queues \
escript/rabbitmq-streams \
escript/vmware-rabbitmq \
escript/rabbitmq-upgrade

escript:: $(LINKED_ESCRIPTS)

# Record the build and link dependency: the target files are linked to
# their first dependency.
rabbitmq-plugins = escript/rabbitmqctl
rabbitmq-diagnostics = escript/rabbitmqctl
rabbitmq-queues = escript/rabbitmqctl
rabbitmq-streams = escript/rabbitmqctl
rabbitmq-upgrade = escript/rabbitmqctl
vmware-rabbitmq = escript/rabbitmqctl
escript/rabbitmq-plugins escript/rabbitmq-diagnostics escript/rabbitmq-queues escript/rabbitmq-streams escript/rabbitmq-upgrade escript/vmware-rabbitmq: escript/rabbitmqctl

# We use hardlinks or symlinks in the `escript` directory and
# install's PREFIX when a single escript can have several names (eg.
# rabbitmq-plugins, rabbitmq-plugins and rabbitmq-diagnostics).
Expand All @@ -109,10 +92,9 @@ else
link_escript = ln -f "$(dir $(2))$(notdir $(1))" "$(2)"
endif

# Elixir dependencies are fetched and compiled as part of the alias
# `mix make_all`. We do not fetch and build them in `make deps` because
# mix(1) startup time is quite high. Thus we prefer to run it once, even
# though it kind of breaks the Erlang.mk model.
# Erlang.mk will fetch dependencies as it now has native Elixir support.
# However we are still using Mix for tests and this means Mix will fetch
# test dependencies.
#
# We write `y` on mix stdin because it asks approval to install Hex if
# it's missing. Another way to do it is to use `mix local.hex` but it
Expand All @@ -127,7 +109,7 @@ endif
# otherwise mix(1) complains about missing dependencies (the non-prod
# ones).

$(LINKED_ESCRIPTS):
$(LINKED_ESCRIPTS): $(ESCRIPT_FILE)
$(verbose) rm -f "$@"
$(gen_verbose) $(call link_escript,$<,$@)

Expand Down Expand Up @@ -160,19 +142,19 @@ dialyzer:: escript
install: $(ESCRIPT_FILE)
ifdef PREFIX
$(gen_verbose) mkdir -p "$(DESTDIR)$(PREFIX)"
$(verbose) $(foreach script,$(ACTUAL_ESCRIPTS), \
cmp -s "$(script)" "$(DESTDIR)$(PREFIX)/$(notdir $(script))" || \
cp "$(script)" "$(DESTDIR)$(PREFIX)/$(notdir $(script))";)
$(verbose) \
cmp -s "$(ESCRIPT_FILE)" "$(DESTDIR)$(PREFIX)/$(notdir $(ESCRIPT_FILE))" || \
cp "$(ESCRIPT_FILE)" "$(DESTDIR)$(PREFIX)/$(notdir $(ESCRIPT_FILE))"
$(verbose) $(foreach script,$(LINKED_ESCRIPTS), \
$(call link_escript,$($(notdir $(script))),$(DESTDIR)$(PREFIX)/$(notdir $(script)));)
$(call link_escript,$(ESCRIPT_FILE),$(DESTDIR)$(PREFIX)/$(notdir $(script)));)
else
$(verbose) echo "You must specify a PREFIX" 1>&2; false
endif

clean:: clean-mix

clean-mix:
$(gen_verbose) rm -f $(ACTUAL_ESCRIPTS) $(LINKED_ESCRIPTS)
$(gen_verbose) rm -f $(ESCRIPT_FILE) $(LINKED_ESCRIPTS)
$(verbose) echo y | mix clean

format:
Expand Down
27 changes: 1 addition & 26 deletions deps/rabbitmq_cli/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule RabbitMQCtl.MixfileBase do
prune_code_paths: false,
elixirc_options: [ignore_module_conflict: true],
deps: deps(Mix.env()),
aliases: aliases(),
xref: [
exclude: [
CSV,
Expand Down Expand Up @@ -144,6 +143,7 @@ defmodule RabbitMQCtl.MixfileBase do
fake_cmd = "true"
is_bazel = System.get_env("IS_BAZEL") != nil

# Note that normal deps will be fetched by Erlang.mk on build.
[
{
:json,
Expand Down Expand Up @@ -209,29 +209,4 @@ defmodule RabbitMQCtl.MixfileBase do
[]
end
end

defp aliases do
[
make_deps: [
"deps.get",
"deps.compile"
],
make_app: [
"compile",
"escript.build"
],
make_all: [
"deps.get",
"deps.compile",
"compile",
"escript.build"
],
make_all_in_src_archive: [
"deps.get --only prod",
"deps.compile",
"compile",
"escript.build"
]
]
end
end

0 comments on commit c22a46b

Please sign in to comment.