func Equal(label1, label2, pkg string) bool
Equal returns true if label1 and label2 are equal. The function takes care of the optional ":" prefix and differences between long-form labels and local labels (relative to pkg).
func Shorten(input, pkg string) string
Shorten rewrites labels to use the canonical form (the form recommended by build-style). "//foo/bar:bar" => "//foo/bar", or ":bar" if the label belongs to pkg
Label represents a Bazel target label.
type Label struct { Repository string // Repository of the target, can be empty if the target belongs to the current repository Package string // Package of a target, can be empty for top packages Target string // Name of the target, should be always non-empty }
func Parse(target string) Label
Parse parses an absolute Bazel label (eg. //devtools/buildozer:rule) and returns the corresponding Label object.
func ParseRelative(input, pkg string) Label
ParseRelative parses a label `input` which may be absolute or relative. If it's relative then it's considered to belong to `pkg`
func (l Label) Format() string
Format returns a string representation of a label. It's always absolute but the target name is omitted if it's equal to the package directory, e.g. "//package/foo:foo" is formatted as "//package/foo".
func (l Label) FormatRelative(pkg string) string
FormatRelative returns a string representation of a label relative to `pkg` (relative label if it represents a target in the same package, absolute otherwise)