NameDateSize

..10-Aug-20184 KiB

android/10-Aug-20184 KiB

Android.bp10-Aug-20188.1 KiB

androidmk/10-Aug-20184 KiB

bootstrap.bash10-Aug-2018916

bpf/10-Aug-20184 KiB

bpfix/10-Aug-20184 KiB

build_test.bash10-Aug-20181.5 KiB

cc/10-Aug-20184 KiB

cmd/10-Aug-20184 KiB

doc.go10-Aug-20182.5 KiB

docs/10-Aug-20184 KiB

env/10-Aug-20184 KiB

finder/10-Aug-20184 KiB

genrule/10-Aug-20184 KiB

jar/10-Aug-20184 KiB

java/10-Aug-20184 KiB

navbar.md10-Aug-201896

OWNERS10-Aug-2018332

phony/10-Aug-20184 KiB

PREUPLOAD.cfg10-Aug-201829

python/10-Aug-20184 KiB

README.md10-Aug-20187 KiB

root.bp10-Aug-2018225

scripts/10-Aug-20184 KiB

shared/10-Aug-20184 KiB

soong.bash10-Aug-2018915

soong.bootstrap.in10-Aug-201898

soong_ui.bash10-Aug-20181.9 KiB

third_party/10-Aug-20184 KiB

ui/10-Aug-20184 KiB

zip/10-Aug-20184 KiB

README.md

