| // gotoolchain provides information about the Go toolchain used on the host by |
| // rules_go. |
| package gotoolchain |
| |
| import ( |
| "fmt" |
| "path/filepath" |
| "strings" |
| |
| "github.com/bazelbuild/rules_go/go/runfiles" |
| ) |
| |
| func mustRunfile(s string) string { |
| // TODO(tim): I couldn't find out why there is a prefix. |
| s = strings.TrimPrefix(s, "external/") |
| res, err := runfiles.Rlocation(s) |
| if err != nil { |
| panic(fmt.Sprintf("runfile %q not found: %v", s, err)) |
| } |
| abs, err := filepath.Abs(res) |
| if err != nil { |
| panic(fmt.Sprintf("cant make runfile %q absolute: %v", s, err)) |
| } |
| return abs |
| } |
| |
| var ( |
| // Go is a path to the `go` executable. |
| Go = mustRunfile(`GOTOOL`) |
| // Root is the GOROOT path. |
| Root = mustRunfile(`GOROOT`) |
| ) |