@@ -2,6 +2,7 @@ package driverbuilder
2
2
3
3
import (
4
4
"bufio"
5
+ "bytes"
5
6
"context"
6
7
_ "embed"
7
8
"errors"
@@ -13,7 +14,6 @@ import (
13
14
"os/exec"
14
15
"os/user"
15
16
"path/filepath"
16
- "strings"
17
17
"time"
18
18
)
19
19
@@ -67,24 +67,35 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
67
67
// if an unsupported target is passed.
68
68
// Go on skipping automatic kernel headers download.
69
69
if err == nil {
70
- slog .Info ("Trying automatic kernel headers download. " )
70
+ slog .Info ("Trying automatic kernel headers download" )
71
71
kernelDownloadScript , err := builder .KernelDownloadScript (realBuilder , nil , kr )
72
+ // Patch kernel download script to echo KERNELDIR.
73
+ // We need to capture KERNELDIR to later pass it as env variable to the build.
74
+ kernelDownloadScript += "\n echo $KERNELDIR"
72
75
if err == nil {
73
76
out , err := exec .Command ("bash" , "-c" , kernelDownloadScript ).Output ()
74
77
if err == nil {
75
- path := strings .TrimSuffix (string (out ), "\n " )
78
+ // Scan all stdout line by line and
79
+ // store last line as KERNELDIR path.
80
+ reader := bytes .NewReader (out )
81
+ scanner := bufio .NewScanner (reader )
82
+ var path string
83
+ for scanner .Scan () {
84
+ path = scanner .Text ()
85
+ }
86
+ slog .Info ("Setting KERNELDIR env var" , "path" , path )
76
87
// add the kerneldir path to env
77
88
lbp .envMap [kernelDirEnv ] = path
78
89
defer func () {
79
90
_ = os .RemoveAll ("/tmp/kernel-download" )
80
91
_ = os .RemoveAll (path )
81
92
}()
82
93
} else {
83
- slog .Warn ("Failed to download headers. " , "err" , err )
94
+ slog .Warn ("Failed to download headers" , "err" , err )
84
95
}
85
96
}
86
97
} else {
87
- slog .Info ("Skipping kernel headers automatic download. " , "err" , err )
98
+ slog .Info ("Skipping kernel headers automatic download" , "err" , err )
88
99
}
89
100
}
90
101
@@ -137,7 +148,7 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
137
148
srcProbePath := vv .GetProbeFullPath (c )
138
149
139
150
if len (lbp .srcDir ) == 0 {
140
- slog .Info ("Downloading driver sources. " )
151
+ slog .Info ("Downloading driver sources" )
141
152
// Download src!
142
153
libsDownloadScript , err := builder .LibsDownloadScript (c )
143
154
if err != nil {
@@ -168,14 +179,14 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
168
179
169
180
stdout , err := cmd .StdoutPipe ()
170
181
if err != nil {
171
- slog .Warn ("Failed to pipe stdout. Trying without piping. " , "err" , err )
182
+ slog .Warn ("Failed to pipe stdout" , "err" , err )
172
183
_ , err = cmd .CombinedOutput ()
173
184
} else {
174
185
cmd .Stderr = cmd .Stdout // redirect stderr to stdout so that we catch it
175
186
defer stdout .Close ()
176
187
err = cmd .Start ()
177
188
if err != nil {
178
- slog .Warn ("Failed to execute command. " , "err" , err )
189
+ slog .Warn ("Failed to execute command" , "err" , err )
179
190
} else {
180
191
// print the output of the subprocess line by line
181
192
scanner := bufio .NewScanner (stdout )
0 commit comments