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