pkg/build: extract bazel build errors

We currently manually call extractRootCause in few selected places
to denote kernel build errors that we want to report to developers.
The rest are considered infra errors that we don't report.
This does not work well. We are missing fuchsia and gvisor build errors.
Treat all external command exection failures as kernel build errors instead.
Let's see how this works in practice.
Also add bazel-specfic error patterns and tests.
This commit is contained in:
Dmitry Vyukov 2019-03-29 11:00:34 +01:00
parent 6b138f0f3c
commit 9633c5c8a1
5 changed files with 29 additions and 5 deletions

View File

@ -41,7 +41,8 @@ func Image(targetOS, targetArch, vmType, kernelDir, outputDir, compiler, userspa
return fmt.Errorf("failed to write config file: %v", err)
}
}
return builder.build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir, cmdlineFile, sysctlFile, config)
err = builder.build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir, cmdlineFile, sysctlFile, config)
return extractRootCause(err)
}
func Clean(targetOS, targetArch, vmType, kernelDir string) error {
@ -125,6 +126,9 @@ func CompilerIdentity(compiler string) (string, error) {
}
func extractRootCause(err error) error {
if err == nil {
return nil
}
verr, ok := err.(*osutil.VerboseError)
if !ok {
return err
@ -159,8 +163,10 @@ type buildFailureCause struct {
var buildFailureCauses = [...]buildFailureCause{
{pattern: []byte(": error: ")},
{pattern: []byte("ERROR: ")},
{pattern: []byte(": fatal error: ")},
{pattern: []byte(": undefined reference to")},
{weak: true, pattern: []byte(": final link failed: ")},
{weak: true, pattern: []byte("collect2: error: ")},
{weak: true, pattern: []byte("FAILED: Build did NOT complete")},
}

View File

@ -66,6 +66,24 @@ make: *** Waiting for unfinished jobs....
`,
"/gcc-5.5.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.5.0/plugin/include/builtins.h:23:17: fatal error: mpc.h: No such file or directory",
},
{`
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Analyzing: target //runsc:runsc (1 packages loaded)
Analyzing: target //runsc:runsc (5 packages loaded)
Analyzing: target //runsc:runsc (15 packages loaded)
Analyzing: target //runsc:runsc (92 packages loaded)
Analyzing: target //runsc:runsc (99 packages loaded)
Analyzing: target //runsc:runsc (115 packages loaded)
ERROR: /syzkaller/managers/ptrace-direct-overlay-host/kernel/vdso/BUILD:13:1: no such target '@bazel_tools//tools/cpp:cc_flags': target 'cc_flags' not declared in package 'tools/cpp' defined by /syzkaller/home/.cache/bazel/_bazel_root/e1c9d86bae2b34f90e83d224bc900958/external/bazel_tools/tools/cpp/BUILD and referenced by '//vdso:vdso'
ERROR: Analysis of target '//runsc:runsc' failed; build aborted: Analysis failed
INFO: Elapsed time: 14.914s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (189 packages loaded)
`,
"ERROR: Analysis of target '//runsc:runsc' failed; build aborted: Analysis failed",
},
} {
got := extractCauseInner([]byte(s.e))
if !bytes.Equal([]byte(s.expect), got) {

View File

@ -66,7 +66,7 @@ func (linux) buildKernel(kernelDir, outputDir, compiler string, config []byte) e
}
cmd.Dir = kernelDir
if _, err := osutil.Run(time.Hour, cmd); err != nil {
return extractRootCause(err)
return err
}
vmlinux := filepath.Join(kernelDir, "vmlinux")
outputVmlinux := filepath.Join(outputDir, "obj", "vmlinux")

View File

@ -41,13 +41,13 @@ no options SVS
// Build tools before building kernel
if _, err := osutil.RunCmd(10*time.Minute, kernelDir, "./build.sh", "-m", targetArch,
"-U", "-u", "-j"+strconv.Itoa(runtime.NumCPU()), "tools"); err != nil {
return extractRootCause(err)
return err
}
// Build kernel
if _, err := osutil.RunCmd(10*time.Minute, kernelDir, "./build.sh", "-m", targetArch,
"-U", "-u", "-j"+strconv.Itoa(runtime.NumCPU()), "kernel="+kernelName); err != nil {
return extractRootCause(err)
return err
}
for _, s := range []struct{ dir, src, dst string }{
{compileDir, "netbsd.gdb", "obj/netbsd.gdb"},

View File

@ -35,7 +35,7 @@ func (ctx openbsd) build(targetArch, vmType, kernelDir, outputDir, compiler, use
}
for _, tgt := range []string{"clean", "obj", "config", "all"} {
if err := ctx.make(compileDir, tgt); err != nil {
return extractRootCause(err)
return err
}
}
for _, s := range []struct{ dir, src, dst string }{