Skip to content

Commit 238b729

Browse files
Merge pull request #13471 from kartg/source-bundle-make-target
(Updated) Adding a "source-bundle" target to the Makefile (cherry picked from commit 916b032) Conflicts: Makefile
1 parent d31e515 commit 238b729

File tree

1 file changed

+149
-111
lines changed

1 file changed

+149
-111
lines changed

Makefile

Lines changed: 149 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,17 @@ define restore_hex_cache_from_erl_term
107107
endef
108108

109109
# --------------------------------------------------------------------
110-
# Distribution.
110+
# Distribution - common variables and generic functions.
111111
# --------------------------------------------------------------------
112112

113-
.PHONY: source-dist clean-source-dist
114-
115-
SOURCE_DIST_BASE ?= rabbitmq-server
116-
SOURCE_DIST_SUFFIXES ?= tar.xz
117-
SOURCE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_DIST_BASE)-$(PROJECT_VERSION)
118-
119-
# The first source distribution file is used by packages: if the archive
120-
# type changes, you must update all packages' Makefile.
121-
SOURCE_DIST_FILES = $(addprefix $(SOURCE_DIST).,$(SOURCE_DIST_SUFFIXES))
122-
123-
.PHONY: $(SOURCE_DIST_FILES)
124-
125-
source-dist: $(SOURCE_DIST_FILES)
126-
@:
127-
128113
RSYNC ?= rsync
129114
RSYNC_V_0 =
130115
RSYNC_V_1 = -v
131116
RSYNC_V_2 = -v
132117
RSYNC_V = $(RSYNC_V_$(V))
133-
RSYNC_FLAGS += -a $(RSYNC_V) \
118+
BASE_RSYNC_FLAGS += -a $(RSYNC_V) \
119+
--delete \
120+
--delete-excluded \
134121
--exclude '.sw?' --exclude '.*.sw?' \
135122
--exclude '*.beam' \
136123
--exclude '*.d' \
@@ -162,7 +149,6 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
162149
--exclude '$(notdir $(DEPS_DIR))/' \
163150
--exclude 'hexer*' \
164151
--exclude 'logs/' \
165-
--exclude 'packaging' \
166152
--exclude 'PKG_*.md' \
167153
--exclude '/plugins/' \
168154
--include 'cli/plugins' \
@@ -185,9 +171,21 @@ RSYNC_FLAGS += -a $(RSYNC_V) \
185171
--exclude '/ranch/doc/' \
186172
--exclude '/ranch/examples/' \
187173
--exclude '/sockjs/examples/' \
188-
--exclude '/workflow_sources/' \
189-
--delete \
190-
--delete-excluded
174+
--exclude '/workflow_sources/'
175+
176+
SOURCE_DIST_RSYNC_FLAGS += $(BASE_RSYNC_FLAGS) \
177+
--exclude 'packaging' \
178+
--exclude 'test'
179+
180+
# For source-bundle, explicitly include folders that are needed
181+
# for tests to execute. These are added before excludes from
182+
# the base flags so rsync honors the first match.
183+
SOURCE_BUNDLE_RSYNC_FLAGS += \
184+
--include 'rabbit_shovel_test/ebin' \
185+
--include 'rabbit_shovel_test/ebin/*' \
186+
--include 'rabbitmq_ct_helpers/tools' \
187+
--include 'rabbitmq_ct_helpers/tools/*' \
188+
$(BASE_RSYNC_FLAGS)
191189

192190
TAR ?= tar
193191
TAR_V_0 =
@@ -205,65 +203,125 @@ ZIP_V_1 =
205203
ZIP_V_2 =
206204
ZIP_V = $(ZIP_V_$(V))
207205

