Skip to content

Commit b4efe04

Browse files
authored
Merge pull request #11338 from rabbitmq/loic-make-make-maker
Making make better
2 parents f39b7bb + bd06d8c commit b4efe04

File tree

8 files changed

+83
-79
lines changed

8 files changed

+83
-79
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PROJECT_DESCRIPTION = RabbitMQ Server
55
# other components. If PROJECT_VERSION is unset, then an empty variable
66
# is propagated and the default version will fallback to the default
77
# value from rabbitmq-components.mk.
8-
export RABBITMQ_VERSION = $(PROJECT_VERSION)
8+
export RABBITMQ_VERSION := $(PROJECT_VERSION)
99

1010
# Release artifacts are put in $(PACKAGES_DIR).
1111
PACKAGES_DIR ?= $(abspath PACKAGES)
@@ -29,6 +29,7 @@ DEP_PLUGINS = rabbit_common/mk/rabbitmq-dist.mk \
2929

3030
DISABLE_DISTCLEAN = 1
3131

32+
ifeq ($(filter-out xref,$(MAKECMDGOALS)),)
3233
XREF_SCOPE = app deps
3334

3435
# We add all the applications that are in non-standard paths
@@ -47,12 +48,19 @@ XREF_IGNORE = [ \
4748

4849
# Include Elixir libraries in the Xref checks.
4950
xref: ERL_LIBS := $(ERL_LIBS):$(CURDIR)/apps:$(CURDIR)/deps:$(dir $(shell elixir --eval ":io.format '~s~n', [:code.lib_dir :elixir ]"))
51+
endif
5052

5153
ifneq ($(wildcard deps/.hex/cache.erl),)
5254
deps:: restore-hex-cache-ets-file
5355
endif
5456

5557
include rabbitmq-components.mk
58+
59+
# Set PROJECT_VERSION, calculated in rabbitmq-components.mk,
60+
# in stone now, because in this Makefile we will be using it
61+
# multiple times (including for release file names and whatnot).
62+
PROJECT_VERSION := $(PROJECT_VERSION)
63+
5664
include erlang.mk
5765
include mk/github-actions.mk
5866
include mk/bazel.mk

deps/rabbit/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@ ifdef TRACE_SUPERVISOR2
247247
RMQ_ERLC_OPTS += -DTRACE_SUPERVISOR2=true
248248
endif
249249

250-
ifndef USE_PROPER_QC
251-
# PropEr needs to be installed for property checking
252-
# http://proper.softlab.ntua.gr/
253-
USE_PROPER_QC := $(shell $(ERL) -eval 'io:format({module, proper} =:= code:ensure_loaded(proper)), halt().')
254-
RMQ_ERLC_OPTS += $(if $(filter true,$(USE_PROPER_QC)),-Duse_proper_qc)
255-
endif
256-
257250
# --------------------------------------------------------------------
258251
# Documentation.
259252
# --------------------------------------------------------------------

deps/rabbit_common/mk/rabbitmq-dist.mk

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -214,77 +214,32 @@ do-dist:: $(DIST_EZS)
214214
CLI_SCRIPTS_LOCK = $(CLI_SCRIPTS_DIR).lock
215215
CLI_ESCRIPTS_LOCK = $(CLI_ESCRIPTS_DIR).lock
216216

217+
ifeq ($(MAKELEVEL),0)
217218
ifneq ($(filter-out rabbit_common amqp10_common rabbitmq_stream_common,$(PROJECT)),)
218219
app:: install-cli
219220
test-build:: install-cli
220221
endif
222+
endif
221223

222224
install-cli: install-cli-scripts install-cli-escripts
223225
@:
224226

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-
251227
install-cli-scripts:
252228
$(gen_verbose) \
253229
set -e; \
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"; \
230+
test -d "$(DEPS_DIR)/rabbit/scripts"; \
263231
if command -v flock >/dev/null; then \
264232
flock $(CLI_SCRIPTS_LOCK) \
265233
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'; \
234+
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/'; \
271235
elif command -v lockf >/dev/null; then \
272236
lockf $(CLI_SCRIPTS_LOCK) \
273237
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'; \
238+
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/'; \
279239
else \
280240
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; \
241+
cp -a $(DEPS_DIR)/rabbit/scripts/* $(CLI_SCRIPTS_DIR)/; \
286242
fi
287-
endif
288243

289244
install-cli-escripts:
290245
$(gen_verbose) \

deps/rabbit_common/mk/rabbitmq-run.mk

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ RABBITMQ_ENABLED_PLUGINS_FILE ?= $(call node_enabled_plugins_file,$(RABBITMQ_NOD
9696
RABBITMQ_LOG ?= debug,+color
9797
export RABBITMQ_LOG
9898

99-
# erlang.mk adds dependencies' ebin directory to ERL_LIBS. This is
100-
# a sane default, but we prefer to rely on the .ez archives in the
101-
# `plugins` directory so the plugin code is executed. The `plugins`
102-
# directory is added to ERL_LIBS by rabbitmq-env.
103-
DIST_ERL_LIBS = $(patsubst :%,%,$(patsubst %:,%,$(subst :$(APPS_DIR):,:,$(subst :$(DEPS_DIR):,:,:$(ERL_LIBS):))))
99+
FAST_RUN_BROKER ?= 1
100+
101+
ifeq ($(FAST_RUN_BROKER),1)
102+
DIST_TARGET = $(if $(NOBUILD),,all)
103+
PLUGINS_FROM_DEPS_DIR = 1
104+
endif
104105

105106
ifdef PLUGINS_FROM_DEPS_DIR
106-
RMQ_PLUGINS_DIR=$(DEPS_DIR)
107+
RMQ_PLUGINS_DIR = $(DEPS_DIR)
108+
DIST_ERL_LIBS = $(ERL_LIBS)
107109
else
108-
RMQ_PLUGINS_DIR=$(CURDIR)/$(DIST_DIR)
110+
RMQ_PLUGINS_DIR = $(CURDIR)/$(DIST_DIR)
111+
# We do not want to add apps/ or deps/ to ERL_LIBS
112+
# when running the release from dist. The `plugins`
113+
# directory is added to ERL_LIBS by rabbitmq-env.
114+
DIST_ERL_LIBS = $(patsubst :%,%,$(patsubst %:,%,$(subst :$(APPS_DIR):,:,$(subst :$(DEPS_DIR):,:,:$(ERL_LIBS):))))
109115
endif
110116

111117
node_plugins_dir = $(if $(RABBITMQ_PLUGINS_DIR),$(RABBITMQ_PLUGINS_DIR),$(if $(EXTRA_PLUGINS_DIR),$(EXTRA_PLUGINS_DIR):$(RMQ_PLUGINS_DIR),$(RMQ_PLUGINS_DIR)))
@@ -410,6 +416,42 @@ stop-brokers stop-cluster:
410416
done; \
411417
wait
412418

419+
# --------------------------------------------------------------------
420+
# Code reloading.
421+
#
422+
# For `make run-broker` either do:
423+
# * make RELOAD=1
424+
# * make all reload-broker (can't do this alongside -j flag)
425+
# * make && make reload-broker (fine with -j flag)
426+
#
427+
# Or if recompiling a specific application:
428+
# * make -C deps/rabbit RELOAD=1
429+
#
430+
# For `make start-cluster` use the `reload-cluster` target.
431+
# Same constraints apply as with `reload-broker`:
432+
# * make all reload-cluster
433+
# * make && make reload-cluster
434+
# --------------------------------------------------------------------
435+
436+
reload-broker:
437+
$(exec_verbose) ERL_LIBS="$(DIST_ERL_LIBS)" \
438+
$(RABBITMQCTL) -n $(RABBITMQ_NODENAME) \
439+
eval "io:format(\"~p~n\", [c:lm()])."
440+
441+
ifeq ($(MAKELEVEL),0)
442+
ifdef RELOAD
443+
all:: reload-broker
444+
endif
445+
endif
446+
447+
reload-cluster:
448+
@for n in $$(seq $(NODES) -1 1); do \
449+
nodename="rabbit-$$n@$(HOSTNAME)"; \
450+
$(MAKE) reload-broker \
451+
RABBITMQ_NODENAME="$$nodename" & \
452+
done; \
453+
wait
454+
413455
# --------------------------------------------------------------------
414456
# Used by testsuites.
415457
# --------------------------------------------------------------------

deps/rabbitmq_auth_backend_oauth2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BUILD_WITHOUT_QUIC=1
66
export BUILD_WITHOUT_QUIC
77

88
LOCAL_DEPS = inets public_key
9-
BUILD_DEPS = rabbit_common oauth2_client
9+
BUILD_DEPS = rabbit_common
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_mqtt emqtt
1212

deps/rabbitmq_cli/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ app:: $(ESCRIPTS)
7878
@:
7979

8080
rabbitmqctl_srcs := mix.exs \
81-
$(shell find config lib -name "*.ex" -o -name "*.exs")
81+
$(call core_find,config/,*.exs) \
82+
$(call core_find,lib/,*.ex)
8283

8384
# Elixir dependencies are fetched and compiled as part of the alias
8485
# `mix make_all`. We do not fetch and build them in `make deps` because

erlang.mk

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
1818
export ERLANG_MK_FILENAME
1919

20-
ERLANG_MK_VERSION = 04c473a
20+
ERLANG_MK_VERSION = 2022.05.31-69-gb54e4b5-dirty
2121
ERLANG_MK_WITHOUT =
2222

2323
# Make 3.81 and 3.82 are deprecated.
@@ -184,8 +184,9 @@ core_http_get = curl -Lf$(if $(filter-out 0,$(V)),,s)o $(call core_native_path,$
184184

185185
core_eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
186186

187-
# We skip files that contain spaces or '#' because they end up causing issues.
188-
core_find = $(if $(wildcard $1),$(shell find $(1:%/=%) \( -type l -o -type f \) -name $(subst *,\*,$2) -not -name "*[ \#]*"))
187+
# We skip files that contain spaces because they end up causing issues.
188+
# Files that begin with a dot are already ignored by the wildcard function.
189+
core_find = $(foreach f,$(wildcard $(1:%/=%)/$2),$(if $(wildcard $f/.),$(call core_find,$f,$2),$(if $(wildcard $f),$f)))
189190

190191
core_lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(1)))))))))))))))))))))))))))
191192

@@ -3564,8 +3565,10 @@ export DEPS_DIR
35643565
REBAR_DEPS_DIR = $(DEPS_DIR)
35653566
export REBAR_DEPS_DIR
35663567

3568+
# When testing Erlang.mk and updating these, make sure
3569+
# to delete test/test_rebar_git before running tests again.
35673570
REBAR3_GIT ?= https://github.com/erlang/rebar3
3568-
REBAR3_COMMIT ?= 3f563feaf1091a1980241adefa83a32dd2eebf7c # 3.20.0
3571+
REBAR3_COMMIT ?= bde4b54248d16280b2c70a244aca3bb7566e2033 # 3.23.0
35693572

35703573
CACHE_DEPS ?= 0
35713574

@@ -4018,7 +4021,7 @@ define dep_autopatch_rebar.erl
40184021
false -> ok;
40194022
{_, Files0} ->
40204023
Files = [begin
4021-
hd(filelib:wildcard("$(call core_native_path,$(DEPS_DIR)/$1/src/**/" ++ filename:rootname(F) ++ ".*rl")))
4024+
hd(filelib:wildcard("$(call core_native_path,$(DEPS_DIR)/$1/src/)**/" ++ filename:rootname(F) ++ ".*rl"))
40224025
end || "src/" ++ F <- Files0],
40234026
Names = [[" ", case lists:reverse(F) of
40244027
"lre." ++ Elif -> lists:reverse(Elif);
@@ -4147,8 +4150,8 @@ define dep_autopatch_rebar.erl
41474150
"\t$$\(CC) -o $$\@ $$\? $$\(LDFLAGS) $$\(ERL_LDFLAGS) $$\(DRV_LDFLAGS) $$\(LDLIBS) $$\(EXE_LDFLAGS)",
41484151
case {filename:extension(Output), $(PLATFORM)} of
41494152
{[], _} -> "\n";
4150-
{".so", darwin} -> "-shared\n";
4151-
{".dylib", darwin} -> "-shared\n";
4153+
{".so", darwin} -> " -shared\n";
4154+
{".dylib", darwin} -> " -shared\n";
41524155
{_, darwin} -> "\n";
41534156
_ -> " -shared\n"
41544157
end])
@@ -4665,7 +4668,6 @@ define makedep.erl
46654668
end,
46664669
MakeDepend = fun
46674670
(F, Fd, Mod, StartLocation) ->
4668-
{ok, Filename} = file:pid2name(Fd),
46694671
case io:parse_erl_form(Fd, undefined, StartLocation) of
46704672
{ok, AbsData, EndLocation} ->
46714673
case AbsData of
@@ -5838,7 +5840,7 @@ else
58385840

