Skip to content

Commit

Permalink
bpf2go: deal with missing debug.ReadBuildInfo
Browse files Browse the repository at this point in the history
bazel currently doesn't support debug.ReadBuildInfo. Default to
a hardcoded module name to make things work again.

Signed-off-by: folbrich <frank.olbricht@gmail.com>
  • Loading branch information
folbricht authored and lmb committed Apr 12, 2023
1 parent dd8ab94 commit b04b758
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
5 changes: 1 addition & 4 deletions cmd/bpf2go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
5 changes: 1 addition & 4 deletions cmd/bpf2go/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions cmd/bpf2go/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b04b758

Please sign in to comment.