Skip to content

Commit 140ebcd

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. 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
1 parent 04a8067 commit 140ebcd

File tree

36 files changed

+974
-4025
lines changed

36 files changed

+974
-4025
lines changed

Makefile

Lines changed: 0 additions & 106 deletions
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,
@@ -85,54 +77,6 @@ ifdef PLUGINS
8577
RABBITMQ_ENABLED_PLUGINS ?= $(call comma_list,$(PLUGINS))
8678
endif
8779

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

@@ -344,47 +279,6 @@ clean-$(1):
344279
clean:: clean-$(1)
345280
endef
346281

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

deps/amqp10_client/Makefile

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

deps/rabbit/Makefile

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 41 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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: ERL_LIBS = $(APPS_DIR):$(DEPS_DIR):$(ELIXIR_LIBS)
88

99
# --------------------------------------------------------------------
1010
# Common Test flags.

deps/rabbitmq_auth_backend_cache/Makefile

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)