...

Source file src/edge-infra.dev/pkg/lib/build/bazel/info.go

Documentation: edge-infra.dev/pkg/lib/build/bazel

     1  package bazel
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // Bin returns the bazel-bin directory
     9  func Bin() (string, error) {
    10  	bin, err := Info("bazel-bin")
    11  	if err != nil {
    12  		return "", infoErr("Bin", "bazel-bin", err)
    13  	}
    14  	return bin, nil
    15  }
    16  
    17  // Genfiles returns the bazel-genfiles directory
    18  func Genfiles() (string, error) {
    19  	genfiles, err := Info("bazel-genfiles")
    20  	if err != nil {
    21  		return "", infoErr("Genfiles", "bazel-genfiles", err)
    22  	}
    23  	return genfiles, nil
    24  }
    25  
    26  // Testlogs returns the bazel-testlogs directory
    27  func Testlogs() (string, error) {
    28  	testlogs, err := Info("bazel-testlogs")
    29  	if err != nil {
    30  		return "", infoErr("TestLogs", "bazel-testlogs", err)
    31  	}
    32  	return testlogs, nil
    33  }
    34  
    35  // Info returns the passed-in `bazel info` key
    36  func Info(key string) (string, error) {
    37  	out, err := Command("info", key).Output()
    38  	if err != nil {
    39  		return "", err
    40  	}
    41  	if len(out) == 0 {
    42  		return "", fmt.Errorf("bazel.Info: unable to find %s, no output received", key)
    43  	}
    44  	return strings.Trim(string(out), "\n"), nil
    45  }
    46  
    47  func infoErr(scope, msg string, e error) error {
    48  	return fmt.Errorf("bazel.%s: failed to get Bazel info key %s. error: %w", scope, msg, e)
    49  }
    50  

View as plain text