• Home
Name Date Size #Lines LOC

..--

android/03-May-2024-41,68729,176

androidmk/03-May-2024-4,8804,063

apex/03-May-2024-16,11512,621

bazel/03-May-2024-2,0691,682

bloaty/03-May-2024-376253

bp2build/03-May-2024-6,5225,623

bpf/03-May-2024-267188

bpfix/03-May-2024-2,6822,273

cc/03-May-2024-38,47227,568

cmd/03-May-2024-15,75512,578

cuj/03-May-2024-284212

dexpreopt/03-May-2024-2,7071,731

docs/03-May-2024-849650

etc/03-May-2024-867631

filesystem/03-May-2024-1,451984

finder/03-May-2024-5,3013,912

genrule/03-May-2024-1,8121,400

jar/03-May-2024-441343

java/03-May-2024-34,45324,241

kernel/03-May-2024-257179

licenses/03-May-2024-1,4761,242

linkerconfig/03-May-2024-360267

makedeps/03-May-2024-528448

partner/03-May-2024-336256

phony/03-May-2024-9267

python/03-May-2024-2,4401,614

remoteexec/03-May-2024-282190

response/03-May-2024-254200

rust/03-May-2024-9,6546,909

scripts/03-May-2024-7,3755,107

sdk/03-May-2024-10,0487,836

sh/03-May-2024-781550

shared/03-May-2024-313186

symbol_inject/03-May-2024-3,4873,078

sysprop/03-May-2024-973710

tests/03-May-2024-926708

third_party/zip/03-May-2024-3,6372,830

tradefed/03-May-2024-611465

ui/03-May-2024-15,83511,304

xml/03-May-2024-263182

zip/03-May-2024-2,0631,627

.gitignoreD03-May-20247 21

Android.bpD03-May-20242.2 KiB119108

OWNERSD03-May-2024388 1916

PREUPLOAD.cfgD03-May-2024159 75

README.mdD03-May-202421.5 KiB607482

TEST_MAPPINGD03-May-202482 87

bootstrap.bashD03-May-2024916 246

build_kzip.bashD03-May-20242.7 KiB5623

build_test.bashD03-May-20241.9 KiB5922

doc.goD03-May-20242.5 KiB571

go.modD03-May-2024254 126

navbar.mdD03-May-202496 43

root.bpD03-May-2024225 54

soong.bashD03-May-2024915 236

soong.bootstrap.inD03-May-202498 43

soong_ui.bashD03-May-20241.9 KiB5929

