Label

A BUILD target identifier.

Label

Label Label(label_string, *, relative_to_caller_repository=False)

Creates a Label referring to a BUILD target. Use this function only when you want to give a default value for the label attributes. The argument must refer to an absolute label. Example:
Label("//tools:default")

Parameters

Parameter Description
label_string

string

the label string.

relative_to_caller_repository

bool

Deprecated. Do not use. When relative_to_caller_repository is True and the calling thread is a rule's implementation function, then a repo-relative label //foo:bar is resolved relative to the rule's repository. For calls to Label from any other thread, or calls in which the relative_to_caller_repository flag is False, a repo-relative label is resolved relative to the file in which the Label() call appears.

name

string Label.name

The name of this label within the package. For instance:
Label("//pkg/foo:abc").name == "abc"

package

string Label.package

The package part of this label. For instance:
Label("//pkg/foo:abc").package == "pkg/foo"

relative

Label Label.relative(relName)

Resolves a label that is either absolute (starts with //) or relative to the current package. If this label is in a remote repository, the argument will be resolved relative to that repository. If the argument contains a repository, it will be returned as-is. Reserved labels will also be returned as-is.
For example:
Label("//foo/bar:baz").relative(":quux") == Label("//foo/bar:quux")
Label("//foo/bar:baz").relative("//wiz:quux") == Label("//wiz:quux")
Label("@repo//foo/bar:baz").relative("//wiz:quux") == Label("@repo//wiz:quux")
Label("@repo//foo/bar:baz").relative("//visibility:public") == Label("//visibility:public")
Label("@repo//foo/bar:baz").relative("@other//wiz:quux") == Label("@other//wiz:quux")

Parameters

Parameter Description
relName

string

The label that will be resolved relative to this one.

workspace_root

string Label.workspace_root

Returns the execution root for the workspace of this label, relative to the execroot. For instance:
Label("@repo//pkg/foo:abc").workspace_root == "external/repo"