blob: 1a4ce640101d87d9d38f47a5fc1e7c4c2f6bf1b7 [file] [log] [blame]
package cockroachdb
import (
"os/exec"
"path/filepath"
"runtime"
"go.skia.org/infra/bazel/go/bazel"
"go.skia.org/infra/go/skerr"
)
// FindCockroach returns the path to the `cockroach` binary downloaded by Bazel.
//
// Calling this function from any Go package will automatically establish a Bazel dependency on the
// corresponding external Bazel repository.
func FindCockroach() (string, error) {
if !bazel.InBazelTest() {
return exec.LookPath("cockroach")
}
if runtime.GOOS == "linux" {
return filepath.Join(bazel.RunfilesDir(), "external", "cockroachdb_linux", "cockroach"), nil
}
return "", skerr.Fmt("unsupported runtime.GOOS: %q", runtime.GOOS)
}