Skip to content

Commit 6faaf13

Browse files
Merge pull request #13472 from rabbitmq/mergify/bp/v4.1.x/pr-13471
(Updated) Adding a "source-bundle" target to the Makefile (backport #13471)
2 parents 1da0f9d + d0d7587 commit 6faaf13

File tree

1 file changed

+149
-112
lines changed

1 file changed

+149
-112
lines changed

Makefile

Lines changed: 149 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -134,30 +134,17 @@ define restore_hex_cache_from_erl_term
134134
endef
135135

136136
# --------------------------------------------------------------------
137-
# Distribution.
137+
# Distribution - common variables and generic functions.
138138
# --------------------------------------------------------------------
139139

140-
.PHONY: source-dist clean-source-dist
141-
142-
SOURCE_DIST_BASE ?= rabbitmq-server
143-
SOURCE_DIST_SUFFIXES ?= tar.xz
144-
SOURCE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_DIST_BASE)-$(PROJECT_VERSION)
145-
146-
# The first source distribution file is used by packages: if the archive
147-
# type changes, you must update all packages' Makefile.
148-
SOURCE_DIST_FILES = $(addprefix $(SOURCE_DIST).,$(SOURCE_DIST_SUFFIXES))
149-
150-
.PHONY: $(SOURCE_DIST_FILES)
151-
152-
source-dist: $(SOURCE_DIST_FILES)
153-
@:
154-
155140
RSYNC ?= rsync
156141
RSYNC_V_0 =
157142
RSYNC_V_1 = -v
158143
RSYNC_V_2 = -v
159144
RSYNC_V = $(RSYNC_V_$(V))
160-
RSYNC_FLAGS += -a $(RSYNC_V) \
145+
BASE_RSYNC_FLAGS += -a $(RSYNC_V) \
146+
--delete \
147+
--delete-excluded \
161148
--exclude '.sw?' --exclude '.*.sw?' \
162149
--exclude '*.beam' \
163150
--exclude '*.d' \
@@ -188,12 +175,10 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
188175
--exclude '$(notdir $(DEPS_DIR))/' \
189176
--exclude 'hexer*' \
190177
--exclude 'logs/' \
191-
--exclude 'packaging' \
192178
--exclude 'PKG_*.md' \
193179
--exclude '/plugins/' \
194180
--include 'cli/plugins' \
195181
--exclude '$(notdir $(DIST_DIR))/' \
196-
--exclude 'test' \
197182
--exclude '/$(notdir $(PACKAGES_DIR))/' \
198183
--exclude '/PACKAGES/' \
199184
--exclude '/amqp_client/doc/' \
@@ -208,9 +193,21 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
208193
--exclude '/ranch/doc/' \
209194
--exclude '/ranch/examples/' \
210195
--exclude '/sockjs/examples/' \
211-
--exclude '/workflow_sources/' \
212-
--delete \
213-
--delete-excluded
196+
--exclude '/workflow_sources/'
197+
198+
SOURCE_DIST_RSYNC_FLAGS += $(BASE_RSYNC_FLAGS) \
199+
--exclude 'packaging' \
200+
--exclude 'test'
201+
202+
# For source-bundle, explicitly include folders that are needed
203+
# for tests to execute. These are added before excludes from
204+
# the base flags so rsync honors the first match.
205+
SOURCE_BUNDLE_RSYNC_FLAGS += \
206+
--include 'rabbit_shovel_test/ebin' \
207+
--include 'rabbit_shovel_test/ebin/*' \
208+
--include 'rabbitmq_ct_helpers/tools' \
209+
--include 'rabbitmq_ct_helpers/tools/*' \
210+
$(BASE_RSYNC_FLAGS)
214211

215212
TAR ?= tar
216213
TAR_V_0 =
@@ -228,65 +225,125 @@ ZIP_V_1 =
228225
ZIP_V_2 =
229226
ZIP_V = $(ZIP_V_$(V))
230227

