Skip to content

Commit 38f5422

Browse files
committed
Revert "Use Erlang.mk's native Elixir support for CLI"
This reverts commit 398a845.
1 parent 398a845 commit 38f5422

File tree

34 files changed

+4104
-1111
lines changed

34 files changed

+4104
-1111
lines changed

Makefile

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ DISABLE_DISTCLEAN = 1
3131

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+
3438
# For Elixir protocols the right fix is to include the consolidated/
3539
# folders in addition to ebin/. However this creates conflicts because
3640
# some modules are duplicated. So instead we ignore warnings from
@@ -44,12 +48,64 @@ XREF_IGNORE = [ \
4448
# Include Elixir libraries in the Xref checks.
4549
xref: ERL_LIBS := $(ERL_LIBS):$(CURDIR)/apps:$(CURDIR)/deps:$(dir $(shell elixir --eval ":io.format '~s~n', [:code.lib_dir :elixir ]"))
4650

51+
ifneq ($(wildcard deps/.hex/cache.erl),)
52+
deps:: restore-hex-cache-ets-file
53+
endif
54+
4755
include rabbitmq-components.mk
4856
include erlang.mk
4957
include mk/github-actions.mk
5058
include mk/bazel.mk
5159
include mk/topic-branches.mk
5260

61+
# --------------------------------------------------------------------
62+
# Mix Hex cache management.
63+
# --------------------------------------------------------------------
64+
65+
# We restore the initial Hex cache.ets file from an Erlang term created
66+
# at the time the source archive was prepared.
67+
#
68+
# See the `$(SOURCE_DIST)` recipe for the reason behind this step.
69+
70+
restore-hex-cache-ets-file: deps/.hex/cache.ets
71+
72+
deps/.hex/cache.ets: deps/.hex/cache.erl
73+
$(gen_verbose) $(call erlang,$(call restore_hex_cache_from_erl_term,$<,$@))
74+
75+
define restore_hex_cache_from_erl_term
76+
In = "$(1)",
77+
Out = "$(2)",
78+
{ok, [Props, Entries]} = file:consult(In),
79+
Name = proplists:get_value(name, Props),
80+
Type = proplists:get_value(type, Props),
81+
Access = proplists:get_value(protection, Props),
82+
NamedTable = proplists:get_bool(named_table, Props),
83+
Keypos = proplists:get_value(keypos, Props),
84+
Heir = proplists:get_value(heir, Props),
85+
ReadConc = proplists:get_bool(read_concurrency, Props),
86+
WriteConc = proplists:get_bool(write_concurrency, Props),
87+
Compressed = proplists:get_bool(compressed, Props),
88+
Options0 = [
89+
Type,
90+
Access,
91+
{keypos, Keypos},
92+
{heir, Heir},
93+
{read_concurrency, ReadConc},
94+
{write_concurrency, WriteConc}],
95+
Options1 = case NamedTable of
96+
true -> [named_table | Options0];
97+
false -> Options0
98+
end,
99+
Options2 = case Compressed of
100+
true -> [compressed | Options0];
101+
false -> Options0
102+
end,
103+
Tab = ets:new(Name, Options2),
104+
[true = ets:insert(Tab, Entry) || Entry <- Entries],
105+
ok = ets:tab2file(Tab, Out),
106+
init:stop().
107+
endef
108+
53109
# --------------------------------------------------------------------
54110
# Distribution - common variables and generic functions.
55111
# --------------------------------------------------------------------
@@ -192,6 +248,14 @@ $(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
192248
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$$$|include ../../erlang.mk|" \
193249
$$@/deps/$$$$(basename $$$$dep)/Makefile && \
194250
rm $$@/deps/$$$$(basename $$$$dep)/Makefile.bak; \
251+
mix_exs=$$@/deps/$$$$(basename $$$$dep)/mix.exs; \
252+
if test -f $$$$mix_exs; then \
253+
(cd $$$$(dirname "$$$$mix_exs") && \
254+
(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) && \
255+
env DEPS_DIR=$$@/deps MIX_HOME=$$@/deps/.mix HEX_HOME=$$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix deps.get --only prod && \
256+
cp $(CURDIR)/mk/rabbitmq-mix.mk . && \
257+
rm -rf _build deps); \
258+
fi; \
195259
if test -f "$$$$dep/license_info"; then \
196260
cp "$$$$dep/license_info" "$$@/deps/licensing/license_info_$$$$(basename $$$$dep)"; \
197261
cat "$$$$dep/license_info" >> $$@/LICENSE; \
@@ -216,6 +280,7 @@ $(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
216280
done
217281
$${verbose} echo "PLUGINS := $(PLUGINS)" > $$@/plugins.mk
218282
$${verbose} sort -r < "$$@.git-times.txt" | head -n 1 > "$$@.git-time.txt"
283+
$${verbose} $$(call erlang,$$(call dump_hex_cache_to_erl_term,$$(call core_native_path,$$@),$$(call core_native_path,$$@.git-time.txt)))
219284
$${verbose} find $$@ -print0 | xargs -0 touch -t "$$$$(cat $$@.git-time.txt)"
220285
$${verbose} rm "$$@.git-times.txt" "$$@.git-time.txt"
221286

@@ -257,6 +322,47 @@ clean-$(1):
257322
clean:: clean-$(1)
258323
endef
259324

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

deps/amqp10_client/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT = amqp10_client
2-
PROJECT_DESCRIPTION = AMQP 1.0 client
2+
PROJECT_DESCRIPTION = AMQP 1.0 client from the RabbitMQ Project
3+
PROJECT_MOD = amqp10_client_app
34

45
define PROJECT_APP_EXTRA_KEYS
56
%% Hex.pm package informations.

deps/oauth2_client/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT = oauth2_client
22
PROJECT_DESCRIPTION = OAuth2 client from the RabbitMQ Project
3+
PROJECT_MOD = oauth2_client_app
34

45
BUILD_DEPS = rabbit
56
DEPS = rabbit_common jose
@@ -17,8 +18,5 @@ DEP_PLUGINS = rabbit_common/mk/rabbitmq-macros.mk \
1718
rabbit_common/mk/rabbitmq-test.mk \
1819
rabbit_common/mk/rabbitmq-tools.mk
1920

20-
# Required to properly autopatch jose.
21-
ELIXIR = system
22-
2321
include rabbitmq-components.mk
2422
include erlang.mk

deps/rabbit/src/rabbit_variable_queue.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,6 @@ determine_persist_to(Version,
22182218
%% via the direct client), we make a guess based on the number of
22192219
%% headers.
22202220

2221-
%% @todo We can probably simplify this.
22222221
{MetaSize, _BodySize} = mc:size(Msg),
22232222
case BodySize >= IndexMaxSize of
22242223
true -> msg_store;

deps/rabbit_common/mk/rabbitmq-build.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ TEST_ERLC_OPTS += +nowarn_export_all
1515
ifneq ($(filter-out rabbit_common amqp_client,$(PROJECT)),)
1616
# Add the CLI ebin directory to the code path for the compiler: plugin
1717
# CLI extensions may access behaviour modules defined in this directory.
18-
19-
RMQ_ERLC_OPTS += -pa $(DEPS_DIR)/rabbitmq_cli/ebin
18+
RMQ_ERLC_OPTS += -pa $(DEPS_DIR)/rabbitmq_cli/_build/dev/lib/rabbitmqctl/ebin
2019
endif
2120

2221
RMQ_ERLC_OPTS += +deterministic

deps/rabbit_common/mk/rabbitmq-dist.mk

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
.PHONY: dist test-dist do-dist cli-scripts cli-escripts clean-dist
22

3-
DIST_DIR ?= $(CURDIR)/plugins
4-
CLI_SCRIPTS_DIR ?= $(CURDIR)/sbin
5-
CLI_ESCRIPTS_DIR ?= $(CURDIR)/escript
3+
DIST_DIR = plugins
4+
CLI_SCRIPTS_DIR = sbin
5+
CLI_ESCRIPTS_DIR = escript
6+
MIX = echo y | mix
67

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

8182
# Real entry point: it tests the existence of an .app file to determine
8283
# if it is an Erlang application (and therefore if it should be provided
83-
# as an .ez plugin archive) and calls do_ez_target_erlangmk.
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.
8488
#
8589
# $(call ez_target,path_to_app)
8690

8791
define ez_target
8892
dist_$(1)_appdir = $(2)
8993
dist_$(1)_appfile = $$(dist_$(1)_appdir)/ebin/$(1).app
94+
dist_$(1)_mixfile = $$(dist_$(1)_appdir)/mix.exs
9095

9196
$$(if $$(shell test -f $$(dist_$(1)_appfile) && echo OK), \
9297
$$(eval $$(call do_ez_target_erlangmk,$(1),$$(call get_app_version,$$(dist_$(1)_appfile)),$$(dist_$(1)_appdir))))
@@ -112,8 +117,9 @@ endif
112117
endif
113118

114119
# The actual recipe to create the .ez plugin archive. Some variables
115-
# are defined in the do_ez_target_erlangmk macro
116-
# above. All .ez archives are also listed in this macro.
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.
117123

118124
RSYNC ?= rsync
119125
RSYNC_V_0 =
@@ -198,7 +204,7 @@ test-dist:: $(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST) test-build
198204
$(MAYBE_APPS_LIST)"; \
199205
fi
200206

201-
DIST_EZS = $(ERLANGMK_DIST_EZS)
207+
DIST_EZS = $(ERLANGMK_DIST_EZS) $(MIX_DIST_EZS)
202208

203209
do-dist:: $(DIST_EZS)
204210
$(verbose) unwanted='$(filter-out $(DIST_EZS) $(EXTRA_DIST_EZS), \
@@ -216,21 +222,90 @@ endif
216222
install-cli: install-cli-scripts install-cli-escripts
217223
@:
218224

219-
install-cli-scripts: | $(CLI_SCRIPTS_DIR)
225+
ifeq ($(PROJECT),rabbit)
226+
install-cli-scripts:
227+
$(gen_verbose) \
228+
if command -v flock >/dev/null; then \
229+
flock $(CLI_SCRIPTS_LOCK) \
230+
sh -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
231+
for file in scripts/*; do \
232+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
233+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
234+
done'; \
235+
elif command -v lockf >/dev/null; then \
236+
lockf $(CLI_SCRIPTS_LOCK) \
237+
sh -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
238+
for file in scripts/*; do \
239+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
240+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
241+
done'; \
242+
else \
243+
mkdir -p "$(CLI_SCRIPTS_DIR)" && \
244+
for file in scripts/*; do \
245+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
246+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
247+
done; \
248+
fi
249+
else
250+
251+
install-cli-scripts:
220252
$(gen_verbose) \
221253
set -e; \
222-
test -d "$(DEPS_DIR)/rabbit/scripts"; \
223-
$(call maybe_flock,$(CLI_SCRIPTS_LOCK), \
224-
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/)
254+
if test -d "$(DEPS_DIR)/rabbit/scripts"; then \
255+
rabbit_scripts_dir='$(DEPS_DIR)/rabbit/scripts'; \
256+
elif test -d "$(DEPS_DIR)/../scripts"; then \
257+
rabbit_scripts_dir='$(DEPS_DIR)/../scripts'; \
258+
else \
259+
echo 'rabbit/scripts directory not found' 1>&2; \
260+
exit 1; \
261+
fi; \
262+
test -d "$$rabbit_scripts_dir"; \
263+
if command -v flock >/dev/null; then \
264+
flock $(CLI_SCRIPTS_LOCK) \
265+
sh -e -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
266+
for file in "'$$rabbit_scripts_dir'"/*; do \
267+
test -f "$$file"; \
268+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
269+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
270+
done'; \
271+
elif command -v lockf >/dev/null; then \
272+
lockf $(CLI_SCRIPTS_LOCK) \
273+
sh -e -c 'mkdir -p "$(CLI_SCRIPTS_DIR)" && \
274+
for file in "'$$rabbit_scripts_dir'"/*; do \
275+
test -f "$$file"; \
276+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
277+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
278+
done'; \
279+
else \
280+
mkdir -p "$(CLI_SCRIPTS_DIR)" && \
281+
for file in "$$rabbit_scripts_dir"/*; do \
282+
test -f "$$file"; \
283+
cmp -s "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")" || \
284+
cp -a "$$file" "$(CLI_SCRIPTS_DIR)/$$(basename "$$file")"; \
285+
done; \
286+
fi
287+
endif
225288

226-
install-cli-escripts: | $(CLI_ESCRIPTS_DIR)
227-
$(gen_verbose) $(call maybe_flock,$(CLI_ESCRIPTS_LOCK), \
289+
install-cli-escripts:
290+
$(gen_verbose) \
291+
if command -v flock >/dev/null; then \
292+
flock $(CLI_ESCRIPTS_LOCK) \
293+
sh -c 'mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
228294
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
229295
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
230-
DESTDIR= IS_DEP=1)
231-
232-
$(CLI_SCRIPTS_DIR) $(CLI_ESCRIPTS_DIR):
233-
$(verbose) mkdir -p $@
296+
DESTDIR='; \
297+
elif command -v lockf >/dev/null; then \
298+
lockf $(CLI_ESCRIPTS_LOCK) \
299+
sh -c 'mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
300+
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
301+
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
302+
DESTDIR='; \
303+
else \
304+
mkdir -p "$(CLI_ESCRIPTS_DIR)" && \
305+
$(MAKE) -C "$(DEPS_DIR)/rabbitmq_cli" install \
306+
PREFIX="$(abspath $(CLI_ESCRIPTS_DIR))" \
307+
DESTDIR= ; \
308+
fi
234309

235310
clean-dist::
236311
$(gen_verbose) rm -rf \

0 commit comments

Comments
 (0)