Fix kselftest builds when specifying an output dir
cover Fix kselftest builds when specifying an output dir
From: "Tyler Hicks" <[email protected]>
When attempting to build kselftests with a separate output directory, a number of the tests fail to build.
For example,
$ rm -rf build && \ make INSTALL_HDR_PATH=build/usr headers_install > /dev/null && \ make O=build FORCE_TARGETS=1 TARGETS=breakpoints -C tools/testing/selftests > /dev/null /usr/bin/ld: cannot open output file build/kselftest/breakpoints/step_after_suspend_test: No such file or directory collect2: error: ld returned 1 exit status make[1]: *** [../lib.mk:146: build/kselftest/breakpoints/step_after_suspend_test] Error 1 make: *** [Makefile:163: all] Error 2
This has already been addressed upstream with v5.18 commit 5ad51ab618de ("selftests: set the BUILD variable to absolute path"). It is a clean cherry pick to the linux-5.15.y and linux-5.10.y branches.
Tyler
Muhammad Usama Anjum (1):
selftests: set the BUILD variable to absolute path
tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/1 selftests: set the BUILD variable to absolute path
From: Muhammad Usama Anjum <[email protected]>
commit 5ad51ab618de5d05f4e692ebabeb6fe6289aaa57 upstream.
The build of kselftests fails if relative path is specified through KBUILD_OUTPUT or O=<path> method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails.
make[1]: Entering directory '/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa'
gcc mixer-test.c -L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test
/usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-test
Set the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make.
--- tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
tools/testing/selftests/Makefile +17 -9
@@ -114,19 +114,27 @@ ifdef building_out_of_srctree override LDFLAGS = endif -ifneq ($(O),) - BUILD := $(O)/kselftest +top_srcdir ?= ../../.. + +ifeq ("$(origin O)", "command line") + KBUILD_OUTPUT := $(O) +endif + +ifneq ($(KBUILD_OUTPUT),) + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot + # expand a shell special character '~'. We use a somewhat tedious way here. + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) + $(if $(abs_objtree),, \ + $(error failed to create output directory "$(KBUILD_OUTPUT)")) + # $(realpath ...) resolves symlinks + abs_objtree := $(realpath $(abs_objtree)) + BUILD := $(abs_objtree)/kselftest else - ifneq ($(KBUILD_OUTPUT),) - BUILD := $(KBUILD_OUTPUT)/kselftest - else - BUILD := $(shell pwd) - DEFAULT_INSTALL_HDR_PATH := 1 - endif + BUILD := $(CURDIR) + DEFAULT_INSTALL_HDR_PATH := 1 endif # Prepare for headers install -top_srcdir ?= ../../.. include $(top_srcdir)/scripts/subarch.include ARCH ?= $(SUBARCH) export KSFT_KHDR_INSTALL_DONE := 1
Signature · 1 line
2.34.1
Greg KH
maintainerRe: [PATCH 5.15 5.10 1/1] selftests: set the BUILD variable to absolute path
Quoted 18 lines · Tyler Hicks
From: Muhammad Usama Anjum <[email protected]>
commit
5ad51ab618de5d05f4e692ebabeb6fe6289aaa57upstream.The build of kselftests fails if relative path is specified through
KBUILD_OUTPUTor O=<path> method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails.make[1]: Entering directory '
/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa'
gccmixer-test.c-L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test
/usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-testSet the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make.
Quoted 7 lines
Signed-off-by Muhammad Usama Anjum <[email protected]>Signed-off-by Shuah Khan <[email protected]>Signed-off-by Tyler Hicks (Microsoft) <[email protected]>--- tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
Now queued up, thanks.
greg k-h