From 4e1e8035f3a8696dbf410a4576b51f68f62e6830 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 18 Aug 2018 22:04:17 -0700 Subject: pkg/build: update gvisor race build process Use separate target as this is something that can be upstreamed. --- pkg/build/gvisor.go | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'pkg') diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go index ea961d6ae..5628d6628 100644 --- a/pkg/build/gvisor.go +++ b/pkg/build/gvisor.go @@ -4,7 +4,6 @@ package build import ( - "fmt" "path/filepath" "strings" "time" @@ -16,42 +15,26 @@ type gvisor struct{} func (gvisor gvisor) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir, cmdlineFile, sysctlFile string, config []byte) error { + outBinary := "" args := []string{"build", "--verbose_failures"} if strings.Contains(" "+string(config)+" ", " -race ") { - args = append(args, "--features=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, "runsc") + outBinary = filepath.Join(kernelDir, filepath.FromSlash(outBinary)) if _, err := osutil.RunCmd(20*time.Minute, kernelDir, compiler, args...); err != nil { return err } - if err := gvisor.copyBinary(kernelDir, outputDir); err != nil { + if err := osutil.CopyFile(outBinary, filepath.Join(outputDir, "image")); err != nil { return err } - if len(config) != 0 { - if err := osutil.WriteFile(filepath.Join(outputDir, "kernel.config"), config); err != nil { - return fmt.Errorf("failed to save kernel config: %v", err) - } - } osutil.RunCmd(10*time.Minute, kernelDir, compiler, "shutdown") return nil } -func (gvisor) copyBinary(kernelDir, outputDir string) error { - // Funny it's not possible to understand what bazel actually built... - for _, typ := range []string{ - "linux_amd64_pure_stripped", - "linux_amd64_static_stripped", - "linux_amd64_static_race_stripped", - } { - runsc := filepath.Join(kernelDir, "bazel-bin", "runsc", typ, "runsc") - if !osutil.IsExist(runsc) { - continue - } - return osutil.CopyFile(runsc, filepath.Join(outputDir, "image")) - } - return fmt.Errorf("failed to locate bazel output") -} - func (gvisor) clean(kernelDir string) error { // Let's assume that bazel always properly handles build without cleaning (until proven otherwise). return nil -- cgit mrf-deployment