blob: 4923e677c531a78aa77d29a9d95d7bd275aa8d4d [file] [log] [blame]
Serge Bazanskiab4ef132021-09-24 13:58:13 +02001// gotoolchain provides information about the Go toolchain used on the host by
2// rules_go.
3package gotoolchain
4
5import (
6 "fmt"
Tim Windelschmidt244b5672024-02-06 10:18:56 +01007 "path/filepath"
Serge Bazanskiae574132021-12-17 17:28:52 +01008 "strings"
Serge Bazanskiab4ef132021-09-24 13:58:13 +02009
Tim Windelschmidt244b5672024-02-06 10:18:56 +010010 "github.com/bazelbuild/rules_go/go/runfiles"
Serge Bazanskiab4ef132021-09-24 13:58:13 +020011)
12
13func mustRunfile(s string) string {
Tim Windelschmidt244b5672024-02-06 10:18:56 +010014 // TODO(tim): I couldn't find out why there is a prefix.
15 s = strings.TrimPrefix(s, "external/")
16 res, err := runfiles.Rlocation(s)
Serge Bazanskiab4ef132021-09-24 13:58:13 +020017 if err != nil {
18 panic(fmt.Sprintf("runfile %q not found: %v", s, err))
19 }
Tim Windelschmidt244b5672024-02-06 10:18:56 +010020 abs, err := filepath.Abs(res)
21 if err != nil {
22 panic(fmt.Sprintf("cant make runfile %q absolute: %v", s, err))
23 }
24 return abs
Serge Bazanskiab4ef132021-09-24 13:58:13 +020025}
26
27var (
28 // Go is a path to the `go` executable.
29 Go = mustRunfile(`GOTOOL`)
30 // Root is the GOROOT path.
31 Root = mustRunfile(`GOROOT`)
32)