208-
.PHONY: $(SOURCE_DIST)
209-
.PHONY: clean-source-dist distclean-packages clean-unpacked-source-dist
210-
211-
$(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
212-
$(verbose) mkdir -p $(dir $@)
213-
$(gen_verbose) $(RSYNC) $(RSYNC_FLAGS) ./ $@/
214-
$(verbose) echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > "$@/git-revisions.txt"
215-
$(verbose) echo "$(PROJECT) $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> "$@/git-revisions.txt"
216-
$(verbose) echo "$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > "$@.git-times.txt"
217-
$(verbose) cat packaging/common/LICENSE.head > $@/LICENSE
218-
$(verbose) mkdir -p $@/deps/licensing
219-
$(verbose) set -e; for dep in $$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
220-
$(RSYNC) $(RSYNC_FLAGS) \
221-
$$dep \
222-
$@/deps; \
206+
ifeq ($(shell tar --version | grep -c "GNU tar"),0)
207+
# Skip all flags if this is Darwin (a.k.a. macOS, a.k.a. OS X)
208+
ifeq ($(shell uname | grep -c "Darwin"),0)
209+
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --uid 0 \
210+
--gid 0 \
211+
--numeric-owner \
212+
--no-acls \
213+
--no-fflags \
214+
--no-xattrs
215+
endif
216+
else
217+
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --owner 0 \
218+
--group 0 \
219+
--numeric-owner
220+
endif
221+
222+
DIST_SUFFIXES ?= tar.xz
223+
224+
# Function to create distribution targets
225+
# Args: $(1) - Full distribution path
226+
# $(2) - RSYNC flags to use
227+
define create_dist_target
228+
$(1): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
229+
$${verbose} mkdir -p $$(dir $$@)
230+
$${gen_verbose} $${RSYNC} $(2) ./ $$@/
231+
$${verbose} echo "$(PROJECT_DESCRIPTION) $(PROJECT_VERSION)" > $$@/git-revisions.txt
232+
$${verbose} echo "$(PROJECT) $$$$(git rev-parse HEAD) $$$$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)" >> $$@/git-revisions.txt
233+
$${verbose} echo "$$$$(TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')" > $$@.git-times.txt
234+
$${verbose} cat packaging/common/LICENSE.head > $$@/LICENSE
235+
$${verbose} mkdir -p $$@/deps/licensing
236+
$${verbose} set -e; for dep in $$$$(cat $(ERLANG_MK_RECURSIVE_DEPS_LIST) | LC_COLLATE=C sort); do \
237+
$${RSYNC} $(2) \
238+
$$$$dep \
239+
$$@/deps; \
223240
rm -f \
224-
$@/deps/rabbit_common/rebar.config \
225-
$@/deps/rabbit_common/rebar.lock; \
226-
if test -f $@/deps/$$(basename $$dep)/erlang.mk && \
227-
test "$$(wc -l $@/deps/$$(basename $$dep)/erlang.mk | awk '{print $$1;}')" = "1" && \
228-
grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" $@/deps/$$(basename $$dep)/erlang.mk; then \
229-
echo "include ../../erlang.mk" > $@/deps/$$(basename $$dep)/erlang.mk; \
241+
$$@/deps/rabbit_common/rebar.config \
242+
$$@/deps/rabbit_common/rebar.lock; \
243+
if test -f $$@/deps/$$$$(basename $$$$dep)/erlang.mk && \
244+
test "$$$$(wc -l $$@/deps/$$$$(basename $$$$dep)/erlang.mk | awk '{print $$$$1;}')" = "1" && \
245+
grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$$$" $$@/deps/$$$$(basename $$$$dep)/erlang.mk; then \
246+
echo "include ../../erlang.mk" > $$@/deps/$$$$(basename $$$$dep)/erlang.mk; \
230247
fi; \
231-
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$|include ../../erlang.mk|" \
232-
$@/deps/$$(basename $$dep)/Makefile && \
233-
rm $@/deps/$$(basename $$dep)/Makefile.bak; \
234-
mix_exs=$@/deps/$$(basename $$dep)/mix.exs; \
235-
if test -f $$mix_exs; then \
236-
(cd $$(dirname "$$mix_exs") && \
237-
(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) && \
238-
env DEPS_DIR=$@/deps MIX_HOME=$@/deps/.mix HEX_HOME=$@/deps/.hex MIX_ENV=prod FILL_HEX_CACHE=yes mix deps.get --only prod && \
248+
sed -E -i.bak "s|^[[:blank:]]*include[[:blank:]]+\.\./.*erlang.mk$$$$|include ../../erlang.mk|" \
249+
$$@/deps/$$$$(basename $$$$dep)/Makefile && \
250+
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 && \
239256
cp $(CURDIR)/mk/rabbitmq-mix.mk . && \
240257
rm -rf _build deps); \
241258
fi; \
242-
if test -f "$$dep/license_info"; then \
243-
cp "$$dep/license_info" "$@/deps/licensing/license_info_$$(basename "$$dep")"; \
244-
cat "$$dep/license_info" >> $@/LICENSE; \
259+
if test -f "$$$$dep/license_info"; then \
260+
cp "$$$$dep/license_info" "$$@/deps/licensing/license_info_$$$$(basename $$$$dep)"; \
261+
cat "$$$$dep/license_info" >> $$@/LICENSE; \
245262
fi; \
246-
find "$$dep" -maxdepth 1 -name 'LICENSE-*' -exec cp '{}' $@/deps/licensing \; ; \
247-
(cd $$dep; \
248-
echo "$$(basename "$$dep") $$(git rev-parse HEAD) $$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)") \
249-
>> "$@/git-revisions.txt"; \
250-
! test -d $$dep/.git || (cd $$dep; \
251-
echo "$$(env TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')") \
252-
>> "$@.git-times.txt"; \
263+
find "$$$$dep" -maxdepth 1 -name 'LICENSE-*' -exec cp '{}' $$@/deps/licensing \; ; \
264+
(cd $$$$dep; \
265+
echo "$$$$(basename "$$$$dep") $$$$(git rev-parse HEAD) $$$$(git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)") \
266+
>> "$$@/git-revisions.txt"; \
267+
! test -d $$$$dep/.git || (cd $$$$dep; \
268+
echo "$$$$(env TZ= git --no-pager log -n 1 --format='%cd' --date='format-local:%Y%m%d%H%M.%S')") \
269+
>> "$$@.git-times.txt"; \
253270
done
254-
$(verbose) cat packaging/common/LICENSE.tail >> $@/LICENSE
255-
$(verbose) find $@/deps/licensing -name 'LICENSE-*' -exec cp '{}' $@ \;
256-
$(verbose) rm -rf $@/deps/licensing
257-
$(verbose) for file in $$(find $@ -name '*.app.src'); do \
271+
$${verbose} cat packaging/common/LICENSE.tail >> $$@/LICENSE
272+
$${verbose} find $$@/deps/licensing -name 'LICENSE-*' -exec cp '{}' $$@ \;
273+
$${verbose} rm -rf $$@/deps/licensing
274+
$${verbose} for file in $$$$(find $$@ -name '*.app.src'); do \
258275
sed -E -i.bak \
259276
-e 's/[{]vsn[[:blank:]]*,[[:blank:]]*(""|"0.0.0")[[:blank:]]*}/{vsn, "$(PROJECT_VERSION)"}/' \
260277
-e 's/[{]broker_version_requirements[[:blank:]]*,[[:blank:]]*\[\][[:blank:]]*}/{broker_version_requirements, ["$(PROJECT_VERSION)"]}/' \
261-
$$file; \
262-
rm $$file.bak; \
278+
$$$$file; \
279+
rm $$$$file.bak; \
263280
done
264-
$(verbose) echo "PLUGINS := $(PLUGINS)" > $@/plugins.mk
265-
# Remember the latest Git timestamp.
266-
$(verbose) sort -r < "[email protected]" | head -n 1 > "[email protected]"
281+
$${verbose} echo "PLUGINS := $(PLUGINS)" > $$@/plugins.mk
282+
$${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)))
284+
$${verbose} find $$@ -print0 | xargs -0 touch -t "$$$$(cat $$@.git-time.txt)"
285+
$${verbose} rm "$$@.git-times.txt" "$$@.git-time.txt"
286+
287+
$(1).manifest: $(1)
288+
$${gen_verbose} cd $$(dir $$@) && \
289+
find $$(notdir $$<) | LC_COLLATE=C sort > $$@
290+
291+
$(1).tar.xz: $(1).manifest
292+
$${gen_verbose} cd $$(dir $$@) && \
293+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
294+
$${XZ} > $$@
295+
296+
$(1).tar.gz: $(1).manifest
297+
$${gen_verbose} cd $$(dir $$@) && \
298+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
299+
$${GZIP} --best > $$@
300+
301+
$(1).tar.bz2: $(1).manifest
302+
$${gen_verbose} cd $$(dir $$@) && \
303+
$${TAR} $${TAR_V} $${TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS} --no-recursion -T $$(notdir $$<) -cf - | \
304+
$${BZIP2} > $$@
305+
306+
$(1).zip: $(1).manifest
307+
$${verbose} rm -f $$@
308+
$${gen_verbose} cd $$(dir $$@) && \
309+
$${ZIP} $${ZIP_V} --names-stdin $$@ < $$(notdir $$<)
310+
311+
endef
312+
313+
# Function to create clean targets
314+
# Args: $(1) - Base name (e.g. SOURCE_DIST_BASE or BUNDLE_DIST_BASE)
315+
define create_clean_targets
316+
.PHONY: clean-$(1)
317+
318+
clean-$(1):
319+
$${gen_verbose} rm -rf -- $(1)-*
320+
321+
# Add each clean target to the clean:: rule
322+
clean:: clean-$(1)
323+
endef
324+
267325
# Mix Hex component requires a cache file, otherwise it refuses to build
268326
# offline... That cache is an ETS table with all the applications we
269327
# depend on, plus some versioning informations and checksums. There
@@ -277,11 +335,6 @@ $(SOURCE_DIST): $(ERLANG_MK_RECURSIVE_DEPS_LIST)
277335
#
278336
# The ETS file must be recreated before compiling RabbitMQ. See the
279337
# `restore-hex-cache-ets-file` Make target.
280-
$(verbose) $(call erlang,$(call dump_hex_cache_to_erl_term,$(call core_native_path,$@),$(call core_native_path,[email protected])))
281-
# Fix file timestamps to have reproducible source archives.
282-
$(verbose) find $@ -print0 | xargs -0 touch -t "$$(cat "[email protected]")"
283-
284-
285338
define dump_hex_cache_to_erl_term
286339
In = "$(1)/deps/.hex/cache.ets",
287340
Out = "$(1)/deps/.hex/cache.erl",
@@ -310,50 +363,35 @@ define dump_hex_cache_to_erl_term
310363
init:stop().
311364
endef
312365

