diff options
| author | Andrei Vagin <avagin@google.com> | 2020-11-12 22:13:03 -0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-11-13 10:16:13 +0100 |
| commit | 4a7fa9b416fd0a961793328a785666d6d2c5976d (patch) | |
| tree | 574dc066be5979765e80e4e69b28234a05a0731d /pkg | |
| parent | 964579c32651d56c73d4b7f25ce965a4fb207cf3 (diff) | |
build/gvisor: get a path to the runsc binary from bazel
Right now, we use a hard-coded path, but Dmirty found that it is wrong
for the current versions of bazel and gvisor.
Signed-off-by: Andrei Vagin <avagin@google.com>
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/gvisor.go | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go index 45940cd14..035f8e20e 100644 --- a/pkg/build/gvisor.go +++ b/pkg/build/gvisor.go @@ -4,7 +4,9 @@ package build import ( + "fmt" "path/filepath" + "regexp" "strings" "time" @@ -13,32 +15,46 @@ import ( type gvisor struct{} +var bazelTargetPath = regexp.MustCompile(`(?sm:.*^)\s*Outputs: \[(.*)\](?sm:$.*)`) + func (gvisor gvisor) build(params *Params) error { // Bring down bazel daemon right away. We don't need it running and consuming memory. defer osutil.RunCmd(10*time.Minute, params.KernelDir, params.Compiler, "shutdown") config := " " + string(params.Config) + " " args := []string{"build", "--verbose_failures"} - outBinary := "" + target := "//runsc:runsc" if strings.Contains(config, " -cover ") { args = append(args, []string{ "--collect_code_coverage", "--instrumentation_filter=//pkg/...,-//pkg/sentry/platform/..."}...) } if strings.Contains(config, " -race ") { - args = append(args, "--features=race", "//runsc:runsc-race") - outBinary = "bazel-bin/runsc/linux_amd64_static_race_stripped/runsc-race" - } else { - args = append(args, "//runsc:runsc") - outBinary = "bazel-bin/runsc/linux_amd64_pure_stripped/runsc" + args = append(args, "--features=race") + target = "//runsc:runsc-race" } - outBinary = filepath.Join(params.KernelDir, filepath.FromSlash(outBinary)) + args = append(args, target) // The 1 hour timeout is quite high. But we've seen false positives with 20 mins // on the first build after bazel/deps update. Also other gvisor instances running // on the same machine contribute to longer build times. if _, err := osutil.RunCmd(60*time.Minute, params.KernelDir, params.Compiler, args...); err != nil { return err } + + // Find out a path to the runsc binary. + out, err := osutil.RunCmd(time.Minute, params.KernelDir, params.Compiler, + "aquery", fmt.Sprintf("mnemonic(\"GoLink\", %s)", target)) + if err != nil { + return err + } + + match := bazelTargetPath.FindSubmatch(out) + if match == nil { + return fmt.Errorf("faile to find the runsc binary") + } + outBinary := string(match[1]) + outBinary = filepath.Join(params.KernelDir, filepath.FromSlash(outBinary)) + if err := osutil.CopyFile(outBinary, filepath.Join(params.OutputDir, "image")); err != nil { return err } |
