diff options
| author | Dean Deng <deandeng@google.com> | 2020-12-03 10:32:17 -0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-12-03 20:43:51 +0100 |
| commit | 9e0b299f6daa2b5e1aee3fb4a049df106157d236 (patch) | |
| tree | 4f912066fa7b6a39f5a75b649c4f14dc5f52a896 /pkg | |
| parent | 643fdf46845e2154338b833203e1e778d38b524f (diff) | |
pkg/build: fix config parsing for gVisor
In the previous method, string comparisons did not work properly for the
last flag because it is followed by a newline character.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/gvisor.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go index 035f8e20e..d0711ee70 100644 --- a/pkg/build/gvisor.go +++ b/pkg/build/gvisor.go @@ -21,15 +21,15 @@ 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) + " " + config := strings.Fields(string(params.Config)) args := []string{"build", "--verbose_failures"} target := "//runsc:runsc" - if strings.Contains(config, " -cover ") { + if coverageEnabled(config) { args = append(args, []string{ "--collect_code_coverage", "--instrumentation_filter=//pkg/...,-//pkg/sentry/platform/..."}...) } - if strings.Contains(config, " -race ") { + if raceEnabled(config) { args = append(args, "--features=race") target = "//runsc:runsc-race" } @@ -50,7 +50,7 @@ func (gvisor gvisor) build(params *Params) error { match := bazelTargetPath.FindSubmatch(out) if match == nil { - return fmt.Errorf("faile to find the runsc binary") + return fmt.Errorf("failed to find the runsc binary") } outBinary := string(match[1]) outBinary = filepath.Join(params.KernelDir, filepath.FromSlash(outBinary)) @@ -65,3 +65,21 @@ func (gvisor) clean(kernelDir, targetArch string) error { // Let's assume that bazel always properly handles build without cleaning (until proven otherwise). return nil } + +func coverageEnabled(config []string) bool { + for _, flag := range config { + if flag == "-cover" { + return true + } + } + return false +} + +func raceEnabled(config []string) bool { + for _, flag := range config { + if flag == "-race" { + return true + } + } + return false +} |