313-
$(SOURCE_DIST).manifest: $(SOURCE_DIST)
314-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
315-
find $(notdir $(SOURCE_DIST)) | LC_COLLATE=C sort > $@
366+
# --------------------------------------------------------------------
367+
# Distribution - public targets
368+
# --------------------------------------------------------------------
316369

317-
ifeq ($(shell tar --version | grep -c "GNU tar"),0)
318-
# Skip all flags if this is Darwin (a.k.a. macOS, a.k.a. OS X)
319-
ifeq ($(shell uname | grep -c "Darwin"),0)
320-
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --uid 0 \
321-
--gid 0 \
322-
--numeric-owner \
323-
--no-acls \
324-
--no-fflags \
325-
--no-xattrs
326-
endif
327-
else
328-
TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS = --owner 0 \
329-
--group 0 \
330-
--numeric-owner
331-
endif
370+
SOURCE_DIST_BASE ?= rabbitmq-server
371+
SOURCE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_DIST_BASE)-$(PROJECT_VERSION)
372+
SOURCE_DIST_FILES = $(addprefix $(SOURCE_DIST).,$(DIST_SUFFIXES))
332373

333-
$(SOURCE_DIST).tar.gz: $(SOURCE_DIST).manifest
334-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
335-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
336-
$(GZIP) --best > $@
374+
.PHONY: source-dist
375+
source-dist: $(SOURCE_DIST_FILES)
376+
@:
377+
378+
$(eval $(call create_dist_target,$(SOURCE_DIST),$(SOURCE_DIST_RSYNC_FLAGS)))
337379

