labels

package
v0.0.0-...-93fe2d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package labels contains helper functions for working with labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

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

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

Types

type 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
}

Label represents a Bazel target label.

func Parse

func Parse(target string) Label

Parse parses an absolute Bazel label (eg. //devtools/buildozer:rule) and returns the corresponding Label object.

func ParseRelative

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 (Label) Format

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 (Label) FormatRelative

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL