* [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds
@ 2024-12-23 8:33 Li Zhijian
2025-01-02 12:03 ` Quentin Monnet
2025-01-14 22:35 ` Andrii Nakryiko
0 siblings, 2 replies; 4+ messages in thread
From: Li Zhijian @ 2024-12-23 8:33 UTC (permalink / raw)
To: linux-kselftest
Cc: Masahiro Yamada, linux-kernel, bpf, Shuah Khan, Li Zhijian
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.
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
Cc: Masahiro Yamada <masahiroy@kernel.org>
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 3d8a80abd4f0..ab82278353cf 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds
2024-12-23 8:33 [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds Li Zhijian
@ 2025-01-02 12:03 ` Quentin Monnet
2025-01-14 22:35 ` Andrii Nakryiko
1 sibling, 0 replies; 4+ messages in thread
From: Quentin Monnet @ 2025-01-02 12:03 UTC (permalink / raw)
To: Li Zhijian, linux-kselftest
Cc: Masahiro Yamada, linux-kernel, bpf, Shuah Khan
2024-12-23 16:33 UTC+0800 ~ Li Zhijian <lizhijian@fujitsu.com>
> 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.
>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
I simply tested with "make V=1 O=build/ TARGETS=hid kselftest-all", this
approach fixes the build just as well as v1. Thanks!
Tested-by: Quentin Monnet <qmo@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds
2024-12-23 8:33 [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds Li Zhijian
2025-01-02 12:03 ` Quentin Monnet
@ 2025-01-14 22:35 ` Andrii Nakryiko
2025-01-15 1:45 ` Zhijian Li (Fujitsu)
1 sibling, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2025-01-14 22:35 UTC (permalink / raw)
To: Li Zhijian
Cc: linux-kselftest, Masahiro Yamada, linux-kernel, bpf, Shuah Khan
On Mon, Dec 23, 2024 at 12:33 AM Li Zhijian <lizhijian@fujitsu.com> 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.
>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> Cc: Masahiro Yamada <masahiroy@kernel.org>
>
> 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(-)
>
Is this intended to go through the bpf-next tree? I don't see it in
our patchworks, so please rebase and resend (unless this was routed
through some other tree already)
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 3d8a80abd4f0..ab82278353cf 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
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds
2025-01-14 22:35 ` Andrii Nakryiko
@ 2025-01-15 1:45 ` Zhijian Li (Fujitsu)
0 siblings, 0 replies; 4+ messages in thread
From: Zhijian Li (Fujitsu) @ 2025-01-15 1:45 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: linux-kselftest, Masahiro Yamada, linux-kernel, bpf, Shuah Khan
Hi Andrii
I am delighted to hear from you.
I will rebase and resent it to bpf soon.
On 15/01/2025 06:35, Andrii Nakryiko wrote:
> On Mon, Dec 23, 2024 at 12:33 AM Li Zhijian<lizhijian@fujitsu.com> 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.
>>
>> Signed-off-by: Li Zhijian<lizhijian@fujitsu.com>
>> ---
>> Cc: Masahiro Yamada<masahiroy@kernel.org>
>>
>> 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(-)
>>
> Is this intended to go through the bpf-next tree? I don't see it in
> our patchworks, so please rebase and resend (unless this was routed
> through some other tree already)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-15 1:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-23 8:33 [PATCH for-next v2] selftests/Makefile: override the srctree for out-of-tree builds Li Zhijian
2025-01-02 12:03 ` Quentin Monnet
2025-01-14 22:35 ` Andrii Nakryiko
2025-01-15 1:45 ` Zhijian Li (Fujitsu)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®