native.cc_library. Note that the native module is only available in the loading phase (i.e. for macros, not for rule implementations). Attributes will ignore None values, and treat them as if the attribute was unset.
The following functions are also available:
Members
- existing_rule
- existing_rules
- exports_files
- glob
- module_name
- module_version
- package_default_visibility
- package_group
- package_name
- package_relative_label
- repo_name
- repository_name
- subpackages
existing_rule
None if no rule instance of that name exists.
Here, an immutable dict-like object means a deeply immutable object x supporting dict-like iteration, len(x), name in x, x[name], x.get(name), x.items(), x.keys(), and x.values().
The result contains an entry for each attribute, with the exception of private ones (whose names do not start with a letter) and a few unrepresentable legacy attribute types. In addition, the dict contains entries for the rule instance’s name and kind (for example, 'cc_binary').
The values of the result represent attribute values as follows:
- Attributes of type str, int, and bool are represented as is.
- Labels are converted to strings of the form
':foo'for targets in the same package or'//pkg:name'for targets in a different package. - Lists are represented as tuples, and dicts are converted to new, mutable dicts. Their elements are recursively converted in the same fashion.
selectvalues are returned with their contents transformed as described above.- Attributes for which no value was specified during rule instantiation and whose default value is computed are excluded from the result. (Computed defaults cannot be computed until the analysis phase.).
BUILD files brittle and order-dependent. Also, beware that it differs subtly from the two other conversions of rule attribute values from internal form to Starlark: one used by computed defaults, the other used by ctx.attr.foo.
Parameters
ParameterDescriptionnamestring;
required
The name of the target.
existing_rules
existing_rule(name).
Here, an immutable dict-like object means a deeply immutable object x supporting dict-like iteration, len(x), name in x, x[name], x.get(name), x.items(), x.keys(), and x.values().
If possible, use this function only in implementation functions of rule finalizer symbolic macros. Use of this function in other contexts is not recommened, and will be disabled in a future Bazel release; it makes BUILD files brittle and order-dependent.
exports_files
Parameters
ParameterDescriptionsrcssequence of string s;
required
The list of files to export.
visibilitysequence; or None;
default is None
A visibility declaration can to be specified. The files will be visible to the targets specified. If no visibility is specified, the files will be visible to every package.
licensessequence of string s; or None;
default is None
Licenses to be specified.
glob
- Matches at least one pattern in
include. - Does not match any of the patterns in
exclude(default[]).
exclude_directories argument is enabled (set to 1), files of type directory will be omitted from the results (default 1).
Parameters
ParameterDescriptionincludesequence of string s;
default is []
The list of glob patterns to include.
excludesequence of string s;
default is []
The list of glob patterns to exclude.
exclude_directoriesint;
default is 1
A flag whether to exclude directories or not.
allow_empty
default is unbound
Whether we allow glob patterns to match nothing. If `allow_empty` is False, each individual include pattern must match something and also the final result must be non-empty (after the matches of the `exclude` patterns are excluded).
module_name
module.name field seen in module_ctx.modules.
May return None.
module_version
module.version field seen in module_ctx.modules.
May return None.
package_default_visibility
default_visibility parameter of package(), extended to include the package itself.
package_group
visibility attributes.
Parameters
ParameterDescriptionnamestring;
required
The unique name for this rule.
packagessequence of string s;
default is []
A complete enumeration of packages in this group.
includessequence of string s;
default is []
Other package groups that are included in this one.
package_name
some/package/BUILD, its value will be some/package. If the BUILD file calls a function defined in a .bzl file, package_name() will match the caller BUILD file package. The value will always be an empty string for the root package.
package_relative_label
BUILD file for which the current macro is executing). If the input is already a Label, it is returned unchanged.
This function may only be called while evaluating a BUILD file and the macros it directly or indirectly calls; it may not be called in (for instance) a rule implementation function.
The result of this function is the same Label value as would be produced by passing the given string to a label-valued attribute of a target declared in the BUILD file.
Usage note: The difference between this function and Label() is that Label() uses the context of the package of the .bzl file that called it, not the package of the BUILD file. Use Label() when you need to refer to a fixed target that is hardcoded into the macro, such as a compiler. Use package_relative_label() when you need to normalize a label string supplied by the BUILD file to a Label object. (There is no way to convert a string to a Label in the context of a package other than the BUILD file or the calling .bzl file. For that reason, outer macros should always prefer to pass Label objects to inner macros rather than label strings.)
Parameters
ParameterDescriptioninputstring; or Label;
required
The input label string or Label object. If a Label object is passed, it’s returned as is.
repo_name
repository_name
--+incompatible_enable_deprecated_label_apis
Deprecated. Prefer to use repo_name instead, which doesn’t contain the spurious leading at-sign, but behaves identically otherwise.
The canonical name of the repository containing the package currently being evaluated, with a single at-sign ( @) prefixed. For example, in packages that are called into existence by the WORKSPACE stanza local_repository(name='local', path=...) it will be set to @local. In packages in the main repository, it will be set to @.
subpackages
Parameters
ParameterDescriptionincludesequence of string s;
required
The list of glob patterns to include in subpackages scan.
excludesequence of string s;
default is []
The list of glob patterns to exclude from subpackages scan.
allow_emptybool;
default is False
Whether we fail if the call returns an empty list. By default empty list indicates potential error in BUILD file where the call to subpackages() is superflous. Setting to true allows this function to succeed in that case.