build: refactor Makefile -ct and -prop target generation

Do not pre-generate all the -ct and -prop targets,
rather generate only the one that is in the specified build target
This commit is contained in:
Zaiming (Stone) Shi 2023-10-27 07:49:44 +02:00
parent 97601171a5
commit 5c14ac2e50
2 changed files with 38 additions and 15 deletions

View File

@ -1,3 +1,8 @@
ifeq ($(DEBUG),1)
DEBUG_INFO = $(info $1)
else
DEBUG_INFO = @:
endif
REBAR = $(CURDIR)/rebar3
BUILD = $(CURDIR)/build
SCRIPTS = $(CURDIR)/scripts
@ -23,10 +28,10 @@ export EMQX_EE_DASHBOARD_VERSION ?= e1.3.0
# so the shell script will be executed tons of times.
# https://github.com/emqx/emqx/pull/10627
ifeq ($(strip $(OTP_VSN)),)
export OTP_VSN := $(shell $(SCRIPTS)/get-otp-vsn.sh)
export OTP_VSN := $(shell $(SCRIPTS)/get-otp-vsn.sh)
endif
ifeq ($(strip $(ELIXIR_VSN)),)
export ELIXIR_VSN := $(shell $(SCRIPTS)/get-elixir-vsn.sh)
export ELIXIR_VSN := $(shell $(SCRIPTS)/get-elixir-vsn.sh)
endif
PROFILE ?= emqx
@ -101,31 +106,44 @@ static_checks:
./scripts/check-i18n-style.sh
./scripts/check_missing_reboot_apps.exs
APPS=$(shell $(SCRIPTS)/find-apps.sh)
# Allow user-set CASES environment variable
ifneq ($(CASES),)
CASES_ARG := --case $(CASES)
endif
.PHONY: $(APPS:%=%-ct)
## example:
## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct
define gen-app-ct-target
$1-ct: $(REBAR) merge-config clean-test-cluster-config
$(eval SUITES := $(shell $(SCRIPTS)/find-suites.sh $1))
ifneq ($(SUITES),)
ENABLE_COVER_COMPILE=1 $(REBAR) ct -c -v \
--readable=$(CT_READABLE) \
--name $(CT_NODE_NAME) \
--cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \
--suite $(SUITES)
ENABLE_COVER_COMPILE=1 $(REBAR) ct -c -v \
--readable=$(CT_READABLE) \
--name $(CT_NODE_NAME) \
--cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \
--suite $(SUITES) \
$(CASES_ARG)
else
@echo 'No suites found for $1'
@echo 'No suites found for $1'
endif
endef
$(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
ifneq ($(filter %-ct,$(MAKECMDGOALS)),)
app_to_test := $(patsubst %-ct,%,$(filter %-ct,$(MAKECMDGOALS)))
$(call DEBUG_INFO,app_to_test $(app_to_test))
$(eval $(call gen-app-ct-target,$(app_to_test)))
endif
## apps/name-prop targets
.PHONY: $(APPS:%=%-prop)
define gen-app-prop-target
$1-prop:
$(REBAR) proper -d test/props -v -m $(shell $(SCRIPTS)/find-props.sh $1)
endef
$(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
ifneq ($(filter %-prop,$(MAKECMDGOALS)),)
app_to_test := $(patsubst %-prop,%,$(filter %-prop,$(MAKECMDGOALS)))
$(call DEBUG_INFO,app_to_test $(app_to_test))
$(eval $(call gen-app-prop-target,$(app_to_test)))
endif
.PHONY: ct-suite
ct-suite: $(REBAR) merge-config clean-test-cluster-config
@ -303,3 +321,7 @@ fmt: $(REBAR)
.PHONY: clean-test-cluster-config
clean-test-cluster-config:
@rm -f apps/emqx_conf/data/configs/cluster.hocon || true
.PHONY: spellcheck
spellcheck:
./scripts/spellcheck/spellcheck.sh _build/docgen/$(PROFILE)/schema-en.json

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
## If EMQX_CT_SUITES is provided, it prints the variable.
## If EMQX_CT_SUITES or SUITES is provided, it prints the variable.
## Otherwise this script tries to find all test/*_SUITE.erl files of then given app,
## file names are separated by comma for rebar3 ct's `--suite` option
@ -12,7 +12,8 @@ set -euo pipefail
# ensure dir
cd -P -- "$(dirname -- "$0")/.."
## EMQX_CT_SUITES is useful in ad-hoc runs
## EMQX_CT_SUITES or SUITES is useful in ad-hoc runs
EMQX_CT_SUITES="${EMQX_CT_SUITES:-${SUITES:-}}"
if [ -n "${EMQX_CT_SUITES:-}" ]; then
echo "${EMQX_CT_SUITES}"
exit 0