Skip to content
Permalink
Browse files

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.
  • Loading branch information...
dvyukov committed Mar 29, 2019
1 parent 6b138f0 commit 9633c5c8a1a030cdfdc0f94ae460314c7fc15faa
Showing with 29 additions and 5 deletions.
  1. +7 −1 pkg/build/build.go
  2. +18 −0 pkg/build/build_test.go
  3. +1 −1 pkg/build/linux.go
  4. +2 −2 pkg/build/netbsd.go
  5. +1 −1 pkg/build/openbsd.go
@@ -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")},
}
@@ -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) {
@@ -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")
@@ -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"},
@@ -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 }{

1 comment on commit 9633c5c

@dvyukov

This comment has been minimized.

Copy link
Collaborator Author

commented on 9633c5c Mar 29, 2019

@prattmic @nlacasse FYI
Our builds seem to be failing for the past 2 week, but we didn't notice.

Please sign in to comment.
You can’t perform that action at this time.