Skip to content

Commit c5d150a

Browse files
committed
Use Erlang.mk's native Elixir support for CLI
This avoids using Mix while compiling which simplifies a number of things and let us do further build improvements later on. Elixir is only enabled from within rabbitmq_cli currently. Eunit is disabled since there are only Elixir tests. Dialyzer will force-enable Elixir in order to process Elixir-compiled beam files. This commit also includes a few changes that are related: * The Erlang distribution will now be started for parallel-ct * Many unnecessary PROJECT_MOD lines have been removed * `eunit_formatters` has been removed, it provides little value * The new `maybe_flock` Erlang.mk function is used where possible * Build test deps when testing rabbitmq_cli (Mix won't do it anymore) * rabbitmq_ct_helpers now use the early plugins to have Dialyzer properly set up
1 parent cc0989f commit c5d150a

File tree

36 files changed

+1027
-4047
lines changed

36 files changed

+1027
-4047
lines changed

Makefile

-106
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ DISABLE_DISTCLEAN = 1
3131
ifeq ($(filter-out xref,$(MAKECMDGOALS)),)
3232
XREF_SCOPE = app deps
3333

34-
# We add all the applications that are in non-standard paths
35-
# so they are included in the analyses as well.
36-
XREF_EXTRA_APP_DIRS = $(filter-out deps/rabbitmq_cli/_build/dev/lib/rabbit_common/,$(wildcard deps/rabbitmq_cli/_build/dev/lib/*/)) deps/rabbitmq_prelaunch/
37-
3834
# For Elixir protocols the right fix is to include the consolidated/
3935
# folders in addition to ebin/. However this creates conflicts because
4036
# some modules are duplicated. So instead we ignore warnings from
@@ -49,10 +45,6 @@ XREF_IGNORE = [ \
4945
xref: ERL_LIBS := $(ERL_LIBS):$(CURDIR)/apps:$(CURDIR)/deps:$(dir $(shell elixir --eval ':io.format "~s~n", [:code.lib_dir :elixir ]'))
5046
endif
5147

52-
ifneq ($(wildcard deps/.hex/cache.erl),)
53-
deps:: restore-hex-cache-ets-file
54-
endif
55-
5648
include rabbitmq-components.mk
5749

5850
# Set PROJECT_VERSION, calculated in rabbitmq-components.mk,
@@ -84,54 +76,6 @@ ifdef PLUGINS
8476
RABBITMQ_ENABLED_PLUGINS ?= $(call comma_list,$(PLUGINS))
8577
endif
8678

87-
# --------------------------------------------------------------------
88-
# Mix Hex cache management.
89-
# --------------------------------------------------------------------
90-
91-
# We restore the initial Hex cache.ets file from an Erlang term created
92-
# at the time the source archive was prepared.
93-
#
94-
# See the `$(SOURCE_DIST)` recipe for the reason behind this step.
95-
96-
restore-hex-cache-ets-file: deps/.hex/cache.ets
97-
98-
deps/.hex/cache.ets: deps/.hex/cache.erl
99-
$(gen_verbose) $(call erlang,$(call restore_hex_cache_from_erl_term,$<,$@))
100-
101-
define restore_hex_cache_from_erl_term
102-
In = "$(1)",
103-
Out = "$(2)",
104-
{ok, [Props, Entries]} = file:consult(In),
105-
Name = proplists:get_value(name, Props),
106-
Type = proplists:get_value(type, Props),
107-
Access = proplists:get_value(protection, Props),
108-
NamedTable = proplists:get_bool(named_table, Props),
109-
Keypos = proplists:get_value(keypos, Props),
110-
Heir = proplists:get_value(heir, Props),
111-
ReadConc = proplists:get_bool(read_concurrency, Props),
112-
WriteConc = proplists:get_bool(write_concurrency, Props),
113-
Compressed = proplists:get_bool(compressed, Props),
114-
Options0 = [
115-
Type,
116-
Access,
117-
{keypos, Keypos},
118-
{heir, Heir},
119-
{read_concurrency, ReadConc},
120-
{write_concurrency, WriteConc}],
121-
Options1 = case NamedTable of
122-
true -> [named_table | Options0];
123-
false -> Options0
124-
end,
125-
Options2 = case Compressed of
126-
true -> [compressed | Options0];
127-
false -> Options0
128-
end,
129-
Tab = ets:new(Name, Options2),
130-
[true = ets:insert(Tab, Entry) || Entry <- Entries],
131-
ok = ets:tab2file(Tab, Out),
132-
init:stop().
133-
endef
134-
13579
# --------------------------------------------------------------------
13680
# Distribution - common variables and generic functions.
13781
# --------------------------------------------------------------------
@@ -263,14 +207,6 @@ $(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
263207
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$$$|include ../../erlang.mk|" \
264208
$$@/deps/$$$$(basename $$$$dep)/Makefile && \
265209
rm $$@/deps/$$$$(basename $$$$dep)/Makefile.bak; \
266-
mix_exs=$$@/deps/$$$$(basename $$$$dep)/mix.exs; \
267-
if test -f $$$$mix_exs; then \
268-
(cd $$$$(dirname "$$$$mix_exs") && \
269-
(test -d $$@/deps/.hex || env DEPS_DIR=$$@/deps MIX_HOME=$$@/deps/.mix HEX_HOME=$$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix local.hex --force) && \
270-
env DEPS_DIR=$$@/deps MIX_HOME=$$@/deps/.mix HEX_HOME=$$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix deps.get --only prod && \
271-
cp $(CURDIR)/mk/rabbitmq-mix.mk . && \
272-
rm -rf _build deps); \
273-
fi; \
274210
if test -f "$$$$dep/license_info"; then \
275211
cp "$$$$dep/license_info" "$$@/deps/licensing/license_info_$$$$(basename $$$$dep)"; \
276212
cat "$$$$dep/license_info" >> $$@/LICENSE; \
@@ -295,7 +231,6 @@ $(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
295231
done
296232
$${verbose} echo "PLUGINS := $(PLUGINS)" > $$@/plugins.mk
297233
$${verbose} sort -r < "$$@.git-times.txt" | head -n 1 > "$$@.git-time.txt"
298-
$${verbose} $$(call erlang,$$(call dump_hex_cache_to_erl_term,$$(call core_native_path,$$@),$$(call core_native_path,$$@.git-time.txt)))
299234
$${verbose} find $$@ -print0 | xargs -0 touch -t "$$$$(cat $$@.git-time.txt)"
300235
$${verbose} rm "$$@.git-times.txt" "$$@.git-time.txt"
301236

@@ -337,47 +272,6 @@ clean-$(1):
337272
clean:: clean-$(1)
338273
endef
339274

340-
# Mix Hex component requires a cache file, otherwise it refuses to build
341-
# offline... That cache is an ETS table with all the applications we
342-
# depend on, plus some versioning informations and checksums. There
343-
# are two problems with that: the table contains a date (`last_update`
344-
# field) and `ets:tab2file()` produces a different file each time it's
345-
# called.
346-
#
347-
# To make our source archive reproducible, we fix the time of the
348-
# `last_update` field to the last Git commit and dump the content of the
349-
# table as an Erlang term to a text file.
350-
#
351-
# The ETS file must be recreated before compiling RabbitMQ. See the
352-
# `restore-hex-cache-ets-file` Make target.
353-
define dump_hex_cache_to_erl_term
354-
In = "$(1)/deps/.hex/cache.ets",
355-
Out = "$(1)/deps/.hex/cache.erl",
356-
{ok, DateStr} = file:read_file("$(2)"),
357-
{match, Date} = re:run(DateStr,
358-
"^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})\.([0-9]{2})",
359-
[{capture, all_but_first, list}]),
360-
[Year, Month, Day, Hour, Min, Sec] = [erlang:list_to_integer(V) || V <- Date],
361-
{ok, Tab} = ets:file2tab(In),
362-
true = ets:insert(Tab, {last_update, {{Year, Month, Day}, {Hour, Min, Sec}}}),
363-
Props = [
364-
Prop
365-
|| {Key, _} = Prop <- ets:info(Tab),
366-
Key =:= name orelse
367-
Key =:= type orelse
368-
Key =:= protection orelse
369-
Key =:= named_table orelse
370-
Key =:= keypos orelse
371-
Key =:= heir orelse
372-
Key =:= read_concurrency orelse
373-
Key =:= write_concurrency orelse
374-
Key =:= compressed],
375-
Entries = ets:tab2list(Tab),
376-
ok = file:write_file(Out, io_lib:format("~w.~n~w.~n", [Props, Entries])),
377-
ok = file:delete(In),
378-
init:stop().
379-
endef
380-
381275
# --------------------------------------------------------------------
382276
# Distribution - public targets
383277
# --------------------------------------------------------------------

deps/amqp10_client/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
PROJECT = amqp10_client
22
PROJECT_DESCRIPTION = AMQP 1.0 client
3-
PROJECT_MOD = amqp10_client_app
43

54
define PROJECT_APP_EXTRA_KEYS
65
%% Hex.pm package informations.

deps/oauth2_client/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
PROJECT = oauth2_client
22
PROJECT_DESCRIPTION = OAuth2 client from the RabbitMQ Project
3-
PROJECT_MOD = oauth2_client_app
43

54
BUILD_DEPS = rabbit
65
DEPS = rabbit_common jose
@@ -12,5 +11,8 @@ PLT_APPS = rabbit
1211
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
1312
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
1413

14+
# Required to properly autopatch jose.
15+
ELIXIR = system
16+
1517
include rabbitmq-components.mk
1618
include erlang.mk

deps/rabbit/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ tpl_parallel_ct_test_spec_set_$1 = $$(call tpl_parallel_ct_test_spec,$(PARALLEL_
328328
parallel-ct-set-$(1): test-build
329329
$(verbose) mkdir -p $(CT_LOGS_DIR)
330330
$(verbose) $$(call core_render,tpl_parallel_ct_test_spec_set_$(1),ct.set-$(1).spec)
331+
$$(eval ERL := erl -noinput -boot no_dot_erlang)
331332
$$(call erlang,$$(call ct_master.erl,ct.set-$(1).spec),-sname parallel_ct_$(PROJECT)@localhost -hidden -kernel net_ticktime 5)
332333
endef
333334

@@ -337,6 +338,7 @@ $(foreach set,1 2 3 4,$(eval $(call parallel_ct_set_target,$(set))))
337338

338339
parallel-ct: test-build
339340
$(verbose) mkdir -p $(CT_LOGS_DIR)
341+
$(eval ERL := erl -noinput -boot no_dot_erlang)
340342
$(call erlang,$(call ct_master.erl,ct.test.spec),-sname parallel_ct_$(PROJECT)@localhost -hidden -kernel net_ticktime 5)
341343

342344
# --------------------------------------------------------------------

deps/rabbit/src/rabbit_variable_queue.erl

+1
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ determine_persist_to(Msg,
18801880
%% via the direct client), we make a guess based on the number of
18811881
%% headers.
18821882

1883+
%% @todo We can probably simplify this.
18831884
{MetaSize, _BodySize} = mc:size(Msg),
18841885
case BodySize >= IndexMaxSize of
18851886
true -> msg_store;

deps/rabbit_common/mk/rabbitmq-build.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ifneq ($(filter rabbitmq_cli,$(BUILD_DEPS) $(DEPS)),)
1212
# Add the CLI ebin directory to the code path for the compiler: plugin
1313
# CLI extensions may access behaviour modules defined in this directory.
1414

15-
RMQ_ERLC_OPTS += -pa $(DEPS_DIR)/rabbitmq_cli/_build/dev/lib/rabbitmqctl/ebin
15+
RMQ_ERLC_OPTS += -pa $(DEPS_DIR)/rabbitmq_cli/ebin
1616
endif
1717

1818
RMQ_ERLC_OPTS += +deterministic

deps/rabbit_common/mk/rabbitmq-dist.mk

+13-41
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
DIST_DIR ?= $(CURDIR)/plugins
44
CLI_SCRIPTS_DIR ?= $(CURDIR)/sbin
55
CLI_ESCRIPTS_DIR ?= $(CURDIR)/escript
6-
MIX = echo y | mix
76

87
# Set $(DIST_AS_EZS) to a non-empty value to enable the packaging of
98
# plugins as .ez archives.
@@ -81,17 +80,13 @@ endef
8180

8281
# Real entry point: it tests the existence of an .app file to determine
8382
# if it is an Erlang application (and therefore if it should be provided
84-
# as an .ez plugin archive) and calls do_ez_target_erlangmk. If instead
85-
# it finds a Mix configuration file, it is skipped, as the only elixir
86-
# applications in the directory are used by rabbitmq_cli and compiled
87-
# with it.
83+
# as an .ez plugin archive) and calls do_ez_target_erlangmk.
8884
#
8985
# $(call ez_target,path_to_app)
9086

9187
define ez_target
9288
dist_$(1)_appdir = $(2)
9389
dist_$(1)_appfile = $$(dist_$(1)_appdir)/ebin/$(1).app
94-
dist_$(1)_mixfile = $$(dist_$(1)_appdir)/mix.exs
9590

9691
$$(if $$(shell test -f $$(dist_$(1)_appfile) && echo OK), \
9792
$$(eval $$(call do_ez_target_erlangmk,$(1),$$(call get_app_version,$$(dist_$(1)_appfile)),$$(dist_$(1)_appdir))))
@@ -117,9 +112,8 @@ endif
117112
endif
118113

119114
# The actual recipe to create the .ez plugin archive. Some variables
120-
# are defined in the do_ez_target_erlangmk and do_ez_target_mix macros
121-
# above. All .ez archives are also listed in this do_ez_target_erlangmk
122-
# and do_ez_target_mix macros.
115+
# are defined in the do_ez_target_erlangmk macro
116+
# above. All .ez archives are also listed in this macro.
123117

124118
RSYNC ?= rsync
125119
RSYNC_V_0 =
@@ -200,7 +194,7 @@ test-dist:: $(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) test-build
200194
$(MAYBE_APPS_LIST)"; \
201195
fi
202196

203-
DIST_EZS = $(ERLANGMK_DIST_EZS) $(MIX_DIST_EZS)
197+
DIST_EZS = $(ERLANGMK_DIST_EZS)
204198

205199
do-dist:: $(DIST_EZS)
206200
$(verbose) unwanted='$(filter-out $(DIST_EZS) $(EXTRA_DIST_EZS), \
@@ -223,43 +217,21 @@ endif
223217
install-cli: install-cli-scripts install-cli-escripts
224218
@:
225219

226-
install-cli-scripts:
220+
install-cli-scripts: | $(CLI_SCRIPTS_DIR)
227221
$(gen_verbose) \
228222
set -e; \
229223
test -d "$(DEPS_DIR)/rabbit/scripts"; \
230-
if command -v flock >/dev/null; then \
231-
flock $(CLI_SCRIPTS_LOCK) \
232-
sh -e -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
233-
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/'; \
234-
elif command -v lockf >/dev/null; then \
235-
lockf $(CLI_SCRIPTS_LOCK) \
236-
sh -e -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
237-
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/'; \
238-
else \
239-
mkdir -p "$(CLI_SCRIPTS_DIR)" && \
240-
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/; \
241-
fi
224+
$(call maybe_flock,$(CLI_SCRIPTS_LOCK), \
225+
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/)
242226

243-
install-cli-escripts:
244-
$(gen_verbose) \
245-
if command -v flock >/dev/null; then \
246-
flock $(CLI_ESCRIPTS_LOCK) \
247-
sh -c 'mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
248-
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
249-
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
250-
DESTDIR='; \
251-
elif command -v lockf >/dev/null; then \
252-
lockf $(CLI_ESCRIPTS_LOCK) \
253-
sh -c 'mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
227+
install-cli-escripts: | $(CLI_ESCRIPTS_DIR)
228+
$(gen_verbose) $(call maybe_flock,$(CLI_ESCRIPTS_LOCK), \
254229
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
255230
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
256-
DESTDIR='; \
257-
else \
258-
mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
259-
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
260-
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
261-
DESTDIR= ; \
262-
fi
231+
DESTDIR= IS_DEP=1)
232+
233+
$(CLI_SCRIPTS_DIR) $(CLI_ESCRIPTS_DIR):
234+
$(verbose) mkdir -p $@
263235

264236
clean-dist::
265237
$(gen_verbose) rm -rf \

deps/rabbit_common/mk/rabbitmq-early-plugin.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
DIALYZER_OPTS ?= -Werror_handling -Wunmatched_returns -Wunknown
66

7-
dialyze: ERL_LIBS = $(APPS_DIR):$(DEPS_DIR):$(DEPS_DIR)/rabbitmq_cli/_build/dev/lib:$(dir $(shell elixir --eval ':io.format "~s~n", [:code.lib_dir :elixir ]'))
7+
dialyze: ELIXIR_LIBS = $(dir $(shell readlink -f `which elixir`))/../lib
8+
dialyze: ERL_LIBS = $(APPS_DIR):$(DEPS_DIR):$(ELIXIR_LIBS)
89

910
# --------------------------------------------------------------------
1011
# Common Test flags.

deps/rabbitmq_auth_backend_cache/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endef
1919
DEPS = rabbit_common rabbit
2020
TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers
2121

22-
PLT_APPS += rabbitmqctl
22+
PLT_APPS += rabbitmq_cli
2323

2424
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
2525
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk

deps/rabbitmq_auth_backend_oauth2/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BUILD_DEPS = rabbit_common rabbitmq_cli
1010
DEPS = rabbit cowlib jose base64url oauth2_client
1111
TEST_DEPS = cowboy rabbitmq_web_dispatch rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client rabbitmq_web_mqtt emqtt rabbitmq_amqp_client
1212

13-
PLT_APPS += rabbitmqctl
13+
PLT_APPS += rabbitmq_cli
1414

1515
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
1616
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
@@ -19,5 +19,8 @@ dep_base64url = hex 1.0.1
1919

2020
dep_emqtt = git https://github.com/emqx/emqtt.git 1.11.0
2121

22+
# Required to properly autopatch jose.
23+
ELIXIR = system
24+
2225
include ../../rabbitmq-components.mk
2326
include ../../erlang.mk

deps/rabbitmq_aws/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
PROJECT = rabbitmq_aws
22
PROJECT_DESCRIPTION = A minimalistic AWS API interface used by rabbitmq-autocluster (3.6.x) and other RabbitMQ plugins
3-
PROJECT_MOD = rabbitmq_aws_app
43
PROJECT_REGISTERED = rabbitmq_aws
54

65
define PROJECT_ENV

0 commit comments

Comments
 (0)