From 7a2fd7bf965b556aec2de7bd810fd56caf0dc68a Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 29 Mar 2024 11:37:04 +0100 Subject: [PATCH] fix(pkg/driverbuilder): fix `local` executor to correctly fetch KERNELDIR. Signed-off-by: Federico Di Pierro --- pkg/driverbuilder/local.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/driverbuilder/local.go b/pkg/driverbuilder/local.go index 280ad7e2..2c8b24da 100644 --- a/pkg/driverbuilder/local.go +++ b/pkg/driverbuilder/local.go @@ -2,6 +2,7 @@ package driverbuilder import ( "bufio" + "bytes" "context" _ "embed" "errors" @@ -13,7 +14,6 @@ import ( "os/exec" "os/user" "path/filepath" - "strings" "time" ) @@ -69,10 +69,21 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error { if err == nil { slog.Info("Trying automatic kernel headers download.") kernelDownloadScript, err := builder.KernelDownloadScript(realBuilder, nil, kr) + // Patch kernel download script to echo KERNELDIR. + // We need to capture KERNELDIR to later pass it as env variable to the build. + kernelDownloadScript += "\necho $KERNELDIR" if err == nil { out, err := exec.Command("bash", "-c", kernelDownloadScript).Output() if err == nil { - path := strings.TrimSuffix(string(out), "\n") + // Scan all stdout line by line and + // store last line as KERNELDIR path. + reader := bytes.NewReader(out) + scanner := bufio.NewScanner(reader) + var path string + for scanner.Scan() { + path = scanner.Text() + } + slog.Warn("Setting KERNELDIR", "path", path) // add the kerneldir path to env lbp.envMap[kernelDirEnv] = path defer func() {