tools/testing/selftests/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Fixes an issue where out-of-tree kselftest builds fail when building
the BPF and bpftools components. The failure occurs because the top-level
Makefile passes a relative srctree path to its sub-Makefiles, which
leads to errors in locating necessary files.
For example, the following error is encountered:
```
$ make V=1 O=$build/ TARGETS=hid kselftest-all
...
make -C ../tools/testing/selftests all
make[4]: Entering directory '/path/to/linux/tools/testing/selftests/hid'
make -C /path/to/linux/tools/testing/selftests/../../../tools/lib/bpf OUTPUT=/path/to/linux/O/kselftest/hid/tools/build/libbpf/ \
EXTRA_CFLAGS='-g -O0' \
DESTDIR=/path/to/linux/O/kselftest/hid/tools prefix= all install_headers
make[5]: Entering directory '/path/to/linux/tools/lib/bpf'
...
make[5]: Entering directory '/path/to/linux/tools/bpf/bpftool'
Makefile:127: ../tools/build/Makefile.feature: No such file or directory
make[5]: *** No rule to make target '../tools/build/Makefile.feature'. Stop.
```
To resolve this, override the srctree in the kselftests's top Makefile
when performing an out-of-tree build. This ensures that all sub-Makefiles
have the correct path to the source tree, preventing directory resolution
errors.
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Tested-by: Quentin Monnet <qmo@kernel.org>
---
Cc: Masahiro Yamada <masahiroy@kernel.org>
V3:
collected Tested-by and rebased on bpf-next
V2:
- handle srctree in selftests itself rather than the linux' top Makefile # Masahiro Yamada <masahiroy@kernel.org>
V1: https://lore.kernel.org/lkml/20241217031052.69744-1-lizhijian@fujitsu.com/
---
tools/testing/selftests/Makefile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 2401e973c359..f04a3b0003f6 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -154,15 +154,19 @@ override LDFLAGS =
override MAKEFLAGS =
endif
+top_srcdir ?= ../../..
+
# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
# KBUILD_OUTPUT with selftest objects and headers installed
# by selftests Makefile or lib.mk.
+# Override the `srctree` variable to ensure it is correctly resolved in
+# sub-Makefiles, such as those within `bpf`, when managing targets like
+# `net` and `hid`.
ifdef building_out_of_srctree
override LDFLAGS =
+override srctree := $(top_srcdir)
endif
-top_srcdir ?= ../../..
-
ifeq ("$(origin O)", "command line")
KBUILD_OUTPUT := $(O)
endif
--
2.44.0
On 1/15/25 2:47 AM, Li Zhijian wrote: > Fixes an issue where out-of-tree kselftest builds fail when building > the BPF and bpftools components. The failure occurs because the top-level > Makefile passes a relative srctree path to its sub-Makefiles, which > leads to errors in locating necessary files. > > For example, the following error is encountered: > > ``` > $ make V=1 O=$build/ TARGETS=hid kselftest-all > ... > make -C ../tools/testing/selftests all > make[4]: Entering directory '/path/to/linux/tools/testing/selftests/hid' > make -C /path/to/linux/tools/testing/selftests/../../../tools/lib/bpf OUTPUT=/path/to/linux/O/kselftest/hid/tools/build/libbpf/ \ > EXTRA_CFLAGS='-g -O0' \ > DESTDIR=/path/to/linux/O/kselftest/hid/tools prefix= all install_headers > make[5]: Entering directory '/path/to/linux/tools/lib/bpf' > ... > make[5]: Entering directory '/path/to/linux/tools/bpf/bpftool' > Makefile:127: ../tools/build/Makefile.feature: No such file or directory > make[5]: *** No rule to make target '../tools/build/Makefile.feature'. Stop. > ``` > > To resolve this, override the srctree in the kselftests's top Makefile > when performing an out-of-tree build. This ensures that all sub-Makefiles > have the correct path to the source tree, preventing directory resolution > errors. > > Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com> > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> > Tested-by: Quentin Monnet <qmo@kernel.org> [...] > tools/testing/selftests/Makefile | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) Shuah, want to pick this up given its the top-level Makefile or want us to route it via bpf-next with your Ack? Fwiw, BPF CI went through fine.
ping... On 15/01/2025 23:06, Daniel Borkmann wrote: > On 1/15/25 2:47 AM, Li Zhijian wrote: >> Fixes an issue where out-of-tree kselftest builds fail when building >> the BPF and bpftools components. The failure occurs because the top-level >> Makefile passes a relative srctree path to its sub-Makefiles, which >> leads to errors in locating necessary files. >> >> For example, the following error is encountered: >> >> ``` >> $ make V=1 O=$build/ TARGETS=hid kselftest-all >> ... >> make -C ../tools/testing/selftests all >> make[4]: Entering directory '/path/to/linux/tools/testing/selftests/hid' >> make -C /path/to/linux/tools/testing/selftests/../../../tools/lib/bpf OUTPUT=/path/to/linux/O/kselftest/hid/tools/build/libbpf/ \ >> EXTRA_CFLAGS='-g -O0' \ >> DESTDIR=/path/to/linux/O/kselftest/hid/tools prefix= all install_headers >> make[5]: Entering directory '/path/to/linux/tools/lib/bpf' >> ... >> make[5]: Entering directory '/path/to/linux/tools/bpf/bpftool' >> Makefile:127: ../tools/build/Makefile.feature: No such file or directory >> make[5]: *** No rule to make target '../tools/build/Makefile.feature'. Stop. >> ``` >> >> To resolve this, override the srctree in the kselftests's top Makefile >> when performing an out-of-tree build. This ensures that all sub-Makefiles >> have the correct path to the source tree, preventing directory resolution >> errors. >> >> Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com> >> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> >> Tested-by: Quentin Monnet <qmo@kernel.org> > > [...] >> tools/testing/selftests/Makefile | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) > > Shuah, want to pick this up given its the top-level Makefile or want us to > route it via bpf-next with your Ack? Fwiw, BPF CI went through fine.
© 2016 - 2025 Red Hat, Inc.