Skip to content

Commit

Permalink
fix(pkg/driverbuilder): fix local executor to correctly fetch KERNE…
Browse files Browse the repository at this point in the history
…LDIR.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed Mar 29, 2024
1 parent a6610e6 commit 8ea62ad
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pkg/driverbuilder/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driverbuilder

import (
"bufio"
"bytes"
"context"
_ "embed"
"errors"
Expand All @@ -13,7 +14,6 @@ import (
"os/exec"
"os/user"
"path/filepath"
"strings"
"time"
)

Expand Down Expand Up @@ -67,24 +67,35 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
// if an unsupported target is passed.
// Go on skipping automatic kernel headers download.
if err == nil {
slog.Info("Trying automatic kernel headers download.")
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.Info("Setting KERNELDIR env var", "path", path)
// add the kerneldir path to env
lbp.envMap[kernelDirEnv] = path
defer func() {
_ = os.RemoveAll("/tmp/kernel-download")
_ = os.RemoveAll(path)
}()
} else {
slog.Warn("Failed to download headers.", "err", err)
slog.Warn("Failed to download headers", "err", err)
}
}
} else {
slog.Info("Skipping kernel headers automatic download.", "err", err)
slog.Info("Skipping kernel headers automatic download", "err", err)
}
}

Expand Down Expand Up @@ -137,7 +148,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
srcProbePath := vv.GetProbeFullPath(c)

if len(lbp.srcDir) == 0 {
slog.Info("Downloading driver sources.")
slog.Info("Downloading driver sources")
// Download src!
libsDownloadScript, err := builder.LibsDownloadScript(c)
if err != nil {
Expand Down Expand Up @@ -168,14 +179,14 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {

stdout, err := cmd.StdoutPipe()
if err != nil {
slog.Warn("Failed to pipe stdout. Trying without piping.", "err", err)
slog.Warn("Failed to pipe stdout", "err", err)
_, err = cmd.CombinedOutput()
} else {
cmd.Stderr = cmd.Stdout // redirect stderr to stdout so that we catch it
defer stdout.Close()
err = cmd.Start()
if err != nil {
slog.Warn("Failed to execute command.", "err", err)
slog.Warn("Failed to execute command", "err", err)
} else {
// print the output of the subprocess line by line
scanner := bufio.NewScanner(stdout)
Expand Down

0 comments on commit 8ea62ad

Please sign in to comment.