Build into a subdirectory rather than the package source directory

This requires some upstream fixes for srcdir != builddir.
This commit is contained in:
Richard W.M. Jones 2024-01-23 14:16:56 +00:00
parent fb41373acc
commit 8233ecfd32
3 changed files with 324 additions and 2 deletions

View File

@ -0,0 +1,24 @@
From 93a1538808ac7f9788336a7e35168d851e8b2c72 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 23 Jan 2024 13:24:48 +0000
Subject: [PATCH 1/2] common/bitmaps: Fix tests when srcdir != builddir
---
common/bitmap/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/common/bitmap/Makefile.am b/common/bitmap/Makefile.am
index 3b7f4b44f..93ca1ee43 100644
--- a/common/bitmap/Makefile.am
+++ b/common/bitmap/Makefile.am
@@ -52,6 +52,7 @@ check_PROGRAMS = test-bitmap
test_bitmap_SOURCES = test-bitmap.c bitmap.c bitmap.h
test_bitmap_CPPFLAGS = \
-I$(top_srcdir)/include \
+ -I$(top_builddir)/include \
-I$(top_srcdir)/common/include \
$(NULL)
test_bitmap_CFLAGS = $(WARNINGS_CFLAGS)
--
2.43.0

View File

@ -0,0 +1,284 @@
From ac60163ceba1b951e1d2f0625552e6a45d85f666 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 23 Jan 2024 13:35:02 +0000
Subject: [PATCH 2/2] tests: Fix tests to work with srcdir != builddir
---
tests/test-cc-cpp.sh | 2 +-
tests/test-cc-ocaml.sh | 2 +-
tests/test-cc.sh | 2 +-
tests/test-curl-header-script-fail.sh | 2 +-
tests/test-linuxdisk-copy-out.sh | 4 ++--
tests/test-multi-conn-name.sh | 6 ++++--
tests/test-multi-conn.sh | 20 +++++++++++---------
tests/test-plugin-docs.sh | 2 +-
tests/test-shebang-cc.sh | 3 +++
tests/test-tar.sh | 2 +-
tests/cc-shebang.c | 4 +++-
tests/test-read-password-plugin.c | 4 +++-
12 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/tests/test-cc-cpp.sh b/tests/test-cc-cpp.sh
index ebbdab31d..dd9bf58d8 100755
--- a/tests/test-cc-cpp.sh
+++ b/tests/test-cc-cpp.sh
@@ -55,6 +55,6 @@ rm -f $out
nbdkit cc $script \
CC="$CXX" \
- EXTRA_CFLAGS="-I$abs_top_srcdir/include" \
+ EXTRA_CFLAGS="-I$abs_top_srcdir/include -I../include" \
--run 'nbdinfo --size $uri' > $out
test "$(cat $out)" -eq $((100 * 1024 * 1024))
diff --git a/tests/test-cc-ocaml.sh b/tests/test-cc-ocaml.sh
index 68972fce0..79eb678df 100755
--- a/tests/test-cc-ocaml.sh
+++ b/tests/test-cc-ocaml.sh
@@ -57,6 +57,6 @@ cleanup_fn rm -f $out
rm -f $out
nbdkit -v cc $script a=1 b=2 c=3 d=4 \
- CC="$OCAMLOPT" CFLAGS="-output-obj -runtime-variant _pic -I $abs_top_srcdir/plugins/ocaml $OCAML_PLUGIN_LIBRARIES NBDKit.cmx -cclib -L../plugins/ocaml/.libs -cclib -lnbdkitocaml" \
+ CC="$OCAMLOPT" CFLAGS="-output-obj -runtime-variant _pic -I $abs_top_srcdir/plugins/ocaml -I ../plugins/ocaml $OCAML_PLUGIN_LIBRARIES NBDKit.cmx -cclib -L../plugins/ocaml/.libs -cclib -lnbdkitocaml" \
--run 'nbdinfo --size $uri' > $out
test "$(cat $out)" -eq $((512 * 2048))
diff --git a/tests/test-cc.sh b/tests/test-cc.sh
index 2646704be..5c1db8b96 100755
--- a/tests/test-cc.sh
+++ b/tests/test-cc.sh
@@ -53,6 +53,6 @@ cleanup_fn rm -f $out
rm -f $out
nbdkit cc $script \
- EXTRA_CFLAGS="-I$abs_top_srcdir/include" \
+ EXTRA_CFLAGS="-I$abs_top_srcdir/include -I../include" \
--run 'nbdinfo --size $uri' > $out
test "$(cat $out)" -eq $((100 * 1024 * 1024))
diff --git a/tests/test-curl-header-script-fail.sh b/tests/test-curl-header-script-fail.sh
index cf9614f96..282e0ddf0 100755
--- a/tests/test-curl-header-script-fail.sh
+++ b/tests/test-curl-header-script-fail.sh
@@ -50,7 +50,7 @@ cleanup_fn rm -f $errors
# This command is expected to fail.
nbdkit -rfv \
curl file:$PWD/disk protocols=file \
- header-script=$PWD/test-curl-header-script-fail.script \
+ header-script=$abs_top_srcdir/tests/test-curl-header-script-fail.script \
--run 'nbdinfo --no-content $uri' >$errors 2>&1 ||:
cat $errors
diff --git a/tests/test-linuxdisk-copy-out.sh b/tests/test-linuxdisk-copy-out.sh
index 8c2f44bad..81b5b7439 100755
--- a/tests/test-linuxdisk-copy-out.sh
+++ b/tests/test-linuxdisk-copy-out.sh
@@ -65,14 +65,14 @@ guestfish --ro -a linuxdisk-copy-out.img -m /dev/sda <<EOF
tar-out / - | cat >/dev/null
# Download some files and compare to local copies.
- download /Makefile linuxdisk-copy-out.test1
+ download /virtual-disk.c linuxdisk-copy-out.test1
download /Makefile.am linuxdisk-copy-out.test2
download /nbdkit-linuxdisk-plugin.pod linuxdisk-copy-out.test3
download /filesystem.c linuxdisk-copy-out.test4
EOF
# Compare downloaded files to local versions.
-cmp linuxdisk-copy-out.test1 $srcdir/../plugins/linuxdisk/Makefile
+cmp linuxdisk-copy-out.test1 $srcdir/../plugins/linuxdisk/virtual-disk.c
cmp linuxdisk-copy-out.test2 $srcdir/../plugins/linuxdisk/Makefile.am
cmp linuxdisk-copy-out.test3 $srcdir/../plugins/linuxdisk/nbdkit-linuxdisk-plugin.pod
cmp linuxdisk-copy-out.test4 $srcdir/../plugins/linuxdisk/filesystem.c
diff --git a/tests/test-multi-conn-name.sh b/tests/test-multi-conn-name.sh
index 6a180db72..2d2072925 100755
--- a/tests/test-multi-conn-name.sh
+++ b/tests/test-multi-conn-name.sh
@@ -42,6 +42,8 @@ requires_nbdsh_uri
requires nbdsh -c 'print(h.set_opt_mode)'
requires dd iflag=count_bytes </dev/null
+plugin=$srcdir/../tests/test-multi-conn-plugin.sh
+
files="test-multi-conn-name.out"
rm -f $files
cleanup_fn rm -f $files
@@ -69,7 +71,7 @@ print(bytes(h["b1"].pread(1, 0)))
'
# Without the knob we flush all exports
-nbdkit -vf sh test-multi-conn-plugin.sh --filter=multi-conn \
+nbdkit -vf sh $plugin --filter=multi-conn \
--run 'export uri; nbdsh -c "$script"' > test-multi-conn-name.out || fail=1
diff -u <(cat <<\EOF
b'A'
@@ -77,7 +79,7 @@ b'B'
EOF
) test-multi-conn-name.out || fail=1
# But with the knob, our flush is specific to the correct export
-nbdkit -vf sh test-multi-conn-plugin.sh --filter=multi-conn \
+nbdkit -vf sh $plugin --filter=multi-conn \
multi-conn-exportname=true \
--run 'export uri; nbdsh -c "$script"' > test-multi-conn-name.out || fail=1
diff -u <(cat <<\EOF
diff --git a/tests/test-multi-conn.sh b/tests/test-multi-conn.sh
index 3383cd246..eec225c2a 100755
--- a/tests/test-multi-conn.sh
+++ b/tests/test-multi-conn.sh
@@ -41,6 +41,8 @@ requires_plugin sh
requires_nbdsh_uri
requires dd iflag=count_bytes </dev/null
+plugin=$srcdir/../tests/test-multi-conn-plugin.sh
+
files="test-multi-conn.out test-multi-conn.stat"
rm -f $files
cleanup_fn rm -f $files
@@ -63,7 +65,7 @@ print(h[0].can_multi_conn())
# Demonstrate the caching present without use of filter
for filter in '' '--filter=multi-conn multi-conn-mode=plugin'; do
- nbdkit -vf sh test-multi-conn-plugin.sh $filter \
+ nbdkit -vf sh $plugin $filter \
--run 'handles=4 nbdsh -c "$preamble" -c "
# Without flush, reads cache, and writes do not affect persistent data
print(bytes(h[0].pread(4, 0)))
@@ -109,7 +111,7 @@ done
# Demonstrate specifics of FUA flag
for filter in '' '--filter=multi-conn multi-conn-mode=plugin'; do
- nbdkit -vf sh test-multi-conn-plugin.sh $filter \
+ nbdkit -vf sh $plugin $filter \
--run 'nbdsh -c "$preamble" -c "
# Some servers let FUA flush all outstanding requests
h[0].pwrite(b'\''hello '\'', 0)
@@ -123,7 +125,7 @@ EOF
) test-multi-conn.out || fail=1
done
for filter in '' '--filter=multi-conn multi-conn-mode=plugin'; do
- nbdkit -vf sh test-multi-conn-plugin.sh strictfua=1 $filter \
+ nbdkit -vf sh $plugin strictfua=1 $filter \
--run 'nbdsh -c "$preamble" -c "
# But it is also compliant for a server that only flushes the exact request
h[0].pwrite(b'\''hello '\'', 0)
@@ -155,7 +157,7 @@ done
# mode is also able to supply multi-conn by a different technique.
for filter in '--filter=multi-conn' 'strictfua=1 --filter=multi-conn' \
'--filter=multi-conn multi-conn-mode=plugin --filter=cache' ; do
- nbdkit -vf sh test-multi-conn-plugin.sh $filter \
+ nbdkit -vf sh $plugin $filter \
--run 'nbdsh -c "$preamble" -c "
# FUA writes are immediately visible on all connections
h[0].cache(12, 0)
@@ -175,7 +177,7 @@ EOF
done
# unsafe mode intentionally lacks consistency, use at your own risk
-nbdkit -vf sh test-multi-conn-plugin.sh \
+nbdkit -vf sh $plugin \
--filter=multi-conn multi-conn-mode=unsafe \
--run 'nbdsh -c "$preamble" -c "
h[0].cache(12, 0)
@@ -193,7 +195,7 @@ EOF
) test-multi-conn.out || fail=1
# auto mode devolves to multi-conn disable when connections are serialized
-nbdkit -vf sh test-multi-conn-plugin.sh --filter=noparallel \
+nbdkit -vf sh $plugin --filter=noparallel \
serialize=connections --filter=multi-conn --filter=cache \
--run 'handles=1 nbdsh -c "$preamble"
' > test-multi-conn.out || fail=1
@@ -208,7 +210,7 @@ for level in off connection fast; do
plugin 'plugin --filter=cache'; do
echo "setup: $level $mode" >> test-multi-conn.stat
# Flush with no activity
- nbdkit -vf sh test-multi-conn-plugin.sh --filter=multi-conn \
+ nbdkit -vf sh $plugin --filter=multi-conn \
--filter=stats statsfile=test-multi-conn.stat statsappend=true \
multi-conn-track-dirty=$level multi-conn-mode=$mode \
--run 'nbdsh -c "$preamble" -c "
@@ -217,7 +219,7 @@ h[0].pread(1, 0)
h[0].flush()
"' > test-multi-conn.out || fail=1
# Client that flushes assuming multi-conn semantics
- nbdkit -vf sh test-multi-conn-plugin.sh --filter=multi-conn \
+ nbdkit -vf sh $plugin --filter=multi-conn \
--filter=stats statsfile=test-multi-conn.stat statsappend=true \
multi-conn-track-dirty=$level multi-conn-mode=$mode \
--run 'handles=4 nbdsh -c "$preamble" -c "
@@ -230,7 +232,7 @@ h[3].flush()
h[3].flush()
"' > test-multi-conn.out || fail=1
# Client that flushes assuming inconsistent semantics
- nbdkit -vf sh test-multi-conn-plugin.sh --filter=multi-conn \
+ nbdkit -vf sh $plugin --filter=multi-conn \
--filter=stats statsfile=test-multi-conn.stat statsappend=true \
multi-conn-track-dirty=$level multi-conn-mode=$mode \
--run 'nbdsh -c "$preamble" -c "
diff --git a/tests/test-plugin-docs.sh b/tests/test-plugin-docs.sh
index 772cfff07..e329035da 100755
--- a/tests/test-plugin-docs.sh
+++ b/tests/test-plugin-docs.sh
@@ -59,7 +59,7 @@ run_test ()
{
plugin="$1"
- pod=../plugins/$plugin/nbdkit-$plugin-plugin.pod
+ pod=$srcdir/../plugins/$plugin/nbdkit-$plugin-plugin.pod
test -f "$pod"
# Get the key=value lines from the help output.
diff --git a/tests/test-shebang-cc.sh b/tests/test-shebang-cc.sh
index b25b789f7..674d0fcef 100755
--- a/tests/test-shebang-cc.sh
+++ b/tests/test-shebang-cc.sh
@@ -45,6 +45,9 @@ requires_run
requires_plugin cc
requires guestfish --version
+# This variable is used by $script.
+export abs_top_srcdir
+
$script -fv \
EXTRA_CFLAGS="-I$abs_top_srcdir/include" \
--run '
diff --git a/tests/test-tar.sh b/tests/test-tar.sh
index 9c9b3974f..d1a602b99 100755
--- a/tests/test-tar.sh
+++ b/tests/test-tar.sh
@@ -45,7 +45,7 @@ cleanup_fn rm -f $files
# Create a tar file containing the disk image plus some other random
# files that hopefully will be ignored.
-tar cf tar.tar test-tar.sh Makefile disk Makefile.am
+tar cf tar.tar Makefile disk functions.sh
tar tvvf tar.tar
# Run nbdkit.
diff --git a/tests/cc-shebang.c b/tests/cc-shebang.c
index de2730f67..882fa2c1c 100755
--- a/tests/cc-shebang.c
+++ b/tests/cc-shebang.c
@@ -1,5 +1,7 @@
#if 0
-exec nbdkit cc "$0" "$@"
+exec nbdkit cc "$0" "$@" \
+ EXTRA_CFLAGS="-I.. -I../include \
+ -I$abs_top_srcdir/include"
#endif
#include <stdint.h>
#include <string.h>
diff --git a/tests/test-read-password-plugin.c b/tests/test-read-password-plugin.c
index 3f0a95153..703fc724d 100755
--- a/tests/test-read-password-plugin.c
+++ b/tests/test-read-password-plugin.c
@@ -1,5 +1,7 @@
#if 0
-exec nbdkit cc "$0" "$@" EXTRA_CFLAGS="-I.. -I$abs_top_srcdir/include"
+exec nbdkit cc "$0" "$@" \
+ EXTRA_CFLAGS="-I.. -I../include \
+ -I$abs_top_srcdir/include"
#endif
/* nbdkit
* Copyright Red Hat
--
2.43.0

View File

@ -46,7 +46,7 @@
%global verify_tarball_signature 1 %global verify_tarball_signature 1
# If there are patches which touch autotools files, set this to 1. # If there are patches which touch autotools files, set this to 1.
%global patches_touch_autotools %{nil} %global patches_touch_autotools 1
# The source directory. # The source directory.
%global source_directory 1.37-development %global source_directory 1.37-development
@ -84,6 +84,10 @@ Source6: %{modulename}.te
Source7: %{modulename}.if Source7: %{modulename}.if
Source8: %{modulename}.fc Source8: %{modulename}.fc
# Upstream patches to fix srcdir != builddir
Patch: 0001-common-bitmaps-Fix-tests-when-srcdir-builddir.patch
Patch: 0002-tests-Fix-tests-to-work-with-srcdir-builddir.patch
BuildRequires: make BuildRequires: make
%if 0%{patches_touch_autotools} %if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool BuildRequires: autoconf, automake, libtool
@ -696,6 +700,10 @@ autoreconf -i
%build %build
mkdir build_native
pushd build_native
%global _configure ../configure
# Golang bindings are not enabled in the build since they don't # Golang bindings are not enabled in the build since they don't
# need to be. Most people would use them by copying the upstream # need to be. Most people would use them by copying the upstream
# package into their vendor/ directory. # package into their vendor/ directory.
@ -787,8 +795,11 @@ make -f %{_datadir}/selinux/devel/Makefile %{modulename}.pp
bzip2 -9 %{modulename}.pp bzip2 -9 %{modulename}.pp
%endif %endif
popd
%install %install
pushd build_native
%make_install %make_install
# Delete libtool crap. # Delete libtool crap.
@ -819,10 +830,12 @@ install -m 0755 %{SOURCE5} $RPM_BUILD_ROOT%{_rpmconfigdir}/
install -D -m 0644 %{modulename}.pp.bz2 $RPM_BUILD_ROOT%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2 install -D -m 0644 %{modulename}.pp.bz2 $RPM_BUILD_ROOT%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2
install -D -p -m 0644 selinux/%{modulename}.if $RPM_BUILD_ROOT%{_datadir}/selinux/devel/include/distributed/%{modulename}.if install -D -p -m 0644 selinux/%{modulename}.if $RPM_BUILD_ROOT%{_datadir}/selinux/devel/include/distributed/%{modulename}.if
%endif %endif
popd
%check %check
%ifnarch %{broken_test_arches} %ifnarch %{broken_test_arches}
pushd build_native
function skip_test () function skip_test ()
{ {
for f in "$@"; do for f in "$@"; do
@ -867,6 +880,7 @@ export LIBGUESTFS_TRACE=1
cat tests/test-suite.log cat tests/test-suite.log
exit 1 exit 1
} }
popd
%endif %endif
@ -1269,7 +1283,7 @@ fi
# Include the source of the example plugins in the documentation. # Include the source of the example plugins in the documentation.
%doc plugins/example*/*.c %doc plugins/example*/*.c
%if !0%{?rhel} %if !0%{?rhel}
%doc plugins/example4/nbdkit-example4-plugin %doc build_native/plugins/example4/nbdkit-example4-plugin
%doc plugins/lua/example.lua %doc plugins/lua/example.lua
%endif %endif
%if !0%{?rhel} && 0%{?have_ocaml} %if !0%{?rhel} && 0%{?have_ocaml}