Skip to content

Commit 46cdadb

Browse files
kartgmergify[bot]
authored andcommitted
Adding a "source-bundle" target that largely duplicates the "source-dist" target
The main difference is that the "bundle" target does NOT exclude packaging and testing directories, which enables packaging and testing of the source archive. Signed-off-by: Kartik Ganesh <[email protected]> (cherry picked from commit 54cbb74)
1 parent 1da0f9d commit 46cdadb

File tree

1 file changed

+128
-13
lines changed

1 file changed

+128
-13
lines changed

Makefile

Lines changed: 128 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ endef
137137
# Distribution.
138138
# --------------------------------------------------------------------
139139

140+
140141
.PHONY: source-dist clean-source-dist
141142

142143
SOURCE_DIST_BASE ?= rabbitmq-server
@@ -152,12 +153,26 @@ SOURCE_DIST_FILES = $(addprefix $(SOURCE_DIST).,$(SOURCE_DIST_SUFFIXES))
152153
source-dist: $(SOURCE_DIST_FILES)
153154
@:
154155

156+
.PHONY: source-bundle clean-source-bundle
157+
158+
SOURCE_BUNDLE_BASE ?= rabbitmq-server-bundle
159+
BUNDLE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_BUNDLE_BASE)-$(PROJECT_VERSION)
160+
161+
BUNDLE_DIST_FILES = $(addprefix $(BUNDLE_DIST).,$(SOURCE_DIST_SUFFIXES))
162+
163+
.PHONY: $(BUNDLE_DIST_FILES)
164+
165+
source-bundle: $(BUNDLE_DIST_FILES)
166+
@:
167+
155168
RSYNC ?= rsync
156169
RSYNC_V_0 =
157170
RSYNC_V_1 = -v
158171
RSYNC_V_2 = -v
159172
RSYNC_V = $(RSYNC_V_$(V))
160-
RSYNC_FLAGS += -a $(RSYNC_V) \
173+
BASE_RSYNC_FLAGS += -a $(RSYNC_V) \
174+
--delete \
175+
--delete-excluded \
161176
--exclude '.sw?' --exclude '.*.sw?' \
162177
--exclude '*.beam' \
163178
--exclude '*.d' \
@@ -188,12 +203,10 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
188203
--exclude '$(notdir $(DEPS_DIR))/' \
189204
--exclude 'hexer*' \
190205
--exclude 'logs/' \
191-
--exclude 'packaging' \
192206
--exclude 'PKG_*.md' \
193207
--exclude '/plugins/' \
194208
--include 'cli/plugins' \
195209
--exclude '$(notdir $(DIST_DIR))/' \
196-
--exclude 'test' \
197210
--exclude '/$(notdir $(PACKAGES_DIR))/' \
198211
--exclude '/PACKAGES/' \
199212
--exclude '/amqp_client/doc/' \
@@ -208,9 +221,21 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
208221
--exclude '/ranch/doc/' \
209222
--exclude '/ranch/examples/' \
210223
--exclude '/sockjs/examples/' \
211-
--exclude '/workflow_sources/' \
212-
--delete \
213-
--delete-excluded
224+
--exclude '/workflow_sources/'
225+
226+
SOURCE_DIST_RSYNC_FLAGS += $(BASE_RSYNC_FLAGS) \
227+
--exclude 'packaging' \
228+
--exclude 'test'
229+
230+
# For source-bundle, explicitly include folders that are needed
231+
# for tests to execute. These are added before excludes from
232+
# the base flags so rsync honors the first match.
233+
SOURCE_BUNDLE_RSYNC_FLAGS += \
234+
--include 'rabbit_shovel_test/ebin' \
235+
--include 'rabbit_shovel_test/ebin/*' \
236+
--include 'rabbitmq_ct_helpers/tools' \
237+
--include 'rabbitmq_ct_helpers/tools/*' \
238+
$(BASE_RSYNC_FLAGS)
214239

215240
TAR ?= tar
216241
TAR_V_0 =
@@ -233,14 +258,14 @@ ZIP_V = $(ZIP_V_$(V))
233258

