diff --git a/.gitignore b/.gitignore index 8cd82b1fb5..45a2bb1e51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ make_config.mk +test_config.mk rocksdb.pc *.a diff --git a/Makefile b/Makefile index a92ea2c2f2..1c36a70166 100644 --- a/Makefile +++ b/Makefile @@ -303,7 +303,7 @@ endif endif export JAVAC_ARGS -CLEAN_FILES += make_config.mk rocksdb.pc +CLEAN_FILES += make_config.mk test_config.mk rocksdb.pc ifeq ($(V), 1) $(info $(shell uname -a)) diff --git a/common.mk b/common.mk index 1532ae29b3..f1554406cf 100644 --- a/common.mk +++ b/common.mk @@ -14,6 +14,11 @@ endif ifeq ($(TEST_TMPDIR),) TEST_TMPDIR := $(TMPD) endif +# Avoid setting up the tmp directory on Makefile restarts or when the target +# isn't a check target +ifeq ($(MAKE_RESTARTS),) +ifneq ($(filter %check,$(MAKECMDGOALS)),) + ifeq ($(TEST_TMPDIR),) ifeq ($(BASE_TMPDIR),) BASE_TMPDIR :=$(TMPDIR) @@ -28,4 +33,19 @@ BASE_TMPDIR :=/dev/shm endif TEST_TMPDIR := $(shell mktemp -d "$(BASE_TMPDIR)/rocksdb.XXXX") endif + +# The `export` line below doesn't work in case Make restarts (due to included +# makefiles getting remade), so we need to output the directory we created into +# a temporary config file that will be included by the `include` directive below +# in case of a restart (we don't want to output it into make_config.mk in order +# to avoid having the TEST_TMPDIR implicitly set for test that are run through +# makefiles that include make_config.mk, and because we don't want to change +# make_config.mk on every run) +$(shell echo 'TEST_TMPDIR?=$(TEST_TMPDIR)' > test_config.mk) + +endif +endif + +-include test_config.mk + export TEST_TMPDIR