Skip to content

Commit

Permalink
makefile: fix parallel make check failing on the first run (#177)
Browse files Browse the repository at this point in the history
After the changes in #141, parallel `make check` started failing with the
following GNU Parallel error:

> Option tmpdir requires an argument

This is caused by the fact that `test_config.mk` uses `?=` for setting
`TEST_TMPDIR` and on make restarts this doesn't work for some reason
(perhaps having to do with empty `TEST_TMPDIR` being somehow exported).

Replace it with a check for empty value and unconditional assignment
instead. While at it, include `test_config.mk` only on make restarts for
check targets instead of forcing everything that makes use of `TEST_TMPDIR`
to reuse the unit tests configuration.

Also use 6 Xs for the mktemp template in order to support BusyBox mktemp
and maybe some others as well, that require the template to end with 6 Xs
exactly.
  • Loading branch information
isaac-io committed Oct 19, 2022
1 parent 765f24b commit c3c47f1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +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),)

# Avoid setting up the tmp directory when the target isn't a check target or
# on Makefile restarts
ifneq ($(filter %check,$(MAKECMDGOALS)),)
ifeq ($(MAKE_RESTARTS),)

ifeq ($(TEST_TMPDIR),)
ifeq ($(BASE_TMPDIR),)
Expand All @@ -27,11 +28,13 @@ ifeq ($(BASE_TMPDIR),)
BASE_TMPDIR :=/tmp
endif
# Use /dev/shm on Linux if it has the sticky bit set (otherwise, /tmp or other
# base dir), and create a randomly-named rocksdb.XXXX directory therein.
# base dir), and create a randomly-named rocksdb.XXXXXX directory therein.
ifneq ($(shell [ "$$(uname -s)" = "Linux" ] && [ -k /dev/shm ] && echo 1),)
BASE_TMPDIR :=/dev/shm
endif
TEST_TMPDIR := $(shell mktemp -d "$(BASE_TMPDIR)/rocksdb.XXXX")
# Use 6 Xs in the template in order to appease the BusyBox mktemp command,
# which requires the template to end with exactly 6 Xs.
TEST_TMPDIR := $(shell mktemp -d "$(BASE_TMPDIR)/rocksdb.XXXXXX")
endif

# The `export` line below doesn't work in case Make restarts (due to included
Expand All @@ -41,11 +44,15 @@ endif
# 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)
$(shell printf 'ifeq ($$(TEST_TMPDIR),)\nTEST_TMPDIR:=$(TEST_TMPDIR)\nendif\n' > test_config.mk)

else

# If neither TEST_TMPDIR nor TMPD were specified, try to load TEST_TMPDIR from
# a previous run as saved in test_config.mk (generated by the shell call above)
include test_config.mk

endif
endif

-include test_config.mk

export TEST_TMPDIR

0 comments on commit c3c47f1

Please sign in to comment.