231-
.PHONY: $(SOURCE_DIST)
232-
.PHONY: clean-source-dist distclean-packages clean-unpacked-source-dist
233-
234-
$(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
235-
$(verbose) mkdir -p $(dir $@)
236-
$(gen_verbose) $(RSYNC) $(RSYNC_FLAGS) ./ $@/
237-
$(verbose) echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > "$@/git-revisions.txt"
238-
$(verbose) echo "$(PROJECT) $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> "$@/git-revisions.txt"
239-
$(verbose) echo "$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > "$@.git-times.txt"
240-
$(verbose) cat packaging/common/LICENSE.head > $@/LICENSE
241-
$(verbose) mkdir -p $@/deps/licensing
242-
$(verbose) set -e; for dep in $$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
243-
$(RSYNC) $(RSYNC_FLAGS) \
244-
$$dep \
245-
$@/deps; \
228+
ifeq ($(shell tar --version | grep -c "GNU tar"),0)
229+
# Skip all flags if this is Darwin (a.k.a. macOS, a.k.a. OS X)
230+
ifeq ($(shell uname | grep -c "Darwin"),0)
231+
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --uid 0 \
232+
--gid 0 \
233+
--numeric-owner \
234+
--no-acls \
235+
--no-fflags \
236+
--no-xattrs
237+
endif
238+
else
239+
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --owner 0 \
240+
--group 0 \
241+
--numeric-owner
242+
endif
243+
244+
DIST_SUFFIXES ?= tar.xz
245+
246+
# Function to create distribution targets
247+
# Args: $(1) - Full distribution path
248+
# $(2) - RSYNC flags to use
249+
define create_dist_target
250+
$(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
251+
$${verbose} mkdir -p $$(dir $$@)
252+
$${gen_verbose} $${RSYNC} $(2) ./ $$@/
253+
$${verbose} echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > $$@/git-revisions.txt
254+
$${verbose} echo "$(PROJECT) $$$$(git rev-parse HEAD) $$$$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> $$@/git-revisions.txt
255+
$${verbose} echo "$$$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > $$@.git-times.txt
256+
$${verbose} cat packaging/common/LICENSE.head > $$@/LICENSE
257+
$${verbose} mkdir -p $$@/deps/licensing
258+
$${verbose} set -e; for dep in $$$$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
259+
$${RSYNC} $(2) \
260+
$$$$dep \
261+
$$@/deps; \
246262
rm -f \
247-
$@/deps/rabbit_common/rebar.config \
248-
$@/deps/rabbit_common/rebar.lock; \
249-
if test -f $@/deps/$$(basename $$dep)/erlang.mk && \
250-
test "$$(wc -l $@/deps/$$(basename $$dep)/erlang.mk | awk '{print $$1;}')" = "1" && \
251-
grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" $@/deps/$$(basename $$dep)/erlang.mk; then \
252-
echo "include ../../erlang.mk" > $@/deps/$$(basename $$dep)/erlang.mk; \
263+
$$@/deps/rabbit_common/rebar.config \
264+
$$@/deps/rabbit_common/rebar.lock; \
265+
if test -f $$@/deps/$$$$(basename $$$$dep)/erlang.mk && \
266+
test "$$$$(wc -l $$@/deps/$$$$(basename $$$$dep)/erlang.mk | awk '{print $$$$1;}')" = "1" && \
267+
grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$$$" $$@/deps/$$$$(basename $$$$dep)/erlang.mk; then \
268+
echo "include ../../erlang.mk" > $$@/deps/$$$$(basename $$$$dep)/erlang.mk; \
253269
fi; \
254-
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$|include ../../erlang.mk|" \
255-
$@/deps/$$(basename $$dep)/Makefile && \
256-
rm $@/deps/$$(basename $$dep)/Makefile.bak; \
257-
mix_exs=$@/deps/$$(basename $$dep)/mix.exs; \
258-
if test -f $$mix_exs; then \
259-
(cd $$(dirname "$$mix_exs") && \
260-
(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) && \
261-
env DEPS_DIR=$@/deps MIX_HOME=$@/deps/.mix HEX_HOME=$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix deps.get --only prod && \
270+
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$$$|include ../../erlang.mk|" \
271+
$$@/deps/$$$$(basename $$$$dep)/Makefile && \
272+
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 && \
262278
cp $(CURDIR)/mk/rabbitmq-mix.mk . && \
263279
rm -rf _build deps); \
264280
fi; \
265-
if test -f "$$dep/license_info"; then \
266-
cp "$$dep/license_info" "$@/deps/licensing/license_info_$$(basename "$$dep")"; \
267-
cat "$$dep/license_info" >> $@/LICENSE; \
281+
if test -f "$$$$dep/license_info"; then \
282+
cp "$$$$dep/license_info" "$$@/deps/licensing/license_info_$$$$(basename $$$$dep)"; \
283+
cat "$$$$dep/license_info" >> $$@/LICENSE; \
268284
fi; \
269-
find "$$dep" -maxdepth 1 -name 'LICENSE-*' -exec cp '{}' $@/deps/licensing \; ; \
270-
(cd $$dep; \
271-
echo "$$(basename "$$dep") $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)") \
272-
>> "$@/git-revisions.txt"; \
273-
! test -d $$dep/.git || (cd $$dep; \
274-
echo "$$(env TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')") \
275-
>> "$@.git-times.txt"; \
285+
find "$$$$dep" -maxdepth 1 -name 'LICENSE-*' -exec cp '{}' $$@/deps/licensing \; ; \
286+
(cd $$$$dep; \
287+
echo "$$$$(basename "$$$$dep") $$$$(git rev-parse HEAD) $$$$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)") \
288+
>> "$$@/git-revisions.txt"; \
289+
! test -d $$$$dep/.git || (cd $$$$dep; \
290+
echo "$$$$(env TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')") \
291+
>> "$$@.git-times.txt"; \
276292
done
277-
$(verbose) cat packaging/common/LICENSE.tail >> $@/LICENSE
278-
$(verbose) find $@/deps/licensing -name 'LICENSE-*' -exec cp '{}' $@ \;
279-
$(verbose) rm -rf $@/deps/licensing
280-
$(verbose) for file in $$(find $@ -name '*.app.src'); do \
293+
$${verbose} cat packaging/common/LICENSE.tail >> $$@/LICENSE
294+
$${verbose} find $$@/deps/licensing -name 'LICENSE-*' -exec cp '{}' $$@ \;
295+
$${verbose} rm -rf $$@/deps/licensing
296+
$${verbose} for file in $$$$(find $$@ -name '*.app.src'); do \
281297
sed -E -i.bak \
282298
-e 's/[{]vsn[[:blank:]]*,[[:blank:]]*(""|"0.0.0")[[:blank:]]*}/{vsn, "$(PROJECT_VERSION)"}/' \
283299
-e 's/[{]broker_version_requirements[[:blank:]]*,[[:blank:]]*\[\][[:blank:]]*}/{broker_version_requirements, ["$(PROJECT_VERSION)"]}/' \
284-
$$file; \
285-
rm $$file.bak; \
300+
$$$$file; \
301+
rm $$$$file.bak; \
286302
done
287-
$(verbose) echo "PLUGINS := $(PLUGINS)" > $@/plugins.mk
288-
# Remember the latest Git timestamp.
289-
$(verbose) sort -r < "[email protected]" | head -n 1 > "[email protected]"
303+
$${verbose} echo "PLUGINS := $(PLUGINS)" > $$@/plugins.mk
304+
$${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)))
306+
$${verbose} find $$@ -print0 | xargs -0 touch -t "$$$$(cat $$@.git-time.txt)"
307+
$${verbose} rm "$$@.git-times.txt" "$$@.git-time.txt"
308+
309+
$(1).manifest: $(1)
310+
$${gen_verbose} cd $$(dir $$@) && \
311+
find $$(notdir $$<) | LC_COLLATE=C sort > $$@
312+
313+
$(1).tar.xz: $(1).manifest
314+
$${gen_verbose} cd $$(dir $$@) && \
315+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
316+
$${XZ} > $$@
317+
318+
$(1).tar.gz: $(1).manifest
319+
$${gen_verbose} cd $$(dir $$@) && \
320+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
321+
$${GZIP} --best > $$@
322+
323+
$(1).tar.bz2: $(1).manifest
324+
$${gen_verbose} cd $$(dir $$@) && \
325+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
326+
$${BZIP2} > $$@
327+
328+
$(1).zip: $(1).manifest
329+
$${verbose} rm -f $$@
330+
$${gen_verbose} cd $$(dir $$@) && \
331+
$${ZIP} $${ZIP_V} --names-stdin $$@ < $$(notdir $$<)
332+
333+
endef
334+
335+
# Function to create clean targets
336+
# Args: $(1) - Base name (e.g. SOURCE_DIST_BASE or BUNDLE_DIST_BASE)
337+
define create_clean_targets
338+
.PHONY: clean-$(1)
339+
340+
clean-$(1):
341+
$${gen_verbose} rm -rf -- $(1)-*
342+
343+
# Add each clean target to the clean:: rule
344+
clean:: clean-$(1)
345+
endef
346+
290347
# Mix Hex component requires a cache file, otherwise it refuses to build
291348
# offline... That cache is an ETS table with all the applications we
292349
# depend on, plus some versioning informations and checksums. There
@@ -300,11 +357,6 @@ $(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
300357
#
301358
# The ETS file must be recreated before compiling RabbitMQ. See the
302359
# `restore-hex-cache-ets-file` Make target.
303-
$(verbose) $(call erlang,$(call dump_hex_cache_to_erl_term,$(call core_native_path,$@),$(call core_native_path,[email protected])))
304-
# Fix file timestamps to have reproducible source archives.
305-
$(verbose) find $@ -print0 | xargs -0 touch -t "$$(cat "[email protected]")"
306-
307-
308360
define dump_hex_cache_to_erl_term
309361
In = "$(1)/deps/.hex/cache.ets",
310362
Out = "$(1)/deps/.hex/cache.erl",
@@ -333,50 +385,35 @@ define dump_hex_cache_to_erl_term
333385
init:stop().
334386
endef
335387

336-
$(SOURCE_DIST).manifest: $(SOURCE_DIST)
337-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
338-
find $(notdir $(SOURCE_DIST)) | LC_COLLATE=C sort > $@
388+
# --------------------------------------------------------------------
389+
# Distribution - public targets
390+
# --------------------------------------------------------------------
339391

340-
ifeq ($(shell tar --version | grep -c "GNU tar"),0)
341-
# Skip all flags if this is Darwin (a.k.a. macOS, a.k.a. OS X)
342-
ifeq ($(shell uname | grep -c "Darwin"),0)
343-
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --uid 0 \
344-
--gid 0 \
345-
--numeric-owner \
346-
--no-acls \
347-
--no-fflags \
348-
--no-xattrs
349-
endif
350-
else
351-
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --owner 0 \
352-
--group 0 \
353-
--numeric-owner
354-
endif
392+
SOURCE_DIST_BASE ?= rabbitmq-server
393+
SOURCE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_DIST_BASE)-$(PROJECT_VERSION)
394+
SOURCE_DIST_FILES = $(addprefix $(SOURCE_DIST).,$(DIST_SUFFIXES))
355395