58395841
ci:: $(addprefix ci-,$(CI_OTP))
58405842

5841-
ci-prepare: $(addprefix $(KERL_INSTALL_DIR)/,$(CI_OTP))
5843+
ci-prepare: $(addprefix ci-prepare-,$(CI_OTP))
58425844

58435845
ci-setup::
58445846
$(verbose) :
@@ -5850,7 +5852,10 @@ ci_verbose_0 = @echo " CI " $(1);
58505852
ci_verbose = $(ci_verbose_$(V))
58515853

58525854
define ci_target
5853-
ci-$1: $(KERL_INSTALL_DIR)/$2
5855+
ci-prepare-$1: $(KERL_INSTALL_DIR)/$2
5856+
$(verbose) :
5857+
5858+
ci-$1: ci-prepare-$1
58545859
$(verbose) $(MAKE) --no-print-directory clean
58555860
$(ci_verbose) \
58565861
PATH="$(KERL_INSTALL_DIR)/$2/bin:$(PATH)" \

rabbitmq-components.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif
1414
PROJECT_VERSION := $(RABBITMQ_VERSION)
1515

1616
ifeq ($(PROJECT_VERSION),)
17-
PROJECT_VERSION := $(shell \
17+
PROJECT_VERSION = $(shell \
1818
if test -f git-revisions.txt; then \
1919
head -n1 git-revisions.txt | \
2020
awk '{print $$$(words $(PROJECT_DESCRIPTION) version);}'; \

0 commit comments

Comments
 (0)