--- layout: documentation title: Common Definitions --- #parse("com/google/devtools/build/docgen/templates/be/header.vm")

Common definitions

This section defines various terms and concepts that are common to many functions or build rules below.

Contents

Bourne shell tokenization

Certain string attributes of some rules are split into multiple words according to the tokenization rules of the Bourne shell: unquoted spaces delimit separate words, and single- and double-quotes characters and backslashes are used to prevent tokenization.

Those attributes that are subject to this tokenization are explicitly indicated as such in their definitions in this document.

Attributes subject to "Make" variable expansion and Bourne shell tokenization are typically used for passing arbitrary options to compilers and other tools. Examples of such attributes are cc_library.copts and java_library.javacopts. Together these substitutions allow a single string variable to expand into a configuration-specific list of option words.

Label expansion

Some string attributes of a very few rules are subject to label expansion: if those strings contain a valid label as a substring, such as //mypkg:target, and that label is a declared prerequisite of the current rule, it is expanded into the pathname of the file represented by the target //mypkg:target.

Example attributes include genrule.cmd and cc_binary.linkopts. The details may vary significantly in each case, over such issues as: whether relative labels are expanded; how labels that expand to multiple files are treated, etc. Consult the rule attribute documentation for specifics.

Attributes common to all build rules

#macro(commonAttributeDoc $type $attributeMap) #foreach ($name in $attributeMap.keySet()) #end
Attribute Description
${name} ${attributeMap.get($name).htmlDocumentation}
#end

This section describes attributes that are common to all build rules.
Please note that it is an error to list the same label twice in a list of labels attribute.

#commonAttributeDoc("common" $commonAttributes)

Attributes common to all test rules (*_test)

This section describes attributes that are common to all test rules.

#commonAttributeDoc("test" $testAttributes)

Attributes common to all binary rules (*_binary)

This section describes attributes that are common to all binary rules.

#commonAttributeDoc("binary" $binaryAttributes)

Configurable attributes

Most rule attributes can be "configured" so that their values can depend on the command-line flags passed to Bazel. This can be used, for example, to declare platform-dependent srcs or custom compiler flags depending on the compilation mode. This feature is very close in spirit to abi_deps, except that it's not limited to cc_* rules and the deps attribute.

Implicit output targets

When you define a build rule in a BUILD file, you are explicitly declaring a new, named rule target in a package. Many build rule functions also implicitly entail one or more output file targets, whose contents and meaning are rule-specific. For example, when you explicitly declare a java_binary(name='foo', ...) rule, you are also implicitly declaring an output file target foo_deploy.jar as a member of the same package. (This particular target is a self-contained Java archive suitable for deployment.)

Implicit output targets are first-class members of the global target graph. Just like other targets, they are built on demand, either when specified in the top-level built command, or when they are necessary prerequisites for other build targets. They can be referenced as dependencies in BUILD files, and can be observed in the output of analysis tools such as bazel query.

For each kind of build rule, the rule's documentation contains a special section detailing the names and contents of any implicit outputs entailed by a declaration of that kind of rule.

An important but somewhat subtle distinction between the two namespaces used by the build system: labels identify targets, which may be rules or files, and file targets may be divided into either source (or input) file targets and derived (or output) file targets. These are the things you can mention in BUILD files, build from the command-line, or examine using bazel query; this is the target namespace. Each file target corresponds to one actual file on disk (the "file system namespace"); each rule target may correspond to zero, one or more actual files on disk. There may be files on disk that have no corresponding target; for example, .o object files produced during C++ compilation cannot be referenced from within BUILD files or from the command line. In this way, the build tool may hide certain implementation details of how it does its job. This is explained more fully in the BUILD Concept Reference.

#parse("com/google/devtools/build/docgen/templates/be/footer.vm")