Skip to content

Commit

Permalink
core/test.mk: Rebuild out-of-date test modules only
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
dumbbell committed Apr 20, 2020
1 parent 44b3c70 commit 9a53fea
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
22 changes: 18 additions & 4 deletions core/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
45 changes: 44 additions & 1 deletion test/core_app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

# We will sleep for 1 second in several places, in case the underlying
# filesystem does not support sub-second timestamps. This is to make
# sure that we can compare file timestamps effectively.
$t sleep 1 && 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 1 && 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 1 && 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

0 comments on commit 9a53fea

Please sign in to comment.