1# Soong
2
3Soong is the replacement for the old Android make-based build system.  It
4replaces Android.mk files with Android.bp files, which are JSON-like simple
5declarative descriptions of modules to build.
6
7## Android.bp file format
8
9By design, Android.bp files are very simple.  There are no conditionals or
10control flow statements - any complexity is handled in build logic written in
11Go.  The syntax and semantics of Android.bp files are intentionally similar
12to [Bazel BUILD files](https://www.bazel.io/versions/master/docs/be/overview.html)
13when possible.
14
15### Modules
16
17A module in an Android.bp file starts with a module type, followed by a set of
18properties in `name: value,` format:
19
20```
21cc_binary {
22    name: "gzip",
23    srcs: ["src/test/minigzip.c"],
24    shared_libs: ["libz"],
25    stl: "none",
26}
27```
28
29Every module must have a `name` property, and the value must be unique across
30all Android.bp files.
31
32For a list of valid module types and their properties see
33[$OUT_DIR/soong/.bootstrap/docs/soong_build.html](https://go/Android.bp).
34
35### Variables
36
37An Android.bp file may contain top-level variable assignments:
38```
39gzip_srcs = ["src/test/minigzip.c"],
40
41cc_binary {
42    name: "gzip",
43    srcs: gzip_srcs,
44    shared_libs: ["libz"],
45    stl: "none",
46}
47```
48
49Variables are scoped to the remainder of the file they are declared in, as well
50as any child blueprint files.  Variables are immutable with one exception - they
51can be appended to with a += assignment, but only before they have been
52referenced.
53
54### Comments
55Android.bp files can contain C-style multiline `/* */` and C++ style single-line
56`//` comments.
57
58### Types
59
60Variables and properties are strongly typed, variables dynamically based on the
61first assignment, and properties statically by the module type.  The supported
62types are:
63* Bool (`true` or `false`)
64* Integers (`int`)
65* Strings (`"string"`)
66* Lists of strings (`["string1", "string2"]`)
67* Maps (`{key1: "value1", key2: ["value2"]}`)
68
69Maps may values of any type, including nested maps.  Lists and maps may have
70trailing commas after the last value.
71
72### Operators
73
74Strings, lists of strings, and maps can be appended using the `+` operator.
75Integers can be summed up using the `+` operator. Appending a map produces the
76union of keys in both maps, appending the values of any keys that are present
77in both maps.
78
79### Defaults modules
80
81A defaults module can be used to repeat the same properties in multiple modules.
82For example:
83
84```
85cc_defaults {
86    name: "gzip_defaults",
87    shared_libs: ["libz"],
88    stl: "none",
89}
90
91cc_binary {
92    name: "gzip",
93    defaults: ["gzip_defaults"],
94    srcs: ["src/test/minigzip.c"],
95}
96```
97
98### Name resolution
99
100Soong provides the ability for modules in different directories to specify
101the same name, as long as each module is declared within a separate namespace.
102A namespace can be declared like this:
103
104```
105soong_namespace {
106    imports: ["path/to/otherNamespace1", "path/to/otherNamespace2"],
107}
108```
109
110Each Soong module is assigned a namespace based on its location in the tree.
111Each Soong module is considered to be in the namespace defined by the
112soong_namespace found in an Android.bp in the current directory or closest
113ancestor directory, unless no such soong_namespace module is found, in which
114case the module is considered to be in the implicit root namespace.
115
116When Soong attempts to resolve dependency D declared my module M in namespace
117N which imports namespaces I1, I2, I3..., then if D is a fully-qualified name
118of the form "//namespace:module", only the specified namespace will be searched
119for the specified module name. Otherwise, Soong will first look for a module
120named D declared in namespace N. If that module does not exist, Soong will look
121for a module named D in namespaces I1, I2, I3... Lastly, Soong will look in the
122root namespace.
123
124Until we have fully converted from Make to Soong, it will be necessary for the
125Make product config to specify a value of PRODUCT_SOONG_NAMESPACES. Its value
126should be a space-separated list of namespaces that Soong export to Make to be
127built by the `m` command. After we have fully converted from Make to Soong, the
128details of enabling namespaces could potentially change.
129
130### Formatter
131
132Soong includes a canonical formatter for blueprint files, similar to
133[gofmt](https://golang.org/cmd/gofmt/).  To recursively reformat all Android.bp files
134in the current directory:
135```
136bpfmt -w .
137```
138
139The canonical format includes 4 space indents, newlines after every element of a
140multi-element list, and always includes a trailing comma in lists and maps.
141
142### Convert Android.mk files
143
144Soong includes a tool perform a first pass at converting Android.mk files
145to Android.bp files:
146
147```
148androidmk Android.mk > Android.bp
149```
150
151The tool converts variables, modules, comments, and some conditionals, but any
152custom Makefile rules, complex conditionals or extra includes must be converted
153by hand.
154
155#### Differences between Android.mk and Android.bp
156
157* Android.mk files often have multiple modules with the same name (for example
158for static and shared version of a library, or for host and device versions).
159Android.bp files require unique names for every module, but a single module can
160be built in multiple variants, for example by adding `host_supported: true`.
161The androidmk converter will produce multiple conflicting modules, which must
162be resolved by hand to a single module with any differences inside
163`target: { android: { }, host: { } }` blocks.
164
165## Build logic
166
167The build logic is written in Go using the
168[blueprint](http://godoc.org/github.com/google/blueprint) framework.  Build
169logic receives module definitions parsed into Go structures using reflection
170and produces build rules.  The build rules are collected by blueprint and
171written to a [ninja](http://ninja-build.org) build file.
172
173## Other documentation
174
175* [Best Practices](docs/best_practices.md)
176* [Build Performance](docs/perf.md)
177* [Generating CLion Projects](docs/clion.md)
178* Make-specific documentation: [build/make/README.md](https://android.googlesource.com/platform/build/+/master/README.md)
179
180## FAQ
181
182### How do I write conditionals?
183
184Soong deliberately does not support conditionals in Android.bp files.
185Instead, complexity in build rules that would require conditionals are handled
186in Go, where high level language features can be used and implicit dependencies
187introduced by conditionals can be tracked.  Most conditionals are converted
188to a map property, where one of the values in the map will be selected and
189appended to the top level properties.
190
191For example, to support architecture specific files:
192```
193cc_library {
194    ...
195    srcs: ["generic.cpp"],
196    arch: {
197        arm: {
198            srcs: ["arm.cpp"],
199        },
200        x86: {
201            srcs: ["x86.cpp"],
202        },
203    },
204}
205```
206
207See [art/build/art.go](https://android.googlesource.com/platform/art/+/master/build/art.go)
208or [external/llvm/soong/llvm.go](https://android.googlesource.com/platform/external/llvm/+/master/soong/llvm.go)
209for examples of more complex conditionals on product variables or environment variables.
210
211## Contact
212
213Email android-building@googlegroups.com (external) for any questions, or see
214[go/soong](http://go/soong) (internal).
215