vnames.jsonD03-May-2024174 1615

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
7See [Simple Build
8Configuration](https://source.android.com/compatibility/tests/development/blueprints)
9on source.android.com to read how Soong is configured for testing.
10
11## Android.bp file format
12
13By design, Android.bp files are very simple.  There are no conditionals or
14control flow statements - any complexity is handled in build logic written in
15Go.  The syntax and semantics of Android.bp files are intentionally similar
16to [Bazel BUILD files](https://www.bazel.io/versions/master/docs/be/overview.html)
17when possible.
18
19### Modules
20
21A module in an Android.bp file starts with a module type, followed by a set of
22properties in `name: value,` format:
23
24```
25cc_binary {
26    name: "gzip",
27    srcs: ["src/test/minigzip.c"],
28    shared_libs: ["libz"],
29    stl: "none",
30}
31```
32
33Every module must have a `name` property, and the value must be unique across
34all Android.bp files.
35
36For a list of valid module types and their properties see
37[$OUT_DIR/soong/docs/soong_build.html](https://ci.android.com/builds/latest/branches/aosp-build-tools/targets/linux/view/soong_build.html).
38
39### File lists
40
41Properties that take a list of files can also take glob patterns and output path
42expansions.
43
44* Glob patterns can contain the normal Unix wildcard `*`, for example `"*.java"`.
45
46  Glob patterns can also contain a single `**` wildcard as a path element, which
47  will match zero or more path elements. For example, `java/**/*.java` will match
48  `java/Main.java` and `java/com/android/Main.java`.
49
50* Output path expansions take the format `:module` or `:module{.tag}`, where
51  `module` is the name of a module that produces output files, and it expands to
52  a list of those output files. With the optional `{.tag}` suffix, the module
53  may produce a different list of outputs according to `tag`.
54
55  For example, a `droiddoc` module with the name "my-docs" would return its
56  `.stubs.srcjar` output with `":my-docs"`, and its `.doc.zip` file with
57  `":my-docs{.doc.zip}"`.
58
59  This is commonly used to reference `filegroup` modules, whose output files
60  consist of their `srcs`.
61
62### Variables
63
64An Android.bp file may contain top-level variable assignments:
65```
66gzip_srcs = ["src/test/minigzip.c"],
67
68cc_binary {
69    name: "gzip",
70    srcs: gzip_srcs,
71    shared_libs: ["libz"],
72    stl: "none",
73}
74```
75
76Variables are scoped to the remainder of the file they are declared in, as well
77as any child Android.bp files.  Variables are immutable with one exception - they
78can be appended to with a += assignment, but only before they have been
79referenced.
80
81### Comments
82
83Android.bp files can contain C-style multiline `/* */` and C++ style single-line
84`//` comments.
85
86### Types
87
88Variables and properties are strongly typed, variables dynamically based on the
89first assignment, and properties statically by the module type.  The supported
90types are:
91* Bool (`true` or `false`)
92* Integers (`int`)
93* Strings (`"string"`)
94* Lists of strings (`["string1", "string2"]`)
95* Maps (`{key1: "value1", key2: ["value2"]}`)
96
97Maps may values of any type, including nested maps.  Lists and maps may have
98trailing commas after the last value.
99
100Strings can contain double quotes using `\"`, for example `"cat \"a b\""`.
101
102### Operators
103
104Strings, lists of strings, and maps can be appended using the `+` operator.
105Integers can be summed up using the `+` operator. Appending a map produces the
106union of keys in both maps, appending the values of any keys that are present
107in both maps.
108
109### Defaults modules
110
111A defaults module can be used to repeat the same properties in multiple modules.
112For example:
113
114```
115cc_defaults {
116    name: "gzip_defaults",
117    shared_libs: ["libz"],
118    stl: "none",
119}
120
121cc_binary {
122    name: "gzip",
123    defaults: ["gzip_defaults"],
124    srcs: ["src/test/minigzip.c"],
125}
126```
127
128### Packages
129
130The build is organized into packages where each package is a collection of related files and a
131specification of the dependencies among them in the form of modules.
132
133A package is defined as a directory containing a file named `Android.bp`, residing beneath the
134top-level directory in the build and its name is its path relative to the top-level directory. A
135package includes all files in its directory, plus all subdirectories beneath it, except those which
136themselves contain an `Android.bp` file.
137
138The modules in a package's `Android.bp` and included files are part of the module.
139
140For example, in the following directory tree (where `.../android/` is the top-level Android
141directory) there are two packages, `my/app`, and the subpackage `my/app/tests`. Note that
142`my/app/data` is not a package, but a directory belonging to package `my/app`.
143
144    .../android/my/app/Android.bp
145    .../android/my/app/app.cc
146    .../android/my/app/data/input.txt
147    .../android/my/app/tests/Android.bp
148    .../android/my/app/tests/test.cc
149
150This is based on the Bazel package concept.
151
152The `package` module type allows information to be specified about a package. Only a single
153`package` module can be specified per package and in the case where there are multiple `.bp` files
154in the same package directory it is highly recommended that the `package` module (if required) is
155specified in the `Android.bp` file.
156
157Unlike most module type `package` does not have a `name` property. Instead the name is set to the
158name of the package, e.g. if the package is in `top/intermediate/package` then the package name is
159`//top/intermediate/package`.
160
161E.g. The following will set the default visibility for all the modules defined in the package and
162any subpackages that do not set their own default visibility (irrespective of whether they are in
163the same `.bp` file as the `package` module) to be visible to all the subpackages by default.
164
165```
166package {
167    default_visibility: [":__subpackages"]
168}
169```
170
171### Referencing Modules
172
173A module `libfoo` can be referenced by its name
174
175```
176cc_binary {
177    name: "app",
178    shared_libs: ["libfoo"],
179}
180```
181
182Obviously, this works only if there is only one `libfoo` module in the source
183tree. Ensuring such name uniqueness for larger trees may become problematic. We
184might also want to use the same name in multiple mutually exclusive subtrees
185(for example, implementing different devices) deliberately in order to describe
186a functionally equivalent module. Enter Soong namespaces.
187
188#### Namespaces
189
190A presense of the `soong_namespace {..}` in an Android.bp file defines a
191**namespace**. For instance, having
192
193```
194soong_namespace {
195    ...
196}
197...
198```
199
200in `device/google/bonito/Android.bp` informs Soong that within the
201`device/google/bonito` package the module names are unique, that is, all the
202modules defined in the Android.bp files in the `device/google/bonito/` tree have
203unique names. However, there may be modules with the same names outside
204`device/google/bonito` tree. Indeed, there is a module `"pixelstats-vendor"`
205both in `device/google/bonito/pixelstats` and in
206`device/google/coral/pixelstats`.
207
208The name of a namespace is the path of its directory. The name of the namespace
209in the example above is thus `device/google/bonito`.
210
211An implicit **global namespace** corresponds to the source tree as a whole. It
212has empty name.
213
214A module name's **scope** is the smallest namespace containing it. Suppose a
215source tree has `device/my` and `device/my/display` namespaces. If `libfoo`
216module is defined in `device/co/display/lib/Android.bp`, its namespace is
217`device/co/display`.
218
219The name uniqueness thus means that module's name is unique within its scope. In
220other words, "//_scope_:_name_" is globally unique module reference, e.g,
221`"//device/google/bonito:pixelstats-vendor"`. _Note_ that the name of the
222namespace for a module may be different from module's package name: `libfoo`
223belongs to `device/my/display` namespace but is contained in
224`device/my/display/lib` package.
225
226#### Name Resolution
227
228The form of a module reference determines how Soong locates the module.
229
230For a **global reference** of the "//_scope_:_name_" form, Soong verifies there
231is a namespace called "_scope_", then verifies it contains a "_name_" module and
232uses it. Soong verifies there is only one "_name_" in "_scope_" at the beginning
233when it parses Android.bp files.
234
235A **local reference** has "_name_" form, and resolving it involves looking for a
236module "_name_" in one or more namespaces. By default only the global namespace
237is searched for "_name_" (in other words, only the modules not belonging to an
238explicitly defined scope are considered). The `imports` attribute of the
239`soong_namespaces` allows to specify where to look for modules . For instance,
240with `device/google/bonito/Android.bp` containing
241
242```
243soong_namespace {
244    imports: [
245        "hardware/google/interfaces",
246        "hardware/google/pixel",
247        "hardware/qcom/bootctrl",
248    ],
249}
250```
251
252a reference to `"libpixelstats"` will resolve to the module defined in
253`hardware/google/pixel/pixelstats/Android.bp` because this module is in
254`hardware/google/pixel` namespace.
255
256**TODO**: Conventionally, languages with similar concepts provide separate
257constructs for namespace definition and name resolution (`namespace` and `using`
258in C++, for instance). Should Soong do that, too?
259
260#### Referencing modules in makefiles
261
262While we are gradually converting makefiles to Android.bp files, Android build
263is described by a mixture of Android.bp and Android.mk files, and a module
264defined in an Android.mk file can reference a module defined in Android.bp file.
265For instance, a binary still defined in an Android.mk file may have a library
266defined in already converted Android.bp as a dependency.
267
268A module defined in an Android.bp file and belonging to the global namespace can
269be referenced from a makefile without additional effort. If a module belongs to
270an explicit namespace, it can be referenced from a makefile only after after the
271name of the namespace has been added to the value of PRODUCT_SOONG_NAMESPACES
272variable.
273
274Note that makefiles have no notion of namespaces and exposing namespaces with
275the same modules via PRODUCT_SOONG_NAMESPACES may cause Make failure. For
276instance, exposing both `device/google/bonito` and `device/google/coral`
277namespaces will cause Make failure because it will see two targets for the
278`pixelstats-vendor` module.
279
280### Visibility
281
282The `visibility` property on a module controls whether the module can be
283used by other packages. Modules are always visible to other modules declared
284in the same package. This is based on the Bazel visibility mechanism.
285
286If specified the `visibility` property must contain at least one rule.
287
288Each rule in the property must be in one of the following forms:
289* `["//visibility:public"]`: Anyone can use this module.
290* `["//visibility:private"]`: Only rules in the module's package (not its
291subpackages) can use this module.
292* `["//visibility:override"]`: Discards any rules inherited from defaults or a
293creating module. Can only be used at the beginning of a list of visibility
294rules.
295* `["//some/package:__pkg__", "//other/package:__pkg__"]`: Only modules in
296`some/package` and `other/package` (defined in `some/package/*.bp` and
297`other/package/*.bp`) have access to this module. Note that sub-packages do not
298have access to the rule; for example, `//some/package/foo:bar` or
299`//other/package/testing:bla` wouldn't have access. `__pkg__` is a special
300module and must be used verbatim. It represents all of the modules in the
301package.
302* `["//project:__subpackages__", "//other:__subpackages__"]`: Only modules in
303packages `project` or `other` or in one of their sub-packages have access to
304this module. For example, `//project:rule`, `//project/library:lib` or
305`//other/testing/internal:munge` are allowed to depend on this rule (but not
306`//independent:evil`)
307* `["//project"]`: This is shorthand for `["//project:__pkg__"]`
308* `[":__subpackages__"]`: This is shorthand for `["//project:__subpackages__"]`
309where `//project` is the module's package, e.g. using `[":__subpackages__"]` in
310`packages/apps/Settings/Android.bp` is equivalent to
311`//packages/apps/Settings:__subpackages__`.
312* `["//visibility:legacy_public"]`: The default visibility, behaves as
313`//visibility:public` for now. It is an error if it is used in a module.
314
315The visibility rules of `//visibility:public` and `//visibility:private` cannot
316be combined with any other visibility specifications, except
317`//visibility:public` is allowed to override visibility specifications imported
318through the `defaults` property.
319
320Packages outside `vendor/` cannot make themselves visible to specific packages
321in `vendor/`, e.g. a module in `libcore` cannot declare that it is visible to
322say `vendor/google`, instead it must make itself visible to all packages within
323`vendor/` using `//vendor:__subpackages__`.
324
325If a module does not specify the `visibility` property then it uses the
326`default_visibility` property of the `package` module in the module's package.
327
328If the `default_visibility` property is not set for the module's package then
329it will use the `default_visibility` of its closest ancestor package for which
330a `default_visibility` property is specified.
331
332If no `default_visibility` property can be found then the module uses the
333global default of `//visibility:legacy_public`.
334
335The `visibility` property has no effect on a defaults module although it does
336apply to any non-defaults module that uses it. To set the visibility of a
337defaults module, use the `defaults_visibility` property on the defaults module;
338not to be confused with the `default_visibility` property on the package module.
339
340Once the build has been completely switched over to soong it is possible that a
341global refactoring will be done to change this to `//visibility:private` at
342which point all packages that do not currently specify a `default_visibility`
343property will be updated to have
344`default_visibility = [//visibility:legacy_public]` added. It will then be the
345owner's responsibility to replace that with a more appropriate visibility.
346
347### Formatter
348
349Soong includes a canonical formatter for Android.bp files, similar to
350[gofmt](https://golang.org/cmd/gofmt/).  To recursively reformat all Android.bp files
351in the current directory:
352```
353bpfmt -w .
354```
355
356The canonical format includes 4 space indents, newlines after every element of a
357multi-element list, and always includes a trailing comma in lists and maps.
358
359### Convert Android.mk files
360
361Soong includes a tool perform a first pass at converting Android.mk files
362to Android.bp files:
363
364```
365androidmk Android.mk > Android.bp
366```
367
368The tool converts variables, modules, comments, and some conditionals, but any
369custom Makefile rules, complex conditionals or extra includes must be converted
370by hand.
371
372#### Differences between Android.mk and Android.bp
373
374* Android.mk files often have multiple modules with the same name (for example
375for static and shared version of a library, or for host and device versions).
376Android.bp files require unique names for every module, but a single module can
377be built in multiple variants, for example by adding `host_supported: true`.
378The androidmk converter will produce multiple conflicting modules, which must
379be resolved by hand to a single module with any differences inside
380`target: { android: { }, host: { } }` blocks.
381
382### Conditionals
383
384Soong deliberately does not support most conditionals in Android.bp files.  We
385suggest removing most conditionals from the build.  See
386[Best Practices](docs/best_practices.md#removing-conditionals) for some
387examples on how to remove conditionals.
388
389Most conditionals supported natively by Soong are converted to a map
390property.  When building the module one of the properties in the map will be
391selected, and its values appended to the property with the same name at the
392top level of the module.
393
394For example, to support architecture specific files:
395```
396cc_library {
397    ...
398    srcs: ["generic.cpp"],
399    arch: {
400        arm: {
401            srcs: ["arm.cpp"],
402        },
403        x86: {
404            srcs: ["x86.cpp"],
405        },
406    },
407}
408```
409
410When building the module for arm the `generic.cpp` and `arm.cpp` sources will
411be built.  When building for x86 the `generic.cpp` and 'x86.cpp' sources will
412be built.
413
414#### Soong Config Variables
415
416When converting vendor modules that contain conditionals, simple conditionals
417can be supported through Soong config variables using `soong_config_*`
418modules that describe the module types, variables and possible values:
419
420```
421soong_config_module_type {
422    name: "acme_cc_defaults",
423    module_type: "cc_defaults",
424    config_namespace: "acme",
425    variables: ["board"],
426    bool_variables: ["feature"],
427    value_variables: ["width"],
428    properties: ["cflags", "srcs"],
429}
430
431soong_config_string_variable {
432    name: "board",
433    values: ["soc_a", "soc_b", "soc_c"],
434}
435```
436
437This example describes a new `acme_cc_defaults` module type that extends the
438`cc_defaults` module type, with three additional conditionals based on
439variables `board`, `feature` and `width`, which can affect properties `cflags`
440and `srcs`. Additionally, each conditional will contain a `conditions_default`
441property can affect `cflags` and `srcs` in the following conditions:
442
443* bool variable (e.g. `feature`): the variable is unspecified or not set to a true value
444* value variable (e.g. `width`): the variable is unspecified
445* string variable (e.g. `board`): the variable is unspecified or the variable is set to a string unused in the
446given module. For example, with `board`, if the `board`
447conditional contains the properties `soc_a` and `conditions_default`, when
448board=soc_b, the `cflags` and `srcs` values under `conditions_default` will be
449used. To specify that no properties should be amended for `soc_b`, you can set
450`soc_b: {},`.
451
452The values of the variables can be set from a product's `BoardConfig.mk` file:
453```
454SOONG_CONFIG_NAMESPACES += acme
455SOONG_CONFIG_acme += \
456    board \
457    feature \
458    width \
459
460SOONG_CONFIG_acme_board := soc_a
461SOONG_CONFIG_acme_feature := true
462SOONG_CONFIG_acme_width := 200
463```
464
465The `acme_cc_defaults` module type can be used anywhere after the definition in
466the file where it is defined, or can be imported into another file with:
467```
468soong_config_module_type_import {
469    from: "device/acme/Android.bp",
470    module_types: ["acme_cc_defaults"],
471}
472```
473
474It can used like any other module type:
475```
476acme_cc_defaults {
477    name: "acme_defaults",
478    cflags: ["-DGENERIC"],
479    soong_config_variables: {
480        board: {
481            soc_a: {
482                cflags: ["-DSOC_A"],
483            },
484            soc_b: {
485                cflags: ["-DSOC_B"],
486            },
487            conditions_default: {
488                cflags: ["-DSOC_DEFAULT"],
489            },
490        },
491        feature: {
492            cflags: ["-DFEATURE"],
493            conditions_default: {
494                cflags: ["-DFEATURE_DEFAULT"],
495            },
496        },
497        width: {
498            cflags: ["-DWIDTH=%s"],
499            conditions_default: {
500                cflags: ["-DWIDTH=DEFAULT"],
501            },
502        },
503    },
504}
505
506cc_library {
507    name: "libacme_foo",
508    defaults: ["acme_defaults"],
509    srcs: ["*.cpp"],
510}
511```
512
513With the `BoardConfig.mk` snippet above, `libacme_foo` would build with
514`cflags: "-DGENERIC -DSOC_A -DFEATURE -DWIDTH=200"`.
515
516Alternatively, with `DefaultBoardConfig.mk`:
517
518```
519SOONG_CONFIG_NAMESPACES += acme
520SOONG_CONFIG_acme += \
521    board \
522    feature \
523    width \
524
525SOONG_CONFIG_acme_feature := false
526```
527
528then `libacme_foo` would build with `cflags: "-DGENERIC -DSOC_DEFAULT -DFEATURE_DEFAULT -DSIZE=DEFAULT"`.
529
530Alternatively, with `DefaultBoardConfig.mk`:
531
532```
533SOONG_CONFIG_NAMESPACES += acme
534SOONG_CONFIG_acme += \
535    board \
536    feature \
537    width \
538
539SOONG_CONFIG_acme_board := soc_c
540```
541
542then `libacme_foo` would build with `cflags: "-DGENERIC -DSOC_DEFAULT
543-DFEATURE_DEFAULT -DSIZE=DEFAULT"`.
544
545`soong_config_module_type` modules will work best when used to wrap defaults
546modules (`cc_defaults`, `java_defaults`, etc.), which can then be referenced
547by all of the vendor's other modules using the normal namespace and visibility
548rules.
549
550## Build logic
551
552The build logic is written in Go using the
553[blueprint](http://godoc.org/github.com/google/blueprint) framework.  Build
554logic receives module definitions parsed into Go structures using reflection
555and produces build rules.  The build rules are collected by blueprint and
556written to a [ninja](http://ninja-build.org) build file.
557
558## Other documentation
559
560* [Best Practices](docs/best_practices.md)
561* [Build Performance](docs/perf.md)
562* [Generating CLion Projects](docs/clion.md)
563* [Generating YouCompleteMe/VSCode compile\_commands.json file](docs/compdb.md)
564* Make-specific documentation: [build/make/README.md](https://android.googlesource.com/platform/build/+/master/README.md)
565
566## Developing for Soong
567
568To load Soong code in a Go-aware IDE, create a directory outside your android tree and then:
569```bash
570apt install bindfs
571export GOPATH=<path to the directory you created>
572build/soong/scripts/setup_go_workspace_for_soong.sh
573```
574
575This will bind mount the Soong source directories into the directory in the layout expected by
576the IDE.
577
578### Running Soong in a debugger
579
580To run the soong_build process in a debugger, install `dlv` and then start the build with
581`SOONG_DELVE=<listen addr>` in the environment.
582For example:
583```bash
584SOONG_DELVE=:1234 m nothing
585```
586and then in another terminal:
587```
588dlv connect :1234
589```
590
591If you see an error:
592```
593Could not attach to pid 593: this could be caused by a kernel
594security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope
595```
596you can temporarily disable
597[Yama's ptrace protection](https://www.kernel.org/doc/Documentation/security/Yama.txt)
598using:
599```bash
600sudo sysctl -w kernel.yama.ptrace_scope=0
601```
602
603## Contact
604
605Email android-building@googlegroups.com (external) for any questions, or see
606[go/soong](http://go/soong) (internal).
607