-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pkg/driverbuilder): properly export KERNELDIR in kernel-download scripts #330
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,9 +113,9 @@ func (bp *KubernetesBuildProcessor) buildModule(b *builder.Build) error { | |
} | ||
|
||
// We run a script that downloads libs, | ||
// download and extracts kernelURLs saving its output to KERNELDIR env variable, | ||
// then downloads and extracts kernelURLs exporting KERNELDIR env variable, | ||
// then finally runs the build script. | ||
res = fmt.Sprintf("%s\nexport KERNELDIR=$(%s)\n%s", libsDownloadScript, kernelDownloadScript, res) | ||
res = fmt.Sprintf("%s\n%s\n%s", libsDownloadScript, kernelDownloadScript, res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since everything is put in a single bash script here, we don't even need to source kernel-download script. |
||
|
||
if c.ModuleFilePath != "" { | ||
res = fmt.Sprintf("%s\n%s", "touch "+moduleLockFile, res) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropped some |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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) | ||
} | ||
} | ||
|
||
|
@@ -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 { | ||
|
@@ -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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Source the
download-headers
script so thatKERNELDIR
gets set.