Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(go-licences): fix running on macOS when Go is upgraded #369

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tools/sggolicenses/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/fs"
"os/exec"
"path/filepath"
"runtime"
"strings"

"go.einride.tech/sage/sg"
Expand Down Expand Up @@ -55,6 +56,16 @@ 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 go-licenses tool is not run with a GOROOT environment variable,
// that call will return the GOROOT path used during build time of go-licenses. 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 {
Expand Down