338-
$(SOURCE_DIST).tar.bz2: $(SOURCE_DIST).manifest
339-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
340-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
341-
$(BZIP2) > $@
380+
SOURCE_BUNDLE_BASE ?= rabbitmq-server-bundle
381+
SOURCE_BUNDLE_DIST ?= $(PACKAGES_DIR)/$(SOURCE_BUNDLE_BASE)-$(PROJECT_VERSION)
382+
SOURCE_BUNDLE_FILES = $(addprefix $(SOURCE_BUNDLE_DIST).,$(DIST_SUFFIXES))
342383

343-
$(SOURCE_DIST).tar.xz: $(SOURCE_DIST).manifest
344-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
345-
$(TAR) $(TAR_V) $(TAR_FLAGS_FOR_REPRODUCIBLE_BUILDS) --no-recursion -T $(SOURCE_DIST).manifest -cf - | \
346-
$(XZ) > $@
384+
.PHONY: source-bundle
385+
source-bundle: $(SOURCE_BUNDLE_FILES)
386+
@:
347387

348-
$(SOURCE_DIST).zip: $(SOURCE_DIST).manifest
349-
$(verbose) rm -f $@
350-
$(gen_verbose) cd $(dir $(SOURCE_DIST)) && \
351-
$(ZIP) $(ZIP_V) --names-stdin $@ < $(SOURCE_DIST).manifest
388+
$(eval $(call create_dist_target,$(SOURCE_BUNDLE_DIST),$(SOURCE_BUNDLE_RSYNC_FLAGS)))
352389

353-
clean:: clean-source-dist
390+
# Create the clean targets for both distributions
391+
$(eval $(call create_clean_targets,$(SOURCE_DIST_BASE)))
392+
$(eval $(call create_clean_targets,$(SOURCE_BUNDLE_BASE)))
354393

355-
clean-source-dist:
356-
$(gen_verbose) rm -rf -- $(SOURCE_DIST_BASE)-*
394+
.PHONY: distclean-packages clean-unpacked-source-dist
357395

358396
distclean:: distclean-packages
359397

0 commit comments

Comments
 (0)