1*9e94795aSAndroid Build Coastguard Worker# Build System Changes for Android.mk/Android.bp Writers 2*9e94795aSAndroid Build Coastguard Worker 3*9e94795aSAndroid Build Coastguard Worker## Soong genrules are now sandboxed 4*9e94795aSAndroid Build Coastguard Worker 5*9e94795aSAndroid Build Coastguard WorkerPreviously, soong genrules could access any files in the source tree, without specifying them as 6*9e94795aSAndroid Build Coastguard Workerinputs. This makes them incorrect in incremental builds, and incompatible with RBE and Bazel. 7*9e94795aSAndroid Build Coastguard Worker 8*9e94795aSAndroid Build Coastguard WorkerNow, genrules are sandboxed so they can only access their listed srcs. Modules denylisted in 9*9e94795aSAndroid Build Coastguard Workergenrule/allowlists.go are exempt from this. You can also set `BUILD_BROKEN_GENRULE_SANDBOXING` 10*9e94795aSAndroid Build Coastguard Workerin board config to disable this behavior. 11*9e94795aSAndroid Build Coastguard Worker 12*9e94795aSAndroid Build Coastguard Worker## Partitions are no longer affected by previous builds 13*9e94795aSAndroid Build Coastguard Worker 14*9e94795aSAndroid Build Coastguard WorkerPartition builds used to include everything in their staging directories, and building an 15*9e94795aSAndroid Build Coastguard Workerindividual module will install it to the staging directory. Thus, previously, `m mymodule` followed 16*9e94795aSAndroid Build Coastguard Workerby `m` would cause `mymodule` to be presinstalled on the device, even if it wasn't listed in 17*9e94795aSAndroid Build Coastguard Worker`PRODUCT_PACKAGES`. 18*9e94795aSAndroid Build Coastguard Worker 19*9e94795aSAndroid Build Coastguard WorkerThis behavior has been changed, and now the partition images only include what they'd have if you 20*9e94795aSAndroid Build Coastguard Workerdid a clean build. This behavior can be disabled by setting the 21*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_INCORRECT_PARTITION_IMAGES` environment variable or board config variable. 22*9e94795aSAndroid Build Coastguard Worker 23*9e94795aSAndroid Build Coastguard WorkerManually adding make rules that build to the staging directories without going through the make 24*9e94795aSAndroid Build Coastguard Workermodule system will not be compatible with this change. This includes many usages of 25*9e94795aSAndroid Build Coastguard Worker`LOCAL_POST_INSTALL_CMD`. 26*9e94795aSAndroid Build Coastguard Worker 27*9e94795aSAndroid Build Coastguard Worker## Perform validation of Soong plugins 28*9e94795aSAndroid Build Coastguard Worker 29*9e94795aSAndroid Build Coastguard WorkerEach Soong plugin will require manual work to migrate to Bazel. In order to 30*9e94795aSAndroid Build Coastguard Workerminimize the manual work outside of build/soong, we are restricting plugins to 31*9e94795aSAndroid Build Coastguard Workerthose that exist today and those in vendor or hardware directories. 32*9e94795aSAndroid Build Coastguard Worker 33*9e94795aSAndroid Build Coastguard WorkerIf you need to extend the build system via a plugin, please reach out to the 34*9e94795aSAndroid Build Coastguard Workerbuild team via email [email protected] (external) for any 35*9e94795aSAndroid Build Coastguard Workerquestions, or see [go/soong](http://go/soong) (internal). 36*9e94795aSAndroid Build Coastguard Worker 37*9e94795aSAndroid Build Coastguard WorkerTo omit the validation, `BUILD_BROKEN_PLUGIN_VALIDATION` expects a 38*9e94795aSAndroid Build Coastguard Workerspace-separated list of plugins to omit from the validation. This must be set 39*9e94795aSAndroid Build Coastguard Workerwithin a product configuration .mk file, board config .mk file, or buildspec.mk. 40*9e94795aSAndroid Build Coastguard Worker 41*9e94795aSAndroid Build Coastguard Worker## Python 2 to 3 migration 42*9e94795aSAndroid Build Coastguard Worker 43*9e94795aSAndroid Build Coastguard WorkerThe path set when running builds now makes the `python` executable point to python 3, 44*9e94795aSAndroid Build Coastguard Workerwhereas on previous versions it pointed to python 2. If you still have python 2 scripts, 45*9e94795aSAndroid Build Coastguard Workeryou can change the shebang line to use `python2` explicitly. This only applies for 46*9e94795aSAndroid Build Coastguard Workerscripts run directly from makefiles, or from soong genrules. 47*9e94795aSAndroid Build Coastguard Worker 48*9e94795aSAndroid Build Coastguard WorkerIn addition, `python_*` soong modules no longer allow python 2. 49*9e94795aSAndroid Build Coastguard Worker 50*9e94795aSAndroid Build Coastguard WorkerPython 2 is slated for complete removal in V. 51*9e94795aSAndroid Build Coastguard Worker 52*9e94795aSAndroid Build Coastguard Worker## Stop referencing sysprop_library directly from cc modules 53*9e94795aSAndroid Build Coastguard Worker 54*9e94795aSAndroid Build Coastguard WorkerFor the migration to Bazel, we are no longer mapping sysprop_library targets 55*9e94795aSAndroid Build Coastguard Workerto their generated `cc_library` counterparts when dependning on them from a 56*9e94795aSAndroid Build Coastguard Workercc module. Instead, directly depend on the generated module by prefixing the 57*9e94795aSAndroid Build Coastguard Workermodule name with `lib`. For example, depending on the following module: 58*9e94795aSAndroid Build Coastguard Worker 59*9e94795aSAndroid Build Coastguard Worker``` 60*9e94795aSAndroid Build Coastguard Workersysprop_library { 61*9e94795aSAndroid Build Coastguard Worker name: "foo", 62*9e94795aSAndroid Build Coastguard Worker srcs: ["foo.sysprop"], 63*9e94795aSAndroid Build Coastguard Worker} 64*9e94795aSAndroid Build Coastguard Worker``` 65*9e94795aSAndroid Build Coastguard Worker 66*9e94795aSAndroid Build Coastguard Workerfrom a module named `bar` can be done like so: 67*9e94795aSAndroid Build Coastguard Worker 68*9e94795aSAndroid Build Coastguard Worker``` 69*9e94795aSAndroid Build Coastguard Workercc_library { 70*9e94795aSAndroid Build Coastguard Worker name: "bar", 71*9e94795aSAndroid Build Coastguard Worker srcs: ["bar.cc"], 72*9e94795aSAndroid Build Coastguard Worker deps: ["libfoo"], 73*9e94795aSAndroid Build Coastguard Worker} 74*9e94795aSAndroid Build Coastguard Worker``` 75*9e94795aSAndroid Build Coastguard Worker 76*9e94795aSAndroid Build Coastguard WorkerFailure to do this will result in an error about a missing variant. 77*9e94795aSAndroid Build Coastguard Worker 78*9e94795aSAndroid Build Coastguard Worker## Gensrcs starts disallowing depfile property 79*9e94795aSAndroid Build Coastguard Worker 80*9e94795aSAndroid Build Coastguard WorkerTo migrate all gensrcs to Bazel, we are restricting the use of depfile property 81*9e94795aSAndroid Build Coastguard Workerbecause Bazel requires specifying the dependencies directly. 82*9e94795aSAndroid Build Coastguard Worker 83*9e94795aSAndroid Build Coastguard WorkerTo fix existing uses, remove depfile and directly specify all the dependencies 84*9e94795aSAndroid Build Coastguard Workerin .bp files. For example: 85*9e94795aSAndroid Build Coastguard Worker 86*9e94795aSAndroid Build Coastguard Worker``` 87*9e94795aSAndroid Build Coastguard Workergensrcs { 88*9e94795aSAndroid Build Coastguard Worker name: "framework-cppstream-protos", 89*9e94795aSAndroid Build Coastguard Worker tools: [ 90*9e94795aSAndroid Build Coastguard Worker "aprotoc", 91*9e94795aSAndroid Build Coastguard Worker "protoc-gen-cppstream", 92*9e94795aSAndroid Build Coastguard Worker ], 93*9e94795aSAndroid Build Coastguard Worker cmd: "mkdir -p $(genDir)/$(in) " + 94*9e94795aSAndroid Build Coastguard Worker "&& $(location aprotoc) " + 95*9e94795aSAndroid Build Coastguard Worker " --plugin=$(location protoc-gen-cppstream) " + 96*9e94795aSAndroid Build Coastguard Worker " -I . " + 97*9e94795aSAndroid Build Coastguard Worker " $(in) ", 98*9e94795aSAndroid Build Coastguard Worker srcs: [ 99*9e94795aSAndroid Build Coastguard Worker "bar.proto", 100*9e94795aSAndroid Build Coastguard Worker ], 101*9e94795aSAndroid Build Coastguard Worker output_extension: "srcjar", 102*9e94795aSAndroid Build Coastguard Worker} 103*9e94795aSAndroid Build Coastguard Worker``` 104*9e94795aSAndroid Build Coastguard Workerwhere `bar.proto` imports `external.proto` would become 105*9e94795aSAndroid Build Coastguard Worker 106*9e94795aSAndroid Build Coastguard Worker``` 107*9e94795aSAndroid Build Coastguard Workergensrcs { 108*9e94795aSAndroid Build Coastguard Worker name: "framework-cppstream-protos", 109*9e94795aSAndroid Build Coastguard Worker tools: [ 110*9e94795aSAndroid Build Coastguard Worker "aprotoc", 111*9e94795aSAndroid Build Coastguard Worker "protoc-gen-cpptream", 112*9e94795aSAndroid Build Coastguard Worker ], 113*9e94795aSAndroid Build Coastguard Worker tool_files: [ 114*9e94795aSAndroid Build Coastguard Worker "external.proto", 115*9e94795aSAndroid Build Coastguard Worker ], 116*9e94795aSAndroid Build Coastguard Worker cmd: "mkdir -p $(genDir)/$(in) " + 117*9e94795aSAndroid Build Coastguard Worker "&& $(location aprotoc) " + 118*9e94795aSAndroid Build Coastguard Worker " --plugin=$(location protoc-gen-cppstream) " + 119*9e94795aSAndroid Build Coastguard Worker " $(in) ", 120*9e94795aSAndroid Build Coastguard Worker srcs: [ 121*9e94795aSAndroid Build Coastguard Worker "bar.proto", 122*9e94795aSAndroid Build Coastguard Worker ], 123*9e94795aSAndroid Build Coastguard Worker output_extension: "srcjar", 124*9e94795aSAndroid Build Coastguard Worker} 125*9e94795aSAndroid Build Coastguard Worker``` 126*9e94795aSAndroid Build Coastguard Workeras in https://android-review.googlesource.com/c/platform/frameworks/base/+/2125692/. 127*9e94795aSAndroid Build Coastguard Worker 128*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_DEPFILE` can be used to allowlist usage of depfile in `gensrcs`. 129*9e94795aSAndroid Build Coastguard Worker 130*9e94795aSAndroid Build Coastguard WorkerIf `depfile` is needed for generating javastream proto, `java_library` with `proto.type` 131*9e94795aSAndroid Build Coastguard Workerset `stream` is the alternative solution. Sees 132*9e94795aSAndroid Build Coastguard Workerhttps://android-review.googlesource.com/c/platform/packages/modules/Permission/+/2118004/ 133*9e94795aSAndroid Build Coastguard Workerfor an example. 134*9e94795aSAndroid Build Coastguard Worker 135*9e94795aSAndroid Build Coastguard Worker## Genrule starts disallowing directory inputs 136*9e94795aSAndroid Build Coastguard Worker 137*9e94795aSAndroid Build Coastguard WorkerTo better specify the inputs to the build, we are restricting use of directories 138*9e94795aSAndroid Build Coastguard Workeras inputs to genrules. 139*9e94795aSAndroid Build Coastguard Worker 140*9e94795aSAndroid Build Coastguard WorkerTo fix existing uses, change inputs to specify the inputs and update the command 141*9e94795aSAndroid Build Coastguard Workeraccordingly. For example: 142*9e94795aSAndroid Build Coastguard Worker 143*9e94795aSAndroid Build Coastguard Worker``` 144*9e94795aSAndroid Build Coastguard Workergenrule: { 145*9e94795aSAndroid Build Coastguard Worker name: "foo", 146*9e94795aSAndroid Build Coastguard Worker srcs: ["bar"], 147*9e94795aSAndroid Build Coastguard Worker cmd: "cp $(location bar)/*.xml $(gendir)", 148*9e94795aSAndroid Build Coastguard Worker ... 149*9e94795aSAndroid Build Coastguard Worker} 150*9e94795aSAndroid Build Coastguard Worker``` 151*9e94795aSAndroid Build Coastguard Worker 152*9e94795aSAndroid Build Coastguard Workerwould become 153*9e94795aSAndroid Build Coastguard Worker 154*9e94795aSAndroid Build Coastguard Worker``` 155*9e94795aSAndroid Build Coastguard Workergenrule: { 156*9e94795aSAndroid Build Coastguard Worker name: "foo", 157*9e94795aSAndroid Build Coastguard Worker srcs: ["bar/*.xml"], 158*9e94795aSAndroid Build Coastguard Worker cmd: "cp $(in) $(gendir)", 159*9e94795aSAndroid Build Coastguard Worker ... 160*9e94795aSAndroid Build Coastguard Worker} 161*9e94795aSAndroid Build Coastguard Worker``` 162*9e94795aSAndroid Build Coastguard Worker 163*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_INPUT_DIR_MODULES` can be used to allowlist specific directories 164*9e94795aSAndroid Build Coastguard Workerwith genrules that have input directories. 165*9e94795aSAndroid Build Coastguard Worker 166*9e94795aSAndroid Build Coastguard Worker## Dexpreopt starts enforcing `<uses-library>` checks (for Java modules) 167*9e94795aSAndroid Build Coastguard Worker 168*9e94795aSAndroid Build Coastguard WorkerIn order to construct correct class loader context for dexpreopt, build system 169*9e94795aSAndroid Build Coastguard Workerneeds to know about the shared library dependencies of Java modules listed in 170*9e94795aSAndroid Build Coastguard Workerthe `<uses-library>` tags in the manifest. Since the build system does not have 171*9e94795aSAndroid Build Coastguard Workeraccess to the manifest contents, that information must be present in the build 172*9e94795aSAndroid Build Coastguard Workerfiles. In simple cases Soong is able to infer it from its knowledge of Java SDK 173*9e94795aSAndroid Build Coastguard Workerlibraries and the `libs` property in Android.bp, but in more complex cases it is 174*9e94795aSAndroid Build Coastguard Workernecessary to add the missing information in Android.bp/Android.mk manually. 175*9e94795aSAndroid Build Coastguard Worker 176*9e94795aSAndroid Build Coastguard WorkerTo specify a list of libraries for a given modules, use: 177*9e94795aSAndroid Build Coastguard Worker 178*9e94795aSAndroid Build Coastguard Worker* Android.bp properties: `uses_libs`, `optional_uses_libs` 179*9e94795aSAndroid Build Coastguard Worker* Android.mk variables: `LOCAL_USES_LIBRARIES`, `LOCAL_OPTIONAL_USES_LIBRARIES` 180*9e94795aSAndroid Build Coastguard Worker 181*9e94795aSAndroid Build Coastguard WorkerIf a library is in `libs`, it usually should *not* be added to the above 182*9e94795aSAndroid Build Coastguard Workerproperties, and Soong should be able to infer the `<uses-library>` tag. But 183*9e94795aSAndroid Build Coastguard Workersometimes a library also needs additional information in its 184*9e94795aSAndroid Build Coastguard WorkerAndroid.bp/Android.mk file (e.g. when it is a `java_library` rather than a 185*9e94795aSAndroid Build Coastguard Worker`java_sdk_library`, or when the library name is different from its module name, 186*9e94795aSAndroid Build Coastguard Workeror when the module is defined in Android.mk rather than Android.bp). In such 187*9e94795aSAndroid Build Coastguard Workercases it is possible to tell the build system that the library provides a 188*9e94795aSAndroid Build Coastguard Worker`<uses-library>` with a given name (however, this is discouraged and will be 189*9e94795aSAndroid Build Coastguard Workerdeprecated in the future, and it is recommended to fix the underlying problem): 190*9e94795aSAndroid Build Coastguard Worker 191*9e94795aSAndroid Build Coastguard Worker* Android.bp property: `provides_uses_lib` 192*9e94795aSAndroid Build Coastguard Worker* Android.mk variable: `LOCAL_PROVIDES_USES_LIBRARY` 193*9e94795aSAndroid Build Coastguard Worker 194*9e94795aSAndroid Build Coastguard WorkerIt is possible to disable the check on a per-module basis. When doing that it is 195*9e94795aSAndroid Build Coastguard Workeralso recommended to disable dexpreopt, as disabling a failed check will result 196*9e94795aSAndroid Build Coastguard Workerin incorrect class loader context recorded in the .odex file, which will cause 197*9e94795aSAndroid Build Coastguard Workerclass loader context mismatch and dexopt at first boot. 198*9e94795aSAndroid Build Coastguard Worker 199*9e94795aSAndroid Build Coastguard Worker* Android.bp property: `enforce_uses_lib` 200*9e94795aSAndroid Build Coastguard Worker* Android.mk variable: `LOCAL_ENFORCE_USES_LIBRARIES` 201*9e94795aSAndroid Build Coastguard Worker 202*9e94795aSAndroid Build Coastguard WorkerFinally, it is possible to globally disable the check: 203*9e94795aSAndroid Build Coastguard Worker 204*9e94795aSAndroid Build Coastguard Worker* For a given product: `PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true` 205*9e94795aSAndroid Build Coastguard Worker* On the command line: `RELAX_USES_LIBRARY_CHECK=true` 206*9e94795aSAndroid Build Coastguard Worker 207*9e94795aSAndroid Build Coastguard WorkerThe environment variable overrides the product variable, so it is possible to 208*9e94795aSAndroid Build Coastguard Workerdisable the check for a product, but quickly re-enable it for a local build. 209*9e94795aSAndroid Build Coastguard Worker 210*9e94795aSAndroid Build Coastguard Worker## `LOCAL_REQUIRED_MODULES` requires listed modules to exist {#BUILD_BROKEN_MISSING_REQUIRED_MODULES} 211*9e94795aSAndroid Build Coastguard Worker 212*9e94795aSAndroid Build Coastguard WorkerModules listed in `LOCAL_REQUIRED_MODULES`, `LOCAL_HOST_REQUIRED_MODULES` and 213*9e94795aSAndroid Build Coastguard Worker`LOCAL_TARGET_REQUIRED_MODULES` need to exist unless `ALLOW_MISSING_DEPENDENCIES` 214*9e94795aSAndroid Build Coastguard Workeris set. 215*9e94795aSAndroid Build Coastguard Worker 216*9e94795aSAndroid Build Coastguard WorkerTo temporarily relax missing required modules check, use: 217*9e94795aSAndroid Build Coastguard Worker 218*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_MISSING_REQUIRED_MODULES := true` 219*9e94795aSAndroid Build Coastguard Worker 220*9e94795aSAndroid Build Coastguard Worker## Changes in system properties settings 221*9e94795aSAndroid Build Coastguard Worker 222*9e94795aSAndroid Build Coastguard Worker### Product variables 223*9e94795aSAndroid Build Coastguard Worker 224*9e94795aSAndroid Build Coastguard WorkerSystem properties for each of the partition is supposed to be set via following 225*9e94795aSAndroid Build Coastguard Workerproduct config variables. 226*9e94795aSAndroid Build Coastguard Worker 227*9e94795aSAndroid Build Coastguard WorkerFor system partition, 228*9e94795aSAndroid Build Coastguard Worker 229*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_SYSTEM_PROPERTIES` 230*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_SYSTEM_DEFAULT_PROPERTIES` is highly discouraged. Will be deprecated. 231*9e94795aSAndroid Build Coastguard Worker 232*9e94795aSAndroid Build Coastguard WorkerFor vendor partition, 233*9e94795aSAndroid Build Coastguard Worker 234*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_VENDOR_PROPERTIES` 235*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_PROPERTY_OVERRIDES` is highly discouraged. Will be deprecated. 236*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_DEFAULT_PROPERTY_OVERRIDES` is also discouraged. Will be deprecated. 237*9e94795aSAndroid Build Coastguard Worker 238*9e94795aSAndroid Build Coastguard WorkerFor odm partition, 239*9e94795aSAndroid Build Coastguard Worker 240*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_ODM_PROPERTIES` 241*9e94795aSAndroid Build Coastguard Worker 242*9e94795aSAndroid Build Coastguard WorkerFor system_ext partition, 243*9e94795aSAndroid Build Coastguard Worker 244*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_SYSTEM_EXT_PROPERTIES` 245*9e94795aSAndroid Build Coastguard Worker 246*9e94795aSAndroid Build Coastguard WorkerFor product partition, 247*9e94795aSAndroid Build Coastguard Worker 248*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_PRODUCT_PROPERTIES` 249*9e94795aSAndroid Build Coastguard Worker 250*9e94795aSAndroid Build Coastguard Worker### Duplication is not allowed within a partition 251*9e94795aSAndroid Build Coastguard Worker 252*9e94795aSAndroid Build Coastguard WorkerFor each partition, having multiple sysprop assignments for the same name is 253*9e94795aSAndroid Build Coastguard Workerprohibited. For example, the following will now trigger an error: 254*9e94795aSAndroid Build Coastguard Worker 255*9e94795aSAndroid Build Coastguard Worker`PRODUCT_VENDOR_PROPERTIES += foo=true foo=false` 256*9e94795aSAndroid Build Coastguard Worker 257*9e94795aSAndroid Build Coastguard WorkerHaving duplication across partitions are still allowed. So, the following is 258*9e94795aSAndroid Build Coastguard Workernot an error: 259*9e94795aSAndroid Build Coastguard Worker 260*9e94795aSAndroid Build Coastguard Worker`PRODUCT_VENDOR_PROPERTIES += foo=true` 261*9e94795aSAndroid Build Coastguard Worker`PRODUCT_SYSTEM_PROPERTIES += foo=false` 262*9e94795aSAndroid Build Coastguard Worker 263*9e94795aSAndroid Build Coastguard WorkerIn that case, the final value is determined at runtime. The precedence is 264*9e94795aSAndroid Build Coastguard Worker 265*9e94795aSAndroid Build Coastguard Worker* product 266*9e94795aSAndroid Build Coastguard Worker* odm 267*9e94795aSAndroid Build Coastguard Worker* vendor 268*9e94795aSAndroid Build Coastguard Worker* system_ext 269*9e94795aSAndroid Build Coastguard Worker* system 270*9e94795aSAndroid Build Coastguard Worker 271*9e94795aSAndroid Build Coastguard WorkerSo, `foo` becomes `true` because vendor has higher priority than system. 272*9e94795aSAndroid Build Coastguard Worker 273*9e94795aSAndroid Build Coastguard WorkerTo temporarily turn the build-time restriction off, use 274*9e94795aSAndroid Build Coastguard Worker 275*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_DUP_SYSPROP := true` 276*9e94795aSAndroid Build Coastguard Worker 277*9e94795aSAndroid Build Coastguard Worker### Optional assignments 278*9e94795aSAndroid Build Coastguard Worker 279*9e94795aSAndroid Build Coastguard WorkerSystem properties can now be set as optional using the new syntax: 280*9e94795aSAndroid Build Coastguard Worker 281*9e94795aSAndroid Build Coastguard Worker`name ?= value` 282*9e94795aSAndroid Build Coastguard Worker 283*9e94795aSAndroid Build Coastguard WorkerThen the system property named `name` gets the value `value` only when there 284*9e94795aSAndroid Build Coastguard Workeris no other non-optional assignments having the same name. For example, the 285*9e94795aSAndroid Build Coastguard Workerfollowing is allowed and `foo` gets `true` 286*9e94795aSAndroid Build Coastguard Worker 287*9e94795aSAndroid Build Coastguard Worker`PRODUCT_VENDOR_PROPERTIES += foo=true foo?=false` 288*9e94795aSAndroid Build Coastguard Worker 289*9e94795aSAndroid Build Coastguard WorkerNote that the order between the optional and the non-optional assignments 290*9e94795aSAndroid Build Coastguard Workerdoesn't matter. The following gives the same result as above. 291*9e94795aSAndroid Build Coastguard Worker 292*9e94795aSAndroid Build Coastguard Worker`PRODUCT_VENDOR_PROPERTIES += foo?=false foo=true` 293*9e94795aSAndroid Build Coastguard Worker 294*9e94795aSAndroid Build Coastguard WorkerOptional assignments can be duplicated and in that case their order matters. 295*9e94795aSAndroid Build Coastguard WorkerSpecifically, the last one eclipses others. 296*9e94795aSAndroid Build Coastguard Worker 297*9e94795aSAndroid Build Coastguard Worker`PRODUCT_VENDOR_PROPERTIES += foo?=apple foo?=banana foo?=mango` 298*9e94795aSAndroid Build Coastguard Worker 299*9e94795aSAndroid Build Coastguard WorkerWith above, `foo` becomes `mango` since its the last one. 300*9e94795aSAndroid Build Coastguard Worker 301*9e94795aSAndroid Build Coastguard WorkerNote that this behavior is different from the previous behavior of preferring 302*9e94795aSAndroid Build Coastguard Workerthe first one. To go back to the original behavior for compatability reason, 303*9e94795aSAndroid Build Coastguard Workeruse: 304*9e94795aSAndroid Build Coastguard Worker 305*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_DUP_SYSPROP := true` 306*9e94795aSAndroid Build Coastguard Worker 307*9e94795aSAndroid Build Coastguard Worker## ELF prebuilts in `PRODUCT_COPY_FILES` {#BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES} 308*9e94795aSAndroid Build Coastguard Worker 309*9e94795aSAndroid Build Coastguard WorkerELF prebuilts in `PRODUCT_COPY_FILES` that are installed into these paths are an 310*9e94795aSAndroid Build Coastguard Workererror: 311*9e94795aSAndroid Build Coastguard Worker 312*9e94795aSAndroid Build Coastguard Worker* `<partition>/bin/*` 313*9e94795aSAndroid Build Coastguard Worker* `<partition>/lib/*` 314*9e94795aSAndroid Build Coastguard Worker* `<partition>/lib64/*` 315*9e94795aSAndroid Build Coastguard Worker 316*9e94795aSAndroid Build Coastguard WorkerDefine prebuilt modules and add them to `PRODUCT_PACKAGES` instead. 317*9e94795aSAndroid Build Coastguard WorkerTo temporarily relax this check and restore the behavior prior to this change, 318*9e94795aSAndroid Build Coastguard Workerset `BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES := true` in `BoardConfig.mk`. 319*9e94795aSAndroid Build Coastguard Worker 320*9e94795aSAndroid Build Coastguard Worker## COPY_HEADERS usage now produces warnings {#copy_headers} 321*9e94795aSAndroid Build Coastguard Worker 322*9e94795aSAndroid Build Coastguard WorkerWe've considered `BUILD_COPY_HEADERS`/`LOCAL_COPY_HEADERS` to be deprecated for 323*9e94795aSAndroid Build Coastguard Workera long time, and the places where it's been able to be used have shrinked over 324*9e94795aSAndroid Build Coastguard Workerthe last several releases. Equivalent functionality is not available in Soong. 325*9e94795aSAndroid Build Coastguard Worker 326*9e94795aSAndroid Build Coastguard WorkerSee the [build/soong/docs/best_practices.md#headers] for more information about 327*9e94795aSAndroid Build Coastguard Workerhow best to handle headers in Android. 328*9e94795aSAndroid Build Coastguard Worker 329*9e94795aSAndroid Build Coastguard Worker## `m4` is not available on `$PATH` 330*9e94795aSAndroid Build Coastguard Worker 331*9e94795aSAndroid Build Coastguard WorkerThere is a prebuilt of it available in prebuilts/build-tools, and a make 332*9e94795aSAndroid Build Coastguard Workervariable `M4` that contains the path. 333*9e94795aSAndroid Build Coastguard Worker 334*9e94795aSAndroid Build Coastguard WorkerBeyond the direct usage, whenever you use bison or flex directly, they call m4 335*9e94795aSAndroid Build Coastguard Workerbehind the scene, so you must set the M4 environment variable (and depend upon 336*9e94795aSAndroid Build Coastguard Workerit for incremental build correctness): 337*9e94795aSAndroid Build Coastguard Worker 338*9e94795aSAndroid Build Coastguard Worker``` 339*9e94795aSAndroid Build Coastguard Worker$(intermediates)/foo.c: .KATI_IMPLICIT_OUTPUTS := $(intermediates)/foo.h 340*9e94795aSAndroid Build Coastguard Worker$(intermediates)/foo.c: $(LOCAL_PATH)/foo.y $(M4) $(BISON) $(BISON_DATA) 341*9e94795aSAndroid Build Coastguard Worker M4=$(M4) $(BISON) ... 342*9e94795aSAndroid Build Coastguard Worker``` 343*9e94795aSAndroid Build Coastguard Worker 344*9e94795aSAndroid Build Coastguard Worker## Rules executed within limited environment 345*9e94795aSAndroid Build Coastguard Worker 346*9e94795aSAndroid Build Coastguard WorkerWith `ALLOW_NINJA_ENV=false` (soon to be the default), ninja, and all the 347*9e94795aSAndroid Build Coastguard Workerrules/actions executed within it will only have access to a limited number of 348*9e94795aSAndroid Build Coastguard Workerenvironment variables. Ninja does not track when environment variables change 349*9e94795aSAndroid Build Coastguard Workerin order to trigger rebuilds, so changing behavior based on arbitrary variables 350*9e94795aSAndroid Build Coastguard Workeris not safe with incremental builds. 351*9e94795aSAndroid Build Coastguard Worker 352*9e94795aSAndroid Build Coastguard WorkerKati and Soong can safely use environment variables, so the expectation is that 353*9e94795aSAndroid Build Coastguard Workeryou'd embed any environment variables that you need to use within the command 354*9e94795aSAndroid Build Coastguard Workerline generated by those tools. See the [export section](#export_keyword) below 355*9e94795aSAndroid Build Coastguard Workerfor examples. 356*9e94795aSAndroid Build Coastguard Worker 357*9e94795aSAndroid Build Coastguard WorkerFor a temporary workaround, you can set `ALLOW_NINJA_ENV=true` in your 358*9e94795aSAndroid Build Coastguard Workerenvironment to restore the previous behavior, or set 359*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_NINJA_USES_ENV_VAR := <var> <var2> ...` in your `BoardConfig.mk` 360*9e94795aSAndroid Build Coastguard Workerto allow specific variables to be passed through until you've fixed the rules. 361*9e94795aSAndroid Build Coastguard Worker 362*9e94795aSAndroid Build Coastguard Worker## LOCAL_C_INCLUDES outside the source/output trees are an error {#BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS} 363*9e94795aSAndroid Build Coastguard Worker 364*9e94795aSAndroid Build Coastguard WorkerInclude directories are expected to be within the source tree (or in the output 365*9e94795aSAndroid Build Coastguard Workerdirectory, generated during the build). This has been checked in some form 366*9e94795aSAndroid Build Coastguard Workersince Oreo, but now has better checks. 367*9e94795aSAndroid Build Coastguard Worker 368*9e94795aSAndroid Build Coastguard WorkerThere's now a `BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS` variable, that when set, will 369*9e94795aSAndroid Build Coastguard Workerturn these errors into warnings temporarily. I don't expect this to last more 370*9e94795aSAndroid Build Coastguard Workerthan a release, since they're fairly easy to clean up. 371*9e94795aSAndroid Build Coastguard Worker 372*9e94795aSAndroid Build Coastguard WorkerNeither of these cases are supported by Soong, and will produce errors when 373*9e94795aSAndroid Build Coastguard Workerconverting your module. 374*9e94795aSAndroid Build Coastguard Worker 375*9e94795aSAndroid Build Coastguard Worker### Absolute paths 376*9e94795aSAndroid Build Coastguard Worker 377*9e94795aSAndroid Build Coastguard WorkerThis has been checked since Oreo. The common reason to hit this is because a 378*9e94795aSAndroid Build Coastguard Workermakefile is calculating a path, and ran abspath/realpath/etc. This is a problem 379*9e94795aSAndroid Build Coastguard Workerbecause it makes your build non-reproducible. It's very unlikely that your 380*9e94795aSAndroid Build Coastguard Workersource path is the same on every machine. 381*9e94795aSAndroid Build Coastguard Worker 382*9e94795aSAndroid Build Coastguard Worker### Using `../` to leave the source/output directories 383*9e94795aSAndroid Build Coastguard Worker 384*9e94795aSAndroid Build Coastguard WorkerThis is the new check that has been added. In every case I've found, this has 385*9e94795aSAndroid Build Coastguard Workerbeen a mistake in the Android.mk -- assuming that `LOCAL_C_INCLUDES` (which is 386*9e94795aSAndroid Build Coastguard Workerrelative to the top of the source tree) acts like `LOCAL_SRC_FILES` (which is 387*9e94795aSAndroid Build Coastguard Workerrelative to `LOCAL_PATH`). 388*9e94795aSAndroid Build Coastguard Worker 389*9e94795aSAndroid Build Coastguard WorkerSince this usually isn't a valid path, you can almost always just remove the 390*9e94795aSAndroid Build Coastguard Workeroffending line. 391*9e94795aSAndroid Build Coastguard Worker 392*9e94795aSAndroid Build Coastguard Worker 393*9e94795aSAndroid Build Coastguard Worker## `BOARD_HAL_STATIC_LIBRARIES` and `LOCAL_HAL_STATIC_LIBRARIES` are obsolete {#BOARD_HAL_STATIC_LIBRARIES} 394*9e94795aSAndroid Build Coastguard Worker 395*9e94795aSAndroid Build Coastguard WorkerDefine proper HIDL / Stable AIDL HAL instead. 396*9e94795aSAndroid Build Coastguard Worker 397*9e94795aSAndroid Build Coastguard Worker* For libhealthd, use health HAL. See instructions for implementing 398*9e94795aSAndroid Build Coastguard Worker health HAL: 399*9e94795aSAndroid Build Coastguard Worker 400*9e94795aSAndroid Build Coastguard Worker * [hardware/interfaces/health/2.1/README.md] for health 2.1 HAL (recommended) 401*9e94795aSAndroid Build Coastguard Worker * [hardware/interfaces/health/1.0/README.md] for health 1.0 HAL 402*9e94795aSAndroid Build Coastguard Worker 403*9e94795aSAndroid Build Coastguard Worker* For libdumpstate, use at least Dumpstate HAL 1.0. 404*9e94795aSAndroid Build Coastguard Worker 405*9e94795aSAndroid Build Coastguard Worker## PRODUCT_STATIC_BOOT_CONTROL_HAL is obsolete {#PRODUCT_STATIC_BOOT_CONTROL_HAL} 406*9e94795aSAndroid Build Coastguard Worker 407*9e94795aSAndroid Build Coastguard Worker`PRODUCT_STATIC_BOOT_CONTROL_HAL` was the workaround to allow sideloading with 408*9e94795aSAndroid Build Coastguard Workerstatically linked boot control HAL, before shared library HALs were supported 409*9e94795aSAndroid Build Coastguard Workerunder recovery. Android Q has added such support (HALs will be loaded in 410*9e94795aSAndroid Build Coastguard Workerpassthrough mode), and the workarounds are being removed. Targets should build 411*9e94795aSAndroid Build Coastguard Workerand install the recovery variant of boot control HAL modules into recovery 412*9e94795aSAndroid Build Coastguard Workerimage, similar to the ones installed for normal boot. See the change to 413*9e94795aSAndroid Build Coastguard Workercrosshatch for example of this: 414*9e94795aSAndroid Build Coastguard Worker 415*9e94795aSAndroid Build Coastguard Worker* [device/google/crosshatch/bootctrl/Android.bp] for `bootctrl.sdm845` building 416*9e94795aSAndroid Build Coastguard Worker rules 417*9e94795aSAndroid Build Coastguard Worker* [device/google/crosshatch/device.mk] for installing `bootctrl.sdm845.recovery` 418*9e94795aSAndroid Build Coastguard Worker and `[email protected]` into recovery image 419*9e94795aSAndroid Build Coastguard Worker 420*9e94795aSAndroid Build Coastguard Worker[device/google/crosshatch/bootctrl/Android.bp]: https://android.googlesource.com/device/google/crosshatch/+/master/bootctrl/Android.bp 421*9e94795aSAndroid Build Coastguard Worker[device/google/crosshatch/device.mk]: https://android.googlesource.com/device/google/crosshatch/+/master/device.mk 422*9e94795aSAndroid Build Coastguard Worker 423*9e94795aSAndroid Build Coastguard Worker## Deprecation of `BUILD_*` module types 424*9e94795aSAndroid Build Coastguard Worker 425*9e94795aSAndroid Build Coastguard WorkerSee [build/make/Deprecation.md](Deprecation.md) for the current status. 426*9e94795aSAndroid Build Coastguard Worker 427*9e94795aSAndroid Build Coastguard Worker## `PRODUCT_HOST_PACKAGES` split from `PRODUCT_PACKAGES` {#PRODUCT_HOST_PACKAGES} 428*9e94795aSAndroid Build Coastguard Worker 429*9e94795aSAndroid Build Coastguard WorkerPreviously, adding a module to `PRODUCT_PACKAGES` that supported both the host 430*9e94795aSAndroid Build Coastguard Workerand the target (`host_supported` in Android.bp; two modules with the same name 431*9e94795aSAndroid Build Coastguard Workerin Android.mk) would cause both to be built and installed. In many cases you 432*9e94795aSAndroid Build Coastguard Workeronly want either the host or target versions to be built/installed by default, 433*9e94795aSAndroid Build Coastguard Workerand would be over-building with both. So `PRODUCT_PACKAGES` will be changing to 434*9e94795aSAndroid Build Coastguard Workerjust affect target modules, while `PRODUCT_HOST_PACKAGES` is being added for 435*9e94795aSAndroid Build Coastguard Workerhost modules. 436*9e94795aSAndroid Build Coastguard Worker 437*9e94795aSAndroid Build Coastguard WorkerFunctional differences between `PRODUCT_PACKAGES` and `PRODUCT_HOST_PACKAGES`: 438*9e94795aSAndroid Build Coastguard Worker 439*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_HOST_PACKAGES` does not have `_ENG`/`_DEBUG` variants, as that's a 440*9e94795aSAndroid Build Coastguard Worker property of the target, not the host. 441*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_HOST_PACKAGES` does not support `LOCAL_MODULE_OVERRIDES`. 442*9e94795aSAndroid Build Coastguard Worker* `PRODUCT_HOST_PACKAGES` requires listed modules to exist, and be host 443*9e94795aSAndroid Build Coastguard Worker modules. (Unless `ALLOW_MISSING_DEPENDENCIES` is set) 444*9e94795aSAndroid Build Coastguard Worker 445*9e94795aSAndroid Build Coastguard WorkerThis is still an active migration, so currently it still uses 446*9e94795aSAndroid Build Coastguard Worker`PRODUCT_PACKAGES` to make installation decisions, but verifies that if we used 447*9e94795aSAndroid Build Coastguard Worker`PRODUCT_HOST_PACKAGES`, it would trigger installation for all of the same host 448*9e94795aSAndroid Build Coastguard Workerpackages. This check ignores shared libraries, as those are not normally 449*9e94795aSAndroid Build Coastguard Workernecessary in `PRODUCT_*PACKAGES`, and tended to be over-built (especially the 450*9e94795aSAndroid Build Coastguard Worker32-bit variants). 451*9e94795aSAndroid Build Coastguard Worker 452*9e94795aSAndroid Build Coastguard WorkerFuture changes will switch installation decisions to `PRODUCT_HOST_PACKAGES` 453*9e94795aSAndroid Build Coastguard Workerfor host modules, error when there's a host-only module in `PRODUCT_PACKAGES`, 454*9e94795aSAndroid Build Coastguard Workerand do some further cleanup where `LOCAL_REQUIRED_MODULES` are still merged 455*9e94795aSAndroid Build Coastguard Workerbetween host and target modules with the same name. 456*9e94795aSAndroid Build Coastguard Worker 457*9e94795aSAndroid Build Coastguard Worker## `*.c.arm` / `*.cpp.arm` deprecation {#file_arm} 458*9e94795aSAndroid Build Coastguard Worker 459*9e94795aSAndroid Build Coastguard WorkerIn Android.mk files, you used to be able to change LOCAL_ARM_MODE for each 460*9e94795aSAndroid Build Coastguard Workersource file by appending `.arm` to the end of the filename in 461*9e94795aSAndroid Build Coastguard Worker`LOCAL_SRC_FILES`. 462*9e94795aSAndroid Build Coastguard Worker 463*9e94795aSAndroid Build Coastguard WorkerSoong does not support this uncommonly used behavior, instead expecting those 464*9e94795aSAndroid Build Coastguard Workerfiles to be split out into a separate static library that chooses `arm` over 465*9e94795aSAndroid Build Coastguard Worker`thumb` for the entire library. This must now also be done in Android.mk files. 466*9e94795aSAndroid Build Coastguard Worker 467*9e94795aSAndroid Build Coastguard Worker## Windows cross-compiles no longer supported in Android.mk 468*9e94795aSAndroid Build Coastguard Worker 469*9e94795aSAndroid Build Coastguard WorkerModules that build for Windows (our only `HOST_CROSS` OS currently) must now be 470*9e94795aSAndroid Build Coastguard Workerdefined in `Android.bp` files. 471*9e94795aSAndroid Build Coastguard Worker 472*9e94795aSAndroid Build Coastguard Worker## `LOCAL_MODULE_TAGS := eng debug` are obsolete {#LOCAL_MODULE_TAGS} 473*9e94795aSAndroid Build Coastguard Worker 474*9e94795aSAndroid Build Coastguard Worker`LOCAL_MODULE_TAGS` value `eng` and `debug` are now obsolete. They allowed 475*9e94795aSAndroid Build Coastguard Workermodules to specify that they should always be installed on `-eng`, or `-eng` 476*9e94795aSAndroid Build Coastguard Workerand `-userdebug` builds. This conflicted with the ability for products to 477*9e94795aSAndroid Build Coastguard Workerspecify which modules should be installed, effectively making it impossible to 478*9e94795aSAndroid Build Coastguard Workerbuild a stripped down product configuration that did not include those modules. 479*9e94795aSAndroid Build Coastguard Worker 480*9e94795aSAndroid Build Coastguard WorkerFor the equivalent functionality, specify the modules in `PRODUCT_PACKAGES_ENG` 481*9e94795aSAndroid Build Coastguard Workeror `PRODUCT_PACKAGES_DEBUG` in the appropriate product makefiles. 482*9e94795aSAndroid Build Coastguard Worker 483*9e94795aSAndroid Build Coastguard WorkerCore android packages like `su` got added to the list in 484*9e94795aSAndroid Build Coastguard Worker`build/make/target/product/base_system.mk`, but for device-specific modules 485*9e94795aSAndroid Build Coastguard Workerthere are often better base product makefiles to use instead. 486*9e94795aSAndroid Build Coastguard Worker 487*9e94795aSAndroid Build Coastguard Worker## `USER` deprecation {#USER} 488*9e94795aSAndroid Build Coastguard Worker 489*9e94795aSAndroid Build Coastguard Worker`USER` will soon be `nobody` in many cases due to the addition of a sandbox 490*9e94795aSAndroid Build Coastguard Workeraround the Android build. Most of the time you shouldn't need to know the 491*9e94795aSAndroid Build Coastguard Workeridentity of the user running the build, but if you do, it's available in the 492*9e94795aSAndroid Build Coastguard Workermake variable `BUILD_USERNAME` for now. 493*9e94795aSAndroid Build Coastguard Worker 494*9e94795aSAndroid Build Coastguard WorkerSimilarly, the `hostname` tool will also be returning a more consistent value 495*9e94795aSAndroid Build Coastguard Workerof `android-build`. The real value is available as `BUILD_HOSTNAME`. 496*9e94795aSAndroid Build Coastguard Worker 497*9e94795aSAndroid Build Coastguard Worker## `BUILD_NUMBER` removal from Android.mk {#BUILD_NUMBER} 498*9e94795aSAndroid Build Coastguard Worker 499*9e94795aSAndroid Build Coastguard Worker`BUILD_NUMBER` should not be used directly in Android.mk files, as it would 500*9e94795aSAndroid Build Coastguard Workertrigger them to be re-read every time the `BUILD_NUMBER` changes (which it does 501*9e94795aSAndroid Build Coastguard Workeron every build server build). If possible, just remove the use so that your 502*9e94795aSAndroid Build Coastguard Workerbuilds are more reproducible. If you do need it, use `BUILD_NUMBER_FROM_FILE`: 503*9e94795aSAndroid Build Coastguard Worker 504*9e94795aSAndroid Build Coastguard Worker``` make 505*9e94795aSAndroid Build Coastguard Worker$(LOCAL_BUILT_MODULE): 506*9e94795aSAndroid Build Coastguard Worker mytool --build_number $(BUILD_NUMBER_FROM_FILE) -o $@ 507*9e94795aSAndroid Build Coastguard Worker``` 508*9e94795aSAndroid Build Coastguard Worker 509*9e94795aSAndroid Build Coastguard WorkerThat will expand out to a subshell that will read the current `BUILD_NUMBER` 510*9e94795aSAndroid Build Coastguard Workerwhenever it's run. It will not re-run your command if the build number has 511*9e94795aSAndroid Build Coastguard Workerchanged, so incremental builds will have the build number from the last time 512*9e94795aSAndroid Build Coastguard Workerthe particular output was rebuilt. 513*9e94795aSAndroid Build Coastguard Worker 514*9e94795aSAndroid Build Coastguard Worker## `DIST_DIR`, `dist_goal`, and `dist-for-goals` {#dist} 515*9e94795aSAndroid Build Coastguard Worker 516*9e94795aSAndroid Build Coastguard Worker`DIST_DIR` and `dist_goal` are no longer available when reading Android.mk 517*9e94795aSAndroid Build Coastguard Workerfiles (or other build tasks). Always use `dist-for-goals` instead, which takes 518*9e94795aSAndroid Build Coastguard Workera PHONY goal, and a list of files to copy to `$DIST_DIR`. Whenever `dist` is 519*9e94795aSAndroid Build Coastguard Workerspecified, and the goal would be built (either explicitly on the command line, 520*9e94795aSAndroid Build Coastguard Workeror as a dependency of something on the command line), that file will be copied 521*9e94795aSAndroid Build Coastguard Workerinto `$DIST_DIR`. For example, 522*9e94795aSAndroid Build Coastguard Worker 523*9e94795aSAndroid Build Coastguard Worker``` make 524*9e94795aSAndroid Build Coastguard Worker$(call dist-for-goals,foo,bar/baz) 525*9e94795aSAndroid Build Coastguard Worker``` 526*9e94795aSAndroid Build Coastguard Worker 527*9e94795aSAndroid Build Coastguard Workerwill copy `bar/baz` into `$DIST_DIR/baz` when `m foo dist` is run. 528*9e94795aSAndroid Build Coastguard Worker 529*9e94795aSAndroid Build Coastguard Worker#### FILE_NAME_TAG {#FILE_NAME_TAG} 530*9e94795aSAndroid Build Coastguard Worker 531*9e94795aSAndroid Build Coastguard WorkerTo embed the `BUILD_NUMBER` (or for local builds, `eng.${USER}`), include 532*9e94795aSAndroid Build Coastguard Worker`FILE_NAME_TAG_PLACEHOLDER` in the destination: 533*9e94795aSAndroid Build Coastguard Worker 534*9e94795aSAndroid Build Coastguard Worker``` make 535*9e94795aSAndroid Build Coastguard Worker# you can use dist-for-goals-with-filenametag function 536*9e94795aSAndroid Build Coastguard Worker$(call dist-for-goals-with-filenametag,foo,bar.zip) 537*9e94795aSAndroid Build Coastguard Worker# or use FILE_NAME_TAG_PLACEHOLDER manually 538*9e94795aSAndroid Build Coastguard Worker$(call dist-for-goals,foo,bar.zip:baz-FILE_NAME_TAG_PLACEHOLDER.zip) 539*9e94795aSAndroid Build Coastguard Worker``` 540*9e94795aSAndroid Build Coastguard Worker 541*9e94795aSAndroid Build Coastguard WorkerWhich will produce `$DIST_DIR/baz-1234567.zip` on build servers which set 542*9e94795aSAndroid Build Coastguard Worker`BUILD_NUMBER=1234567`, or `$DIST_DIR/baz-eng.builder.zip` for local builds. 543*9e94795aSAndroid Build Coastguard Worker 544*9e94795aSAndroid Build Coastguard WorkerIf you just want to append `BUILD_NUMBER` at the end of basename, use 545*9e94795aSAndroid Build Coastguard Worker`dist-for-goals-with-filenametag` instead of `dist-for-goals`. 546*9e94795aSAndroid Build Coastguard Worker 547*9e94795aSAndroid Build Coastguard Worker#### Renames during copy 548*9e94795aSAndroid Build Coastguard Worker 549*9e94795aSAndroid Build Coastguard WorkerInstead of specifying just a file, a destination name can be specified, 550*9e94795aSAndroid Build Coastguard Workerincluding subdirectories: 551*9e94795aSAndroid Build Coastguard Worker 552*9e94795aSAndroid Build Coastguard Worker``` make 553*9e94795aSAndroid Build Coastguard Worker$(call dist-for-goals,foo,bar/baz:logs/foo.log) 554*9e94795aSAndroid Build Coastguard Worker``` 555*9e94795aSAndroid Build Coastguard Worker 556*9e94795aSAndroid Build Coastguard Workerwill copy `bar/baz` into `$DIST_DIR/logs/foo.log` when `m foo dist` is run. 557*9e94795aSAndroid Build Coastguard Worker 558*9e94795aSAndroid Build Coastguard Worker## `.PHONY` rule enforcement {#phony_targets} 559*9e94795aSAndroid Build Coastguard Worker 560*9e94795aSAndroid Build Coastguard WorkerThere are several new warnings/errors meant to ensure the proper use of 561*9e94795aSAndroid Build Coastguard Worker`.PHONY` targets in order to improve the speed and reliability of incremental 562*9e94795aSAndroid Build Coastguard Workerbuilds. 563*9e94795aSAndroid Build Coastguard Worker 564*9e94795aSAndroid Build Coastguard Worker`.PHONY`-marked targets are often used as shortcuts to provide "friendly" names 565*9e94795aSAndroid Build Coastguard Workerfor real files to be built, but any target marked with `.PHONY` is also always 566*9e94795aSAndroid Build Coastguard Workerconsidered dirty, needing to be rebuilt every build. This isn't a problem for 567*9e94795aSAndroid Build Coastguard Workeraliases or one-off user-requested operations, but if real builds steps depend 568*9e94795aSAndroid Build Coastguard Workeron a `.PHONY` target, it can get quite expensive for what should be a tiny 569*9e94795aSAndroid Build Coastguard Workerbuild. 570*9e94795aSAndroid Build Coastguard Worker 571*9e94795aSAndroid Build Coastguard Worker``` make 572*9e94795aSAndroid Build Coastguard Worker...mk:42: warning: PHONY target "out/.../foo" looks like a real file (contains a "/") 573*9e94795aSAndroid Build Coastguard Worker``` 574*9e94795aSAndroid Build Coastguard Worker 575*9e94795aSAndroid Build Coastguard WorkerBetween this warning and the next, we're requiring that `.PHONY` targets do not 576*9e94795aSAndroid Build Coastguard Workerhave "/" in them, and real file targets do have a "/". This makes it more 577*9e94795aSAndroid Build Coastguard Workerobvious when reading makefiles what is happening, and will help the build 578*9e94795aSAndroid Build Coastguard Workersystem differentiate these in the future too. 579*9e94795aSAndroid Build Coastguard Worker 580*9e94795aSAndroid Build Coastguard Worker``` make 581*9e94795aSAndroid Build Coastguard Worker...mk:42: warning: writing to readonly directory: "kernel-modules" 582*9e94795aSAndroid Build Coastguard Worker``` 583*9e94795aSAndroid Build Coastguard Worker 584*9e94795aSAndroid Build Coastguard WorkerThis warning will show up for one of two reasons: 585*9e94795aSAndroid Build Coastguard Worker 586*9e94795aSAndroid Build Coastguard Worker1. The target isn't intended to be a real file, and should be marked with 587*9e94795aSAndroid Build Coastguard Worker `.PHONY`. This would be the case for this example. 588*9e94795aSAndroid Build Coastguard Worker2. The target is a real file, but it's outside the output directories. All 589*9e94795aSAndroid Build Coastguard Worker outputs from the build system should be within the output directory, 590*9e94795aSAndroid Build Coastguard Worker otherwise `m clean` is unable to clean the build, and future builds may not 591*9e94795aSAndroid Build Coastguard Worker work properly. 592*9e94795aSAndroid Build Coastguard Worker 593*9e94795aSAndroid Build Coastguard Worker``` make 594*9e94795aSAndroid Build Coastguard Worker...mk:42: warning: real file "out/.../foo" depends on PHONY target "buildbins" 595*9e94795aSAndroid Build Coastguard Worker``` 596*9e94795aSAndroid Build Coastguard Worker 597*9e94795aSAndroid Build Coastguard WorkerIf the first target isn't intended to be a real file, then it should be marked 598*9e94795aSAndroid Build Coastguard Workerwith `.PHONY`, which will satisfy this warning. This isn't the case for this 599*9e94795aSAndroid Build Coastguard Workerexample, as we require `.PHONY` targets not to have '/' in them. 600*9e94795aSAndroid Build Coastguard Worker 601*9e94795aSAndroid Build Coastguard WorkerIf the second (PHONY) target is a real file, it may unnecessarily be marked 602*9e94795aSAndroid Build Coastguard Workerwith `.PHONY`. 603*9e94795aSAndroid Build Coastguard Worker 604*9e94795aSAndroid Build Coastguard Worker### `.PHONY` and calling other build systems 605*9e94795aSAndroid Build Coastguard Worker 606*9e94795aSAndroid Build Coastguard WorkerOne common pattern (mostly outside AOSP) that we've seen hit these warning is 607*9e94795aSAndroid Build Coastguard Workerwhen building with external build systems (firmware, bootloader, kernel, etc). 608*9e94795aSAndroid Build Coastguard WorkerThose are often marked as `.PHONY` because the Android build system doesn't 609*9e94795aSAndroid Build Coastguard Workerhave enough dependencies to know when to run the other build system again 610*9e94795aSAndroid Build Coastguard Workerduring an incremental build. 611*9e94795aSAndroid Build Coastguard Worker 612*9e94795aSAndroid Build Coastguard WorkerWe recommend to build these outside of Android, and deliver prebuilts into the 613*9e94795aSAndroid Build Coastguard WorkerAndroid tree instead of decreasing the speed and reliability of the incremental 614*9e94795aSAndroid Build Coastguard WorkerAndroid build. 615*9e94795aSAndroid Build Coastguard Worker 616*9e94795aSAndroid Build Coastguard WorkerIn cases where that's not desired, to preserve the speed of Android 617*9e94795aSAndroid Build Coastguard Workerincrementals, over-specifying dependencies is likely a better option than 618*9e94795aSAndroid Build Coastguard Workermarking it with `.PHONY`: 619*9e94795aSAndroid Build Coastguard Worker 620*9e94795aSAndroid Build Coastguard Worker``` make 621*9e94795aSAndroid Build Coastguard Workerout/target/.../zImage: $(sort $(shell find -L $(KERNEL_SRCDIR))) 622*9e94795aSAndroid Build Coastguard Worker ... 623*9e94795aSAndroid Build Coastguard Worker``` 624*9e94795aSAndroid Build Coastguard Worker 625*9e94795aSAndroid Build Coastguard WorkerFor reliability, many of these other build systems do not guarantee the same 626*9e94795aSAndroid Build Coastguard Workerlevel of incremental build assurances as the Android Build is attempting to do 627*9e94795aSAndroid Build Coastguard Worker-- without custom checks, Make doesn't rebuild objects when CFLAGS change, etc. 628*9e94795aSAndroid Build Coastguard WorkerIn order to fix this, our recommendation is to do clean builds for each of 629*9e94795aSAndroid Build Coastguard Workerthese external build systems every time anything they rely on changes. For 630*9e94795aSAndroid Build Coastguard Workerrelatively smaller builds (like the kernel), this may be reasonable as long as 631*9e94795aSAndroid Build Coastguard Workeryou're not trying to actively debug the kernel. 632*9e94795aSAndroid Build Coastguard Worker 633*9e94795aSAndroid Build Coastguard Worker## `export` and `unexport` deprecation {#export_keyword} 634*9e94795aSAndroid Build Coastguard Worker 635*9e94795aSAndroid Build Coastguard WorkerThe `export` and `unexport` keywords are obsolete, and will throw errors when 636*9e94795aSAndroid Build Coastguard Workerused. 637*9e94795aSAndroid Build Coastguard Worker 638*9e94795aSAndroid Build Coastguard WorkerDevice specific configuration should not be able to affect common core build 639*9e94795aSAndroid Build Coastguard Workersteps -- we're looking at triggering build steps to be invalidated if the set 640*9e94795aSAndroid Build Coastguard Workerof environment variables they can access changes. If device specific 641*9e94795aSAndroid Build Coastguard Workerconfiguration is allowed to change those, switching devices with the same 642*9e94795aSAndroid Build Coastguard Workeroutput directory could become significantly more expensive than it already can 643*9e94795aSAndroid Build Coastguard Workerbe. 644*9e94795aSAndroid Build Coastguard Worker 645*9e94795aSAndroid Build Coastguard WorkerIf used during Android.mk files, and later tasks, it is increasingly likely 646*9e94795aSAndroid Build Coastguard Workerthat they are being used incorrectly. Attempting to change the environment for 647*9e94795aSAndroid Build Coastguard Workera single build step, and instead setting it for hundreds of thousands. 648*9e94795aSAndroid Build Coastguard Worker 649*9e94795aSAndroid Build Coastguard WorkerIt is not recommended to just move the environment variable setting outside of 650*9e94795aSAndroid Build Coastguard Workerthe build (in vendorsetup.sh, or some other configuration script or wrapper). 651*9e94795aSAndroid Build Coastguard WorkerWe expect to limit the environment variables that the build respects in the 652*9e94795aSAndroid Build Coastguard Workerfuture, others will be cleared. (There will be methods to get custom variables 653*9e94795aSAndroid Build Coastguard Workerinto the build, just not to every build step) 654*9e94795aSAndroid Build Coastguard Worker 655*9e94795aSAndroid Build Coastguard WorkerInstead, write the export commands into the rule command lines themselves: 656*9e94795aSAndroid Build Coastguard Worker 657*9e94795aSAndroid Build Coastguard Worker``` make 658*9e94795aSAndroid Build Coastguard Worker$(intermediates)/generated_output.img: 659*9e94795aSAndroid Build Coastguard Worker rm -rf $@ 660*9e94795aSAndroid Build Coastguard Worker export MY_ENV_A="$(MY_A)"; make ... 661*9e94795aSAndroid Build Coastguard Worker``` 662*9e94795aSAndroid Build Coastguard Worker 663*9e94795aSAndroid Build Coastguard WorkerIf you want to set many environment variables, and/or use them many times, 664*9e94795aSAndroid Build Coastguard Workerwrite them out to a script and source the script: 665*9e94795aSAndroid Build Coastguard Worker 666*9e94795aSAndroid Build Coastguard Worker``` make 667*9e94795aSAndroid Build Coastguard Workerenvsh := $(intermediates)/env.sh 668*9e94795aSAndroid Build Coastguard Worker$(envsh): 669*9e94795aSAndroid Build Coastguard Worker rm -rf $@ 670*9e94795aSAndroid Build Coastguard Worker echo 'export MY_ENV_A="$(MY_A)"' >$@ 671*9e94795aSAndroid Build Coastguard Worker echo 'export MY_ENV_B="$(MY_B)"' >>$@ 672*9e94795aSAndroid Build Coastguard Worker 673*9e94795aSAndroid Build Coastguard Worker$(intermediates)/generated_output.img: PRIVATE_ENV := $(envsh) 674*9e94795aSAndroid Build Coastguard Worker$(intermediates)/generated_output.img: $(envsh) a/b/c/package.sh 675*9e94795aSAndroid Build Coastguard Worker rm -rf $@ 676*9e94795aSAndroid Build Coastguard Worker source $(PRIVATE_ENV); make ... 677*9e94795aSAndroid Build Coastguard Worker source $(PRIVATE_ENV); a/b/c/package.sh ... 678*9e94795aSAndroid Build Coastguard Worker``` 679*9e94795aSAndroid Build Coastguard Worker 680*9e94795aSAndroid Build Coastguard Worker## Implicit make rules are obsolete {#implicit_rules} 681*9e94795aSAndroid Build Coastguard Worker 682*9e94795aSAndroid Build Coastguard WorkerImplicit rules look something like the following: 683*9e94795aSAndroid Build Coastguard Worker 684*9e94795aSAndroid Build Coastguard Worker``` make 685*9e94795aSAndroid Build Coastguard Worker$(TARGET_OUT_SHARED_LIBRARIES)/%_vendor.so: $(TARGET_OUT_SHARED_LIBRARIES)/%.so 686*9e94795aSAndroid Build Coastguard Worker ... 687*9e94795aSAndroid Build Coastguard Worker 688*9e94795aSAndroid Build Coastguard Worker%.o : %.foo 689*9e94795aSAndroid Build Coastguard Worker ... 690*9e94795aSAndroid Build Coastguard Worker``` 691*9e94795aSAndroid Build Coastguard Worker 692*9e94795aSAndroid Build Coastguard WorkerThese can have wide ranging effects across unrelated modules, so they're now obsolete. Instead, use static pattern rules, which are similar, but explicitly match the specified outputs: 693*9e94795aSAndroid Build Coastguard Worker 694*9e94795aSAndroid Build Coastguard Worker``` make 695*9e94795aSAndroid Build Coastguard Workerlibs := $(foreach lib,libfoo libbar,$(TARGET_OUT_SHARED_LIBRARIES)/$(lib)_vendor.so) 696*9e94795aSAndroid Build Coastguard Worker$(libs): %_vendor.so: %.so 697*9e94795aSAndroid Build Coastguard Worker ... 698*9e94795aSAndroid Build Coastguard Worker 699*9e94795aSAndroid Build Coastguard Workerfiles := $(wildcard $(LOCAL_PATH)/*.foo) 700*9e94795aSAndroid Build Coastguard Workergen := $(patsubst $(LOCAL_PATH)/%.foo,$(intermediates)/%.o,$(files)) 701*9e94795aSAndroid Build Coastguard Worker$(gen): %.o : %.foo 702*9e94795aSAndroid Build Coastguard Worker ... 703*9e94795aSAndroid Build Coastguard Worker``` 704*9e94795aSAndroid Build Coastguard Worker 705*9e94795aSAndroid Build Coastguard Worker## Removing '/' from Valid Module Names {#name_slash} 706*9e94795aSAndroid Build Coastguard Worker 707*9e94795aSAndroid Build Coastguard WorkerThe build system uses module names in path names in many places. Having an 708*9e94795aSAndroid Build Coastguard Workerextra '/' or '../' being inserted can cause problems -- and not just build 709*9e94795aSAndroid Build Coastguard Workerbreaks, but stranger invalid behavior. 710*9e94795aSAndroid Build Coastguard Worker 711*9e94795aSAndroid Build Coastguard WorkerIn every case we've seen, the fix is relatively simple: move the directory into 712*9e94795aSAndroid Build Coastguard Worker`LOCAL_MODULE_RELATIVE_PATH` (or `LOCAL_MODULE_PATH` if you're still using it). 713*9e94795aSAndroid Build Coastguard WorkerIf this causes multiple modules to be named the same, use unique module names 714*9e94795aSAndroid Build Coastguard Workerand `LOCAL_MODULE_STEM` to change the installed file name: 715*9e94795aSAndroid Build Coastguard Worker 716*9e94795aSAndroid Build Coastguard Worker``` make 717*9e94795aSAndroid Build Coastguard Workerinclude $(CLEAR_VARS) 718*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE := ver1/code.bin 719*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/firmware 720*9e94795aSAndroid Build Coastguard Worker... 721*9e94795aSAndroid Build Coastguard Workerinclude $(BUILD_PREBUILT) 722*9e94795aSAndroid Build Coastguard Worker 723*9e94795aSAndroid Build Coastguard Workerinclude $(CLEAR_VARS) 724*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE := ver2/code.bin 725*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/firmware 726*9e94795aSAndroid Build Coastguard Worker... 727*9e94795aSAndroid Build Coastguard Workerinclude $(BUILD_PREBUILT) 728*9e94795aSAndroid Build Coastguard Worker``` 729*9e94795aSAndroid Build Coastguard Worker 730*9e94795aSAndroid Build Coastguard WorkerCan be rewritten as: 731*9e94795aSAndroid Build Coastguard Worker 732*9e94795aSAndroid Build Coastguard Worker``` 733*9e94795aSAndroid Build Coastguard Workerinclude $(CLEAR_VARS) 734*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE := ver1_code.bin 735*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_STEM := code.bin 736*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/firmware/ver1 737*9e94795aSAndroid Build Coastguard Worker... 738*9e94795aSAndroid Build Coastguard Workerinclude $(BUILD_PREBUILT) 739*9e94795aSAndroid Build Coastguard Worker 740*9e94795aSAndroid Build Coastguard Workerinclude $(CLEAR_VARS) 741*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE := ver2_code.bin 742*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_STEM := code.bin 743*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/firmware/ver2 744*9e94795aSAndroid Build Coastguard Worker... 745*9e94795aSAndroid Build Coastguard Workerinclude $(BUILD_PREBUILT) 746*9e94795aSAndroid Build Coastguard Worker``` 747*9e94795aSAndroid Build Coastguard Worker 748*9e94795aSAndroid Build Coastguard WorkerYou just need to make sure that any other references (`PRODUCT_PACKAGES`, 749*9e94795aSAndroid Build Coastguard Worker`LOCAL_REQUIRED_MODULES`, etc) are converted to the new names. 750*9e94795aSAndroid Build Coastguard Worker 751*9e94795aSAndroid Build Coastguard Worker## Valid Module Names {#name} 752*9e94795aSAndroid Build Coastguard Worker 753*9e94795aSAndroid Build Coastguard WorkerWe've adopted lexical requirements very similar to [Bazel's 754*9e94795aSAndroid Build Coastguard Workerrequirements](https://docs.bazel.build/versions/master/build-ref.html#name) for 755*9e94795aSAndroid Build Coastguard Workertarget names. Valid characters are `a-z`, `A-Z`, `0-9`, and the special 756*9e94795aSAndroid Build Coastguard Workercharacters `_.+-=,@~`. This currently applies to `LOCAL_PACKAGE_NAME`, 757*9e94795aSAndroid Build Coastguard Worker`LOCAL_MODULE`, and `LOCAL_MODULE_SUFFIX`, and `LOCAL_MODULE_STEM*`. 758*9e94795aSAndroid Build Coastguard Worker 759*9e94795aSAndroid Build Coastguard WorkerMany other characters already caused problems if you used them, so we don't 760*9e94795aSAndroid Build Coastguard Workerexpect this to have a large effect. 761*9e94795aSAndroid Build Coastguard Worker 762*9e94795aSAndroid Build Coastguard Worker## PATH Tools {#PATH_Tools} 763*9e94795aSAndroid Build Coastguard Worker 764*9e94795aSAndroid Build Coastguard WorkerThe build has started restricting the external host tools usable inside the 765*9e94795aSAndroid Build Coastguard Workerbuild. This will help ensure that build results are reproducible across 766*9e94795aSAndroid Build Coastguard Workerdifferent machines, and catch mistakes before they become larger issues. 767*9e94795aSAndroid Build Coastguard Worker 768*9e94795aSAndroid Build Coastguard WorkerTo start with, this includes replacing the $PATH with our own directory of 769*9e94795aSAndroid Build Coastguard Workertools, mirroring that of the host PATH. The only difference so far is the 770*9e94795aSAndroid Build Coastguard Workerremoval of the host GCC tools. Anything that is not explicitly in the 771*9e94795aSAndroid Build Coastguard Workerconfiguration as allowed will continue functioning, but will generate a log 772*9e94795aSAndroid Build Coastguard Workermessage. This is expected to become more restrictive over time. 773*9e94795aSAndroid Build Coastguard Worker 774*9e94795aSAndroid Build Coastguard WorkerThe configuration is located in build/soong/ui/build/paths/config.go, and 775*9e94795aSAndroid Build Coastguard Workercontains all the common tools in use in many builds. Anything not in that list 776*9e94795aSAndroid Build Coastguard Workerwill currently print a warning in the `$OUT_DIR/soong.log` file, including the 777*9e94795aSAndroid Build Coastguard Workercommand and arguments used, and the process tree in order to help locate the 778*9e94795aSAndroid Build Coastguard Workerusage. 779*9e94795aSAndroid Build Coastguard Worker 780*9e94795aSAndroid Build Coastguard WorkerIn order to fix any issues brought up by these checks, the best way to fix them 781*9e94795aSAndroid Build Coastguard Workeris to use tools checked into the tree -- either as prebuilts, or building them 782*9e94795aSAndroid Build Coastguard Workeras host tools during the build. 783*9e94795aSAndroid Build Coastguard Worker 784*9e94795aSAndroid Build Coastguard WorkerAs a temporary measure, you can set `TEMPORARY_DISABLE_PATH_RESTRICTIONS=true` 785*9e94795aSAndroid Build Coastguard Workerin your environment to temporarily turn off the error checks and allow any tool 786*9e94795aSAndroid Build Coastguard Workerto be used (with logging). Beware that GCC didn't work well with the interposer 787*9e94795aSAndroid Build Coastguard Workerused for logging, so this may not help in all cases. 788*9e94795aSAndroid Build Coastguard Worker 789*9e94795aSAndroid Build Coastguard Worker## Deprecating / obsoleting envsetup.sh variables in Makefiles 790*9e94795aSAndroid Build Coastguard Worker 791*9e94795aSAndroid Build Coastguard WorkerIt is not required to source envsetup.sh before running a build. Many scripts, 792*9e94795aSAndroid Build Coastguard Workerincluding a majority of our automated build systems, do not do so. Make will 793*9e94795aSAndroid Build Coastguard Workertransparently make every environment variable available as a make variable. 794*9e94795aSAndroid Build Coastguard WorkerThis means that relying on environment variables only set up in envsetup.sh will 795*9e94795aSAndroid Build Coastguard Workerproduce different output for local users and scripted users. 796*9e94795aSAndroid Build Coastguard Worker 797*9e94795aSAndroid Build Coastguard WorkerMany of these variables also include absolute path names, which we'd like to 798*9e94795aSAndroid Build Coastguard Workerkeep out of the generated files, so that you don't need to do a full rebuild if 799*9e94795aSAndroid Build Coastguard Workeryou move the source tree. 800*9e94795aSAndroid Build Coastguard Worker 801*9e94795aSAndroid Build Coastguard WorkerTo fix this, we're marking the variables that are set in envsetup.sh as 802*9e94795aSAndroid Build Coastguard Workerdeprecated in the makefiles. This will trigger a warning every time one is read 803*9e94795aSAndroid Build Coastguard Worker(or written) inside Kati. Once all the warnings have been removed for a 804*9e94795aSAndroid Build Coastguard Workerparticular variable, we'll switch it to obsolete, and any references will become 805*9e94795aSAndroid Build Coastguard Workererrors. 806*9e94795aSAndroid Build Coastguard Worker 807*9e94795aSAndroid Build Coastguard Worker### envsetup.sh variables with make equivalents 808*9e94795aSAndroid Build Coastguard Worker 809*9e94795aSAndroid Build Coastguard Worker| instead of | use | 810*9e94795aSAndroid Build Coastguard Worker|--------------------------------------------------------------|----------------------| 811*9e94795aSAndroid Build Coastguard Worker| OUT {#OUT} | PRODUCT_OUT | 812*9e94795aSAndroid Build Coastguard Worker| ANDROID_HOST_OUT {#ANDROID_HOST_OUT} | HOST_OUT | 813*9e94795aSAndroid Build Coastguard Worker| ANDROID_PRODUCT_OUT {#ANDROID_PRODUCT_OUT} | PRODUCT_OUT | 814*9e94795aSAndroid Build Coastguard Worker| ANDROID_HOST_OUT_TESTCASES {#ANDROID_HOST_OUT_TESTCASES} | HOST_OUT_TESTCASES | 815*9e94795aSAndroid Build Coastguard Worker| ANDROID_TARGET_OUT_TESTCASES {#ANDROID_TARGET_OUT_TESTCASES} | TARGET_OUT_TESTCASES | 816*9e94795aSAndroid Build Coastguard Worker 817*9e94795aSAndroid Build Coastguard WorkerAll of the make variables may be relative paths from the current directory, or 818*9e94795aSAndroid Build Coastguard Workerabsolute paths if the output directory was specified as an absolute path. If you 819*9e94795aSAndroid Build Coastguard Workerneed an absolute variable, convert it to absolute during a rule, so that it's 820*9e94795aSAndroid Build Coastguard Workernot expanded into the generated ninja file: 821*9e94795aSAndroid Build Coastguard Worker 822*9e94795aSAndroid Build Coastguard Worker``` make 823*9e94795aSAndroid Build Coastguard Worker$(PRODUCT_OUT)/gen.img: my/src/path/gen.sh 824*9e94795aSAndroid Build Coastguard Worker export PRODUCT_OUT=$$(cd $(PRODUCT_OUT); pwd); cd my/src/path; ./gen.sh -o $${PRODUCT_OUT}/gen.img 825*9e94795aSAndroid Build Coastguard Worker``` 826*9e94795aSAndroid Build Coastguard Worker 827*9e94795aSAndroid Build Coastguard Worker### ANDROID_BUILD_TOP {#ANDROID_BUILD_TOP} 828*9e94795aSAndroid Build Coastguard Worker 829*9e94795aSAndroid Build Coastguard WorkerIn Android.mk files, you can always assume that the current directory is the 830*9e94795aSAndroid Build Coastguard Workerroot of the source tree, so this can just be replaced with '.' (which is what 831*9e94795aSAndroid Build Coastguard Worker$TOP is hardcoded to), or removed entirely. If you need an absolute path, see 832*9e94795aSAndroid Build Coastguard Workerthe instructions above. 833*9e94795aSAndroid Build Coastguard Worker 834*9e94795aSAndroid Build Coastguard Worker### Stop using PATH directly {#PATH} 835*9e94795aSAndroid Build Coastguard Worker 836*9e94795aSAndroid Build Coastguard WorkerThis isn't only set by envsetup.sh, but it is modified by it. Due to that it's 837*9e94795aSAndroid Build Coastguard Workerrather easy for this to change between different shells, and it's not ideal to 838*9e94795aSAndroid Build Coastguard Workerreread the makefiles every time this changes. 839*9e94795aSAndroid Build Coastguard Worker 840*9e94795aSAndroid Build Coastguard WorkerIn most cases, you shouldn't need to touch PATH at all. When you need to have a 841*9e94795aSAndroid Build Coastguard Workerrule reference a particular binary that's part of the source tree or outputs, 842*9e94795aSAndroid Build Coastguard Workerit's preferrable to just use the path to the file itself (since you should 843*9e94795aSAndroid Build Coastguard Workeralready be adding that as a dependency). 844*9e94795aSAndroid Build Coastguard Worker 845*9e94795aSAndroid Build Coastguard WorkerDepending on the rule, passing the file path itself may not be feasible due to 846*9e94795aSAndroid Build Coastguard Workerlayers of unchangable scripts/binaries. In that case, be sure to add the 847*9e94795aSAndroid Build Coastguard Workerdependency, but modify the PATH within the rule itself: 848*9e94795aSAndroid Build Coastguard Worker 849*9e94795aSAndroid Build Coastguard Worker``` make 850*9e94795aSAndroid Build Coastguard Worker$(TARGET): myscript my/path/binary 851*9e94795aSAndroid Build Coastguard Worker PATH=my/path:$$PATH myscript -o $@ 852*9e94795aSAndroid Build Coastguard Worker``` 853*9e94795aSAndroid Build Coastguard Worker 854*9e94795aSAndroid Build Coastguard Worker### Stop using PYTHONPATH directly {#PYTHONPATH} 855*9e94795aSAndroid Build Coastguard Worker 856*9e94795aSAndroid Build Coastguard WorkerLike PATH, this isn't only set by envsetup.sh, but it is modified by it. Due to 857*9e94795aSAndroid Build Coastguard Workerthat it's rather easy for this to change between different shells, and it's not 858*9e94795aSAndroid Build Coastguard Workerideal to reread the makefiles every time. 859*9e94795aSAndroid Build Coastguard Worker 860*9e94795aSAndroid Build Coastguard WorkerThe best solution here is to start switching to Soong's python building support, 861*9e94795aSAndroid Build Coastguard Workerwhich packages the python interpreter, libraries, and script all into one file 862*9e94795aSAndroid Build Coastguard Workerthat no longer needs PYTHONPATH. See fontchain_lint for examples of this: 863*9e94795aSAndroid Build Coastguard Worker 864*9e94795aSAndroid Build Coastguard Worker* [external/fonttools/Lib/fontTools/Android.bp] for python_library_host 865*9e94795aSAndroid Build Coastguard Worker* [frameworks/base/Android.bp] for python_binary_host 866*9e94795aSAndroid Build Coastguard Worker* [frameworks/base/data/fonts/Android.mk] to execute the python binary 867*9e94795aSAndroid Build Coastguard Worker 868*9e94795aSAndroid Build Coastguard WorkerIf you still need to use PYTHONPATH, do so within the rule itself, just like 869*9e94795aSAndroid Build Coastguard Workerpath: 870*9e94795aSAndroid Build Coastguard Worker 871*9e94795aSAndroid Build Coastguard Worker``` make 872*9e94795aSAndroid Build Coastguard Worker$(TARGET): myscript.py $(sort $(shell find my/python/lib -name '*.py')) 873*9e94795aSAndroid Build Coastguard Worker PYTHONPATH=my/python/lib:$$PYTHONPATH myscript.py -o $@ 874*9e94795aSAndroid Build Coastguard Worker``` 875*9e94795aSAndroid Build Coastguard Worker### Stop using PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE directly {#PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE} 876*9e94795aSAndroid Build Coastguard Worker 877*9e94795aSAndroid Build Coastguard WorkerSpecify Framework Compatibility Matrix Version in device manifest by adding a `target-level` 878*9e94795aSAndroid Build Coastguard Workerattribute to the root element `<manifest>`. If `PRODUCT_COMPATIBILITY_MATRIX_LEVEL_OVERRIDE` 879*9e94795aSAndroid Build Coastguard Workeris 26 or 27, you can add `"target-level"="1"` to your device manifest instead. 880*9e94795aSAndroid Build Coastguard Worker 881*9e94795aSAndroid Build Coastguard Worker### Stop using USE_CLANG_PLATFORM_BUILD {#USE_CLANG_PLATFORM_BUILD} 882*9e94795aSAndroid Build Coastguard Worker 883*9e94795aSAndroid Build Coastguard WorkerClang is the default and only supported Android compiler, so there is no reason 884*9e94795aSAndroid Build Coastguard Workerfor this option to exist. 885*9e94795aSAndroid Build Coastguard Worker 886*9e94795aSAndroid Build Coastguard Worker### Stop using clang property 887*9e94795aSAndroid Build Coastguard Worker 888*9e94795aSAndroid Build Coastguard WorkerThe clang property has been deleted from Soong. To fix any build errors, remove the clang 889*9e94795aSAndroid Build Coastguard Workerproperty from affected Android.bp files using bpmodify. 890*9e94795aSAndroid Build Coastguard Worker 891*9e94795aSAndroid Build Coastguard Worker 892*9e94795aSAndroid Build Coastguard Worker``` make 893*9e94795aSAndroid Build Coastguard Workergo run bpmodify.go -w -m=module_name -remove-property=true -property=clang filepath 894*9e94795aSAndroid Build Coastguard Worker``` 895*9e94795aSAndroid Build Coastguard Worker 896*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_CLANG_PROPERTY` can be used as temporarily workaround 897*9e94795aSAndroid Build Coastguard Worker 898*9e94795aSAndroid Build Coastguard Worker 899*9e94795aSAndroid Build Coastguard Worker### Stop using clang_cflags and clang_asflags 900*9e94795aSAndroid Build Coastguard Worker 901*9e94795aSAndroid Build Coastguard Workerclang_cflags and clang_asflags are deprecated. 902*9e94795aSAndroid Build Coastguard WorkerTo fix any build errors, use bpmodify to either 903*9e94795aSAndroid Build Coastguard Worker - move the contents of clang_asflags/clang_cflags into asflags/cflags or 904*9e94795aSAndroid Build Coastguard Worker - delete clang_cflags/as_flags as necessary 905*9e94795aSAndroid Build Coastguard Worker 906*9e94795aSAndroid Build Coastguard WorkerTo Move the contents: 907*9e94795aSAndroid Build Coastguard Worker``` make 908*9e94795aSAndroid Build Coastguard Workergo run bpmodify.go -w -m=module_name -move-property=true -property=clang_cflags -new-location=cflags filepath 909*9e94795aSAndroid Build Coastguard Worker``` 910*9e94795aSAndroid Build Coastguard Worker 911*9e94795aSAndroid Build Coastguard WorkerTo Delete: 912*9e94795aSAndroid Build Coastguard Worker``` make 913*9e94795aSAndroid Build Coastguard Workergo run bpmodify.go -w -m=module_name -remove-property=true -property=clang_cflags filepath 914*9e94795aSAndroid Build Coastguard Worker``` 915*9e94795aSAndroid Build Coastguard Worker 916*9e94795aSAndroid Build Coastguard Worker`BUILD_BROKEN_CLANG_ASFLAGS` and `BUILD_BROKEN_CLANG_CFLAGS` can be used as temporarily workarounds 917*9e94795aSAndroid Build Coastguard Worker 918*9e94795aSAndroid Build Coastguard Worker### Other envsetup.sh variables {#other_envsetup_variables} 919*9e94795aSAndroid Build Coastguard Worker 920*9e94795aSAndroid Build Coastguard Worker* ANDROID_TOOLCHAIN 921*9e94795aSAndroid Build Coastguard Worker* ANDROID_TOOLCHAIN_2ND_ARCH 922*9e94795aSAndroid Build Coastguard Worker* ANDROID_DEV_SCRIPTS 923*9e94795aSAndroid Build Coastguard Worker* ANDROID_EMULATOR_PREBUILTS 924*9e94795aSAndroid Build Coastguard Worker* ANDROID_PRE_BUILD_PATHS 925*9e94795aSAndroid Build Coastguard Worker 926*9e94795aSAndroid Build Coastguard WorkerThese are all exported from envsetup.sh, but don't have clear equivalents within 927*9e94795aSAndroid Build Coastguard Workerthe makefile system. If you need one of them, you'll have to set up your own 928*9e94795aSAndroid Build Coastguard Workerversion. 929*9e94795aSAndroid Build Coastguard Worker 930*9e94795aSAndroid Build Coastguard Worker## Soong config variables 931*9e94795aSAndroid Build Coastguard Worker 932*9e94795aSAndroid Build Coastguard Worker### Soong config string variables must list all values they can be set to 933*9e94795aSAndroid Build Coastguard Worker 934*9e94795aSAndroid Build Coastguard WorkerIn order to facilitate the transition to bazel, all soong_config_string_variables 935*9e94795aSAndroid Build Coastguard Workermust only be set to a value listed in their `values` property, or an empty string. 936*9e94795aSAndroid Build Coastguard WorkerIt is a build error otherwise. 937*9e94795aSAndroid Build Coastguard Worker 938*9e94795aSAndroid Build Coastguard WorkerExample Android.bp: 939*9e94795aSAndroid Build Coastguard Worker``` 940*9e94795aSAndroid Build Coastguard Workersoong_config_string_variable { 941*9e94795aSAndroid Build Coastguard Worker name: "my_string_variable", 942*9e94795aSAndroid Build Coastguard Worker values: [ 943*9e94795aSAndroid Build Coastguard Worker "foo", 944*9e94795aSAndroid Build Coastguard Worker "bar", 945*9e94795aSAndroid Build Coastguard Worker ], 946*9e94795aSAndroid Build Coastguard Worker} 947*9e94795aSAndroid Build Coastguard Worker 948*9e94795aSAndroid Build Coastguard Workersoong_config_module_type { 949*9e94795aSAndroid Build Coastguard Worker name: "my_cc_defaults", 950*9e94795aSAndroid Build Coastguard Worker module_type: "cc_defaults", 951*9e94795aSAndroid Build Coastguard Worker config_namespace: "my_namespace", 952*9e94795aSAndroid Build Coastguard Worker variables: ["my_string_variable"], 953*9e94795aSAndroid Build Coastguard Worker properties: [ 954*9e94795aSAndroid Build Coastguard Worker "shared_libs", 955*9e94795aSAndroid Build Coastguard Worker "static_libs", 956*9e94795aSAndroid Build Coastguard Worker ], 957*9e94795aSAndroid Build Coastguard Worker} 958*9e94795aSAndroid Build Coastguard Worker``` 959*9e94795aSAndroid Build Coastguard WorkerProduct config: 960*9e94795aSAndroid Build Coastguard Worker``` 961*9e94795aSAndroid Build Coastguard Worker$(call soong_config_set,my_namespace,my_string_variable,baz) # Will be an error as baz is not listed in my_string_variable's values. 962*9e94795aSAndroid Build Coastguard Worker``` 963*9e94795aSAndroid Build Coastguard Worker 964*9e94795aSAndroid Build Coastguard Worker[build/soong/Changes.md]: https://android.googlesource.com/platform/build/soong/+/master/Changes.md 965*9e94795aSAndroid Build Coastguard Worker[build/soong/docs/best_practices.md#headers]: https://android.googlesource.com/platform/build/soong/+/master/docs/best_practices.md#headers 966*9e94795aSAndroid Build Coastguard Worker[external/fonttools/Lib/fontTools/Android.bp]: https://android.googlesource.com/platform/external/fonttools/+/master/Lib/fontTools/Android.bp 967*9e94795aSAndroid Build Coastguard Worker[frameworks/base/Android.bp]: https://android.googlesource.com/platform/frameworks/base/+/master/Android.bp 968*9e94795aSAndroid Build Coastguard Worker[frameworks/base/data/fonts/Android.mk]: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk 969*9e94795aSAndroid Build Coastguard Worker[hardware/interfaces/health/1.0/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/1.0/README.md 970*9e94795aSAndroid Build Coastguard Worker[hardware/interfaces/health/2.1/README.md]: https://android.googlesource.com/platform/hardware/interfaces/+/master/health/2.1/README.md 971