234259
$(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
235260
$(verbose) mkdir -p $(dir $@)
236-
$(gen_verbose) $(RSYNC) $(RSYNC_FLAGS) ./ $@/
261+
$(gen_verbose) $(RSYNC) $(SOURCE_DIST_RSYNC_FLAGS) ./ $@/
237262
$(verbose) echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > "$@/git-revisions.txt"
238263
$(verbose) echo "$(PROJECT) $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> "$@/git-revisions.txt"
239264
$(verbose) echo "$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > "$@.git-times.txt"
240265
$(verbose) cat packaging/common/LICENSE.head > $@/LICENSE
241266
$(verbose) mkdir -p $@/deps/licensing
242267
$(verbose) set -e; for dep in $$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
243-
$(RSYNC) $(RSYNC_FLAGS) \
268+
$(RSYNC) $(SOURCE_DIST_RSYNC_FLAGS) \
244269
$$dep \
245270
$@/deps; \
246271
rm -f \
@@ -287,6 +312,11 @@ $(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
287312
$(verbose) echo "PLUGINS := $(PLUGINS)" > $@/plugins.mk
288313
# Remember the latest Git timestamp.
289314
$(verbose) sort -r < "[email protected]" | head -n 1 > "[email protected]"
315+
$(verbose) $(call erlang,$(call dump_hex_cache_to_erl_term,$(call core_native_path,$@),$(call core_native_path,[email protected])))
316+
# Fix file timestamps to have reproducible source archives.
317+
$(verbose) find $@ -print0 | xargs -0 touch -t "$$(cat "[email protected]")"
318+
319+
290320
# Mix Hex component requires a cache file, otherwise it refuses to build
291321
# offline... That cache is an ETS table with all the applications we
292322
# depend on, plus some versioning informations and checksums. There
@@ -300,11 +330,6 @@ $(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
300330
#
301331
# The ETS file must be recreated before compiling RabbitMQ. See the
302332
# `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-
308333
define dump_hex_cache_to_erl_term
309334
In = "$(1)/deps/.hex/cache.ets",
310335
Out = "$(1)/deps/.hex/cache.erl",
@@ -333,10 +358,77 @@ define dump_hex_cache_to_erl_term
333358
init:stop().
334359
endef
335360

361+
.PHONY: $(BUNDLE_DIST)
362+
363+
$(BUNDLE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
364+
$(verbose) mkdir -p $(dir $@)
365+
$(gen_verbose) $(RSYNC) $(SOURCE_BUNDLE_RSYNC_FLAGS) ./ $@/
366+
$(verbose) echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > "$@/git-revisions.txt"
367+
$(verbose) echo "$(PROJECT) $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> "$@/git-revisions.txt"
368+
$(verbose) echo "$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > "$@.git-times.txt"
369+
$(verbose) cat packaging/common/LICENSE.head > $@/LICENSE
370+
$(verbose) mkdir -p $@/deps/licensing
371+
$(verbose) set -e; for dep in $$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
372+
$(RSYNC) $(SOURCE_BUNDLE_RSYNC_FLAGS) \
373+
$$dep \
374+
$@/deps; \
375+
rm -f \
376+
$@/deps/rabbit_common/rebar.config \
377+
$@/deps/rabbit_common/rebar.lock; \
378+
if test -f $@/deps/$$(basename $$dep)/erlang.mk && \
379+
test "$$(wc -l $@/deps/$$(basename $$dep)/erlang.mk | awk '{print $$1;}')" = "1" && \
380+
grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" $@/deps/$$(basename $$dep)/erlang.mk; then \
381+
echo "include ../../erlang.mk" > $@/deps/$$(basename $$dep)/erlang.mk; \
382+
fi; \
383+
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$|include ../../erlang.mk|" \
384+
$@/deps/$$(basename $$dep)/Makefile && \
385+
rm $@/deps/$$(basename $$dep)/Makefile.bak; \
386+
mix_exs=$@/deps/$$(basename $$dep)/mix.exs; \
387+
if test -f $$mix_exs; then \
388+
(cd $$(dirname "$$mix_exs") && \
389+
(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) && \
390+
env DEPS_DIR=$@/deps MIX_HOME=$@/deps/.mix HEX_HOME=$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix deps.get --only prod && \
391+
cp $(CURDIR)/mk/rabbitmq-mix.mk . && \
392+
rm -rf _build deps); \
393+
fi; \
394+
if test -f "$$dep/license_info"; then \
395+
cp "$$dep/license_info" "$@/deps/licensing/license_info_$$(basename "$$dep")"; \
396+
cat "$$dep/license_info" >> $@/LICENSE; \
397+
fi; \
398+
find "$$dep" -maxdepth 1 -name 'LICENSE-*' -exec cp '{}' $@/deps/licensing \; ; \
399+
(cd $$dep; \
400+
echo "$$(basename "$$dep") $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)") \
401+
>> "$@/git-revisions.txt"; \
402+
! test -d $$dep/.git || (cd $$dep; \
403+
echo "$$(env TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')") \
404+
>> "$@.git-times.txt"; \
405+
done
406+
$(verbose) cat packaging/common/LICENSE.tail >> $@/LICENSE
407+
$(verbose) find $@/deps/licensing -name 'LICENSE-*' -exec cp '{}' $@ \;
408+
$(verbose) rm -rf $@/deps/licensing
409+
$(verbose) for file in $$(find $@ -name '*.app.src'); do \
410+
sed -E -i.bak \
411+
-e 's/[{]vsn[[:blank:]]*,[[:blank:]]*(""|"0.0.0")[[:blank:]]*}/{vsn, "$(PROJECT_VERSION)"}/' \
412+
-e 's/[{]broker_version_requirements[[:blank:]]*,[[:blank:]]*\[\][[:blank:]]*}/{broker_version_requirements, ["$(PROJECT_VERSION)"]}/' \
413+
$$file; \
414+
rm $$file.bak; \
415+
done
416+
$(verbose) echo "PLUGINS := $(PLUGINS)" > $@/plugins.mk
417+
# Remember the latest Git timestamp.
418+
$(verbose) sort -r < "[email protected]" | head -n 1 > "[email protected]"
419+
$(verbose) $(call erlang,$(call dump_hex_cache_to_erl_term,$(call core_native_path,$@),$(call core_native_path,[email protected])))
420+
# Fix file timestamps to have reproducible source archives.
421+
$(verbose) find $@ -print0 | xargs -0 touch -t "$$(cat "[email protected]")"
422+
423+
336424
$(SOURCE_DIST).manifest: $(SOURCE_DIST)
337425
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
338426
find $(notdir $(SOURCE_DIST)) | LC_COLLATE=C sort > $@
339427

428+
$(BUNDLE_DIST).manifest: $(BUNDLE_DIST)
429+
$(gen_verbose) cd $(dir $(BUNDLE_DIST)) && \
430+
find $(notdir $(BUNDLE_DIST)) | LC_COLLATE=C sort > $@
431+
340432
ifeq ($(shell tar --version | grep -c "GNU tar"),0)
341433
# Skip all flags if this is Darwin (a.k.a. macOS, a.k.a. OS X)
342434
ifeq ($(shell uname | grep -c "Darwin"),0)
@@ -373,11 +465,34 @@ $(SOURCE_DIST).zip: $(SOURCE_DIST).manifest
373465
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
374466
$(ZIP) $(ZIP_V) --names-stdin $@ < $(SOURCE_DIST).manifest
375467

468+
$(BUNDLE_DIST).tar.gz: $(BUNDLE_DIST).manifest
469+
$(gen_verbose) cd $(dir $(BUNDLE_DIST)) && \
470+
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(BUNDLE_DIST).manifest -cf - | \
471+
$(GZIP) --best > $@
472+
473+
$(BUNDLE_DIST).tar.bz2: $(BUNDLE_DIST).manifest
474+
$(gen_verbose) cd $(dir $(BUNDLE_DIST)) && \
475+
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(BUNDLE_DIST).manifest -cf - | \
476+
$(BZIP2) > $@
477+
478+
$(BUNDLE_DIST).tar.xz: $(BUNDLE_DIST).manifest
479+
$(gen_verbose) cd $(dir $(BUNDLE_DIST)) && \
480+
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(BUNDLE_DIST).manifest -cf - | \
481+
$(XZ) > $@
482+
483+
$(BUNDLE_DIST).zip: $(BUNDLE_DIST).manifest
484+
$(verbose) rm -f $@
485+
$(gen_verbose) cd $(dir $(BUNDLE_DIST)) && \
486+
$(ZIP) $(ZIP_V) --names-stdin $@ < $(BUNDLE_DIST).manifest
487+
376488
clean:: clean-source-dist
377489

378490
clean-source-dist:
379491
$(gen_verbose) rm -rf -- $(SOURCE_DIST_BASE)-*
380492

493+
clean-source-bundle:
494+
$(gen_verbose) rm -rf -- $(SOURCE_BUNDLE_BASE)-*
495+
381496
distclean:: distclean-packages
382497

383498
distclean-packages:

0 commit comments

Comments
 (0)