aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <[email protected]>2020-04-03 12:29:44 +0200
committerLoïc Hoguin <[email protected]>2020-04-21 10:39:43 +0200
commitc55d0dcd6182983521d4ab34478cfe4b093edb12 (patch)
treebcf4ad7594b970e4f50a90de9c6bd0b2d2fee1ed
parentc1979bea6e66a434d6f71018a9a95b015f8658ed (diff)
downloaderlang.mk-c55d0dcd6182983521d4ab34478cfe4b093edb12.tar.gz
erlang.mk-c55d0dcd6182983521d4ab34478cfe4b093edb12.tar.bz2
erlang.mk-c55d0dcd6182983521d4ab34478cfe4b093edb12.zip
core/test.mk: Rebuild out-of-date test modules only
... instead of always rebuilding all of them each time a testsuite is executed. The only exception is when a Makefile was modified: like for main source files, test modules are all recompiled in this case.
-rw-r--r--core/test.mk22
-rw-r--r--test/core_app.mk45
2 files changed, 62 insertions, 5 deletions
diff --git a/core/test.mk b/core/test.mk
index 43c1390..5bc9272 100644
--- a/core/test.mk
+++ b/core/test.mk
@@ -31,9 +31,23 @@ test-deps: $(ALL_TEST_DEPS_DIRS)
endif
ifneq ($(wildcard $(TEST_DIR)),)
-test-dir:
- $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
- -pa ebin/ -I include/ $(call core_find,$(TEST_DIR)/,*.erl)
+test-dir: $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
+ @:
+
+test_erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
+ $(filter %.erl %.core,$(notdir $(FILES_TO_COMPILE))));
+test_erlc_verbose_2 = set -x;
+test_erlc_verbose = $(test_erlc_verbose_$(V))
+
+define compile_test_erl
+ $(test_erlc_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
+ -pa ebin/ -I include/ $(1)
+endef
+
+ERL_TEST_FILES = $(call core_find,$(TEST_DIR)/,*.erl)
+$(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build: $(ERL_TEST_FILES) $(MAKEFILE_LIST)
+ $(eval FILES_TO_COMPILE := $(if $(filter $(MAKEFILE_LIST),$?),$(filter $(ERL_TEST_FILES),$^),$?))
+ $(if $(strip $(FILES_TO_COMPILE)),$(call compile_test_erl,$(FILES_TO_COMPILE)); touch $@)
endif
test-build:: IS_TEST=1
@@ -70,5 +84,5 @@ clean:: clean-test-dir
clean-test-dir:
ifneq ($(wildcard $(TEST_DIR)/*.beam),)
- $(gen_verbose) rm -f $(TEST_DIR)/*.beam
+ $(gen_verbose) rm -f $(TEST_DIR)/*.beam $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
endif
diff --git a/test/core_app.mk b/test/core_app.mk
index 553f331..7abb9e9 100644
--- a/test/core_app.mk
+++ b/test/core_app.mk
@@ -1682,7 +1682,7 @@ core-app-yrl-header: init
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
-
+
$i "Create a .yrl file"
$t echo "Nonterminals E T F." > $(APP)/src/y_parse.yrl
$t echo "Terminals '+' '*' '(' ')' number." >> $(APP)/src/y_parse.yrl
@@ -2743,3 +2743,46 @@ endif
= application:get_key(my_app, modules), \
[{module, M} = code:load_file(M) || M <- Mods], \
halt()"
+
+core-app-test-build-outofdate-files-only: init
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Generate .erl test files"
+ $t mkdir $(APP)/test/
+ $t printf "%s\n" "-module(use_blue)." > $(APP)/test/use_blue.erl
+ $t printf "%s\n" "-module(use_red)." > $(APP)/test/use_red.erl
+
+ $i "Build the application testsuite"
+ $t $(MAKE) -C $(APP) test-build $v
+
+ $i "Check that all compiled files exist"
+ $t test -f $(APP)/test/use_blue.beam
+ $t test -f $(APP)/test/use_red.beam
+
+ $t $(SLEEP)
+ $t touch $(APP)/build-1
+
+ $i "Re-un the make command; check that nothing is rebuilt"
+ $t $(MAKE) -C $(APP) test-build $v
+ $t test $(APP)/test/use_blue.beam -ot $(APP)/build-1
+ $t test $(APP)/test/use_red.beam -ot $(APP)/build-1
+
+ $i "Touch one .erl file; check that only required files are rebuilt"
+ $t $(SLEEP)
+ $t touch $(APP)/test/use_blue.erl
+ $t $(MAKE) -C $(APP) test-build $v
+ $t test $(APP)/test/use_blue.beam -nt $(APP)/build-1
+ $t test $(APP)/test/use_red.beam -ot $(APP)/build-1
+
+ $t touch $(APP)/build-2
+
+ $i "Touch one Makefile; check that all files are rebuilt"
+ $t $(SLEEP)
+ $t touch $(APP)/Makefile
+ $t $(MAKE) -C $(APP) test-build $v
+ $t test $(APP)/test/use_blue.beam -nt $(APP)/build-2
+ $t test $(APP)/test/use_red.beam -nt $(APP)/build-2