Home | History | Annotate | only in /build/soong
Up to higher level directory
NameDateSize
android/05-Oct-2017
Android.bp05-Oct-20175.7K
androidmk/05-Oct-2017
bootstrap.bash05-Oct-20171.5K
build.ninja.in05-Oct-201730.3K
cc/05-Oct-2017
cmd/05-Oct-2017
doc.go05-Oct-20172.5K
docs/05-Oct-2017
env/05-Oct-2017
genrule/05-Oct-2017
java/05-Oct-2017
phony/05-Oct-2017
PREUPLOAD.cfg05-Oct-201729
README.md05-Oct-20175.2K
root.bp05-Oct-2017746
scripts/05-Oct-2017
soong.bash05-Oct-20171.2K
soong.bootstrap.in05-Oct-201798
soong_ui.bash05-Oct-20173.4K
third_party/05-Oct-2017
ui/05-Oct-2017

README.md

      1 # Soong
      2 
      3 Soong is the replacement for the old Android make-based build system.  It
      4 replaces Android.mk files with Android.bp files, which are JSON-like simple
      5 declarative descriptions of modules to build.
      6 
      7 ## Android.bp file format
      8 
      9 By design, Android.bp files are very simple.  There are no conditionals or
     10 control flow statements - any complexity is handled in build logic written in
     11 Go.  The syntax and semantics of Android.bp files are intentionally similar
     12 to [Bazel BUILD files](https://www.bazel.io/versions/master/docs/be/overview.html)
     13 when possible.
     14 
     15 ### Modules
     16 
     17 A module in an Android.bp file starts with a module type, followed by a set of
     18 properties in `name: value,` format:
     19 
     20 ```
     21 cc_binary {
     22     name: "gzip",
     23     srcs: ["src/test/minigzip.c"],
     24     shared_libs: ["libz"],
     25     stl: "none",
     26 }
     27 ```
     28 
     29 Every module must have a `name` property, and the value must be unique across
     30 all Android.bp files.
     31 
     32 For 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 
     37 An Android.bp file may contain top-level variable assignments:
     38 ```
     39 gzip_srcs = ["src/test/minigzip.c"],
     40 
     41 cc_binary {
     42     name: "gzip",
     43     srcs: gzip_srcs,
     44     shared_libs: ["libz"],
     45     stl: "none",
     46 }
     47 ```
     48 
     49 Variables are scoped to the remainder of the file they are declared in, as well
     50 as any child blueprint files.  Variables are immutable with one exception - they
     51 can be appended to with a += assignment, but only before they have been
     52 referenced.
     53 
     54 ### Comments
     55 Android.bp files can contain C-style multiline `/* */` and C++ style single-line
     56 `//` comments.
     57 
     58 ### Types
     59 
     60 Variables and properties are strongly typed, variables dynamically based on the
     61 first assignment, and properties statically by the module type.  The supported
     62 types are:
     63 * Bool (`true` or `false`)
     64 * Strings (`"string"`)
     65 * Lists of strings (`["string1", "string2"]`)
     66 * Maps (`{key1: "value1", key2: ["value2"]}`)
     67 
     68 Maps may values of any type, including nested maps.  Lists and maps may have
     69 trailing commas after the last value.
     70 
     71 ### Operators
     72 
     73 Strings, lists of strings, and maps can be appended using the `+` operator.
     74 Appending a map produces the union of keys in both maps, appending the values
     75 of any keys that are present in both maps.
     76 
     77 ### Defaults modules
     78 
     79 A defaults module can be used to repeat the same properties in multiple modules.
     80 For example:
     81 
     82 ```
     83 cc_defaults {
     84     name: "gzip_defaults",
     85     shared_libs: ["libz"],
     86     stl: "none",
     87 }
     88 
     89 cc_binary {
     90     name: "gzip",
     91     defaults: ["gzip_defaults"],
     92     srcs: ["src/test/minigzip.c"],
     93 }
     94 ```
     95 
     96 ### Formatter
     97 
     98 Soong includes a canonical formatter for blueprint files, similar to
     99 [gofmt](https://golang.org/cmd/gofmt/).  To recursively reformat all Android.bp files
    100 in the current directory:
    101 ```
    102 bpfmt -w .
    103 ```
    104 
    105 The canonical format includes 4 space indents, newlines after every element of a
    106 multi-element list, and always includes a trailing comma in lists and maps.
    107 
    108 ### Convert Android.mk files
    109 
    110 Soong includes a tool perform a first pass at converting Android.mk files
    111 to Android.bp files:
    112 
    113 ```
    114 androidmk Android.mk > Android.bp
    115 ```
    116 
    117 The tool converts variables, modules, comments, and some conditionals, but any
    118 custom Makefile rules, complex conditionals or extra includes must be converted
    119 by hand.
    120 
    121 #### Differences between Android.mk and Android.bp
    122 
    123 * Android.mk files often have multiple modules with the same name (for example
    124 for static and shared version of a library, or for host and device versions).
    125 Android.bp files require unique names for every module, but a single module can
    126 be built in multiple variants, for example by adding `host_supported: true`.
    127 The androidmk converter will produce multiple conflicting modules, which must
    128 be resolved by hand to a single module with any differences inside
    129 `target: { android: { }, host: { } }` blocks.
    130 
    131 ## Build logic
    132 
    133 The build logic is written in Go using the
    134 [blueprint](http://godoc.org/github.com/google/blueprint) framework.  Build
    135 logic receives module definitions parsed into Go structures using reflection
    136 and produces build rules.  The build rules are collected by blueprint and
    137 written to a [ninja](http://ninja-build.org) build file.
    138 
    139 ## FAQ
    140 
    141 ### How do I write conditionals?
    142 
    143 Soong deliberately does not support conditionals in Android.bp files.
    144 Instead, complexity in build rules that would require conditionals are handled
    145 in Go, where high level language features can be used and implicit dependencies
    146 introduced by conditionals can be tracked.  Most conditionals are converted
    147 to a map property, where one of the values in the map will be selected and
    148 appended to the top level properties.
    149 
    150 For example, to support architecture specific files:
    151 ```
    152 cc_library {
    153     ...
    154     srcs: ["generic.cpp"],
    155     arch: {
    156         arm: {
    157             srcs: ["arm.cpp"],
    158         },
    159         x86: {
    160             srcs: ["x86.cpp"],
    161         },
    162     },
    163 }
    164 ```
    165 
    166 See [art/build/art.go](https://android.googlesource.com/platform/art/+/master/build/art.go)
    167 or [external/llvm/soong/llvm.go](https://android.googlesource.com/platform/external/llvm/+/master/soong/llvm.go)
    168 for examples of more complex conditionals on product variables or environment variables.
    169 
    170 ## Contact
    171 
    172 Email android-building (a] googlegroups.com (external) for any questions, or see
    173 [go/soong](http://go/soong) (internal).
    174