From b04b7582fa60f0af87aac744a63cabe2ffe082e6 Mon Sep 17 00:00:00 2001 From: folbrich Date: Wed, 12 Apr 2023 09:58:20 +0100 Subject: [PATCH] bpf2go: deal with missing debug.ReadBuildInfo bazel currently doesn't support debug.ReadBuildInfo. Default to a hardcoded module name to make things work again. Signed-off-by: folbrich --- cmd/bpf2go/main_test.go | 5 +---- cmd/bpf2go/output.go | 5 +---- cmd/bpf2go/tools.go | 7 ++++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cmd/bpf2go/main_test.go b/cmd/bpf2go/main_test.go index a9e2ab619..f8fa6370b 100644 --- a/cmd/bpf2go/main_test.go +++ b/cmd/bpf2go/main_test.go @@ -49,10 +49,7 @@ func TestRun(t *testing.T) { } } - module, err := currentModule() - if err != nil { - t.Fatal(err) - } + module := currentModule() execInModule("go", "mod", "init", "bpf2go-test") diff --git a/cmd/bpf2go/output.go b/cmd/bpf2go/output.go index 241fad8e6..51f197070 100644 --- a/cmd/bpf2go/output.go +++ b/cmd/bpf2go/output.go @@ -112,10 +112,7 @@ func output(args outputArgs) error { return err } - module, err := currentModule() - if err != nil { - return err - } + module := currentModule() gf := &btf.GoFormatter{ Names: typeNames, diff --git a/cmd/bpf2go/tools.go b/cmd/bpf2go/tools.go index 1a3936f27..d2e020b48 100644 --- a/cmd/bpf2go/tools.go +++ b/cmd/bpf2go/tools.go @@ -83,11 +83,12 @@ func toUpperFirst(str string) string { return string(unicode.ToUpper(first)) + str[n:] } -func currentModule() (string, error) { +func currentModule() string { bi, ok := debug.ReadBuildInfo() if !ok { - return "", fmt.Errorf("determine current module: missing build info") + // Fall back to constant since bazel doesn't support BuildInfo. + return "github.com/cilium/ebpf" } - return bi.Main.Path, nil + return bi.Main.Path }