Skip to content

Commit

Permalink
Clean build cache for non-vendored builds
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Feb 26, 2025
1 parent 1c384d0 commit 9b9ae26
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bpf/build_ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"unicode"
)

const DEBUG = false
const DEBUG = true
const OCI_BIN = "docker"
const GEN_IMG = "ghcr.io/grafana/beyla-ebpf-generator:main"

Expand Down Expand Up @@ -400,6 +400,20 @@ func ensureDirsWritable(files []string) error {
return nil
}

func isModuleVendored(wd string) bool {
return strings.Contains(wd, "/vendor/")
}

func cleanBuildCache() error {
cmd := exec.Command("go", "clean", "-cache")

if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to clean build cache: %w", err)
}

return nil
}

func bail(err error) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down Expand Up @@ -485,4 +499,10 @@ func main() {
if err := cmd.Wait(); err != nil {
bail(fmt.Errorf("error waiting for child process: %w", err))
}

if !isModuleVendored(wd) {
if err := cleanBuildCache(); err != nil {
bail(err)
}
}
}

0 comments on commit 9b9ae26

Please sign in to comment.