Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1 | // Copyright (C) 2018 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 19 | "path" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 20 | "path/filepath" |
Jiyong Park | ab3ceb3 | 2018-10-10 14:05:29 +0900 | [diff] [blame] | 21 | "sort" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 22 | "strings" |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 23 | "sync" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
| 27 | "android/soong/java" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 28 | "android/soong/python" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 29 | |
| 30 | "github.com/google/blueprint" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 31 | "github.com/google/blueprint/bootstrap" |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 32 | "github.com/google/blueprint/proptools" |
| 33 | ) |
| 34 | |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 35 | const ( |
| 36 | imageApexSuffix = ".apex" |
| 37 | zipApexSuffix = ".zipapex" |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 38 | flattenedSuffix = ".flattened" |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 39 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 40 | imageApexType = "image" |
| 41 | zipApexType = "zip" |
| 42 | flattenedApexType = "flattened" |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 43 | ) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 44 | |
| 45 | type dependencyTag struct { |
| 46 | blueprint.BaseDependencyTag |
| 47 | name string |
| 48 | } |
| 49 | |
| 50 | var ( |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 51 | sharedLibTag = dependencyTag{name: "sharedLib"} |
| 52 | executableTag = dependencyTag{name: "executable"} |
| 53 | javaLibTag = dependencyTag{name: "javaLib"} |
| 54 | prebuiltTag = dependencyTag{name: "prebuilt"} |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 55 | testTag = dependencyTag{name: "test"} |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 56 | keyTag = dependencyTag{name: "key"} |
| 57 | certificateTag = dependencyTag{name: "certificate"} |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 58 | usesTag = dependencyTag{name: "uses"} |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 59 | androidAppTag = dependencyTag{name: "androidApp"} |
Anton Hansson | 5053c29 | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 60 | apexAvailWl = makeApexAvailableWhitelist() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 61 | ) |
| 62 | |
Anton Hansson | 5053c29 | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 63 | // This is a map from apex to modules, which overrides the |
| 64 | // apex_available setting for that particular module to make |
| 65 | // it available for the apex regardless of its setting. |
| 66 | // TODO(b/147364041): remove this |
| 67 | func makeApexAvailableWhitelist() map[string][]string { |
| 68 | // The "Module separator"s below are employed to minimize merge conflicts. |
| 69 | m := make(map[string][]string) |
| 70 | // |
| 71 | // Module separator |
| 72 | // |
| 73 | m["com.android.adbd"] = []string{"adbd", "libcrypto"} |
| 74 | // |
| 75 | // Module separator |
| 76 | // |
| 77 | m["com.android.art"] = []string{ |
Anton Hansson | f17f248 | 2020-01-16 09:11:57 +0000 | [diff] [blame^] | 78 | "jacocoagent", |
Anton Hansson | 5053c29 | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 79 | "libadbconnection_server", |
| 80 | "libartd-disassembler", |
| 81 | "libbacktrace", |
| 82 | "libbase", |
| 83 | "libc++", |
| 84 | "libcrypto", |
| 85 | "libdexfile_support", |
| 86 | "libexpat", |
| 87 | "libicuuc", |
| 88 | "liblzma", |
| 89 | "libmeminfo", |
| 90 | "libprocinfo", |
| 91 | "libunwindstack", |
| 92 | "libvixl", |
| 93 | "libvixld", |
| 94 | "libz", |
| 95 | "libziparchive", |
| 96 | "prebuilt_libclang_rt", |
| 97 | } |
| 98 | // |
| 99 | // Module separator |
| 100 | // |
| 101 | m["com.android.bluetooth.updatable"] = []string{ |
| 102 | "android.hardware.audio.common@5.0", |
| 103 | "android.hardware.bluetooth@1.0", |
| 104 | "android.hardware.bluetooth@1.1", |
| 105 | "android.hardware.bluetooth.a2dp@1.0", |
| 106 | "android.hardware.bluetooth.audio@2.0", |
| 107 | "android.hidl.safe_union@1.0", |
| 108 | "libbase", |
| 109 | "libbinderthreadstate", |
| 110 | "libbluetooth", |
| 111 | "libbluetooth_jni", |
| 112 | "libc++", |
| 113 | "libchrome", |
| 114 | "libcrypto", |
| 115 | "libcutils", |
| 116 | "libevent", |
| 117 | "libfmq", |
| 118 | "libhidlbase", |
| 119 | "libprocessgroup", |
| 120 | "libprotobuf-cpp-lite", |
| 121 | "libstatslog", |
| 122 | "libtinyxml2", |
| 123 | "libutils", |
| 124 | "libz", |
| 125 | } |
| 126 | // |
| 127 | // Module separator |
| 128 | // |
| 129 | m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"} |
| 130 | // |
| 131 | // Module separator |
| 132 | // |
| 133 | m["com.android.conscrypt"] = []string{"boringssl_self_test", "libc++", "libcrypto", "libssl"} |
| 134 | // |
| 135 | // Module separator |
| 136 | // |
| 137 | m["com.android.cronet"] = []string{"org.chromium.net.cronet", "prebuilt_libcronet.80.0.3986.0"} |
| 138 | // |
| 139 | // Module separator |
| 140 | // |
| 141 | m["com.android.incremental"] = []string{"libc++", "libdataloader", "libincfs"} |
| 142 | // |
| 143 | // Module separator |
| 144 | // |
| 145 | m["com.android.media"] = []string{ |
| 146 | "android.hardware.cas@1.0", |
| 147 | "android.hardware.cas.native@1.0", |
| 148 | "android.hidl.allocator@1.0", |
| 149 | "android.hidl.memory@1.0", |
| 150 | "android.hidl.memory.token@1.0", |
| 151 | "android.hidl.token@1.0", |
| 152 | "android.hidl.token@1.0-utils", |
| 153 | "libaacextractor", |
| 154 | "libamrextractor", |
| 155 | "libaudioutils", |
| 156 | "libbase", |
| 157 | "libbinderthreadstate", |
| 158 | "libc++", |
| 159 | "libcrypto", |
| 160 | "libcutils", |
| 161 | "libflacextractor", |
| 162 | "libhidlbase", |
| 163 | "libhidlmemory", |
| 164 | "libmidiextractor", |
| 165 | "libmkvextractor", |
| 166 | "libmp3extractor", |
| 167 | "libmp4extractor", |
| 168 | "libmpeg2extractor", |
| 169 | "liboggextractor", |
| 170 | "libprocessgroup", |
| 171 | "libspeexresampler", |
| 172 | "libstagefright_flacdec", |
| 173 | "libutils", |
| 174 | "libwavextractor", |
| 175 | "updatable-media", |
| 176 | } |
| 177 | // |
| 178 | // Module separator |
| 179 | // |
| 180 | m["com.android.media.swcodec"] = []string{ |
| 181 | "android.frameworks.bufferhub@1.0", |
| 182 | "android.hardware.common-ndk_platform", |
| 183 | "android.hardware.graphics.allocator@2.0", |
| 184 | "android.hardware.graphics.allocator@3.0", |
| 185 | "android.hardware.graphics.allocator@4.0", |
| 186 | "android.hardware.graphics.bufferqueue@1.0", |
| 187 | "android.hardware.graphics.bufferqueue@2.0", |
| 188 | "android.hardware.graphics.common@1.0", |
| 189 | "android.hardware.graphics.common@1.1", |
| 190 | "android.hardware.graphics.common@1.2", |
| 191 | "android.hardware.graphics.common-ndk_platform", |
| 192 | "android.hardware.graphics.mapper@2.0", |
| 193 | "android.hardware.graphics.mapper@2.1", |
| 194 | "android.hardware.graphics.mapper@3.0", |
| 195 | "android.hardware.graphics.mapper@4.0", |
| 196 | "android.hardware.media@1.0", |
| 197 | "android.hardware.media.bufferpool@2.0", |
| 198 | "android.hardware.media.c2@1.0", |
| 199 | "android.hardware.media.c2@1.1", |
| 200 | "android.hardware.media.omx@1.0", |
| 201 | "android.hidl.memory@1.0", |
| 202 | "android.hidl.memory.token@1.0", |
| 203 | "android.hidl.safe_union@1.0", |
| 204 | "android.hidl.token@1.0", |
| 205 | "android.hidl.token@1.0-utils", |
| 206 | "libaudioutils", |
| 207 | "libavservices_minijail", |
| 208 | "libbase", |
| 209 | "libbinderthreadstate", |
| 210 | "libc++", |
| 211 | "libcap", |
| 212 | "libcodec2", |
| 213 | "libcodec2_hidl@1.0", |
| 214 | "libcodec2_hidl@1.1", |
| 215 | "libcodec2_soft_aacdec", |
| 216 | "libcodec2_soft_aacenc", |
| 217 | "libcodec2_soft_amrnbdec", |
| 218 | "libcodec2_soft_amrnbenc", |
| 219 | "libcodec2_soft_amrwbdec", |
| 220 | "libcodec2_soft_amrwbenc", |
| 221 | "libcodec2_soft_av1dec_gav1", |
| 222 | "libcodec2_soft_avcdec", |
| 223 | "libcodec2_soft_avcenc", |
| 224 | "libcodec2_soft_common", |
| 225 | "libcodec2_soft_flacdec", |
| 226 | "libcodec2_soft_flacenc", |
| 227 | "libcodec2_soft_g711alawdec", |
| 228 | "libcodec2_soft_g711mlawdec", |
| 229 | "libcodec2_soft_gsmdec", |
| 230 | "libcodec2_soft_h263dec", |
| 231 | "libcodec2_soft_h263enc", |
| 232 | "libcodec2_soft_hevcdec", |
| 233 | "libcodec2_soft_hevcenc", |
| 234 | "libcodec2_soft_mp3dec", |
| 235 | "libcodec2_soft_mpeg2dec", |
| 236 | "libcodec2_soft_mpeg4dec", |
| 237 | "libcodec2_soft_mpeg4enc", |
| 238 | "libcodec2_soft_opusdec", |
| 239 | "libcodec2_soft_opusenc", |
| 240 | "libcodec2_soft_rawdec", |
| 241 | "libcodec2_soft_vorbisdec", |
| 242 | "libcodec2_soft_vp8dec", |
| 243 | "libcodec2_soft_vp8enc", |
| 244 | "libcodec2_soft_vp9dec", |
| 245 | "libcodec2_soft_vp9enc", |
| 246 | "libcodec2_vndk", |
| 247 | "libc_scudo", |
| 248 | "libcutils", |
| 249 | "libfmq", |
| 250 | "libgralloctypes", |
| 251 | "libhardware", |
| 252 | "libhidlbase", |
| 253 | "libhidlmemory", |
| 254 | "libion", |
| 255 | "libmedia_codecserviceregistrant", |
| 256 | "libminijail", |
| 257 | "libopus", |
| 258 | "libprocessgroup", |
| 259 | "libscudo_wrapper", |
| 260 | "libsfplugin_ccodec_utils", |
| 261 | "libspeexresampler", |
| 262 | "libstagefright_amrnb_common", |
| 263 | "libstagefright_bufferpool@2.0.1", |
| 264 | "libstagefright_bufferqueue_helper", |
| 265 | "libstagefright_enc_common", |
| 266 | "libstagefright_flacdec", |
| 267 | "libstagefright_foundation", |
| 268 | "libsync", |
| 269 | "libui", |
| 270 | "libutils", |
| 271 | "libvorbisidec", |
| 272 | "libvpx", |
| 273 | "mediaswcodec", |
| 274 | "prebuilt_libclang_rt", |
| 275 | } |
| 276 | // |
| 277 | // Module separator |
| 278 | // |
| 279 | m["com.android.mediaprovider"] = []string{"libfuse", "MediaProvider", "MediaProviderGoogle"} |
| 280 | // |
| 281 | // Module separator |
| 282 | // |
| 283 | m["com.android.permission"] = []string{"GooglePermissionController", "PermissionController"} |
| 284 | // |
| 285 | // Module separator |
| 286 | // |
| 287 | m["com.android.runtime"] = []string{ |
| 288 | "libbase", |
| 289 | "libc++", |
| 290 | "libdexfile_support", |
| 291 | "liblzma", |
| 292 | "libunwindstack", |
| 293 | "prebuilt_libclang_rt", |
| 294 | } |
| 295 | // |
| 296 | // Module separator |
| 297 | // |
| 298 | m["com.android.resolv"] = []string{"libcrypto", "libnetd_resolv", "libssl"} |
| 299 | // |
| 300 | // Module separator |
| 301 | // |
| 302 | m["com.android.tethering"] = []string{"libbase", "libc++", "libnativehelper_compat_libc++"} |
| 303 | // |
| 304 | // Module separator |
| 305 | // |
| 306 | m["com.android.wifi"] = []string{ |
| 307 | "libbase", |
| 308 | "libc++", |
| 309 | "libcutils", |
| 310 | "libprocessgroup", |
| 311 | "libutils", |
| 312 | "libwifi-jni", |
| 313 | "wifi-service-resources", |
| 314 | } |
| 315 | // |
| 316 | // Module separator |
| 317 | // |
| 318 | return m |
| 319 | } |
| 320 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 321 | func init() { |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 322 | android.RegisterModuleType("apex", BundleFactory) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 323 | android.RegisterModuleType("apex_test", testApexBundleFactory) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 324 | android.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 325 | android.RegisterModuleType("apex_defaults", defaultsFactory) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 326 | android.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 327 | android.RegisterModuleType("override_apex", overrideApexFactory) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 328 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 329 | android.PreDepsMutators(RegisterPreDepsMutators) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 330 | android.PostDepsMutators(RegisterPostDepsMutators) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 331 | |
| 332 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 333 | apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) |
| 334 | sort.Strings(*apexFileContextsInfos) |
| 335 | ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " ")) |
| 336 | }) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 337 | } |
| 338 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 339 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 340 | ctx.TopDown("apex_vndk", apexVndkMutator).Parallel() |
| 341 | ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel() |
| 342 | } |
| 343 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 344 | func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 345 | ctx.BottomUp("apex_deps", apexDepsMutator) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 346 | ctx.BottomUp("apex", apexMutator).Parallel() |
| 347 | ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel() |
| 348 | ctx.BottomUp("apex_uses", apexUsesMutator).Parallel() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 351 | // Mark the direct and transitive dependencies of apex bundles so that they |
| 352 | // can be built for the apex bundles. |
Jiyong Park | a308ea1 | 2019-11-15 10:38:39 +0900 | [diff] [blame] | 353 | func apexDepsMutator(mctx android.BottomUpMutatorContext) { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 354 | if a, ok := mctx.Module().(*apexBundle); ok { |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 355 | apexBundleName := mctx.ModuleName() |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 356 | mctx.WalkDeps(func(child, parent android.Module) bool { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 357 | depName := mctx.OtherModuleName(child) |
| 358 | // If the parent is apexBundle, this child is directly depended. |
| 359 | _, directDep := parent.(*apexBundle) |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 360 | if a.installable() && !a.testApex { |
Alex Light | f98087f | 2019-02-04 14:45:06 -0800 | [diff] [blame] | 361 | // TODO(b/123892969): Workaround for not having any way to annotate test-apexs |
| 362 | // non-installable apex's cannot be installed and so should not prevent libraries from being |
| 363 | // installed to the system. |
| 364 | android.UpdateApexDependency(apexBundleName, depName, directDep) |
| 365 | } |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 366 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 367 | if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() && |
| 368 | (directDep || am.DepIsInSameApex(mctx, child)) { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 369 | am.BuildForApex(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 370 | return true |
| 371 | } else { |
| 372 | return false |
| 373 | } |
| 374 | }) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // Create apex variations if a module is included in APEX(s). |
| 379 | func apexMutator(mctx android.BottomUpMutatorContext) { |
| 380 | if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 381 | am.CreateApexVariations(mctx) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 382 | } else if _, ok := mctx.Module().(*apexBundle); ok { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 383 | // apex bundle itself is mutated so that it and its modules have same |
| 384 | // apex variant. |
| 385 | apexBundleName := mctx.ModuleName() |
| 386 | mctx.CreateVariations(apexBundleName) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 387 | } else if o, ok := mctx.Module().(*OverrideApex); ok { |
| 388 | apexBundleName := o.GetOverriddenModuleName() |
| 389 | if apexBundleName == "" { |
| 390 | mctx.ModuleErrorf("base property is not set") |
| 391 | return |
| 392 | } |
| 393 | mctx.CreateVariations(apexBundleName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 394 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 395 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 396 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 397 | |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 398 | var ( |
| 399 | apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey") |
| 400 | apexFileContextsInfosMutex sync.Mutex |
| 401 | ) |
| 402 | |
| 403 | func apexFileContextsInfos(config android.Config) *[]string { |
| 404 | return config.Once(apexFileContextsInfosKey, func() interface{} { |
| 405 | return &[]string{} |
| 406 | }).(*[]string) |
| 407 | } |
| 408 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 409 | func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) { |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 410 | apexFileContextsInfosMutex.Lock() |
| 411 | defer apexFileContextsInfosMutex.Unlock() |
| 412 | apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 413 | *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo) |
Jooyung Han | 7a78a92 | 2019-10-08 21:59:58 +0900 | [diff] [blame] | 414 | } |
| 415 | |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 416 | func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 417 | if ab, ok := mctx.Module().(*apexBundle); ok { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 418 | var variants []string |
| 419 | switch proptools.StringDefault(ab.properties.Payload_type, "image") { |
| 420 | case "image": |
| 421 | variants = append(variants, imageApexType, flattenedApexType) |
| 422 | case "zip": |
| 423 | variants = append(variants, zipApexType) |
| 424 | case "both": |
| 425 | variants = append(variants, imageApexType, zipApexType, flattenedApexType) |
| 426 | default: |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 427 | mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type) |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 428 | return |
| 429 | } |
| 430 | |
| 431 | modules := mctx.CreateLocalVariations(variants...) |
| 432 | |
| 433 | for i, v := range variants { |
| 434 | switch v { |
| 435 | case imageApexType: |
| 436 | modules[i].(*apexBundle).properties.ApexType = imageApex |
| 437 | case zipApexType: |
| 438 | modules[i].(*apexBundle).properties.ApexType = zipApex |
| 439 | case flattenedApexType: |
| 440 | modules[i].(*apexBundle).properties.ApexType = flattenedApex |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 441 | if !mctx.Config().FlattenApex() && ab.Platform() { |
Sundong Ahn | d95aa2d | 2019-10-08 19:34:03 +0900 | [diff] [blame] | 442 | modules[i].(*apexBundle).MakeAsSystemExt() |
| 443 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 444 | } |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 445 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 446 | } else if _, ok := mctx.Module().(*OverrideApex); ok { |
| 447 | mctx.CreateVariations(imageApexType, flattenedApexType) |
Sundong Ahn | e9b5572 | 2019-09-06 17:37:42 +0900 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 451 | func apexUsesMutator(mctx android.BottomUpMutatorContext) { |
| 452 | if ab, ok := mctx.Module().(*apexBundle); ok { |
| 453 | mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...) |
| 454 | } |
| 455 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 456 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 457 | var ( |
| 458 | useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist") |
| 459 | ) |
| 460 | |
| 461 | // useVendorWhitelist returns the list of APEXes which are allowed to use_vendor. |
| 462 | // When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__, |
| 463 | // which may cause compatibility issues. (e.g. libbinder) |
| 464 | // Even though libbinder restricts its availability via 'apex_available' property and relies on |
| 465 | // yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules |
| 466 | // to avoid similar problems. |
| 467 | func useVendorWhitelist(config android.Config) []string { |
| 468 | return config.Once(useVendorWhitelistKey, func() interface{} { |
| 469 | return []string{ |
| 470 | // swcodec uses "vendor" variants for smaller size |
| 471 | "com.android.media.swcodec", |
| 472 | "test_com.android.media.swcodec", |
| 473 | } |
| 474 | }).([]string) |
| 475 | } |
| 476 | |
| 477 | // setUseVendorWhitelistForTest overrides useVendorWhitelist and must be |
| 478 | // called before the first call to useVendorWhitelist() |
| 479 | func setUseVendorWhitelistForTest(config android.Config, whitelist []string) { |
| 480 | config.Once(useVendorWhitelistKey, func() interface{} { |
| 481 | return whitelist |
| 482 | }) |
| 483 | } |
| 484 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 485 | type apexNativeDependencies struct { |
| 486 | // List of native libraries |
| 487 | Native_shared_libs []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 488 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 489 | // List of native executables |
| 490 | Binaries []string |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 491 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 492 | // List of native tests |
| 493 | Tests []string |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 494 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 495 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 496 | type apexMultilibProperties struct { |
| 497 | // Native dependencies whose compile_multilib is "first" |
| 498 | First apexNativeDependencies |
| 499 | |
| 500 | // Native dependencies whose compile_multilib is "both" |
| 501 | Both apexNativeDependencies |
| 502 | |
| 503 | // Native dependencies whose compile_multilib is "prefer32" |
| 504 | Prefer32 apexNativeDependencies |
| 505 | |
| 506 | // Native dependencies whose compile_multilib is "32" |
| 507 | Lib32 apexNativeDependencies |
| 508 | |
| 509 | // Native dependencies whose compile_multilib is "64" |
| 510 | Lib64 apexNativeDependencies |
| 511 | } |
| 512 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 513 | type apexBundleProperties struct { |
| 514 | // Json manifest file describing meta info of this APEX bundle. Default: |
Dario Freni | 4abb1dc | 2018-11-20 18:04:58 +0000 | [diff] [blame] | 515 | // "apex_manifest.json" |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 516 | Manifest *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 517 | |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 518 | // AndroidManifest.xml file used for the zip container of this APEX bundle. |
| 519 | // If unspecified, a default one is automatically generated. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 520 | AndroidManifest *string `android:"path"` |
Jiyong Park | 40e26a2 | 2019-02-08 02:53:06 +0900 | [diff] [blame] | 521 | |
Roland Levillain | 411c584 | 2019-09-19 16:37:20 +0100 | [diff] [blame] | 522 | // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on |
| 523 | // device (/apex/<apex_name>). |
| 524 | // If unspecified, defaults to the value of name. |
Jiyong Park | 05e70dd | 2019-03-18 14:26:32 +0900 | [diff] [blame] | 525 | Apex_name *string |
| 526 | |
Jiyong Park | d0a65ba | 2018-11-10 06:37:15 +0900 | [diff] [blame] | 527 | // Determines the file contexts file for setting security context to each file in this APEX bundle. |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 528 | // For platform APEXes, this should points to a file under /system/sepolicy |
| 529 | // Default: /system/sepolicy/apex/<module_name>_file_contexts. |
| 530 | File_contexts *string `android:"path"` |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 531 | |
| 532 | // List of native shared libs that are embedded inside this APEX bundle |
| 533 | Native_shared_libs []string |
| 534 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 535 | // List of executables that are embedded inside this APEX bundle |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 536 | Binaries []string |
| 537 | |
| 538 | // List of java libraries that are embedded inside this APEX bundle |
| 539 | Java_libs []string |
| 540 | |
| 541 | // List of prebuilt files that are embedded inside this APEX bundle |
| 542 | Prebuilts []string |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 543 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 544 | // List of tests that are embedded inside this APEX bundle |
| 545 | Tests []string |
| 546 | |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 547 | // Name of the apex_key module that provides the private key to sign APEX |
| 548 | Key *string |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 549 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 550 | // The type of APEX to build. Controls what the APEX payload is. Either |
| 551 | // 'image', 'zip' or 'both'. Default: 'image'. |
| 552 | Payload_type *string |
| 553 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 554 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 555 | // or an android_app_certificate module name in the form ":module". |
| 556 | Certificate *string |
| 557 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 558 | // Whether this APEX is installable to one of the partitions. Default: true. |
| 559 | Installable *bool |
| 560 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 561 | // For native libraries and binaries, use the vendor variant instead of the core (platform) variant. |
| 562 | // Default is false. |
| 563 | Use_vendor *bool |
| 564 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 565 | // For telling the apex to ignore special handling for system libraries such as bionic. Default is false. |
| 566 | Ignore_system_library_special_case *bool |
| 567 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 568 | Multilib apexMultilibProperties |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 569 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 570 | // List of sanitizer names that this APEX is enabled for |
| 571 | SanitizerNames []string `blueprint:"mutated"` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 572 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 573 | PreventInstall bool `blueprint:"mutated"` |
| 574 | |
| 575 | HideFromMake bool `blueprint:"mutated"` |
| 576 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 577 | // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false. |
| 578 | Provide_cpp_shared_libs *bool |
| 579 | |
| 580 | // List of providing APEXes' names so that this APEX can depend on provided shared libraries. |
| 581 | Uses []string |
Nikita Ioffe | 5d5ae76 | 2019-08-31 14:38:05 +0100 | [diff] [blame] | 582 | |
| 583 | // A txt file containing list of files that are whitelisted to be included in this APEX. |
| 584 | Whitelisted_files *string |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 585 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 586 | // package format of this apex variant; could be non-flattened, flattened, or zip. |
| 587 | // imageApex, zipApex or flattened |
| 588 | ApexType apexPackaging `blueprint:"mutated"` |
Sundong Ahn | e8fb724 | 2019-09-17 13:50:45 +0900 | [diff] [blame] | 589 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 590 | // List of SDKs that are used to build this APEX. A reference to an SDK should be either |
| 591 | // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current` |
| 592 | // is implied. This value affects all modules included in this APEX. In other words, they are |
| 593 | // also built with the SDKs specified here. |
| 594 | Uses_sdks []string |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 595 | |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 596 | // Whenever apex_payload.img of the APEX should include dm-verity hashtree. |
| 597 | // Should be only used in tests#. |
| 598 | Test_only_no_hashtree *bool |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 599 | |
| 600 | // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well |
| 601 | // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb |
| 602 | Legacy_android10_support *bool |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 603 | |
| 604 | IsCoverageVariant bool `blueprint:"mutated"` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | type apexTargetBundleProperties struct { |
| 608 | Target struct { |
| 609 | // Multilib properties only for android. |
| 610 | Android struct { |
| 611 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 612 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 613 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 614 | // Multilib properties only for host. |
| 615 | Host struct { |
| 616 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 617 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 618 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 619 | // Multilib properties only for host linux_bionic. |
| 620 | Linux_bionic struct { |
| 621 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 622 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 623 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 624 | // Multilib properties only for host linux_glibc. |
| 625 | Linux_glibc struct { |
| 626 | Multilib apexMultilibProperties |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 627 | } |
| 628 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 629 | } |
| 630 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 631 | type overridableProperties struct { |
| 632 | // List of APKs to package inside APEX |
| 633 | Apps []string |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 634 | |
| 635 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 636 | // (in Make or Soong). |
| 637 | // This does not completely prevent installation of the overridden binaries, but if both |
| 638 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 639 | // from PRODUCT_PACKAGES. |
| 640 | Overrides []string |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 641 | } |
| 642 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 643 | type apexPackaging int |
| 644 | |
| 645 | const ( |
| 646 | imageApex apexPackaging = iota |
| 647 | zipApex |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 648 | flattenedApex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 649 | ) |
| 650 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 651 | // The suffix for the output "file", not the module |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 652 | func (a apexPackaging) suffix() string { |
| 653 | switch a { |
| 654 | case imageApex: |
| 655 | return imageApexSuffix |
| 656 | case zipApex: |
| 657 | return zipApexSuffix |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 658 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 659 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
| 663 | func (a apexPackaging) name() string { |
| 664 | switch a { |
| 665 | case imageApex: |
| 666 | return imageApexType |
| 667 | case zipApex: |
| 668 | return zipApexType |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 669 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 670 | panic(fmt.Errorf("unknown APEX type %d", a)) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 674 | type apexFileClass int |
| 675 | |
| 676 | const ( |
| 677 | etc apexFileClass = iota |
| 678 | nativeSharedLib |
| 679 | nativeExecutable |
| 680 | shBinary |
| 681 | pyBinary |
| 682 | goBinary |
| 683 | javaSharedLib |
| 684 | nativeTest |
| 685 | app |
| 686 | ) |
| 687 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 688 | func (class apexFileClass) NameInMake() string { |
| 689 | switch class { |
| 690 | case etc: |
| 691 | return "ETC" |
| 692 | case nativeSharedLib: |
| 693 | return "SHARED_LIBRARIES" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 694 | case nativeExecutable, shBinary, pyBinary, goBinary: |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 695 | return "EXECUTABLES" |
| 696 | case javaSharedLib: |
| 697 | return "JAVA_LIBRARIES" |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 698 | case nativeTest: |
| 699 | return "NATIVE_TESTS" |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 700 | case app: |
Jiyong Park | f383f7c | 2019-10-11 20:46:25 +0900 | [diff] [blame] | 701 | // b/142537672 Why isn't this APP? We want to have full control over |
| 702 | // the paths and file names of the apk file under the flattend APEX. |
| 703 | // If this is set to APP, then the paths and file names are modified |
| 704 | // by the Make build system. For example, it is installed to |
| 705 | // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of |
| 706 | // /system/apex/<apexname>/app/<Appname> because the build system automatically |
| 707 | // appends module name (which is <apexname>.<Appname> to the path. |
| 708 | return "ETC" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 709 | default: |
Roland Levillain | 4644b22 | 2019-07-31 14:09:17 +0100 | [diff] [blame] | 710 | panic(fmt.Errorf("unknown class %d", class)) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 714 | // apexFile represents a file in an APEX bundle |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 715 | type apexFile struct { |
| 716 | builtFile android.Path |
| 717 | moduleName string |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 718 | installDir string |
| 719 | class apexFileClass |
Jiyong Park | a889484 | 2018-12-19 17:36:39 +0900 | [diff] [blame] | 720 | module android.Module |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 721 | // list of symlinks that will be created in installDir that point to this apexFile |
| 722 | symlinks []string |
| 723 | transitiveDep bool |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 724 | moduleDir string |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 725 | |
| 726 | requiredModuleNames []string |
| 727 | targetRequiredModuleNames []string |
| 728 | hostRequiredModuleNames []string |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 729 | |
| 730 | jacocoReportClassesFile android.Path // only for javalibs and apps |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 731 | } |
| 732 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 733 | func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile { |
| 734 | ret := apexFile{ |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 735 | builtFile: builtFile, |
| 736 | moduleName: moduleName, |
| 737 | installDir: installDir, |
| 738 | class: class, |
| 739 | module: module, |
| 740 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 741 | if module != nil { |
| 742 | ret.moduleDir = ctx.OtherModuleDir(module) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 743 | ret.requiredModuleNames = module.RequiredModuleNames() |
| 744 | ret.targetRequiredModuleNames = module.TargetRequiredModuleNames() |
| 745 | ret.hostRequiredModuleNames = module.HostRequiredModuleNames() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 746 | } |
| 747 | return ret |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | func (af *apexFile) Ok() bool { |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 751 | return af.builtFile != nil && af.builtFile.String() != "" |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 752 | } |
| 753 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 754 | type apexBundle struct { |
| 755 | android.ModuleBase |
| 756 | android.DefaultableModuleBase |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 757 | android.OverridableModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 758 | android.SdkBase |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 759 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 760 | properties apexBundleProperties |
| 761 | targetProperties apexTargetBundleProperties |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 762 | overridableProperties overridableProperties |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 763 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 764 | // specific to apex_vndk modules |
| 765 | vndkProperties apexVndkProperties |
| 766 | |
Colin Cross | a492590 | 2018-11-16 11:36:28 -0800 | [diff] [blame] | 767 | bundleModuleFile android.WritablePath |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 768 | outputFile android.WritablePath |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 769 | installDir android.InstallPath |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 770 | |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 771 | prebuiltFileToDelete string |
| 772 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 773 | public_key_file android.Path |
| 774 | private_key_file android.Path |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 775 | |
| 776 | container_certificate_file android.Path |
| 777 | container_private_key_file android.Path |
| 778 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 779 | fileContexts android.Path |
| 780 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 781 | // list of files to be included in this apex |
| 782 | filesInfo []apexFile |
| 783 | |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 784 | // list of module names that should be installed along with this APEX |
| 785 | requiredDeps []string |
| 786 | |
| 787 | // list of module names that this APEX is depending on (to be shown via *-deps-info target) |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 788 | externalDeps []string |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 789 | // list of module names that this APEX is including (to be shown via *-deps-info target) |
| 790 | internalDeps []string |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 791 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 792 | testApex bool |
| 793 | vndkApex bool |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 794 | artApex bool |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 795 | primaryApexType bool |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 796 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 797 | manifestJsonOut android.WritablePath |
| 798 | manifestPbOut android.WritablePath |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 799 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 800 | // list of commands to create symlinks for backward compatibility. |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 801 | // these commands will be attached as LOCAL_POST_INSTALL_CMD to |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 802 | // apex package itself(for unflattened build) or apex_manifest(for flattened build) |
Jooyung Han | 72bd2f8 | 2019-10-23 16:46:38 +0900 | [diff] [blame] | 803 | // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting. |
| 804 | compatSymlinks []string |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 805 | |
| 806 | // Suffix of module name in Android.mk |
| 807 | // ".flattened", ".apex", ".zipapex", or "" |
| 808 | suffix string |
Jiyong Park | 3a1602e | 2020-01-14 14:39:19 +0900 | [diff] [blame] | 809 | |
| 810 | installedFilesFile android.WritablePath |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 811 | } |
| 812 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 813 | func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 814 | native_shared_libs []string, binaries []string, tests []string, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 815 | target android.Target, imageVariation string) { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 816 | // Use *FarVariation* to be able to depend on modules having |
| 817 | // conflicting variations with this module. This is required since |
| 818 | // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64' |
| 819 | // for native shared libs. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 820 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 821 | {Mutator: "image", Variation: imageVariation}, |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 822 | {Mutator: "link", Variation: "shared"}, |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 823 | {Mutator: "version", Variation: ""}, // "" is the non-stub variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 824 | }...), sharedLibTag, native_shared_libs...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 825 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 826 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 827 | blueprint.Variation{Mutator: "image", Variation: imageVariation}), |
| 828 | executableTag, binaries...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 829 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 830 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 831 | {Mutator: "image", Variation: imageVariation}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 832 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 833 | }...), testTag, tests...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 834 | } |
| 835 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 836 | func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { |
| 837 | if ctx.Os().Class == android.Device { |
| 838 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil) |
| 839 | } else { |
| 840 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil) |
| 841 | if ctx.Os().Bionic() { |
| 842 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil) |
| 843 | } else { |
| 844 | proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil) |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 849 | func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 850 | if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) { |
| 851 | ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true") |
| 852 | } |
| 853 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 854 | targets := ctx.MultiTargets() |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 855 | config := ctx.DeviceConfig() |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 856 | |
| 857 | a.combineProperties(ctx) |
| 858 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 859 | has32BitTarget := false |
| 860 | for _, target := range targets { |
| 861 | if target.Arch.ArchType.Multilib == "lib32" { |
| 862 | has32BitTarget = true |
| 863 | } |
| 864 | } |
| 865 | for i, target := range targets { |
| 866 | // When multilib.* is omitted for native_shared_libs, it implies |
| 867 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 868 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 869 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 870 | {Mutator: "link", Variation: "shared"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 871 | }...), sharedLibTag, a.properties.Native_shared_libs...) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 872 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 873 | // When multilib.* is omitted for tests, it implies |
| 874 | // multilib.both. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 875 | ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 876 | {Mutator: "image", Variation: a.getImageVariation(config)}, |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 877 | {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 878 | }...), testTag, a.properties.Tests...) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 879 | |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 880 | // Add native modules targetting both ABIs |
| 881 | addDependenciesForNativeModules(ctx, |
| 882 | a.properties.Multilib.Both.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 883 | a.properties.Multilib.Both.Binaries, |
| 884 | a.properties.Multilib.Both.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 885 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 886 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 887 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 888 | isPrimaryAbi := i == 0 |
| 889 | if isPrimaryAbi { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 890 | // When multilib.* is omitted for binaries, it implies |
| 891 | // multilib.first. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 892 | ctx.AddFarVariationDependencies(append(target.Variations(), |
| 893 | blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}), |
| 894 | executableTag, a.properties.Binaries...) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 895 | |
| 896 | // Add native modules targetting the first ABI |
| 897 | addDependenciesForNativeModules(ctx, |
| 898 | a.properties.Multilib.First.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 899 | a.properties.Multilib.First.Binaries, |
| 900 | a.properties.Multilib.First.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 901 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 902 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | switch target.Arch.ArchType.Multilib { |
| 906 | case "lib32": |
| 907 | // Add native modules targetting 32-bit ABI |
| 908 | addDependenciesForNativeModules(ctx, |
| 909 | a.properties.Multilib.Lib32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 910 | a.properties.Multilib.Lib32.Binaries, |
| 911 | a.properties.Multilib.Lib32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 912 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 913 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 914 | |
| 915 | addDependenciesForNativeModules(ctx, |
| 916 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 917 | a.properties.Multilib.Prefer32.Binaries, |
| 918 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 919 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 920 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 921 | case "lib64": |
| 922 | // Add native modules targetting 64-bit ABI |
| 923 | addDependenciesForNativeModules(ctx, |
| 924 | a.properties.Multilib.Lib64.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 925 | a.properties.Multilib.Lib64.Binaries, |
| 926 | a.properties.Multilib.Lib64.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 927 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 928 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 929 | |
| 930 | if !has32BitTarget { |
| 931 | addDependenciesForNativeModules(ctx, |
| 932 | a.properties.Multilib.Prefer32.Native_shared_libs, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 933 | a.properties.Multilib.Prefer32.Binaries, |
| 934 | a.properties.Multilib.Prefer32.Tests, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 935 | target, |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 936 | a.getImageVariation(config)) |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 937 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 938 | |
| 939 | if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device { |
| 940 | for _, sanitizer := range ctx.Config().SanitizeDevice() { |
| 941 | if sanitizer == "hwaddress" { |
| 942 | addDependenciesForNativeModules(ctx, |
| 943 | []string{"libclang_rt.hwasan-aarch64-android"}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 944 | nil, nil, target, a.getImageVariation(config)) |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 945 | break |
| 946 | } |
| 947 | } |
| 948 | } |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 949 | } |
| 950 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 951 | } |
| 952 | |
Jiyong Park | ce6aadc | 2019-11-20 13:58:28 +0900 | [diff] [blame] | 953 | // For prebuilt_etc, use the first variant (64 on 64/32bit device, |
| 954 | // 32 on 32bit device) regardless of the TARGET_PREFER_* setting. |
| 955 | // b/144532908 |
| 956 | archForPrebuiltEtc := config.Arches()[0] |
| 957 | for _, arch := range config.Arches() { |
| 958 | // Prefer 64-bit arch if there is any |
| 959 | if arch.ArchType.Multilib == "lib64" { |
| 960 | archForPrebuiltEtc = arch |
| 961 | break |
| 962 | } |
| 963 | } |
| 964 | ctx.AddFarVariationDependencies([]blueprint.Variation{ |
| 965 | {Mutator: "os", Variation: ctx.Os().String()}, |
| 966 | {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, |
| 967 | }, prebuiltTag, a.properties.Prebuilts...) |
| 968 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 969 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 970 | javaLibTag, a.properties.Java_libs...) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 971 | |
Ulya Trafimovich | 4456188 | 2020-01-03 13:25:54 +0000 | [diff] [blame] | 972 | // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library. |
| 973 | if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
| 974 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 975 | javaLibTag, "jacocoagent") |
| 976 | } |
| 977 | |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 978 | if String(a.properties.Key) == "" { |
| 979 | ctx.ModuleErrorf("key is missing") |
| 980 | return |
| 981 | } |
| 982 | ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key)) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 983 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 984 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Jiyong Park | 23c52b0 | 2019-02-02 13:13:47 +0900 | [diff] [blame] | 985 | if cert != "" { |
| 986 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 987 | } |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 988 | |
| 989 | // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks |
| 990 | if len(a.properties.Uses_sdks) > 0 { |
| 991 | sdkRefs := []android.SdkRef{} |
| 992 | for _, str := range a.properties.Uses_sdks { |
| 993 | parsed := android.ParseSdkRef(ctx, str, "uses_sdks") |
| 994 | sdkRefs = append(sdkRefs, parsed) |
| 995 | } |
| 996 | a.BuildWithSdks(sdkRefs) |
| 997 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 998 | } |
| 999 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1000 | func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { |
| 1001 | ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), |
| 1002 | androidAppTag, a.overridableProperties.Apps...) |
| 1003 | } |
| 1004 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1005 | func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1006 | // direct deps of an APEX bundle are all part of the APEX bundle |
| 1007 | return true |
| 1008 | } |
| 1009 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1010 | func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string { |
Jooyung Han | 27151d9 | 2019-12-16 17:45:32 +0900 | [diff] [blame] | 1011 | moduleName := ctx.ModuleName() |
| 1012 | // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list, |
| 1013 | // we check with the pseudo module name to see if its certificate is overridden. |
| 1014 | if a.vndkApex { |
| 1015 | moduleName = vndkApexName |
| 1016 | } |
| 1017 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1018 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 1019 | return ":" + certificate |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1020 | } |
| 1021 | return String(a.properties.Certificate) |
| 1022 | } |
| 1023 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1024 | func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) { |
| 1025 | switch tag { |
| 1026 | case "": |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1027 | return android.Paths{a.outputFile}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1028 | default: |
| 1029 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Jiyong Park | 5a83202 | 2018-12-20 09:54:35 +0900 | [diff] [blame] | 1030 | } |
Jiyong Park | 74e240b | 2018-11-27 21:27:08 +0900 | [diff] [blame] | 1031 | } |
| 1032 | |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1033 | func (a *apexBundle) installable() bool { |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1034 | return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable)) |
Jiyong Park | 92c0f9c | 2018-12-13 23:14:57 +0900 | [diff] [blame] | 1035 | } |
| 1036 | |
Nikita Ioffe | c72b5dd | 2019-12-07 17:30:22 +0000 | [diff] [blame] | 1037 | func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool { |
| 1038 | return proptools.Bool(a.properties.Test_only_no_hashtree) |
| 1039 | } |
| 1040 | |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 1041 | func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1042 | if a.vndkApex { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 1043 | return cc.VendorVariationPrefix + a.vndkVersion(config) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1044 | } |
Jiyong Park | 7c1dc61 | 2019-01-05 11:15:24 +0900 | [diff] [blame] | 1045 | if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 1046 | return cc.VendorVariationPrefix + config.PlatformVndkVersion() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1047 | } else { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 1048 | return android.CoreVariation |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1052 | func (a *apexBundle) EnableSanitizer(sanitizerName string) { |
| 1053 | if !android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1054 | a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName) |
| 1055 | } |
| 1056 | } |
| 1057 | |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 1058 | func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1059 | if android.InList(sanitizerName, a.properties.SanitizerNames) { |
| 1060 | return true |
Jiyong Park | 235e67c | 2019-02-09 11:50:56 +0900 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | // Then follow the global setting |
Jiyong Park | 388ef3f | 2019-01-28 19:47:32 +0900 | [diff] [blame] | 1064 | globalSanitizerNames := []string{} |
| 1065 | if a.Host() { |
| 1066 | globalSanitizerNames = ctx.Config().SanitizeHost() |
| 1067 | } else { |
| 1068 | arches := ctx.Config().SanitizeDeviceArch() |
| 1069 | if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { |
| 1070 | globalSanitizerNames = ctx.Config().SanitizeDevice() |
| 1071 | } |
| 1072 | } |
| 1073 | return android.InList(sanitizerName, globalSanitizerNames) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1074 | } |
| 1075 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 1076 | func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 1077 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 1078 | } |
| 1079 | |
| 1080 | func (a *apexBundle) PreventInstall() { |
| 1081 | a.properties.PreventInstall = true |
| 1082 | } |
| 1083 | |
| 1084 | func (a *apexBundle) HideFromMake() { |
| 1085 | a.properties.HideFromMake = true |
| 1086 | } |
| 1087 | |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1088 | func (a *apexBundle) MarkAsCoverageVariant(coverage bool) { |
| 1089 | a.properties.IsCoverageVariant = coverage |
| 1090 | } |
| 1091 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1092 | // TODO(jiyong) move apexFileFor* close to the apexFile type definition |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1093 | func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1094 | // Decide the APEX-local directory by the multilib of the library |
| 1095 | // In the future, we may query this to the module. |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1096 | var dirInApex string |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1097 | switch ccMod.Arch().ArchType.Multilib { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1098 | case "lib32": |
| 1099 | dirInApex = "lib" |
| 1100 | case "lib64": |
| 1101 | dirInApex = "lib64" |
| 1102 | } |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1103 | dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1104 | if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1105 | dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1106 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1107 | if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) { |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1108 | // Special case for Bionic libs and other libs installed with them. This is |
| 1109 | // to prevent those libs from being included in the search path |
| 1110 | // /apex/com.android.runtime/${LIB}. This exclusion is required because |
| 1111 | // those libs in the Runtime APEX are available via the legacy paths in |
| 1112 | // /system/lib/. By the init process, the libs in the APEX are bind-mounted |
| 1113 | // to the legacy paths and thus will be loaded into the default linker |
| 1114 | // namespace (aka "platform" namespace). If the libs are directly in |
| 1115 | // /apex/com.android.runtime/${LIB} then the same libs will be loaded again |
| 1116 | // into the runtime linker namespace, which will result in double loading of |
| 1117 | // them, which isn't supported. |
| 1118 | dirInApex = filepath.Join(dirInApex, "bionic") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1119 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1120 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1121 | fileToCopy := ccMod.OutputFile().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1122 | return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1123 | } |
| 1124 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1125 | func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1126 | dirInApex := filepath.Join("bin", cc.RelativeInstallPath()) |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1127 | if cc.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1128 | dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) |
Jiyong Park | acbf6c7 | 2019-07-09 16:19:16 +0900 | [diff] [blame] | 1129 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1130 | fileToCopy := cc.OutputFile().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1131 | af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1132 | af.symlinks = cc.Symlinks() |
| 1133 | return af |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1134 | } |
| 1135 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1136 | func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1137 | dirInApex := "bin" |
| 1138 | fileToCopy := py.HostToolPath().Path() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1139 | return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1140 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1141 | func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1142 | dirInApex := "bin" |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1143 | s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) |
| 1144 | if err != nil { |
| 1145 | ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1146 | return apexFile{} |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1147 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1148 | fileToCopy := android.PathForOutput(ctx, s) |
| 1149 | // NB: Since go binaries are static we don't need the module for anything here, which is |
| 1150 | // good since the go tool is a blueprint.Module not an android.Module like we would |
| 1151 | // normally use. |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1152 | return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1155 | func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1156 | dirInApex := filepath.Join("bin", sh.SubDir()) |
| 1157 | fileToCopy := sh.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1158 | af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1159 | af.symlinks = sh.Symlinks() |
| 1160 | return af |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1161 | } |
| 1162 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1163 | // TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency |
| 1164 | type javaLibrary interface { |
| 1165 | android.Module |
| 1166 | java.Dependency |
| 1167 | } |
| 1168 | |
| 1169 | func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1170 | dirInApex := "javalib" |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1171 | fileToCopy := lib.DexJar() |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1172 | af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib) |
| 1173 | af.jacocoReportClassesFile = lib.JacocoReportClassesFile() |
| 1174 | return af |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1175 | } |
| 1176 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1177 | func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1178 | dirInApex := filepath.Join("etc", prebuilt.SubDir()) |
| 1179 | fileToCopy := prebuilt.OutputFile() |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1180 | return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1181 | } |
| 1182 | |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1183 | func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1184 | android.Module |
| 1185 | Privileged() bool |
| 1186 | OutputFile() android.Path |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1187 | JacocoReportClassesFile() android.Path |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1188 | }, pkgName string) apexFile { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1189 | appDir := "app" |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1190 | if aapp.Privileged() { |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 1191 | appDir = "priv-app" |
| 1192 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1193 | dirInApex := filepath.Join(appDir, pkgName) |
| 1194 | fileToCopy := aapp.OutputFile() |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1195 | af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp) |
| 1196 | af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() |
| 1197 | return af |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
Roland Levillain | 935639d | 2019-08-13 14:55:28 +0100 | [diff] [blame] | 1200 | // Context "decorator", overriding the InstallBypassMake method to always reply `true`. |
| 1201 | type flattenedApexContext struct { |
| 1202 | android.ModuleContext |
| 1203 | } |
| 1204 | |
| 1205 | func (c *flattenedApexContext) InstallBypassMake() bool { |
| 1206 | return true |
| 1207 | } |
| 1208 | |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1209 | func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1210 | buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild() |
| 1211 | switch a.properties.ApexType { |
| 1212 | case imageApex: |
| 1213 | if buildFlattenedAsDefault { |
| 1214 | a.suffix = imageApexSuffix |
| 1215 | } else { |
| 1216 | a.suffix = "" |
| 1217 | a.primaryApexType = true |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 1218 | |
| 1219 | if ctx.Config().InstallExtraFlattenedApexes() { |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1220 | a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 1221 | } |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1222 | } |
| 1223 | case zipApex: |
| 1224 | if proptools.String(a.properties.Payload_type) == "zip" { |
| 1225 | a.suffix = "" |
| 1226 | a.primaryApexType = true |
| 1227 | } else { |
| 1228 | a.suffix = zipApexSuffix |
| 1229 | } |
| 1230 | case flattenedApex: |
| 1231 | if buildFlattenedAsDefault { |
| 1232 | a.suffix = "" |
| 1233 | a.primaryApexType = true |
| 1234 | } else { |
| 1235 | a.suffix = flattenedSuffix |
| 1236 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1239 | if len(a.properties.Tests) > 0 && !a.testApex { |
| 1240 | ctx.PropertyErrorf("tests", "property not allowed in apex module type") |
| 1241 | return |
| 1242 | } |
| 1243 | |
Alex Light | fc0bd7c | 2019-01-29 18:31:59 -0800 | [diff] [blame] | 1244 | handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case) |
| 1245 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1246 | // native lib dependencies |
| 1247 | var provideNativeLibs []string |
| 1248 | var requireNativeLibs []string |
| 1249 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1250 | // Check if "uses" requirements are met with dependent apexBundles |
| 1251 | var providedNativeSharedLibs []string |
| 1252 | useVendor := proptools.Bool(a.properties.Use_vendor) |
| 1253 | ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) { |
| 1254 | if ctx.OtherModuleDependencyTag(m) != usesTag { |
| 1255 | return |
| 1256 | } |
| 1257 | otherName := ctx.OtherModuleName(m) |
| 1258 | other, ok := m.(*apexBundle) |
| 1259 | if !ok { |
| 1260 | ctx.PropertyErrorf("uses", "%q is not a provider", otherName) |
| 1261 | return |
| 1262 | } |
| 1263 | if proptools.Bool(other.properties.Use_vendor) != useVendor { |
| 1264 | ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName) |
| 1265 | return |
| 1266 | } |
| 1267 | if !proptools.Bool(other.properties.Provide_cpp_shared_libs) { |
| 1268 | ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName) |
| 1269 | return |
| 1270 | } |
| 1271 | providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...) |
| 1272 | }) |
| 1273 | |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1274 | var filesInfo []apexFile |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1275 | ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1276 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1277 | depName := ctx.OtherModuleName(child) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1278 | if _, isDirectDep := parent.(*apexBundle); isDirectDep { |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1279 | if depTag != keyTag && depTag != certificateTag { |
| 1280 | a.internalDeps = append(a.internalDeps, depName) |
| 1281 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1282 | switch depTag { |
| 1283 | case sharedLibTag: |
| 1284 | if cc, ok := child.(*cc.Module); ok { |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1285 | if cc.HasStubsVariants() { |
| 1286 | provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base()) |
| 1287 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1288 | filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1289 | return true // track transitive dependencies |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1290 | } else { |
| 1291 | ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1292 | } |
| 1293 | case executableTag: |
| 1294 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1295 | filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1296 | return true // track transitive dependencies |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1297 | } else if sh, ok := child.(*android.ShBinary); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1298 | filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1299 | } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1300 | filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py)) |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1301 | } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1302 | filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb)) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1303 | } else { |
Alex Light | 778127a | 2019-02-27 14:19:50 -0800 | [diff] [blame] | 1304 | ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1305 | } |
| 1306 | case javaLibTag: |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1307 | if javaLib, ok := child.(*java.Library); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1308 | af := apexFileForJavaLibrary(ctx, javaLib) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1309 | if !af.Ok() { |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1310 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1311 | } else { |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1312 | filesInfo = append(filesInfo, af) |
| 1313 | return true // track transitive dependencies |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1314 | } |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1315 | } else if sdkLib, ok := child.(*java.SdkLibrary); ok { |
| 1316 | af := apexFileForJavaLibrary(ctx, sdkLib) |
| 1317 | if !af.Ok() { |
| 1318 | ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName) |
| 1319 | return false |
| 1320 | } |
| 1321 | filesInfo = append(filesInfo, af) |
| 1322 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 1323 | pf, _ := sdkLib.OutputFiles(".xml") |
| 1324 | if len(pf) != 1 { |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1325 | ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName) |
| 1326 | return false |
| 1327 | } |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 1328 | filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1329 | return true // track transitive dependencies |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1330 | } else { |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 1331 | ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child)) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1332 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1333 | case androidAppTag: |
| 1334 | pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName) |
| 1335 | if ap, ok := child.(*java.AndroidApp); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1336 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1337 | return true // track transitive dependencies |
| 1338 | } else if ap, ok := child.(*java.AndroidAppImport); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1339 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName)) |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 1340 | } else if ap, ok := child.(*java.AndroidTestHelperApp); ok { |
| 1341 | filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName)) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1342 | } else { |
| 1343 | ctx.PropertyErrorf("apps", "%q is not an android_app module", depName) |
| 1344 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1345 | case prebuiltTag: |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1346 | if prebuilt, ok := child.(android.PrebuiltEtcModule); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1347 | filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1348 | } else { |
| 1349 | ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc module", depName) |
| 1350 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1351 | case testTag: |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1352 | if ccTest, ok := child.(*cc.Module); ok { |
| 1353 | if ccTest.IsTestPerSrcAllTestsVariation() { |
| 1354 | // Multiple-output test module (where `test_per_src: true`). |
| 1355 | // |
| 1356 | // `ccTest` is the "" ("all tests") variation of a `test_per_src` module. |
| 1357 | // We do not add this variation to `filesInfo`, as it has no output; |
| 1358 | // however, we do add the other variations of this module as indirect |
| 1359 | // dependencies (see below). |
| 1360 | return true |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1361 | } else { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1362 | // Single-output test module (where `test_per_src: false`). |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1363 | af := apexFileForExecutable(ctx, ccTest) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1364 | af.class = nativeTest |
| 1365 | filesInfo = append(filesInfo, af) |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1366 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1367 | } else { |
| 1368 | ctx.PropertyErrorf("tests", "%q is not a cc module", depName) |
| 1369 | } |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1370 | case keyTag: |
| 1371 | if key, ok := child.(*apexKey); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1372 | a.private_key_file = key.private_key_file |
| 1373 | a.public_key_file = key.public_key_file |
Jiyong Park | ff1458f | 2018-10-12 21:49:38 +0900 | [diff] [blame] | 1374 | } else { |
| 1375 | ctx.PropertyErrorf("key", "%q is not an apex_key module", depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1376 | } |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1377 | return false |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1378 | case certificateTag: |
| 1379 | if dep, ok := child.(*java.AndroidAppCertificate); ok { |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1380 | a.container_certificate_file = dep.Certificate.Pem |
| 1381 | a.container_private_key_file = dep.Certificate.Key |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 1382 | } else { |
| 1383 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName) |
| 1384 | } |
Jiyong Park | 03b68dd | 2019-07-26 23:20:40 +0900 | [diff] [blame] | 1385 | case android.PrebuiltDepTag: |
| 1386 | // If the prebuilt is force disabled, remember to delete the prebuilt file |
| 1387 | // that might have been installed in the previous builds |
| 1388 | if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() { |
| 1389 | a.prebuiltFileToDelete = prebuilt.InstallFilename() |
| 1390 | } |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1391 | } |
Jooyung Han | 8aee204 | 2019-10-29 05:08:31 +0900 | [diff] [blame] | 1392 | } else if !a.vndkApex { |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1393 | // indirect dependencies |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1394 | if am, ok := child.(android.ApexModule); ok { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1395 | // We cannot use a switch statement on `depTag` here as the checked |
| 1396 | // tags used below are private (e.g. `cc.sharedDepTag`). |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1397 | if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1398 | if cc, ok := child.(*cc.Module); ok { |
| 1399 | if android.InList(cc.Name(), providedNativeSharedLibs) { |
| 1400 | // If we're using a shared library which is provided from other APEX, |
| 1401 | // don't include it in this APEX |
| 1402 | return false |
Jiyong Park | ac2bacd | 2019-02-20 21:49:26 +0900 | [diff] [blame] | 1403 | } |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 1404 | if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1405 | // If the dependency is a stubs lib, don't include it in this APEX, |
| 1406 | // but make sure that the lib is installed on the device. |
| 1407 | // In case no APEX is having the lib, the lib is installed to the system |
| 1408 | // partition. |
| 1409 | // |
| 1410 | // Always include if we are a host-apex however since those won't have any |
| 1411 | // system libraries. |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1412 | if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) { |
| 1413 | a.requiredDeps = append(a.requiredDeps, cc.Name()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1414 | } |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1415 | a.externalDeps = append(a.externalDeps, depName) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1416 | requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base()) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1417 | // Don't track further |
| 1418 | return false |
| 1419 | } |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1420 | af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1421 | af.transitiveDep = true |
| 1422 | filesInfo = append(filesInfo, af) |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1423 | a.internalDeps = append(a.internalDeps, depName) |
| 1424 | a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1425 | return true // track transitive dependencies |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1426 | } |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1427 | } else if cc.IsTestPerSrcDepTag(depTag) { |
| 1428 | if cc, ok := child.(*cc.Module); ok { |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1429 | af := apexFileForExecutable(ctx, cc) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1430 | // Handle modules created as `test_per_src` variations of a single test module: |
| 1431 | // use the name of the generated test binary (`fileToCopy`) instead of the name |
| 1432 | // of the original test module (`depName`, shared by all `test_per_src` |
| 1433 | // variations of that module). |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1434 | af.moduleName = filepath.Base(af.builtFile.String()) |
| 1435 | af.transitiveDep = true |
| 1436 | filesInfo = append(filesInfo, af) |
| 1437 | return true // track transitive dependencies |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1438 | } |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 1439 | } else if java.IsJniDepTag(depTag) { |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1440 | a.externalDeps = append(a.externalDeps, depName) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1441 | return true |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1442 | } else if java.IsStaticLibDepTag(depTag) { |
| 1443 | a.internalDeps = append(a.internalDeps, depName) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1444 | } else if am.CanHaveApexVariants() && am.IsInstallableToApex() { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1445 | ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | return false |
| 1450 | }) |
| 1451 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1452 | // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. |
| 1453 | // Build rules are generated by the dexpreopt singleton, and here we access build artifacts |
| 1454 | // via the global boot image config. |
| 1455 | if a.artApex { |
| 1456 | for arch, files := range java.DexpreoptedArtApexJars(ctx) { |
| 1457 | dirInApex := filepath.Join("javalib", arch.String()) |
| 1458 | for _, f := range files { |
| 1459 | localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String()) |
Jiyong Park | 1833cef | 2019-12-13 13:28:36 +0900 | [diff] [blame] | 1460 | af := newApexFile(ctx, f, localModule, dirInApex, etc, nil) |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 1461 | filesInfo = append(filesInfo, af) |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | |
Jiyong Park | 0ca3ce8 | 2019-02-18 15:25:04 +0900 | [diff] [blame] | 1466 | if a.private_key_file == nil { |
Jiyong Park | fa0a373 | 2018-11-09 05:52:26 +0900 | [diff] [blame] | 1467 | ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key)) |
| 1468 | return |
| 1469 | } |
| 1470 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1471 | // remove duplicates in filesInfo |
| 1472 | removeDup := func(filesInfo []apexFile) []apexFile { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1473 | encountered := make(map[string]bool) |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1474 | result := []apexFile{} |
| 1475 | for _, f := range filesInfo { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1476 | dest := filepath.Join(f.installDir, f.builtFile.Base()) |
| 1477 | if !encountered[dest] { |
| 1478 | encountered[dest] = true |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1479 | result = append(result, f) |
| 1480 | } |
| 1481 | } |
| 1482 | return result |
| 1483 | } |
| 1484 | filesInfo = removeDup(filesInfo) |
| 1485 | |
| 1486 | // to have consistent build rules |
| 1487 | sort.Slice(filesInfo, func(i, j int) bool { |
| 1488 | return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String() |
| 1489 | }) |
| 1490 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1491 | // check apex_available requirements |
Jiyong Park | 3814f4d | 2019-12-02 13:08:53 +0900 | [diff] [blame] | 1492 | if !ctx.Host() && !a.testApex { |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1493 | for _, fi := range filesInfo { |
| 1494 | if am, ok := fi.module.(android.ApexModule); ok { |
Anton Hansson | 5053c29 | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1495 | // vndk {enabled:true} implies visibility to the vndk apex |
| 1496 | if ccm, ok := fi.module.(*cc.Module); ok && ccm.IsVndk() && a.vndkApex { |
| 1497 | continue |
| 1498 | } |
| 1499 | |
| 1500 | if !am.AvailableFor(ctx.ModuleName()) && !whitelistedApexAvailable(ctx.ModuleName(), a.vndkApex, fi.module) { |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1501 | ctx.ModuleErrorf("requires %q that is not available for the APEX", fi.module.Name()) |
Jiyong Park | 3814f4d | 2019-12-02 13:08:53 +0900 | [diff] [blame] | 1502 | // don't stop so that we can report other violations in the same run |
Jiyong Park | 583a226 | 2019-10-08 20:55:38 +0900 | [diff] [blame] | 1503 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1508 | // prepend the name of this APEX to the module names. These names will be the names of |
| 1509 | // modules that will be defined if the APEX is flattened. |
| 1510 | for i := range filesInfo { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 1511 | filesInfo[i].moduleName = filesInfo[i].moduleName + "." + a.Name() + a.suffix |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1512 | } |
| 1513 | |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 1514 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 1515 | a.filesInfo = filesInfo |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1516 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1517 | if a.properties.ApexType != zipApex { |
| 1518 | if a.properties.File_contexts == nil { |
| 1519 | a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") |
| 1520 | } else { |
| 1521 | a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) |
| 1522 | if a.Platform() { |
| 1523 | if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched { |
| 1524 | ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts) |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() { |
| 1529 | ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) |
| 1530 | return |
| 1531 | } |
| 1532 | } |
| 1533 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1534 | // prepare apex_manifest.json |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1535 | a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) |
| 1536 | |
| 1537 | a.setCertificateAndPrivateKey(ctx) |
| 1538 | if a.properties.ApexType == flattenedApex { |
| 1539 | a.buildFlattenedApex(ctx) |
| 1540 | } else { |
| 1541 | a.buildUnflattenedApex(ctx) |
| 1542 | } |
| 1543 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 1544 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
Jiyong Park | 956305c | 2020-01-09 12:32:06 +0900 | [diff] [blame] | 1545 | |
| 1546 | a.buildApexDependencyInfo(ctx) |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 1547 | } |
| 1548 | |
Anton Hansson | 5053c29 | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1549 | func whitelistedApexAvailable(apex string, is_vndk bool, module android.Module) bool { |
| 1550 | key := apex |
| 1551 | key = strings.Replace(key, "test_", "", 1) |
| 1552 | key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1) |
| 1553 | key = strings.Replace(key, "com.android.art.release", "com.android.art", 1) |
| 1554 | |
| 1555 | moduleName := module.Name() |
| 1556 | if strings.Contains(moduleName, "prebuilt_libclang_rt") { |
| 1557 | // This module has variants that depend on the product being built. |
| 1558 | moduleName = "prebuilt_libclang_rt" |
| 1559 | } |
| 1560 | |
| 1561 | if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) { |
| 1562 | return true |
| 1563 | } |
| 1564 | |
| 1565 | return false |
| 1566 | } |
| 1567 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1568 | func newApexBundle() *apexBundle { |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1569 | module := &apexBundle{} |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1570 | module.AddProperties(&module.properties) |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1571 | module.AddProperties(&module.targetProperties) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1572 | module.AddProperties(&module.overridableProperties) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1573 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
Jiyong Park | 397e55e | 2018-10-24 21:09:55 +0900 | [diff] [blame] | 1574 | return class == android.Device && ctx.Config().DevicePrefer32BitExecutables() |
| 1575 | }) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1576 | android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1577 | android.InitDefaultableModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1578 | android.InitSdkAwareModule(module) |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 1579 | android.InitOverridableModule(module, &module.overridableProperties.Overrides) |
Jiyong Park | 48ca7dc | 2018-10-10 14:01:00 +0900 | [diff] [blame] | 1580 | return module |
| 1581 | } |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1582 | |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1583 | func ApexBundleFactory(testApex bool, artApex bool) android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1584 | bundle := newApexBundle() |
| 1585 | bundle.testApex = testApex |
Ulyana Trafimovich | de53441 | 2019-11-08 10:51:01 +0000 | [diff] [blame] | 1586 | bundle.artApex = artApex |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1587 | return bundle |
| 1588 | } |
| 1589 | |
| 1590 | func testApexBundleFactory() android.Module { |
| 1591 | bundle := newApexBundle() |
| 1592 | bundle.testApex = true |
| 1593 | return bundle |
| 1594 | } |
| 1595 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1596 | func BundleFactory() android.Module { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1597 | return newApexBundle() |
| 1598 | } |
| 1599 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1600 | // |
| 1601 | // Defaults |
| 1602 | // |
| 1603 | type Defaults struct { |
| 1604 | android.ModuleBase |
| 1605 | android.DefaultsModuleBase |
| 1606 | } |
| 1607 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1608 | func defaultsFactory() android.Module { |
| 1609 | return DefaultsFactory() |
| 1610 | } |
| 1611 | |
| 1612 | func DefaultsFactory(props ...interface{}) android.Module { |
| 1613 | module := &Defaults{} |
| 1614 | |
| 1615 | module.AddProperties(props...) |
| 1616 | module.AddProperties( |
| 1617 | &apexBundleProperties{}, |
| 1618 | &apexTargetBundleProperties{}, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 1619 | &overridableProperties{}, |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 1620 | ) |
| 1621 | |
| 1622 | android.InitDefaultsModule(module) |
| 1623 | return module |
| 1624 | } |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 1625 | |
| 1626 | // |
| 1627 | // OverrideApex |
| 1628 | // |
| 1629 | type OverrideApex struct { |
| 1630 | android.ModuleBase |
| 1631 | android.OverrideModuleBase |
| 1632 | } |
| 1633 | |
| 1634 | func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1635 | // All the overrides happen in the base module. |
| 1636 | } |
| 1637 | |
| 1638 | // override_apex is used to create an apex module based on another apex module |
| 1639 | // by overriding some of its properties. |
| 1640 | func overrideApexFactory() android.Module { |
| 1641 | m := &OverrideApex{} |
| 1642 | m.AddProperties(&overridableProperties{}) |
| 1643 | |
| 1644 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 1645 | android.InitOverrideModule(m) |
| 1646 | return m |
| 1647 | } |