aboutsummaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
Diffstat (limited to 'mk')
-rw-r--r--mk/common-test.sh11
-rwxr-xr-xmk/debug-test.sh11
-rw-r--r--mk/disable-tests.mk12
-rw-r--r--mk/libraries.mk7
-rw-r--r--mk/patterns.mk4
-rw-r--r--mk/programs.mk12
-rwxr-xr-xmk/run-test.sh38
-rwxr-xr-xmk/run_test.sh46
-rw-r--r--mk/tests.mk6
9 files changed, 92 insertions, 55 deletions
diff --git a/mk/common-test.sh b/mk/common-test.sh
new file mode 100644
index 000000000..0a2e4c1c2
--- /dev/null
+++ b/mk/common-test.sh
@@ -0,0 +1,11 @@
+TESTS_ENVIRONMENT=("TEST_NAME=${test%.*}" 'NIX_REMOTE=')
+
+: ${BASH:=/usr/bin/env bash}
+
+init_test () {
+ cd tests && env "${TESTS_ENVIRONMENT[@]}" $BASH -e init.sh 2>/dev/null > /dev/null
+}
+
+run_test_proper () {
+ cd $(dirname $test) && env "${TESTS_ENVIRONMENT[@]}" $BASH -e $(basename $test)
+}
diff --git a/mk/debug-test.sh b/mk/debug-test.sh
new file mode 100755
index 000000000..b5b628ecd
--- /dev/null
+++ b/mk/debug-test.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -eu -o pipefail
+
+test=$1
+
+dir="$(dirname "${BASH_SOURCE[0]}")"
+source "$dir/common-test.sh"
+
+(init_test)
+run_test_proper
diff --git a/mk/disable-tests.mk b/mk/disable-tests.mk
new file mode 100644
index 000000000..f72f84412
--- /dev/null
+++ b/mk/disable-tests.mk
@@ -0,0 +1,12 @@
+# This file is only active for `./configure --disable-tests`.
+# Running `make check` or `make installcheck` would indicate a mistake in the
+# caller.
+
+installcheck:
+ @echo "Tests are disabled. Configure without '--disable-tests', or avoid calling 'make installcheck'."
+ @exit 1
+
+# This currently has little effect.
+check:
+ @echo "Tests are disabled. Configure without '--disable-tests', or avoid calling 'make check'."
+ @exit 1
diff --git a/mk/libraries.mk b/mk/libraries.mk
index 6541775f3..1bc73d7f7 100644
--- a/mk/libraries.mk
+++ b/mk/libraries.mk
@@ -67,6 +67,7 @@ define build-library
$(1)_LDFLAGS_USE :=
$(1)_LDFLAGS_USE_INSTALLED :=
+ $(1)_LIB_CLOSURE := $(1)
$$(eval $$(call create-dir, $$(_d)))
@@ -125,13 +126,15 @@ define build-library
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/
- +$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$^
+ $$(trace-ld) $(LD) $$(ifndef $(HOST_DARWIN),-U) -r -o $$(_d)/$$($(1)_NAME).o $$^
$$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o
- $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS)
+ $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
$(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a
+ $(1)_LIB_CLOSURE += $$($(1)_LIBS)
+
endif
$(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED)
diff --git a/mk/patterns.mk b/mk/patterns.mk
index 86a724806..c81150260 100644
--- a/mk/patterns.mk
+++ b/mk/patterns.mk
@@ -1,10 +1,10 @@
$(buildprefix)%.o: %.cc
@mkdir -p "$(dir $@)"
- $(trace-cxx) $(CXX) -o $@ -c $< $(CPPFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP
+ $(trace-cxx) $(CXX) -o $@ -c $< $(CPPFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) $(ERROR_SWITCH_ENUM) -MMD -MF $(call filename-to-dep, $@) -MP
$(buildprefix)%.o: %.cpp
@mkdir -p "$(dir $@)"
- $(trace-cxx) $(CXX) -o $@ -c $< $(CPPFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP
+ $(trace-cxx) $(CXX) -o $@ -c $< $(CPPFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) $(ERROR_SWITCH_ENUM) -MMD -MF $(call filename-to-dep, $@) -MP
$(buildprefix)%.o: %.c
@mkdir -p "$(dir $@)"
diff --git a/mk/programs.mk b/mk/programs.mk
index 0fc1990f7..1ee1d3fa5 100644
--- a/mk/programs.mk
+++ b/mk/programs.mk
@@ -3,6 +3,9 @@ programs-list :=
# Build a program with symbolic name $(1). The program is defined by
# various variables prefixed by ‘$(1)_’:
#
+# - $(1)_NAME: the name of the program (e.g. ‘foo’); defaults to
+# $(1).
+#
# - $(1)_DIR: the directory where the (non-installed) program will be
# placed.
#
@@ -23,11 +26,12 @@ programs-list :=
# - $(1)_INSTALL_DIR: the directory where the program will be
# installed; defaults to $(bindir).
define build-program
+ $(1)_NAME ?= $(1)
_d := $(buildprefix)$$($(1)_DIR)
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
$(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs))))
- _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
- $(1)_PATH := $$(_d)/$(1)
+ _libs := $$(foreach lib, $$($(1)_LIBS), $$(foreach lib2, $$($$(lib)_LIB_CLOSURE), $$($$(lib2)_PATH)))
+ $(1)_PATH := $$(_d)/$$($(1)_NAME)
$$(eval $$(call create-dir, $$(_d)))
@@ -38,7 +42,7 @@ define build-program
ifdef $(1)_INSTALL_DIR
- $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1)
+ $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME)
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
@@ -54,7 +58,7 @@ define build-program
else
$(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
- install -t $(DESTDIR)$$($(1)_INSTALL_DIR) $$<
+ +$$(trace-install) install -t $(DESTDIR)$$($(1)_INSTALL_DIR) $$<
endif
endif
diff --git a/mk/run-test.sh b/mk/run-test.sh
new file mode 100755
index 000000000..1a1d65930
--- /dev/null
+++ b/mk/run-test.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+set -eu -o pipefail
+
+red=""
+green=""
+yellow=""
+normal=""
+
+test=$1
+
+dir="$(dirname "${BASH_SOURCE[0]}")"
+source "$dir/common-test.sh"
+
+post_run_msg="ran test $test..."
+if [ -t 1 ]; then
+ red=""
+ green=""
+ yellow=""
+ normal=""
+fi
+
+run_test () {
+ (init_test 2>/dev/null > /dev/null)
+ log="$(run_test_proper 2>&1)" && status=0 || status=$?
+}
+
+run_test
+
+if [ $status -eq 0 ]; then
+ echo "$post_run_msg [${green}PASS$normal]"
+elif [ $status -eq 99 ]; then
+ echo "$post_run_msg [${yellow}SKIP$normal]"
+else
+ echo "$post_run_msg [${red}FAIL$normal]"
+ echo "$log" | sed 's/^/ /'
+ exit "$status"
+fi
diff --git a/mk/run_test.sh b/mk/run_test.sh
deleted file mode 100755
index 7e95df2ac..000000000
--- a/mk/run_test.sh
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-
-set -u
-
-red=""
-green=""
-yellow=""
-normal=""
-
-post_run_msg="ran test $1..."
-if [ -t 1 ]; then
- red=""
- green=""
- yellow=""
- normal=""
-fi
-
-run_test () {
- (cd tests && env ${TESTS_ENVIRONMENT} init.sh 2>/dev/null > /dev/null)
- log="$(cd $(dirname $1) && env ${TESTS_ENVIRONMENT} $(basename $1) 2>&1)"
- status=$?
-}
-
-run_test "$1"
-
-# Hack: Retry the test if it fails with “unexpected EOF reading a line” as these
-# appear randomly without anyone knowing why.
-# See https://github.com/NixOS/nix/issues/3605 for more info
-if [[ $status -ne 0 && $status -ne 99 && \
- "$(uname)" == "Darwin" && \
- "$log" =~ "unexpected EOF reading a line" \
-]]; then
- echo "$post_run_msg [${yellow}FAIL$normal] (possibly flaky, so will be retried)"
- echo "$log" | sed 's/^/ /'
- run_test "$1"
-fi
-
-if [ $status -eq 0 ]; then
- echo "$post_run_msg [${green}PASS$normal]"
-elif [ $status -eq 99 ]; then
- echo "$post_run_msg [${yellow}SKIP$normal]"
-else
- echo "$post_run_msg [${red}FAIL$normal]"
- echo "$log" | sed 's/^/ /'
- exit "$status"
-fi
diff --git a/mk/tests.mk b/mk/tests.mk
index a2e30a378..3ebbd86e3 100644
--- a/mk/tests.mk
+++ b/mk/tests.mk
@@ -8,7 +8,11 @@ define run-install-test
.PHONY: $1.test
$1.test: $1 $(test-deps)
- @env TEST_NAME=$(basename $1) TESTS_ENVIRONMENT="$(tests-environment)" mk/run_test.sh $1 < /dev/null
+ @env BASH=$(bash) $(bash) mk/run-test.sh $1 < /dev/null
+
+ .PHONY: $1.test-debug
+ $1.test-debug: $1 $(test-deps)
+ @env BASH=$(bash) $(bash) mk/debug-test.sh $1 < /dev/null
endef