package bazel import ( "fmt" "strings" ) // Bin returns the bazel-bin directory func Bin() (string, error) { bin, err := Info("bazel-bin") if err != nil { return "", infoErr("Bin", "bazel-bin", err) } return bin, nil } // Genfiles returns the bazel-genfiles directory func Genfiles() (string, error) { genfiles, err := Info("bazel-genfiles") if err != nil { return "", infoErr("Genfiles", "bazel-genfiles", err) } return genfiles, nil } // Testlogs returns the bazel-testlogs directory func Testlogs() (string, error) { testlogs, err := Info("bazel-testlogs") if err != nil { return "", infoErr("TestLogs", "bazel-testlogs", err) } return testlogs, nil } // Info returns the passed-in `bazel info` key func Info(key string) (string, error) { out, err := Command("info", key).Output() if err != nil { return "", err } if len(out) == 0 { return "", fmt.Errorf("bazel.Info: unable to find %s, no output received", key) } return strings.Trim(string(out), "\n"), nil } func infoErr(scope, msg string, e error) error { return fmt.Errorf("bazel.%s: failed to get Bazel info key %s. error: %w", scope, msg, e) }