in bazel/bazel.go [45:68]
func bazelNpmPath(ibazelBinPath string) (string, error) {
s := strings.Split(ibazelBinPath, "/")
for i := 0; i+4 < len(s); i++ {
prefix, nm, scope, pkg, dir, bin := s[0:i], s[i], s[i+1], s[i+2], s[i+3], s[i+4]
if nm == "node_modules" && scope == "@bazel" && pkg == "ibazel" && dir == "bin" {
// See mapping in release/npm/index.js - ibazel is named with "amd64" arch
// but @bazel/bazel uses node arch names
arch := strings.Replace(bin, "amd64", "x64", 1)
dir := strings.Join(append(prefix, nm, scope, "bazel-"+arch), "/")
// Find the bazel binary in the directory - it will have a version number in the name
// so we list all the files and find a bazel-*-$ARCH
if fd, err := os.Open(filepath.FromSlash(dir)); err == nil {
if names, err := fd.Readdirnames(0); err == nil {
for j := 0; j < len(names); j++ {
if strings.HasPrefix(names[j], "bazel-") {
return dir + "/" + names[j], nil
}
}
}
}
}
}
return "", errors.New("bazel binary not found in @bazel/bazel package")
}