356-
$(SOURCE_DIST).tar.gz: $(SOURCE_DIST).manifest
357-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
358-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
359-
$(GZIP) --best > $@
396+
.PHONY: source-dist
397+
source-dist: $(SOURCE_DIST_FILES)
398+
@:
399+
400+
$(eval $(call create_dist_target,$(SOURCE_DIST),$(SOURCE_DIST_RSYNC_FLAGS)))
360401

361-
$(SOURCE_DIST).tar.bz2: $(SOURCE_DIST).manifest
362-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
363-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
364-
$(BZIP2) > $@
402+
SOURCE_BUNDLE_BASE ?= rabbitmq-server-bundle
403+
SOURCE_BUNDLE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_BUNDLE_BASE)-$(PROJECT_VERSION)
404+
SOURCE_BUNDLE_FILES = $(addprefix $(SOURCE_BUNDLE_DIST).,$(DIST_SUFFIXES))
365405

366-
$(SOURCE_DIST).tar.xz: $(SOURCE_DIST).manifest
367-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
368-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
369-
$(XZ) > $@
406+
.PHONY: source-bundle
407+
source-bundle: $(SOURCE_BUNDLE_FILES)
408+
@:
370409

371-
$(SOURCE_DIST).zip: $(SOURCE_DIST).manifest
372-
$(verbose) rm -f $@
373-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
374-
$(ZIP) $(ZIP_V) --names-stdin $@ < $(SOURCE_DIST).manifest
410+
$(eval $(call create_dist_target,$(SOURCE_BUNDLE_DIST),$(SOURCE_BUNDLE_RSYNC_FLAGS)))
375411

376-
clean:: clean-source-dist
412+
# Create the clean targets for both distributions
413+
$(eval $(call create_clean_targets,$(SOURCE_DIST_BASE)))
414+
$(eval $(call create_clean_targets,$(SOURCE_BUNDLE_BASE)))
377415

378-
clean-source-dist:
379-
$(gen_verbose) rm -rf -- $(SOURCE_DIST_BASE)-*
416+
.PHONY: distclean-packages clean-unpacked-source-dist
380417

381418
distclean:: distclean-packages
382419

0 commit comments

Comments
 (0)