diff --git a/tools/sggolicenses/tools.go b/tools/sggolicenses/tools.go index 46e8fa95..398a2d8c 100644 --- a/tools/sggolicenses/tools.go +++ b/tools/sggolicenses/tools.go @@ -8,6 +8,7 @@ import ( "io/fs" "os/exec" "path/filepath" + "runtime" "strings" "go.einride.tech/sage/sg" @@ -55,6 +56,17 @@ func Check(ctx context.Context, disallowedTypes ...string) error { } cmd := Command(ctx, args...) cmd.Dir = filepath.Dir(path) + // go-licenses tries to exclude standard library packages by checking if they are prefixed + // with `runtime.GOROOT()`. However, if the tool is not run with a GOROOT environment variable, + // this will return the GOROOT path used during build time. This typically works on Linux, but on macOS + // with Homebrew, the GOROOT is version prefixed, which breaks as soon as Go is upgraded. + // For example: /opt/homebrew/Cellar/go/1.19.4/libexec + // + // As a workaround, add the GOROOT environment variable to the result of `runtime.GOROOT()` called here. + // This should work as the Sage binary is built on the same machine that executes it. + // See: https://github.com/google/go-licenses/issues/149 + cmd.Env = append(cmd.Env, fmt.Sprintf("GOROOT=%s", runtime.GOROOT())) + commands = append(commands, cmd) return cmd.Start() }); err != nil {