diff mbox series

[2/2] btrfs-progs: library-test: header and BTRFS_FLAT_INCLUDES cleanups

Message ID daa6866b4b135c8befec9c2c30b7857a5e50392c.1711837050.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: header cleanups | expand

Commit Message

Qu Wenruo March 30, 2024, 10:24 p.m. UTC
Macro BTRFS_FLAT_INCLUDES is utilized to indicate if we should include
files directly from the source code headers, or libbtrfsutil headers.

Normally it should only be utlized by libbtrfsutil headers, for
programs they should either rely on the source code headers, or the
libbtrfsutil headers, not both.

The only exception is tests/library-test.c, which during tests we
would prepare a temporary directory and populate it with compiled
libbtrfsutil library and its headers, and compile library-test program
against the libbtrfsutil we built (not the system one).

So library-test is never utilizing any headers inside the source tree,
thus BTRFS_FLAT_INCLUDES is never set for it.

This can be verified by Makefile:

  library-test: tests/library-test.c libbtrfs.so
  	@echo "    [TEST PREP]  $@"$(eval TMPD=$(shell mktemp -d))
  	$(Q)mkdir -p $(TMPD)/include/btrfs && \
  	cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
  	cp libbtrfs.so.0.1 $(TMPD) && \
  	cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(ABSTOPDIR)/,$^) -Wl,-rpath=$(ABSTOPDIR)
  	@echo "    [TEST RUN]   $@"
  	$(Q)cd $(TMPD) && LD_PRELOAD=libbtrfs.so.0.1 ./$@
  	@echo "    [TEST CLEAN] $@"
  	$(Q)$(RM) -rf -- $(TMPD)

Note that, -DBTRFS_FLAT_INCLUDES is only defined in $CFLAGS, and we do
not pass $CFLAGS for the compiling of library-test at all.

So this patch would remove the BTRFS_FLAT_INCLUDES related checks,
replace it with a comment, then cleanup the unused headers.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/library-test.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/tests/library-test.c b/tests/library-test.c
index 3a09044a7d85..87dbba9f219f 100644
--- a/tests/library-test.c
+++ b/tests/library-test.c
@@ -16,31 +16,15 @@ 
  * Boston, MA 021110-1307, USA.
  */
 
-#if BTRFS_FLAT_INCLUDES
-#include "libbtrfs/kerncompat.h"
-#include "libbtrfs/version.h"
-#include "libbtrfs/ioctl.h"
-#include "kernel-lib/rbtree.h"
-#include "kernel-lib/list.h"
-#include "kernel-shared/ctree.h"
-#include "kernel-shared/send.h"
-#include "common/send-stream.h"
-#include "common/send-utils.h"
-#else
 /*
- * This needs to include headers the same way as an external program but must
- * not use the existing system headers, so we use "...".
+ * This program is only linked to libbtrfsutil library, and only include
+ * headers from libbtrfsutil, so we do not use the filepath inside btrfs-progs
+ * source code.
  */
 #include "btrfs/kerncompat.h"
 #include "btrfs/version.h"
-#include "btrfs/rbtree.h"
-#include "btrfs/list.h"
-#include "btrfs/ctree.h"
-#include "btrfs/ioctl.h"
-#include "btrfs/send.h"
 #include "btrfs/send-stream.h"
 #include "btrfs/send-utils.h"
-#endif
 
 /*
  * Reduced code snippet from snapper.git/snapper/Btrfs.cc