Members
- all
- analysis_test_transition
- any
- archive_override
- aspect
- bazel_dep
- bind
- bool
- configuration_field
- depset
- dict
- dir
- enumerate
- exec_group
- fail
- float
- getattr
- git_override
- hasattr
- hash
- int
- len
- list
- local_path_override
- max
- min
- module
- module_extension
- multiple_version_override
- provider
- range
- register_execution_platforms()
- register_execution_platforms(dev_dependency)
- register_toolchains()
- register_toolchains(dev_dependency)
- repository_rule(implementation, attrs, local, environ, configure, remotable, doc)
- repository_rule(implementation, attrs, local, environ, configure, remotable, doc)
- repr
- reversed
- rule
- select
- single_version_override
- sorted
- str
- tag_class
- tuple
- type
- use_extension
- use_repo
- visibility
- workspace
- zip
all
bool all(elements)
all(["hello", 3, True]) == True all([-1, 0, 1]) == False
Parameters
Parameter | Description |
---|---|
elements
|
required A string or a collection of elements. |
analysis_test_transition
transition analysis_test_transition(settings)
Creates a configuration transition to be applied on an analysis-test rule's dependencies. This transition may only be applied on attributes of rules with analysis_test = True
. Such rules are restricted in capabilities (for example, the size of their dependency tree is limited), so transitions created using this function are limited in potential scope as compared to transitions created using transition.
This function is primarily designed to facilitate the Analysis Test Framework core library. See its documentation (or its implementation) for best practices.
Parameters
Parameter | Description |
---|---|
settings
|
required A dictionary containing information about configuration settings which should be set by this configuration transition. Keys are build setting labels and values are their new post-transition values. All other settings are unchanged. Use this to declare specific configuration settings that an analysis test requires to be set in order to pass. |
any
bool any(elements)
any([-1, 0, 1]) == True any([False, 0, ""]) == False
Parameters
Parameter | Description |
---|---|
elements
|
required A string or a collection of elements. |
archive_override
None archive_override(module_name, urls, integrity='', strip_prefix='', patches=[], patch_cmds=[], patch_strip=0)
Parameters
Parameter | Description |
---|---|
module_name
|
required The name of the Bazel module dependency to apply this override to. |
urls
|
string; or Iterable of strings ;
requiredThe URLs of the archive; can be http(s):// or file:// URLs. |
integrity
|
default = '' The expected checksum of the archive file, in Subresource Integrity format. |
strip_prefix
|
default = '' A directory prefix to strip from the extracted files. |
patches
|
Iterable of strings ;
default = []A list of labels pointing to patch files to apply for this module. The patch files must exist in the source tree of the top level project. They are applied in the list order. |
patch_cmds
|
Iterable of strings ;
default = []Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_strip
|
default = 0 Same as the --strip argument of Unix patch. |
aspect
Aspect aspect(implementation, attr_aspects=[], attrs=None, required_providers=[], required_aspect_providers=[], provides=[], requires=[], fragments=[], host_fragments=[], toolchains=[], incompatible_use_toolchain_transition=False, doc='', *, apply_to_generating_rules=False, exec_compatible_with=[], exec_groups=None)
Parameters
Parameter | Description |
---|---|
implementation
|
required A Starlark function that implements this aspect, with exactly two parameters: Target (the target to which the aspect is applied) and ctx (the rule context which the targetis created from). Attributes of the target are available via the ctx.rule field. This function is evaluated during the analysis phase for each application of an aspect to a target.
|
attr_aspects
|
sequence of strings ;
default = []List of attribute names. The aspect propagates along dependencies specified in the attributes of a target with these names. Common values here include deps and exports . The list can also contain a single string "*" to propagate along all dependencies of a target.
|
attrs
|
dict; or None ;
default = NoneA dictionary declaring all the attributes of the aspect. It maps from an attribute name to an attribute object, like `attr.label` or `attr.string` (see attr module). Aspect attributes are available to implementation function as fields of ctx parameter. Implicit attributes starting with Explicit attributes must have type |
required_providers
|
default = [] This attribute allows the aspect to limit its propagation to only the targets whose rules advertise its required providers. The value must be a list containing either individual providers or lists of providers but not both. For example, [[FooInfo], [BarInfo], [BazInfo, QuxInfo]] is a valid value while [FooInfo, BarInfo, [BazInfo, QuxInfo]] is not valid.An unnested list of providers will automatically be converted to a list containing one list of providers. That is, To make some rule (e.g. |
required_aspect_providers
|
default = [] This attribute allows this aspect to inspect other aspects. The value must be a list containing either individual providers or lists of providers but not both. For example, [[FooInfo], [BarInfo], [BazInfo, QuxInfo]] is a valid value while [FooInfo, BarInfo, [BazInfo, QuxInfo]] is not valid.An unnested list of providers will automatically be converted to a list containing one list of providers. That is, To make another aspect (e.g. |
provides
|
default = [] A list of providers that the implementation function must return. It is an error if the implementation function omits any of the types of providers listed here from its return value. However, the implementation function may return additional providers not listed here. Each element of the list is an |
requires
|
sequence of Aspects ;
default = []List of aspects required to be propagated before this aspect. |
fragments
|
sequence of strings ;
default = []List of names of configuration fragments that the aspect requires in target configuration. |
host_fragments
|
sequence of strings ;
default = []List of names of configuration fragments that the aspect requires in host configuration. |
toolchains
|
sequence ;
default = []If set, the set of toolchains this rule requires. The list can contain String, Label, or StarlarkToolchainTypeApi objects, in any combination. Toolchains will be found by checking the current platform, and provided to the rule implementation via ctx.toolchain .
|
incompatible_use_toolchain_transition
|
default = False Deprecated, this is no longer in use and should be removed. |
doc
|
default = '' A description of the aspect that can be extracted by documentation generating tools. |
apply_to_generating_rules
|
default = False If true, the aspect will, when applied to an output file, instead apply to the output file's generating rule. For example, suppose an aspect propagates transitively through attribute `deps` and it is applied to target `alpha`. Suppose `alpha` has `deps = [':beta_output']`, where `beta_output` is a declared output of a target `beta`. Suppose `beta` has a target `charlie` as one of its `deps`. If `apply_to_generating_rules=True` for the aspect, then the aspect will propagate through `alpha`, `beta`, and `charlie`. If False, then the aspect will propagate only to `alpha`. False by default. |
exec_compatible_with
|
sequence of strings ;
default = []A list of constraints on the execution platform that apply to all instances of this aspect. |
exec_groups
|
dict; or None ;
default = NoneDict of execution group name (string) to exec_group s. If set, allows aspects to run actions on multiple execution platforms within a single instance. See execution groups documentation for more info.
|
bazel_dep
None bazel_dep(name, version='', max_compatibility_level=-1, repo_name='', dev_dependency=False)
Parameters
Parameter | Description |
---|---|
name
|
required The name of the module to be added as a direct dependency. |
version
|
default = '' The version of the module to be added as a direct dependency. |
max_compatibility_level
|
default = -1 The maximum compatibility_level supported for the module to be added as a direct dependency. The version of the module implies the minimum compatibility_level supported, as well as the maximum if this attribute is not specified.
|
repo_name
|
default = '' The name of the external repo representing this dependency. This is by default the name of the module. |
dev_dependency
|
default = False If true, this dependency will be ignored if the current module is not the root module or `--ignore_dev_dependency` is enabled. |
bind
None bind(name, actual=None)
Warning: use of bind()
is not recommended. See Consider removing bind for a long discussion of its issues and alternatives.
Gives a target an alias in the //external
package.
Parameters
Parameter | Description |
---|---|
name
|
required The label under '//external' to serve as the alias name |
actual
|
string; or None ;
default = NoneThe real label to be aliased |
bool
bool bool(x=False)
False
if the object is None
, False
, an empty string (""
), the number 0
, or an empty collection (e.g. ()
, []
). Otherwise, it returns True
.
Parameters
Parameter | Description |
---|---|
x
|
default = False The variable to convert. |
configuration_field
LateBoundDefault configuration_field(fragment, name)
Example usage:
Defining a rule attribute:
'_foo': attr.label(default=configuration_field(fragment='java', name='toolchain'))
Accessing in rule implementation:
def _rule_impl(ctx): foo_info = ctx.attr._foo ...
Parameters
Parameter | Description |
---|---|
fragment
|
required The name of a configuration fragment which contains the late-bound value. |
name
|
required The name of the value to obtain from the configuration fragment. |
depset
depset depset(direct=None, order="default", *, transitive=None)
direct
parameter is a list of direct elements of the depset, and transitive
parameter is a list of depsets whose elements become indirect elements of the created depset. The order in which elements are returned when the depset is converted to a list is specified by the order
parameter. See the Depsets overview for more information.
All elements (direct and indirect) of a depset must be of the same type, as obtained by the expression type(x)
.
Because a hash-based set is used to eliminate duplicates during iteration, all elements of a depset should be hashable. However, this invariant is not currently checked consistently in all constructors. Use the --incompatible_always_check_depset_elements flag to enable consistent checking; this will be the default behavior in future releases; see Issue 10313.
In addition, elements must currently be immutable, though this restriction will be relaxed in future.
The order of the created depset should be compatible with the order of its transitive
depsets. "default"
order is compatible with any other order, all other orders are only compatible with themselves.
Note on backward/forward compatibility. This function currently accepts a positional items
parameter. It is deprecated and will be removed in the future, and after its removal direct
will become a sole positional parameter of the depset
function. Thus, both of the following calls are equivalent and future-proof:
depset(['a', 'b'], transitive = [...]) depset(direct = ['a', 'b'], transitive = [...])
Parameters
Parameter | Description |
---|---|
direct
|
sequence; or None ;
default = NoneA list of direct elements of a depset. |
order
|
default = "default" The traversal strategy for the new depset. See here for the possible values. |
transitive
|
sequence of depsets; or None ;
default = NoneA list of depsets whose elements will become indirect elements of the depset. |
dict
dict dict(pairs=[], **kwargs)
Parameters
Parameter | Description |
---|---|
pairs
|
default = [] A dict, or an iterable whose elements are each of length 2 (key, value). |
kwargs
|
required Dictionary of additional entries. |
dir
list dir(x)
Parameters
Parameter | Description |
---|---|
x
|
required The object to check. |
enumerate
list enumerate(list, start=0)
enumerate([24, 21, 84]) == [(0, 24), (1, 21), (2, 84)]
Parameters
Parameter | Description |
---|---|
list
|
required input sequence. |
start
|
default = 0 start index. |
exec_group
exec_group exec_group(toolchains=[], exec_compatible_with=[], copy_from_rule=False)
Parameters
Parameter | Description |
---|---|
toolchains
|
sequence ;
default = []The set of toolchains this execution group requires. The list can contain String, Label, or StarlarkToolchainTypeApi objects, in any combination. |
exec_compatible_with
|
sequence of strings ;
default = []A list of constraints on the execution platform. |
copy_from_rule
|
default = False If set to true, this exec group inherits the toolchains and constraints of the rule to which this group is attached. If set to any other string this will throw an error. |
fail
None fail(msg=None, attr=None, *args)
Parameters
Parameter | Description |
---|---|
msg
|
default = None Deprecated: use positional arguments instead. This argument acts like an implicit leading positional argument. |
attr
|
string; or None ;
default = NoneDeprecated. Causes an optional prefix containing this string to be added to the error message. |
args
|
required A list of values, formatted with str and joined with spaces, that appear in the error message. |
float
float float(x=unbound)
- If
x
is already a float,float
returns it unchanged. - If
x
is a bool,float
returns 1.0 for True and 0.0 for False. - If
x
is an int,float
returns the nearest finite floating-point value to x, or an error if the magnitude is too large. - If
x
is a string, it must be a valid floating-point literal, or be equal (ignoring case) toNaN
,Inf
, orInfinity
, optionally preceded by a+
or-
sign.
float()
returns 0.0.
Parameters
Parameter | Description |
---|---|
x
|
default = unbound The value to convert. |
getattr
unknown getattr(x, name, default=unbound)
default
(if specified) or raises an error. getattr(x, "foobar")
is equivalent to x.foobar
.getattr(ctx.attr, "myattr") getattr(ctx.attr, "myattr", "mydefault")
Parameters
Parameter | Description |
---|---|
x
|
required The struct whose attribute is accessed. |
name
|
required The name of the struct attribute. |
default
|
default = unbound The default value to return in case the struct doesn't have an attribute of the given name. |
git_override
None git_override(module_name, remote, commit='', patches=[], patch_cmds=[], patch_strip=0)
Parameters
Parameter | Description |
---|---|
module_name
|
required The name of the Bazel module dependency to apply this override to. |
remote
|
required The URL of the remote Git repository. |
commit
|
default = '' The commit that should be checked out. |
patches
|
Iterable of strings ;
default = []A list of labels pointing to patch files to apply for this module. The patch files must exist in the source tree of the top level project. They are applied in the list order. |
patch_cmds
|
Iterable of strings ;
default = []Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_strip
|
default = 0 Same as the --strip argument of Unix patch. |
hasattr
bool hasattr(x, name)
x
has an attribute or method of the given name
, otherwise False. Example:hasattr(ctx.attr, "myattr")
Parameters
Parameter | Description |
---|---|
x
|
required The object to check. |
name
|
required The name of the attribute. |
hash
int hash(value)
String.hashCode()
, namely: s[0] * (31^(n-1)) + s[1] * (31^(n-2)) + ... + s[n-1]
Parameters
Parameter | Description |
---|---|
value
|
required String value to hash. |
int
int int(x, base=unbound)
- If
x
is already an int,int
returns it unchanged. - If
x
is a bool,int
returns 1 for True and 0 for False. - If
x
is a string, it must have the format<sign><prefix><digits>
.<sign>
is either"+"
,"-"
, or empty (interpreted as positive).<digits>
are a sequence of digits from 0 up tobase
- 1, where the letters a-z (or equivalently, A-Z) are used as digits for 10-35. In the case wherebase
is 2/8/16,<prefix>
is optional and may be 0b/0o/0x (or equivalently, 0B/0O/0X) respectively; if thebase
is any other value besides these bases or the special value 0, the prefix must be empty. In the case wherebase
is 0, the string is interpreted as an integer literal, in the sense that one of the bases 2/8/10/16 is chosen depending on which prefix if any is used. Ifbase
is 0, no prefix is used, and there is more than one digit, the leading digit cannot be 0; this is to avoid confusion between octal and decimal. The magnitude of the number represented by the string must be within the allowed range for the int type. - If
x
is a float,int
returns the integer value of the float, rounding towards zero. It is an error if x is non-finite (NaN or infinity).
x
is any other type, or if the value is a string not satisfying the above format. Unlike Python's int
function, this function does not allow zero arguments, and does not allow extraneous whitespace for string arguments.Examples:
int("123") == 123 int("-123") == -123 int("+123") == 123 int("FF", 16) == 255 int("0xFF", 16) == 255 int("10", 0) == 10 int("-0x10", 0) == -16 int("-0x10", 0) == -16 int("123.456") == 123
Parameters
Parameter | Description |
---|---|
x
|
required The string to convert. |
base
|
default = unbound The base used to interpret a string value; defaults to 10. Must be between 2 and 36 (inclusive), or 0 to detect the base as if x were an integer literal. This parameter must not be supplied if the value is not a string.
|
len
int len(x)
Parameters
Parameter | Description |
---|---|
x
|
required The value whose length to report. |
list
list list(x=[])
list([1, 2]) == [1, 2] list((2, 3, 2)) == [2, 3, 2] list({5: "a", 2: "b", 4: "c"}) == [5, 2, 4]
Parameters
Parameter | Description |
---|---|
x
|
default = [] The object to convert. |
local_path_override
None local_path_override(module_name, path)
Parameters
Parameter | Description |
---|---|
module_name
|
required The name of the Bazel module dependency to apply this override to. |
path
|
required The path to the directory where this module is. |
max
unknown max(*args)
max(2, 5, 4) == 5 max([5, 6, 3]) == 6
Parameters
Parameter | Description |
---|---|
args
|
required The elements to be checked. |
min
unknown min(*args)
min(2, 5, 4) == 2 min([5, 6, 3]) == 3
Parameters
Parameter | Description |
---|---|
args
|
required The elements to be checked. |
module
None module(name='', version='', compatibility_level=0, repo_name='', bazel_compatibility=[])
It should be called at most once. It can be omitted only if this module is the root module (as in, if it's not going to be depended on by another module).
Parameters
Parameter | Description |
---|---|
name
|
default = '' The name of the module. Can be omitted only if this module is the root module (as in, if it's not going to be depended on by another module). A valid module name must: 1) only contain lowercase letters (a-z), digits (0-9), dots (.), hyphens (-), and underscores (_); 2) begin with a lowercase letter; 3) end with a lowercase letter or digit. |
version
|
default = '' The version of the module. Can be omitted only if this module is the root module (as in, if it's not going to be depended on by another module). |
compatibility_level
|
default = 0 The compatibility level of the module; this should be changed every time a major incompatible change is introduced. This is essentially the "major version" of the module in terms of SemVer, except that it's not embedded in the version string itself, but exists as a separate field. Modules with different compatibility levels participate in version resolution as if they're modules with different names, but the final dependency graph cannot contain multiple modules with the same name but different compatibility levels (unless multiple_version_override is in effect; see there for more details).
|
repo_name
|
default = '' The name of the repository representing this module, as seen by the module itself. By default, the name of the repo is the name of the module. This can be specified to ease migration for projects that have been using a repo name for itself that differs from its module name. |
bazel_compatibility
|
Iterable of strings ;
default = []A list of bazel versions that allows users to declare which Bazel versions are compatible with this module. It does NOT affect dependency resolution, but bzlmod will use this information to check if your current Bazel version is compatible. The format of this value is a string of some constraint values separated by comma. Three constraints are supported: <=X.X.X: The Bazel version must be equal or older than X.X.X. Used when there is a known incompatible change in a newer version. >=X.X.X: The Bazel version must be equal or newer than X.X.X.Used when you depend on some features that are only available since X.X.X. -X.X.X: The Bazel version X.X.X is not compatible. Used when there is a bug in X.X.X that breaks you, but fixed in later versions. |
module_extension
unknown module_extension(implementation, *, tag_classes={}, doc='')
Parameters
Parameter | Description |
---|---|
implementation
|
required The function that implements this module extension. Must take a single parameter, module_ctx . The function is called once at the beginning of a build to determine the set of available repos.
|
tag_classes
|
default = {} A dictionary to declare all the tag classes used by the extension. It maps from the name of the tag class to a tag_class object.
|
doc
|
default = '' A description of the module extension that can be extracted by documentation generating tools. |
multiple_version_override
None multiple_version_override(module_name, versions, registry='')
Parameters
Parameter | Description |
---|---|
module_name
|
required The name of the Bazel module dependency to apply this override to. |
versions
|
Iterable of strings ;
requiredExplicitly specifies the versions allowed to coexist. These versions must already be present in the dependency graph pre-selection. Dependencies on this module will be "upgraded" to the nearest higher allowed version at the same compatibility level, whereas dependencies that have a higher version than any allowed versions at the same compatibility level will cause an error. |
registry
|
default = '' Overrides the registry for this module; instead of finding this module from the default list of registries, the given registry should be used. |
None print(sep=" ", *args)
args
as debug output. It will be prefixed with the string "DEBUG"
and the location (file and line number) of this call. The exact way in which the arguments are converted to strings is unspecified and may change at any time. In particular, it may be different from (and more detailed than) the formatting done by str()
and repr()
.Using print
in production code is discouraged due to the spam it creates for users. For deprecations, prefer a hard error using fail()
whenever possible.
Parameters
Parameter | Description |
---|---|
sep
|
default = " " The separator string between the objects, default is space (" "). |
args
|
required The objects to print. |
provider
unknown provider(doc='', *, fields=None, init=None)
MyInfo = provider() ... def _my_library_impl(ctx): ... my_info = MyInfo(x = 2, y = 3) # my_info.x == 2 # my_info.y == 3 ...
See Rules (Providers) for a comprehensive guide on how to use providers.
Returns a Provider
callable value if init
is not specified.
If init
is specified, returns a tuple of 2 elements: a Provider
callable value and a raw constructor callable value. See Rules (Custom initialization of custom providers) and the discussion of the init
parameter below for details.
Parameters
Parameter | Description |
---|---|
doc
|
default = '' A description of the provider that can be extracted by documentation generating tools. |
fields
|
sequence of strings; or dict; or None ;
default = NoneIf specified, restricts the set of allowed fields. Possible values are:
|
init
|
callable; or None ;
default = NoneAn optional callback for preprocessing and validating the provider's field values during instantiation. If init is specified, provider() returns a tuple of 2 elements: the normal provider symbol and a raw constructor.A precise description follows; see Rules (Custom initialization of providers) for an intuitive discussion and use cases. Let
init callback is not given, a call to the symbol P itself acts as a call to the default constructor function c ; in other words, P(*args, **kwargs) returns c(*args, **kwargs) . For example,MyInfo = provider() m = MyInfo(foo = 1) m is a MyInfo instance with m.foo == 1 .But in the case where
NB: the above steps imply that an error occurs if In this way, the When MyInfo, _new_myinfo = provider(init = ...) |
range
sequence range(start_or_stop, stop_or_none=None, step=1)
start
to stop
, using a step
increment. If a single argument is provided, items will range from 0 to that element.range(4) == [0, 1, 2, 3] range(3, 9, 2) == [3, 5, 7] range(3, 0, -1) == [3, 2, 1]
Parameters
Parameter | Description |
---|---|
start_or_stop
|
required Value of the start element if stop is provided, otherwise value of stop and the actual start is 0 |
stop_or_none
|
int; or None ;
default = Noneoptional index of the first item not to be included in the resulting list; generation of the list stops before stop is reached.
|
step
|
default = 1 The increment (default is 1). It may be negative. |
register_execution_platforms()
None register_execution_platforms(*platform_labels)
Parameters
Parameter | Description |
---|---|
platform_labels
|
sequence of strings ;
requiredThe labels of the platforms to register. |
register_execution_platforms(dev_dependency)
None register_execution_platforms(dev_dependency=False, *platform_labels)
@
or //
). See toolchain resolution for more information.
Parameters
Parameter | Description |
---|---|
dev_dependency
|
default = False If true, the execution platforms will not be registered if the current module is not the root module or `--ignore_dev_dependency` is enabled. |
platform_labels
|
sequence of strings ;
requiredThe labels of the platforms to register. |
register_toolchains()
None register_toolchains(*toolchain_labels)
Parameters
Parameter | Description |
---|---|
toolchain_labels
|
sequence of strings ;
requiredThe labels of the toolchains to register. |
register_toolchains(dev_dependency)
None register_toolchains(dev_dependency=False, *toolchain_labels)
@
or //
). See toolchain resolution for more information.
Parameters
Parameter | Description |
---|---|
dev_dependency
|
default = False If true, the toolchains will not be registered if the current module is not the root module or `--ignore_dev_dependency` is enabled. |
toolchain_labels
|
sequence of strings ;
requiredThe labels of the toolchains to register. |
repository_rule(implementation, attrs, local, environ, configure, remotable, doc)
callable repository_rule(implementation, *, attrs=None, local=False, environ=[], configure=False, remotable=False, doc='')
Parameters
Parameter | Description |
---|---|
implementation
|
required the function that implements this rule. Must have a single parameter, repository_ctx . The function is called during the loading phase for each instance of the rule.
|
attrs
|
dict; or None ;
default = Nonedictionary to declare all the attributes of the rule. It maps from an attribute name to an attribute object (see attr module). Attributes starting with _ are private, and can be used to add an implicit dependency on a label to a file (a repository rule cannot depend on a generated artifact). The attribute name is implicitly added and must not be specified.
|
local
|
default = False Indicate that this rule fetches everything from the local system and should be reevaluated at every fetch. |
environ
|
sequence of strings ;
default = []Provides a list of environment variable that this repository rule depends on. If an environment variable in that list change, the repository will be refetched. |
configure
|
default = False Indicate that the repository inspects the system for configuration purpose |
remotable
|
default = False Experimental. This parameter is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting ---experimental_repo_remote_exec Compatible with remote execution |
doc
|
default = '' A description of the repository rule that can be extracted by documentation generating tools. |
repository_rule(implementation, attrs, local, environ, configure, remotable, doc)
callable repository_rule(implementation, *, attrs=None, local=False, environ=[], configure=False, remotable=False, doc='')
Parameters
Parameter | Description |
---|---|
implementation
|
required the function that implements this rule. Must have a single parameter, repository_ctx . The function is called during the loading phase for each instance of the rule.
|
attrs
|
dict; or None ;
default = Nonedictionary to declare all the attributes of the rule. It maps from an attribute name to an attribute object (see attr module). Attributes starting with _ are private, and can be used to add an implicit dependency on a label to a file (a repository rule cannot depend on a generated artifact). The attribute name is implicitly added and must not be specified.
|
local
|
default = False Indicate that this rule fetches everything from the local system and should be reevaluated at every fetch. |
environ
|
sequence of strings ;
default = []Provides a list of environment variable that this repository rule depends on. If an environment variable in that list change, the repository will be refetched. |
configure
|
default = False Indicate that the repository inspects the system for configuration purpose |
remotable
|
default = False Experimental. This parameter is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting ---experimental_repo_remote_exec Compatible with remote execution |
doc
|
default = '' A description of the repository rule that can be extracted by documentation generating tools. |
repr
string repr(x)
repr("ab") == '"ab"'
Parameters
Parameter | Description |
---|---|
x
|
required The object to convert. |
reversed
list reversed(sequence)
reversed([3, 5, 4]) == [4, 5, 3]
Parameters
Parameter | Description |
---|---|
sequence
|
required The iterable sequence (e.g. list) to be reversed. |
rule
callable rule(implementation, test=False, attrs=None, outputs=None, executable=False, output_to_genfiles=False, fragments=[], host_fragments=[], _skylark_testable=False, toolchains=[], incompatible_use_toolchain_transition=False, doc='', *, provides=[], exec_compatible_with=[], analysis_test=False, build_setting=None, cfg=None, exec_groups=None, compile_one_filetype=None, name=None)
Rules must be assigned to global variables in a .bzl file; the name of the global variable is the rule's name.
Test rules are required to have a name ending in _test
, while all other rules must not have this suffix. (This restriction applies only to rules, not to their targets.)
Parameters
Parameter | Description |
---|---|
implementation
|
required the Starlark function implementing this rule, must have exactly one parameter: ctx. The function is called during the analysis phase for each instance of the rule. It can access the attributes provided by the user. It must create actions to generate all the declared outputs. |
test
|
default = False Whether this rule is a test rule, that is, whether it may be the subject of a blaze test command. All test rules are automatically considered executable; it is unnecessary (and discouraged) to explicitly set executable = True for a test rule. See the Rules page for more information.
|
attrs
|
dict; or None ;
default = Nonedictionary to declare all the attributes of the rule. It maps from an attribute name to an attribute object (see attr module). Attributes starting with _ are private, and can be used to add an implicit dependency on a label. The attribute name is implicitly added and must not be specified. Attributes visibility , deprecation , tags , testonly , and features are implicitly added and cannot be overridden. Most rules need only a handful of attributes. To limit memory usage, the rule function imposes a cap on the size of attrs.
|
outputs
|
dict; or None; or function ;
default = NoneDeprecated. This parameter is deprecated and will be removed soon. Please do not depend on it. It is disabled with ---incompatible_no_rule_outputs_param . Use this flag to verify your code is compatible with its imminent removal. This parameter has been deprecated. Migrate rules to use OutputGroupInfo or attr.output instead. A schema for defining predeclared outputs. Unlike The value of this argument is either a dictionary or a callback function that produces a dictionary. The callback works similar to computed dependency attributes: The function's parameter names are matched against the rule's attributes, so for example if you pass Each entry in the dictionary creates a predeclared output where the key is an identifier and the value is a string template that determines the output's label. In the rule's implementation function, the identifier becomes the field name used to access the output's
In practice, the most common substitution placeholder is |
executable
|
default = False Whether this rule is considered executable, that is, whether it may be the subject of a blaze run command. See the Rules page for more information.
|
output_to_genfiles
|
default = False If true, the files will be generated in the genfiles directory instead of the bin directory. Unless you need it for compatibility with existing rules (e.g. when generating header files for C++), do not set this flag. |
fragments
|
sequence of strings ;
default = []List of names of configuration fragments that the rule requires in target configuration. |
host_fragments
|
sequence of strings ;
default = []List of names of configuration fragments that the rule requires in host configuration. |
_skylark_testable
|
default = False (Experimental) If true, this rule will expose its actions for inspection by rules that depend on it via an Actions provider. The provider is also available to the rule itself by calling ctx.created_actions(). This should only be used for testing the analysis-time behavior of Starlark rules. This flag may be removed in the future. |
toolchains
|
sequence ;
default = []If set, the set of toolchains this rule requires. The list can contain String, Label, or StarlarkToolchainTypeApi objects, in any combination. Toolchains will be found by checking the current platform, and provided to the rule implementation via ctx.toolchain .
|
incompatible_use_toolchain_transition
|
default = False Deprecated, this is no longer in use and should be removed. |
doc
|
default = '' A description of the rule that can be extracted by documentation generating tools. |
provides
|
default = [] A list of providers that the implementation function must return. It is an error if the implementation function omits any of the types of providers listed here from its return value. However, the implementation function may return additional providers not listed here. Each element of the list is an |
exec_compatible_with
|
sequence of strings ;
default = []A list of constraints on the execution platform that apply to all targets of this rule type. |
analysis_test
|
default = False If true, then this rule is treated as an analysis test. Note: Analysis test rules are primarily defined using infrastructure provided in core Starlark libraries. See Testing for guidance. If a rule is defined as an analysis test rule, it becomes allowed to use configuration transitions defined using analysis_test_transition on its attributes, but opts into some restrictions:
|
build_setting
|
BuildSetting; or None ;
default = NoneIf set, describes what kind of build setting this rule is. See the config module. If this is set, a mandatory attribute named "build_setting_default" is automatically added to this rule, with a type corresponding to the value passed in here.
|
cfg
|
default = None If set, points to the configuration transition the rule will apply to its own configuration before analysis. |
exec_groups
|
dict; or None ;
default = NoneDict of execution group name (string) to exec_group s. If set, allows rules to run actions on multiple execution platforms within a single target. See execution groups documentation for more info.
|
compile_one_filetype
|
sequence of strings; or None ;
default = NoneUsed by --compile_one_dependency: if multiple rules consume the specified file, should we choose this rule over others. |
name
|
string; or None ;
default = NoneDeprecated. This parameter is deprecated and will be removed soon. Please do not depend on it. It is disabled with --+incompatible_remove_rule_name_parameter . Use this flag to verify your code is compatible with its imminent removal. Deprecated: do not use. The name of this rule, as understood by Bazel and reported in contexts such as logging, If this parameter is omitted, the rule's name is set to the name of the first Starlark global variable to be bound to this rule within its declaring .bzl module. Thus, Specifying an explicit name for a rule does not change where you are allowed to instantiate the rule. |
select
unknown select(x, no_match_error='')
select()
is the helper function that makes a rule attribute configurable. See build encyclopedia for details.
Parameters
Parameter | Description |
---|---|
x
|
required A dict that maps configuration conditions to values. Each key is a Label or a label string that identifies a config_setting or constraint_value instance. See the documentation on macros for when to use a Label instead of a string. |
no_match_error
|
default = '' Optional custom error to report if no condition matches. |
single_version_override
None single_version_override(module_name, version='', registry='', patches=[], patch_cmds=[], patch_strip=0)
Parameters
Parameter | Description |
---|---|
module_name
|
required The name of the Bazel module dependency to apply this override to. |
version
|
default = '' Overrides the declared version of this module in the dependency graph. In other words, this module will be "pinned" to this override version. This attribute can be omitted if all one wants to override is the registry or the patches. |
registry
|
default = '' Overrides the registry for this module; instead of finding this module from the default list of registries, the given registry should be used. |
patches
|
Iterable of strings ;
default = []A list of labels pointing to patch files to apply for this module. The patch files must exist in the source tree of the top level project. They are applied in the list order. |
patch_cmds
|
Iterable of strings ;
default = []Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_strip
|
default = 0 Same as the --strip argument of Unix patch. |
sorted
list sorted(iterable, *, key=None, reverse=False)
sorted([3, 5, 4]) == [3, 4, 5]
Parameters
Parameter | Description |
---|---|
iterable
|
required The iterable sequence to sort. |
key
|
default = None An optional function applied to each element before comparison. |
reverse
|
default = False Return results in descending order. |
str
string str(x)
str("ab") == "ab" str(8) == "8"
Parameters
Parameter | Description |
---|---|
x
|
required The object to convert. |
tag_class
tag_class tag_class(attrs={}, *, doc='')
Parameters
Parameter | Description |
---|---|
attrs
|
default = {} A dictionary to declare all the attributes of this tag class. It maps from an attribute name to an attribute object (see attr module). |
doc
|
default = '' A description of the tag class that can be extracted by documentation generating tools. |
tuple
tuple tuple(x=())
tuple([1, 2]) == (1, 2) tuple((2, 3, 2)) == (2, 3, 2) tuple({5: "a", 2: "b", 4: "c"}) == (5, 2, 4)
Parameters
Parameter | Description |
---|---|
x
|
default = () The object to convert. |
type
string type(x)
type(2) == "int" type([1]) == "list" type(struct(a = 2)) == "struct"
if type(x) == type([]): # if x is a list
Parameters
Parameter | Description |
---|---|
x
|
required The object to check type of. |
use_extension
module_extension_proxy use_extension(extension_bzl_file, extension_name, *, dev_dependency=False)
Parameters
Parameter | Description |
---|---|
extension_bzl_file
|
required A label to the Starlark file defining the module extension. |
extension_name
|
required The name of the module extension to use. A symbol with this name must be exported by the Starlark file. |
dev_dependency
|
default = False If true, this usage of the module extension will be ignored if the current module is not the root module or `--ignore_dev_dependency` is enabled. |
use_repo
None use_repo(extension_proxy, *args, **kwargs)
Parameters
Parameter | Description |
---|---|
extension_proxy
|
required A module extension proxy object returned by a use_extension call.
|
args
|
required The names of the repos to import. |
kwargs
|
required Specifies certain repos to import into the scope of the current module with different names. The keys should be the name to use in the current scope, whereas the values should be the original names exported by the module extension. |
visibility
None visibility(value)
Sets the load visibility of the .bzl module currently being initialized.
The load visibility of a module governs whether or not other BUILD and .bzl files may load it. (This is distinct from the target visibility of the underlying .bzl source file, which governs whether the file may appear as a dependency of other targets.) Load visibility works at the level of packages: To load a module the file doing the loading must live in a package that has been granted visibility to the module. A module can always be loaded within its own package, regardless of its visibility.
visibility()
may only be called once per .bzl file, and only at the top level, not inside a function. The preferred style is to put this call immediately below the load()
statements and any brief logic needed to determine the argument.
If the flag --check_bzl_visibility
is set to false, load visibility violations will emit warnings but not fail the build.
Parameters
Parameter | Description |
---|---|
value
|
required A list of package specification strings, or a single package specification string. Package specifications follow the same format as for
The "@" syntax is not allowed; all specifications are interpreted relative to the current module's repository. If Note that the flags |
workspace
None workspace(name)
This function can only be used in a WORKSPACE
file and must be declared before all other functions in the WORKSPACE
file. Each WORKSPACE
file should have a workspace
function.
Sets the name for this workspace. Workspace names should be a Java-package-style description of the project, using underscores as separators, e.g., github.com/bazelbuild/bazel should use com_github_bazelbuild_bazel.
This name is used for the directory that the repository's runfiles are stored in. For example, if there is a runfile foo/bar
in the local repository and the WORKSPACE file contains workspace(name = 'baz')
, then the runfile will be available under mytarget.runfiles/baz/foo/bar
. If no workspace name is specified, then the runfile will be symlinked to bar.runfiles/foo/bar
.
Remote repository rule names must be valid workspace names. For example, you could have maven_jar(name = 'foo')
, but not maven_jar(name = 'foo%bar')
, as Bazel would attempt to write a WORKSPACE file for the maven_jar
containing workspace(name = 'foo%bar')
.
Parameters
Parameter | Description |
---|---|
name
|
required the name of the workspace. Names must start with a letter and can only contain letters, numbers, underscores, dashes, and dots. |
zip
list zip(*args)
list
of tuple
s, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The list has the size of the shortest input. With a single iterable argument, it returns a list of 1-tuples. With no arguments, it returns an empty list. Examples:zip() # == [] zip([1, 2]) # == [(1,), (2,)] zip([1, 2], [3, 4]) # == [(1, 3), (2, 4)] zip([1, 2], [3, 4, 5]) # == [(1, 3), (2, 4)]
Parameters
Parameter | Description |
---|---|
args
|
required lists to zip. |