The build files are very simple. There are no conditional or control flow statements.
A module starts with a module type followed by a set of properties in
name: value
format.
bob_binary {
name: "less",
srcs: ["src/less.c"],
ldlibs: ["-lncurses"],
}
Every module has a name
property that is unique.
Bob has a number of module types. The properties available in each module type are documented in the following pages.
- bob_alias
- bob_binary
- bob_defaults
- bob_external_header_library
- bob_external_shared_library
- bob_external_static_library
- bob_generate_binary
- bob_generate_shared_library
- bob_generate_source
- bob_generate_static_library
- bob_install_group
- bob_kernel_module
- bob_resource
- bob_shared_library
- bob_static_library
- bob_transform_source
- bob_genrule
Properties taking filenames also accept glob patterns. *
is the normal
Unix wildcard, so src/*.c
would select all C files in the src
directory. **
will match zero or more path elements, so src/**.c
will match all C files in the src directory and its subdirectories.
Build files may contain top-level variable assignments:
less_srcs = ["src/less.c"]
bob_binary {
name: "less",
srcs: less_srcs,
ldlibs: ["-lncurses"],
}
Before they are referenced, variables can be appended to with
+=
. After they have been referenced by a module they are immutable.
Comments use C-style multiline /* */
and C++ style single-line //
formats.
The type of a variable is determined by the assignment. The type of a property is determined by the module type.
- Bool (
true
orfalse
) - Integers
- Strings (
"string"
) - Lists of strings(
["string1", "string2"]
) - Maps (
{ key1: "value1", key2: 10, key3: ["value3"] }
)
Maps may contain values of any type. Lists and maps may have trailing commas after the last value.
Strings can contain Go templates (except in the name
, defaults
,
and flag_defaults
properties). Go templates start with {{
and end
with }}
. Bob may expand Go templates more that once, which means
that getting literal {{
or }}
is implementation dependent.
Strings, lists of strings, and maps can be appended using the +
operator.
A defaults module can be used to repeat the same properties in
multiple modules (currently restricted to the types bob_binary
,
bob_static_library
, bob_shared_library
and bob_kernel_module
)
bob_defaults {
name: "common_libs",
ldlibs: ["-lncurses"],
}
bob_binary {
name: "less",
defaults: ["common_libs"],
srcs: ["src/less.c"],
}
Defaults can name other defaults.
In most module types, every boolean configuration item (feature) is a map property (lower cased). Within this map the standard module properties can be used. This appends the properties to the module when the feature is enabled.
bob_binary {
name: "less",
srcs: ["src/less.c"],
ldlibs: ["-lncurses"],
use_locales: {
srcs: ["src/locales.c"],
}
}
Features cannot nest. Instead of nesting, separate features should be used.
Configuration values can be used within string properties via Go templates. As with features, the configuration identifier is lower cased.
bob_binary {
name: "less",
srcs: ["src/less.c"],
ldlibs: ["-lncurses"],
use_locales: {
srcs: ["src/locales.c"],
cflags: ["-DDEFAULT_LOCALE={{.default_locale}}"],
}
}
Bob includes a canonical formatter for blueprint files. To format a build file in place:
bpfmt -w build.bp
The canonical format uses 4 space indent, newlines after every element of a multi-element list, and always includes trailing commas.