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 }