blob: c010d4e198af733e7c18e704db618d76c263e6cf [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// 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
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090022 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Jiyong Park0f80c182020-01-31 02:49:53 +090096 m["com.android.adbd"] = []string{
97 "adbd",
98 "bcm_object",
99 "fmtlib",
100 "libadbconnection_server",
101 "libadbd",
102 "libadbd_auth",
103 "libadbd_core",
104 "libadbd_services",
105 "libasyncio",
106 "libbacktrace_headers",
107 "libbase",
108 "libbase_headers",
109 "libbuildversion",
110 "libc++",
111 "libcap",
112 "libcrypto",
113 "libcrypto_utils",
114 "libcutils",
115 "libcutils_headers",
116 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +0900117 "liblog_headers",
118 "libmdnssd",
119 "libminijail",
120 "libminijail_gen_constants",
121 "libminijail_gen_constants_obj",
122 "libminijail_gen_syscall",
123 "libminijail_gen_syscall_obj",
124 "libminijail_generated",
125 "libpackagelistparser",
126 "libpcre2",
127 "libprocessgroup_headers",
128 "libqemu_pipe",
129 "libselinux",
130 "libsystem_headers",
131 "libutils_headers",
132 }
133 //
134 // Module separator
135 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000136 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "art_cmdlineparser_headers",
138 "art_disassembler_headers",
139 "art_libartbase_headers",
140 "bcm_object",
141 "bionic_libc_platform_headers",
142 "core-repackaged-icu4j",
143 "cpp-define-generator-asm-support",
144 "cpp-define-generator-definitions",
145 "crtbegin_dynamic",
146 "crtbegin_dynamic1",
147 "crtbegin_so1",
148 "crtbrand",
149 "conscrypt.module.intra.core.api.stubs",
150 "dex2oat_headers",
151 "dt_fd_forward_export",
152 "fmtlib",
153 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "javavm_headers",
156 "jni_platform_headers",
157 "libPlatformProperties",
158 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libandroidicuinit",
161 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libbacktrace",
165 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900166 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000167 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900168 "libc++_static",
169 "libc++abi",
170 "libc++demangle",
171 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "libdexfile_all_headers",
174 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libfdlibm",
179 "libgtest_prod",
180 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000181 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "libicuuc_headers",
183 "libicuuc_stubdata",
184 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "liblog_headers",
186 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "liblzma",
188 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libnativebridge-headers",
190 "libnativehelper_header_only",
191 "libnativeloader-headers",
192 "libnpt_headers",
193 "libopenjdkjvmti_headers",
194 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libprotobuf-cpp-lite",
197 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000198 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900199 "libv8",
200 "libv8base",
201 "libv8gen",
202 "libv8platform",
203 "libv8sampler",
204 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "libvixl",
206 "libvixld",
207 "libz",
208 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900209 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000211 m["com.android.art.debug"] = artApexContents
212 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000213 //
214 // Module separator
215 //
216 m["com.android.bluetooth.updatable"] = []string{
217 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000218 "android.hardware.bluetooth.a2dp@1.0",
219 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900220 "android.hardware.bluetooth@1.0",
221 "android.hardware.bluetooth@1.1",
222 "android.hardware.graphics.bufferqueue@1.0",
223 "android.hardware.graphics.bufferqueue@2.0",
224 "android.hardware.graphics.common@1.0",
225 "android.hardware.graphics.common@1.1",
226 "android.hardware.graphics.common@1.2",
227 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000228 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900229 "android.hidl.token@1.0",
230 "android.hidl.token@1.0-utils",
231 "avrcp-target-service",
232 "avrcp_headers",
233 "bcm_object",
234 "bluetooth-protos-lite",
235 "bluetooth.mapsapi",
236 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900237 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "fmtlib",
239 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900240 "ipmemorystore-aidl-interfaces-V5-java",
241 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "internal_include_headers",
243 "lib-bt-packets",
244 "lib-bt-packets-avrcp",
245 "lib-bt-packets-base",
246 "libFraunhoferAAC",
247 "libaudio-a2dp-hw-utils",
248 "libaudio-hearing-aid-hw-utils",
249 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000250 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900251 "libbase_headers",
252 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000253 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900254 "libbluetooth-types",
255 "libbluetooth-types-header",
256 "libbluetooth_gd",
257 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 "libbt-audio-hal-interface",
260 "libbt-bta",
261 "libbt-common",
262 "libbt-hci",
263 "libbt-platform-protos-lite",
264 "libbt-protos-lite",
265 "libbt-sbc-decoder",
266 "libbt-sbc-encoder",
267 "libbt-stack",
268 "libbt-utils",
269 "libbtcore",
270 "libbtdevice",
271 "libbte",
272 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000273 "libc++",
274 "libchrome",
275 "libcrypto",
276 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900277 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000278 "libevent",
279 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "libg722codec",
281 "libgtest_prod",
282 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000283 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900284 "libhidlbase-impl-internal",
285 "libhidltransport-impl-internal",
286 "libhwbinder-impl-internal",
287 "libjsoncpp",
288 "liblog_headers",
289 "libmedia_headers",
290 "libmodpb64",
291 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000292 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900293 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000294 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "libprotobuf-java-lite",
296 "libprotobuf-java-micro",
297 "libstagefright_foundation_headers",
298 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000299 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 "libstatssocket",
301 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000302 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900304 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000305 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900306 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900307 "net-utils-services-common",
308 "netd_aidl_interface-unstable-java",
309 "netd_event_listener_interface-java",
310 "netlink-client",
311 "networkstack-aidl-interfaces-unstable-java",
312 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "sap-api-java-static",
314 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000315 }
316 //
317 // Module separator
318 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000320 //
321 // Module separator
322 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900323 m["com.android.conscrypt"] = []string{
324 "bcm_object",
325 "boringssl_self_test",
326 "libc++",
327 "libcrypto",
328 "libnativehelper_header_only",
329 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900330 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900331 }
332 //
333 // Module separator
334 //
335 m["com.android.extservices"] = []string{
336 "flatbuffer_headers",
337 "liblua",
338 "libtextclassifier",
339 "libtextclassifier_hash_static",
340 "libtflite_static",
341 "libutf",
342 "libz_current",
343 "tensorflow_headers",
344 }
345 //
346 // Module separator
347 //
348 m["com.android.cronet"] = []string{
349 "cronet_impl_common_java",
350 "cronet_impl_native_java",
351 "cronet_impl_platform_java",
352 "libcronet.80.0.3986.0",
353 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900354 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900355 "prebuilt_libcronet.80.0.3986.0",
356 }
357 //
358 // Module separator
359 //
360 m["com.android.neuralnetworks"] = []string{
361 "android.hardware.neuralnetworks@1.0",
362 "android.hardware.neuralnetworks@1.1",
363 "android.hardware.neuralnetworks@1.2",
364 "android.hardware.neuralnetworks@1.3",
365 "android.hidl.allocator@1.0",
366 "android.hidl.memory.token@1.0",
367 "android.hidl.memory@1.0",
368 "android.hidl.safe_union@1.0",
369 "bcm_object",
370 "fmtlib",
371 "gemmlowp_headers",
372 "libarect",
373 "libbacktrace_headers",
374 "libbase",
375 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900376 "libbuildversion",
377 "libc++",
378 "libcrypto",
379 "libcrypto_static",
380 "libcutils",
381 "libcutils_headers",
382 "libeigen",
383 "libfmq",
384 "libhidlbase",
385 "libhidlbase-impl-internal",
386 "libhidlmemory",
387 "libhidltransport-impl-internal",
388 "libhwbinder-impl-internal",
389 "libjsoncpp",
390 "liblog_headers",
391 "libmath",
392 "libneuralnetworks_common",
393 "libneuralnetworks_headers",
394 "libprocessgroup",
395 "libprocessgroup_headers",
396 "libprocpartition",
397 "libsync",
398 "libsystem_headers",
399 "libtextclassifier_hash",
400 "libtextclassifier_hash_headers",
401 "libtextclassifier_hash_static",
402 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900403 "libutils_headers",
404 "philox_random",
405 "philox_random_headers",
406 "tensorflow_headers",
407 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000408 //
409 // Module separator
410 //
411 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000412 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900413 "android.hardware.cas.native@1.0",
414 "android.hardware.cas@1.0",
415 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000416 "android.hardware.configstore@1.0",
417 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000418 "android.hardware.graphics.allocator@2.0",
419 "android.hardware.graphics.allocator@3.0",
420 "android.hardware.graphics.bufferqueue@1.0",
421 "android.hardware.graphics.bufferqueue@2.0",
422 "android.hardware.graphics.common@1.0",
423 "android.hardware.graphics.common@1.1",
424 "android.hardware.graphics.common@1.2",
425 "android.hardware.graphics.mapper@2.0",
426 "android.hardware.graphics.mapper@2.1",
427 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000429 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "android.hidl.allocator@1.0",
431 "android.hidl.memory.token@1.0",
432 "android.hidl.memory@1.0",
433 "android.hidl.token@1.0",
434 "android.hidl.token@1.0-utils",
435 "bcm_object",
436 "bionic_libc_platform_headers",
437 "fmtlib",
438 "gl_headers",
439 "libEGL",
440 "libEGL_blobCache",
441 "libEGL_getProcAddress",
442 "libFLAC",
443 "libFLAC-config",
444 "libFLAC-headers",
445 "libGLESv2",
446 "libaacextractor",
447 "libamrextractor",
448 "libarect",
449 "libasync_safe",
450 "libaudio_system_headers",
451 "libaudioclient",
452 "libaudioclient_headers",
453 "libaudiofoundation",
454 "libaudiofoundation_headers",
455 "libaudiomanager",
456 "libaudiopolicy",
457 "libaudioutils",
458 "libaudioutils_fixedfft",
459 "libbacktrace",
460 "libbacktrace_headers",
461 "libbase",
462 "libbase_headers",
463 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900464 "libbluetooth-types-header",
465 "libbufferhub",
466 "libbufferhub_headers",
467 "libbufferhubqueue",
468 "libc++",
469 "libc_headers",
470 "libc_malloc_debug_backtrace",
471 "libcamera_client",
472 "libcamera_metadata",
473 "libcrypto",
474 "libcutils",
475 "libcutils_headers",
476 "libdexfile_external_headers",
477 "libdexfile_support",
478 "libdvr_headers",
479 "libexpat",
480 "libfifo",
481 "libflacextractor",
482 "libgrallocusage",
483 "libgraphicsenv",
484 "libgui",
485 "libgui_headers",
486 "libhardware_headers",
487 "libhidlbase",
488 "libhidlbase-impl-internal",
489 "libhidlmemory",
490 "libhidltransport-impl-internal",
491 "libhwbinder-impl-internal",
492 "libinput",
493 "libjsoncpp",
494 "liblog_headers",
495 "liblzma",
496 "libmath",
497 "libmedia",
498 "libmedia_codeclist",
499 "libmedia_headers",
500 "libmedia_helper",
501 "libmedia_helper_headers",
502 "libmedia_midiiowrapper",
503 "libmedia_omx",
504 "libmediautils",
505 "libmidiextractor",
506 "libmkvextractor",
507 "libmp3extractor",
508 "libmp4extractor",
509 "libmpeg2extractor",
510 "libnativebase_headers",
511 "libnativebridge-headers",
512 "libnativebridge_lazy",
513 "libnativeloader-headers",
514 "libnativeloader_lazy",
515 "libnativewindow_headers",
516 "libnblog",
517 "liboggextractor",
518 "libpackagelistparser",
519 "libpcre2",
520 "libpdx",
521 "libpdx_default_transport",
522 "libpdx_headers",
523 "libpdx_uds",
524 "libprocessgroup",
525 "libprocessgroup_headers",
526 "libprocinfo",
527 "libselinux",
528 "libsonivox",
529 "libspeexresampler",
530 "libspeexresampler",
531 "libstagefright_esds",
532 "libstagefright_flacdec",
533 "libstagefright_flacdec",
534 "libstagefright_foundation",
535 "libstagefright_foundation_headers",
536 "libstagefright_foundation_without_imemory",
537 "libstagefright_headers",
538 "libstagefright_id3",
539 "libstagefright_metadatautils",
540 "libstagefright_mpeg2extractor",
541 "libstagefright_mpeg2support",
542 "libsync",
543 "libsystem_headers",
544 "libui",
545 "libui_headers",
546 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libutils_headers",
548 "libvibrator",
549 "libvorbisidec",
550 "libwavextractor",
551 "libwebm",
552 "media_ndk_headers",
553 "media_plugin_headers",
554 "updatable-media",
555 }
556 //
557 // Module separator
558 //
559 m["com.android.media.swcodec"] = []string{
560 "android.frameworks.bufferhub@1.0",
561 "android.hardware.common-ndk_platform",
562 "android.hardware.configstore-utils",
563 "android.hardware.configstore@1.0",
564 "android.hardware.configstore@1.1",
565 "android.hardware.graphics.allocator@2.0",
566 "android.hardware.graphics.allocator@3.0",
567 "android.hardware.graphics.bufferqueue@1.0",
568 "android.hardware.graphics.bufferqueue@2.0",
569 "android.hardware.graphics.common-ndk_platform",
570 "android.hardware.graphics.common@1.0",
571 "android.hardware.graphics.common@1.1",
572 "android.hardware.graphics.common@1.2",
573 "android.hardware.graphics.mapper@2.0",
574 "android.hardware.graphics.mapper@2.1",
575 "android.hardware.graphics.mapper@3.0",
576 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000577 "android.hardware.media.bufferpool@2.0",
578 "android.hardware.media.c2@1.0",
579 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "android.hardware.media@1.0",
581 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900583 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000584 "android.hidl.safe_union@1.0",
585 "android.hidl.token@1.0",
586 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "fmtlib",
588 "libEGL",
589 "libFLAC",
590 "libFLAC-config",
591 "libFLAC-headers",
592 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900593 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libarect",
595 "libasync_safe",
596 "libaudio_system_headers",
597 "libaudioutils",
598 "libaudioutils",
599 "libaudioutils_fixedfft",
600 "libavcdec",
601 "libavcenc",
602 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000603 "libavservices_minijail",
604 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000606 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900607 "libbase_headers",
608 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900609 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900610 "libbluetooth-types-header",
611 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000612 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900613 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000614 "libcap",
615 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000617 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "libcodec2_hidl@1.1",
619 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000620 "libcodec2_soft_aacdec",
621 "libcodec2_soft_aacenc",
622 "libcodec2_soft_amrnbdec",
623 "libcodec2_soft_amrnbenc",
624 "libcodec2_soft_amrwbdec",
625 "libcodec2_soft_amrwbenc",
626 "libcodec2_soft_av1dec_gav1",
627 "libcodec2_soft_avcdec",
628 "libcodec2_soft_avcenc",
629 "libcodec2_soft_common",
630 "libcodec2_soft_flacdec",
631 "libcodec2_soft_flacenc",
632 "libcodec2_soft_g711alawdec",
633 "libcodec2_soft_g711mlawdec",
634 "libcodec2_soft_gsmdec",
635 "libcodec2_soft_h263dec",
636 "libcodec2_soft_h263enc",
637 "libcodec2_soft_hevcdec",
638 "libcodec2_soft_hevcenc",
639 "libcodec2_soft_mp3dec",
640 "libcodec2_soft_mpeg2dec",
641 "libcodec2_soft_mpeg4dec",
642 "libcodec2_soft_mpeg4enc",
643 "libcodec2_soft_opusdec",
644 "libcodec2_soft_opusenc",
645 "libcodec2_soft_rawdec",
646 "libcodec2_soft_vorbisdec",
647 "libcodec2_soft_vp8dec",
648 "libcodec2_soft_vp8enc",
649 "libcodec2_soft_vp9dec",
650 "libcodec2_soft_vp9enc",
651 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000656 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900657 "libfmq",
658 "libgav1",
659 "libgralloctypes",
660 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libgsm",
663 "libgui_bufferqueue_static",
664 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000665 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900666 "libhardware_headers",
667 "libhevcdec",
668 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000671 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "libhidltransport-impl-internal",
673 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000674 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900675 "libjpeg",
676 "libjsoncpp",
677 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000678 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900679 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000680 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000682 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900683 "libminijail_gen_constants",
684 "libminijail_gen_constants_obj",
685 "libminijail_gen_syscall",
686 "libminijail_gen_syscall_obj",
687 "libminijail_generated",
688 "libmpeg2dec",
689 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000690 "libnativebridge_lazy",
691 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900692 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000693 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000695 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000697 "libscudo_wrapper",
698 "libsfplugin_ccodec_utils",
699 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 "libstagefright_amrnbdec",
701 "libstagefright_amrnbenc",
702 "libstagefright_amrwbdec",
703 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000704 "libstagefright_bufferpool@2.0.1",
705 "libstagefright_bufferqueue_helper",
706 "libstagefright_enc_common",
707 "libstagefright_flacdec",
708 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libstagefright_foundation_headers",
710 "libstagefright_headers",
711 "libstagefright_m4vh263dec",
712 "libstagefright_m4vh263enc",
713 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000714 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000716 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900717 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000718 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900719 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000720 "libvorbisidec",
721 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900722 "libyuv",
723 "libyuv_static",
724 "media_ndk_headers",
725 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000726 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900727 }
728 //
729 // Module separator
730 //
731 m["com.android.mediaprovider"] = []string{
732 "MediaProvider",
733 "MediaProviderGoogle",
734 "fmtlib_ndk",
735 "guava",
736 "libbase_ndk",
737 "libfuse",
738 "libfuse_jni",
739 "libnativehelper_header_only",
740 }
741 //
742 // Module separator
743 //
744 m["com.android.permission"] = []string{
745 "androidx.annotation_annotation",
746 "androidx.annotation_annotation-nodeps",
747 "androidx.lifecycle_lifecycle-common",
748 "androidx.lifecycle_lifecycle-common-java8",
749 "androidx.lifecycle_lifecycle-common-java8-nodeps",
750 "androidx.lifecycle_lifecycle-common-nodeps",
751 "kotlin-annotations",
752 "kotlin-stdlib",
753 "kotlin-stdlib-jdk7",
754 "kotlin-stdlib-jdk8",
755 "kotlinx-coroutines-android",
756 "kotlinx-coroutines-android-nodeps",
757 "kotlinx-coroutines-core",
758 "kotlinx-coroutines-core-nodeps",
759 "libprotobuf-java-lite",
760 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000761 }
762 //
763 // Module separator
764 //
765 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900766 "bionic_libc_platform_headers",
767 "fmtlib",
768 "libarm-optimized-routines-math",
769 "libasync_safe",
770 "libasync_safe_headers",
771 "libbacktrace_headers",
772 "libbase",
773 "libbase_headers",
774 "libc++",
775 "libc_aeabi",
776 "libc_bionic",
777 "libc_bionic_ndk",
778 "libc_bootstrap",
779 "libc_common",
780 "libc_common_shared",
781 "libc_common_static",
782 "libc_dns",
783 "libc_dynamic_dispatch",
784 "libc_fortify",
785 "libc_freebsd",
786 "libc_freebsd_large_stack",
787 "libc_gdtoa",
788 "libc_headers",
789 "libc_init_dynamic",
790 "libc_init_static",
791 "libc_jemalloc_wrapper",
792 "libc_netbsd",
793 "libc_nomalloc",
794 "libc_nopthread",
795 "libc_openbsd",
796 "libc_openbsd_large_stack",
797 "libc_openbsd_ndk",
798 "libc_pthread",
799 "libc_static_dispatch",
800 "libc_syscalls",
801 "libc_tzcode",
802 "libc_unwind_static",
803 "libcutils",
804 "libcutils_headers",
805 "libdebuggerd",
806 "libdebuggerd_common_headers",
807 "libdebuggerd_handler_core",
808 "libdebuggerd_handler_fallback",
809 "libdexfile_external_headers",
810 "libdexfile_support",
811 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900812 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900813 "libgtest_prod",
814 "libjemalloc5",
815 "liblinker_main",
816 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900817 "liblog_headers",
818 "liblz4",
819 "liblzma",
820 "libprocessgroup_headers",
821 "libprocinfo",
822 "libpropertyinfoparser",
823 "libscudo",
824 "libstdc++",
825 "libsystem_headers",
826 "libsystemproperties",
827 "libtombstoned_client_static",
828 "libunwindstack",
829 "libutils_headers",
830 "libz",
831 "libziparchive",
832 }
833 //
834 // Module separator
835 //
836 m["com.android.resolv"] = []string{
837 "bcm_object",
838 "dnsresolver_aidl_interface-unstable-ndk_platform",
839 "fmtlib",
840 "libbacktrace_headers",
841 "libbase",
842 "libbase_headers",
843 "libc++",
844 "libcrypto",
845 "libcutils",
846 "libcutils_headers",
847 "libgtest_prod",
848 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900849 "liblog_headers",
850 "libnativehelper_header_only",
851 "libnetd_client_headers",
852 "libnetd_resolv",
853 "libnetdutils",
854 "libprocessgroup",
855 "libprocessgroup_headers",
856 "libprotobuf-cpp-lite",
857 "libssl",
858 "libstatslog_resolv",
859 "libstatspush_compat",
860 "libstatssocket",
861 "libstatssocket_headers",
862 "libsystem_headers",
863 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900864 "libutils_headers",
865 "netd_event_listener_interface-ndk_platform",
866 "server_configurable_flags",
867 "stats_proto",
868 }
869 //
870 // Module separator
871 //
872 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000873 "libbase",
874 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900875 "libnativehelper_compat_libc++",
876 "android.hardware.tetheroffload.config@1.0",
877 "fmtlib",
878 "libbacktrace_headers",
879 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900880 "libcgrouprc",
881 "libcgrouprc_format",
882 "libcutils",
883 "libcutils_headers",
884 "libhidlbase",
885 "libhidlbase-impl-internal",
886 "libhidltransport-impl-internal",
887 "libhwbinder-impl-internal",
888 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900889 "liblog_headers",
890 "libprocessgroup",
891 "libprocessgroup_headers",
892 "libsystem_headers",
893 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900894 "libutils_headers",
895 "libvndksupport",
896 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000897 }
898 //
899 // Module separator
900 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900901 m["com.android.wifi"] = []string{
902 "PlatformProperties",
903 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900904 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900905 "android.hardware.wifi-V1.1-java",
906 "android.hardware.wifi-V1.2-java",
907 "android.hardware.wifi-V1.3-java",
908 "android.hardware.wifi-V1.4-java",
909 "android.hardware.wifi.hostapd-V1.0-java",
910 "android.hardware.wifi.hostapd-V1.1-java",
911 "android.hardware.wifi.hostapd-V1.2-java",
912 "android.hardware.wifi.supplicant-V1.0-java",
913 "android.hardware.wifi.supplicant-V1.1-java",
914 "android.hardware.wifi.supplicant-V1.2-java",
915 "android.hardware.wifi.supplicant-V1.3-java",
916 "android.hidl.base-V1.0-java",
917 "android.hidl.manager-V1.0-java",
918 "android.hidl.manager-V1.1-java",
919 "android.hidl.manager-V1.2-java",
920 "androidx.annotation_annotation",
921 "androidx.annotation_annotation-nodeps",
922 "bouncycastle-unbundled",
923 "dnsresolver_aidl_interface-V2-java",
924 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900925 "framework-wifi-pre-jarjar",
926 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900927 "ipmemorystore-aidl-interfaces-V3-java",
928 "ipmemorystore-aidl-interfaces-java",
929 "ksoap2",
930 "libbacktrace_headers",
931 "libbase",
932 "libbase_headers",
933 "libc++",
934 "libcutils",
935 "libcutils_headers",
936 "liblog_headers",
937 "libnanohttpd",
938 "libprocessgroup",
939 "libprocessgroup_headers",
940 "libprotobuf-java-lite",
941 "libprotobuf-java-nano",
942 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900943 "libutils_headers",
944 "libwifi-jni",
945 "net-utils-services-common",
946 "netd_aidl_interface-V2-java",
947 "netd_aidl_interface-unstable-java",
948 "netd_event_listener_interface-java",
949 "netlink-client",
950 "networkstack-aidl-interfaces-unstable-java",
951 "networkstack-client",
952 "services.net",
953 "wifi-lite-protos",
954 "wifi-nano-protos",
955 "wifi-service-pre-jarjar",
956 "wifi-service-resources",
957 "prebuilt_androidx.annotation_annotation-nodeps",
958 }
959 //
960 // Module separator
961 //
962 m["com.android.sdkext"] = []string{
963 "fmtlib_ndk",
964 "libbase_ndk",
965 "libprotobuf-cpp-lite-ndk",
966 }
967 //
968 // Module separator
969 //
970 m["com.android.os.statsd"] = []string{
971 "libbacktrace_headers",
972 "libbase_headers",
973 "libc++",
974 "libcutils",
975 "libcutils_headers",
976 "liblog_headers",
977 "libprocessgroup_headers",
978 "libstatssocket",
979 "libsystem_headers",
980 "libutils_headers",
981 }
982 //
983 // Module separator
984 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000985 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900986 "crtbegin_dynamic",
987 "crtbegin_dynamic1",
988 "crtbegin_so",
989 "crtbegin_so1",
990 "crtbegin_static",
991 "crtbrand",
992 "crtend_android",
993 "crtend_so",
994 "libatomic",
995 "libc++_static",
996 "libc++abi",
997 "libc++demangle",
998 "libc_headers",
999 "libclang_rt",
1000 "libgcc_stripped",
1001 "libprofile-clang-extras",
1002 "libprofile-clang-extras_ndk",
1003 "libprofile-extras",
1004 "libprofile-extras_ndk",
1005 "libunwind_llvm",
1006 "ndk_crtbegin_dynamic.27",
1007 "ndk_crtbegin_so.16",
1008 "ndk_crtbegin_so.19",
1009 "ndk_crtbegin_so.21",
1010 "ndk_crtbegin_so.24",
1011 "ndk_crtbegin_so.27",
1012 "ndk_crtend_android.27",
1013 "ndk_crtend_so.16",
1014 "ndk_crtend_so.19",
1015 "ndk_crtend_so.21",
1016 "ndk_crtend_so.24",
1017 "ndk_crtend_so.27",
1018 "ndk_libandroid_support",
1019 "ndk_libc++_static",
1020 "ndk_libc++abi",
1021 "ndk_libunwind",
1022 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001023 return m
1024}
1025
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001027 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001028 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001029 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001030 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001031 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001032 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033
Jooyung Han31c470b2019-10-18 16:26:59 +09001034 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001035 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001036
1037 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1038 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1039 sort.Strings(*apexFileContextsInfos)
1040 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1041 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001042}
1043
Jooyung Han31c470b2019-10-18 16:26:59 +09001044func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1045 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1046 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1047}
1048
Jiyong Parkd1063c12019-07-17 20:08:41 +09001049func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001050 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001051 ctx.BottomUp("apex", apexMutator).Parallel()
1052 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1053 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054}
1055
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056// Mark the direct and transitive dependencies of apex bundles so that they
1057// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001058func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001059 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001060 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001061 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +09001062 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +09001063 ApexName: mctx.ModuleName(),
1064 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +09001065 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001066 directDep = true
1067 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001068 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001069 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001071
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001072 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001073 return
1074 }
1075
Jooyung Han5e9013b2020-03-10 06:23:13 +09001076 cur := mctx.Module().(interface {
1077 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1078 })
1079
Jiyong Parkf760cae2020-02-12 07:53:12 +09001080 mctx.VisitDirectDeps(func(child android.Module) {
1081 depName := mctx.OtherModuleName(child)
1082 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001083 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001084 android.UpdateApexDependency(apexBundles, depName, directDep)
1085 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001086 }
1087 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001088}
1089
1090// Create apex variations if a module is included in APEX(s).
1091func apexMutator(mctx android.BottomUpMutatorContext) {
1092 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001093 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001094 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001095 // apex bundle itself is mutated so that it and its modules have same
1096 // apex variant.
1097 apexBundleName := mctx.ModuleName()
1098 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001099 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1100 apexBundleName := o.GetOverriddenModuleName()
1101 if apexBundleName == "" {
1102 mctx.ModuleErrorf("base property is not set")
1103 return
1104 }
1105 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001106 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001107
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108}
Sundong Ahne9b55722019-09-06 17:37:42 +09001109
Jooyung Han7a78a922019-10-08 21:59:58 +09001110var (
1111 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1112 apexFileContextsInfosMutex sync.Mutex
1113)
1114
1115func apexFileContextsInfos(config android.Config) *[]string {
1116 return config.Once(apexFileContextsInfosKey, func() interface{} {
1117 return &[]string{}
1118 }).(*[]string)
1119}
1120
Jooyung Han54aca7b2019-11-20 02:26:02 +09001121func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001122 apexFileContextsInfosMutex.Lock()
1123 defer apexFileContextsInfosMutex.Unlock()
1124 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001125 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001126}
1127
Sundong Ahne9b55722019-09-06 17:37:42 +09001128func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001129 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001130 var variants []string
1131 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1132 case "image":
1133 variants = append(variants, imageApexType, flattenedApexType)
1134 case "zip":
1135 variants = append(variants, zipApexType)
1136 case "both":
1137 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1138 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001139 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001140 return
1141 }
1142
1143 modules := mctx.CreateLocalVariations(variants...)
1144
1145 for i, v := range variants {
1146 switch v {
1147 case imageApexType:
1148 modules[i].(*apexBundle).properties.ApexType = imageApex
1149 case zipApexType:
1150 modules[i].(*apexBundle).properties.ApexType = zipApex
1151 case flattenedApexType:
1152 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001153 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001154 modules[i].(*apexBundle).MakeAsSystemExt()
1155 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001156 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001157 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001158 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1159 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001160 }
1161}
1162
Jooyung Han5c998b92019-06-27 11:30:33 +09001163func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1164 if ab, ok := mctx.Module().(*apexBundle); ok {
1165 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1166 }
1167}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001168
Jooyung Handc782442019-11-01 03:14:38 +09001169var (
1170 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1171)
1172
1173// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1174// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1175// which may cause compatibility issues. (e.g. libbinder)
1176// Even though libbinder restricts its availability via 'apex_available' property and relies on
1177// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1178// to avoid similar problems.
1179func useVendorWhitelist(config android.Config) []string {
1180 return config.Once(useVendorWhitelistKey, func() interface{} {
1181 return []string{
1182 // swcodec uses "vendor" variants for smaller size
1183 "com.android.media.swcodec",
1184 "test_com.android.media.swcodec",
1185 }
1186 }).([]string)
1187}
1188
1189// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1190// called before the first call to useVendorWhitelist()
1191func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1192 config.Once(useVendorWhitelistKey, func() interface{} {
1193 return whitelist
1194 })
1195}
1196
Jooyung Han01a868d2020-02-27 13:40:44 +09001197type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001198 // List of native libraries
1199 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001200
Jooyung Han643adc42020-02-27 13:50:06 +09001201 // List of JNI libraries
1202 Jni_libs []string
1203
Alex Light9670d332019-01-29 18:07:33 -08001204 // List of native executables
1205 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001206
Roland Levillain630846d2019-06-26 12:48:34 +01001207 // List of native tests
1208 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001209}
Jooyung Han344d5432019-08-23 11:17:39 +09001210
Alex Light9670d332019-01-29 18:07:33 -08001211type apexMultilibProperties struct {
1212 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001213 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001214
1215 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001216 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001217
1218 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001219 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001220
1221 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001222 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001223
1224 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001225 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001226}
1227
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001228type apexBundleProperties struct {
1229 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001230 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001231 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001232
Jiyong Park40e26a22019-02-08 02:53:06 +09001233 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1234 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001235 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001236
Roland Levillain411c5842019-09-19 16:37:20 +01001237 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1238 // device (/apex/<apex_name>).
1239 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001240 Apex_name *string
1241
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001242 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001243 // For platform APEXes, this should points to a file under /system/sepolicy
1244 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1245 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001246
Jooyung Han01a868d2020-02-27 13:40:44 +09001247 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001248
1249 // List of java libraries that are embedded inside this APEX bundle
1250 Java_libs []string
1251
1252 // List of prebuilt files that are embedded inside this APEX bundle
1253 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001254
1255 // Name of the apex_key module that provides the private key to sign APEX
1256 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001257
Alex Light5098a612018-11-29 17:12:15 -08001258 // The type of APEX to build. Controls what the APEX payload is. Either
1259 // 'image', 'zip' or 'both'. Default: 'image'.
1260 Payload_type *string
1261
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001262 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1263 // or an android_app_certificate module name in the form ":module".
1264 Certificate *string
1265
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001266 // Whether this APEX is installable to one of the partitions. Default: true.
1267 Installable *bool
1268
Jiyong Parkda6eb592018-12-19 17:12:36 +09001269 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1270 // Default is false.
1271 Use_vendor *bool
1272
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001273 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1274 Ignore_system_library_special_case *bool
1275
Alex Light9670d332019-01-29 18:07:33 -08001276 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001277
Jiyong Parkf97782b2019-02-13 20:28:58 +09001278 // List of sanitizer names that this APEX is enabled for
1279 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001280
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001281 PreventInstall bool `blueprint:"mutated"`
1282
1283 HideFromMake bool `blueprint:"mutated"`
1284
Jooyung Han5c998b92019-06-27 11:30:33 +09001285 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1286 Provide_cpp_shared_libs *bool
1287
1288 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1289 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001290
1291 // A txt file containing list of files that are whitelisted to be included in this APEX.
1292 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001293
Sundong Ahnabb64432019-10-22 13:58:29 +09001294 // package format of this apex variant; could be non-flattened, flattened, or zip.
1295 // imageApex, zipApex or flattened
1296 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001297
Jiyong Parkd1063c12019-07-17 20:08:41 +09001298 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1299 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1300 // is implied. This value affects all modules included in this APEX. In other words, they are
1301 // also built with the SDKs specified here.
1302 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001303
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001304 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1305 // Should be only used in tests#.
1306 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001307
Jiyong Park956305c2020-01-09 12:32:06 +09001308 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001309
1310 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1311 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1312 // like symlinking to the system libs. Default is false.
1313 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001314
1315 // The minimum SDK version that this apex must be compatibile with.
1316 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001317}
1318
1319type apexTargetBundleProperties struct {
1320 Target struct {
1321 // Multilib properties only for android.
1322 Android struct {
1323 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001324 }
Jooyung Han344d5432019-08-23 11:17:39 +09001325
Alex Light9670d332019-01-29 18:07:33 -08001326 // Multilib properties only for host.
1327 Host struct {
1328 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001329 }
Jooyung Han344d5432019-08-23 11:17:39 +09001330
Alex Light9670d332019-01-29 18:07:33 -08001331 // Multilib properties only for host linux_bionic.
1332 Linux_bionic struct {
1333 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001334 }
Jooyung Han344d5432019-08-23 11:17:39 +09001335
Alex Light9670d332019-01-29 18:07:33 -08001336 // Multilib properties only for host linux_glibc.
1337 Linux_glibc struct {
1338 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001339 }
1340 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001341}
1342
Jiyong Park5d790c32019-11-15 18:40:32 +09001343type overridableProperties struct {
1344 // List of APKs to package inside APEX
1345 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001346
1347 // Names of modules to be overridden. Listed modules can only be other binaries
1348 // (in Make or Soong).
1349 // This does not completely prevent installation of the overridden binaries, but if both
1350 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1351 // from PRODUCT_PACKAGES.
1352 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001353
1354 // Logging Parent value
1355 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001356}
1357
Alex Light5098a612018-11-29 17:12:15 -08001358type apexPackaging int
1359
1360const (
1361 imageApex apexPackaging = iota
1362 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001363 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001364)
1365
Sundong Ahnabb64432019-10-22 13:58:29 +09001366// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001367func (a apexPackaging) suffix() string {
1368 switch a {
1369 case imageApex:
1370 return imageApexSuffix
1371 case zipApex:
1372 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001373 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001374 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001375 }
1376}
1377
1378func (a apexPackaging) name() string {
1379 switch a {
1380 case imageApex:
1381 return imageApexType
1382 case zipApex:
1383 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001384 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001385 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001386 }
1387}
1388
Jiyong Parkf653b052019-11-18 15:39:01 +09001389type apexFileClass int
1390
1391const (
1392 etc apexFileClass = iota
1393 nativeSharedLib
1394 nativeExecutable
1395 shBinary
1396 pyBinary
1397 goBinary
1398 javaSharedLib
1399 nativeTest
1400 app
1401)
1402
Jiyong Park8fd61922018-11-08 02:50:25 +09001403func (class apexFileClass) NameInMake() string {
1404 switch class {
1405 case etc:
1406 return "ETC"
1407 case nativeSharedLib:
1408 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001409 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001410 return "EXECUTABLES"
1411 case javaSharedLib:
1412 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001413 case nativeTest:
1414 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001415 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001416 // b/142537672 Why isn't this APP? We want to have full control over
1417 // the paths and file names of the apk file under the flattend APEX.
1418 // If this is set to APP, then the paths and file names are modified
1419 // by the Make build system. For example, it is installed to
1420 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1421 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1422 // appends module name (which is <apexname>.<Appname> to the path.
1423 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001424 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001425 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001426 }
1427}
1428
Jiyong Parkf653b052019-11-18 15:39:01 +09001429// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001430type apexFile struct {
1431 builtFile android.Path
1432 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001433 installDir string
1434 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001435 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001436 // list of symlinks that will be created in installDir that point to this apexFile
1437 symlinks []string
1438 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001439 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001440
1441 requiredModuleNames []string
1442 targetRequiredModuleNames []string
1443 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001444
Colin Cross503c1d02020-01-28 14:00:53 -08001445 jacocoReportClassesFile android.Path // only for javalibs and apps
1446 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001447 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001448
1449 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001450}
1451
Jiyong Park1833cef2019-12-13 13:28:36 +09001452func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1453 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001454 builtFile: builtFile,
1455 moduleName: moduleName,
1456 installDir: installDir,
1457 class: class,
1458 module: module,
1459 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001460 if module != nil {
1461 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001462 ret.requiredModuleNames = module.RequiredModuleNames()
1463 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1464 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001465 }
1466 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001467}
1468
1469func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001470 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001471}
1472
Jiyong Park7cd10e32020-01-14 09:22:18 +09001473// Path() returns path of this apex file relative to the APEX root
1474func (af *apexFile) Path() string {
1475 return filepath.Join(af.installDir, af.builtFile.Base())
1476}
1477
1478// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1479func (af *apexFile) SymlinkPaths() []string {
1480 var ret []string
1481 for _, symlink := range af.symlinks {
1482 ret = append(ret, filepath.Join(af.installDir, symlink))
1483 }
1484 return ret
1485}
1486
1487func (af *apexFile) AvailableToPlatform() bool {
1488 if af.module == nil {
1489 return false
1490 }
1491 if am, ok := af.module.(android.ApexModule); ok {
1492 return am.AvailableFor(android.AvailableToPlatform)
1493 }
1494 return false
1495}
1496
Jiyong Park678c8812020-02-07 17:25:49 +09001497type depInfo struct {
1498 to string
1499 from []string
1500 isExternal bool
1501}
1502
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001503type apexBundle struct {
1504 android.ModuleBase
1505 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001506 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001507 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001508
Jiyong Park5d790c32019-11-15 18:40:32 +09001509 properties apexBundleProperties
1510 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001511 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001512
Jooyung Hanf21c7972019-12-16 22:32:06 +09001513 // specific to apex_vndk modules
1514 vndkProperties apexVndkProperties
1515
Colin Crossa4925902018-11-16 11:36:28 -08001516 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001517 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001518 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001519
Jiyong Park03b68dd2019-07-26 23:20:40 +09001520 prebuiltFileToDelete string
1521
Jiyong Park42cca6c2019-04-01 11:15:50 +09001522 public_key_file android.Path
1523 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001524
1525 container_certificate_file android.Path
1526 container_private_key_file android.Path
1527
Jooyung Han54aca7b2019-11-20 02:26:02 +09001528 fileContexts android.Path
1529
Jiyong Park8fd61922018-11-08 02:50:25 +09001530 // list of files to be included in this apex
1531 filesInfo []apexFile
1532
Jiyong Park956305c2020-01-09 12:32:06 +09001533 // list of module names that should be installed along with this APEX
1534 requiredDeps []string
1535
Jiyong Park956305c2020-01-09 12:32:06 +09001536 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001537 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001538
Sundong Ahnabb64432019-10-22 13:58:29 +09001539 testApex bool
1540 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001541 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001542 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001543
Jooyung Han214bf372019-11-12 13:03:50 +09001544 manifestJsonOut android.WritablePath
1545 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001546
Jooyung Han002ab682020-01-08 01:57:58 +09001547 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001548 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001549 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001550 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1551 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001552
1553 // Suffix of module name in Android.mk
1554 // ".flattened", ".apex", ".zipapex", or ""
1555 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001556
1557 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001558
1559 // Whether to create symlink to the system file instead of having a file
1560 // inside the apex or not
1561 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001562
1563 // Struct holding the merged notice file paths in different formats
1564 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001565}
1566
Jiyong Park397e55e2018-10-24 21:09:55 +09001567func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001568 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001569 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001570 // Use *FarVariation* to be able to depend on modules having
1571 // conflicting variations with this module. This is required since
1572 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1573 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001574 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001575 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001576 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001577 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001578 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001579
Jooyung Han643adc42020-02-27 13:50:06 +09001580 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1581 {Mutator: "image", Variation: imageVariation},
1582 {Mutator: "link", Variation: "shared"},
1583 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1584 }...), jniLibTag, nativeModules.Jni_libs...)
1585
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001586 ctx.AddFarVariationDependencies(append(target.Variations(),
1587 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001588 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001589
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001590 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001591 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001592 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001593 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001594}
1595
Alex Light9670d332019-01-29 18:07:33 -08001596func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1597 if ctx.Os().Class == android.Device {
1598 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1599 } else {
1600 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1601 if ctx.Os().Bionic() {
1602 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1603 } else {
1604 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1605 }
1606 }
1607}
1608
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001609func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001610 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1611 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1612 }
1613
Jiyong Park397e55e2018-10-24 21:09:55 +09001614 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001615 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001616
1617 a.combineProperties(ctx)
1618
Jiyong Park397e55e2018-10-24 21:09:55 +09001619 has32BitTarget := false
1620 for _, target := range targets {
1621 if target.Arch.ArchType.Multilib == "lib32" {
1622 has32BitTarget = true
1623 }
1624 }
1625 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001626 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001627 // multilib.both
1628 addDependenciesForNativeModules(ctx,
1629 ApexNativeDependencies{
1630 Native_shared_libs: a.properties.Native_shared_libs,
1631 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001632 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001633 Binaries: nil,
1634 },
1635 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001636
Jiyong Park397e55e2018-10-24 21:09:55 +09001637 // Add native modules targetting both ABIs
1638 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001639 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001640 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001641 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001642
Alex Light3d673592019-01-18 14:37:31 -08001643 isPrimaryAbi := i == 0
1644 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001645 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001646 // multilib.first
1647 addDependenciesForNativeModules(ctx,
1648 ApexNativeDependencies{
1649 Native_shared_libs: nil,
1650 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001651 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001652 Binaries: a.properties.Binaries,
1653 },
1654 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001655
1656 // Add native modules targetting the first ABI
1657 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001658 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001659 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001660 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001661 }
1662
1663 switch target.Arch.ArchType.Multilib {
1664 case "lib32":
1665 // Add native modules targetting 32-bit ABI
1666 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001667 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001668 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001669 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001670
1671 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001672 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001673 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001674 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001675 case "lib64":
1676 // Add native modules targetting 64-bit ABI
1677 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001678 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001679 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001680 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001681
1682 if !has32BitTarget {
1683 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001684 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001685 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001686 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001687 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001688
1689 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1690 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1691 if sanitizer == "hwaddress" {
1692 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001693 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001694 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001695 break
1696 }
1697 }
1698 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001699 }
1700
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001701 }
1702
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001703 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1704 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1705 // b/144532908
1706 archForPrebuiltEtc := config.Arches()[0]
1707 for _, arch := range config.Arches() {
1708 // Prefer 64-bit arch if there is any
1709 if arch.ArchType.Multilib == "lib64" {
1710 archForPrebuiltEtc = arch
1711 break
1712 }
1713 }
1714 ctx.AddFarVariationDependencies([]blueprint.Variation{
1715 {Mutator: "os", Variation: ctx.Os().String()},
1716 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1717 }, prebuiltTag, a.properties.Prebuilts...)
1718
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001719 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1720 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001721
Ulya Trafimovich44561882020-01-03 13:25:54 +00001722 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1723 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1724 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1725 javaLibTag, "jacocoagent")
1726 }
1727
Jiyong Park23c52b02019-02-02 13:13:47 +09001728 if String(a.properties.Key) == "" {
1729 ctx.ModuleErrorf("key is missing")
1730 return
1731 }
1732 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001733
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001734 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001735 if cert != "" {
1736 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001737 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001738
1739 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1740 if len(a.properties.Uses_sdks) > 0 {
1741 sdkRefs := []android.SdkRef{}
1742 for _, str := range a.properties.Uses_sdks {
1743 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1744 sdkRefs = append(sdkRefs, parsed)
1745 }
1746 a.BuildWithSdks(sdkRefs)
1747 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001748}
1749
Jiyong Park5d790c32019-11-15 18:40:32 +09001750func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1751 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1752 androidAppTag, a.overridableProperties.Apps...)
1753}
1754
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001755func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1756 // direct deps of an APEX bundle are all part of the APEX bundle
1757 return true
1758}
1759
Colin Cross0ea8ba82019-06-06 14:33:29 -07001760func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001761 moduleName := ctx.ModuleName()
1762 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1763 // we check with the pseudo module name to see if its certificate is overridden.
1764 if a.vndkApex {
1765 moduleName = vndkApexName
1766 }
1767 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001768 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001769 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001770 }
1771 return String(a.properties.Certificate)
1772}
1773
Colin Cross41955e82019-05-29 14:40:35 -07001774func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1775 switch tag {
1776 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001777 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001778 default:
1779 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001780 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001781}
1782
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001783func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001784 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001785}
1786
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001787func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1788 return proptools.Bool(a.properties.Test_only_no_hashtree)
1789}
1790
Jiyong Park7c1dc612019-01-05 11:15:24 +09001791func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001792 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001793 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001794 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001795 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001796 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001797 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001798 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001799 }
1800}
1801
Jiyong Parkf97782b2019-02-13 20:28:58 +09001802func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1803 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1804 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1805 }
1806}
1807
Jiyong Park388ef3f2019-01-28 19:47:32 +09001808func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001809 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1810 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001811 }
1812
1813 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001814 globalSanitizerNames := []string{}
1815 if a.Host() {
1816 globalSanitizerNames = ctx.Config().SanitizeHost()
1817 } else {
1818 arches := ctx.Config().SanitizeDeviceArch()
1819 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1820 globalSanitizerNames = ctx.Config().SanitizeDevice()
1821 }
1822 }
1823 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001824}
1825
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001826func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001827 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001828}
1829
1830func (a *apexBundle) PreventInstall() {
1831 a.properties.PreventInstall = true
1832}
1833
1834func (a *apexBundle) HideFromMake() {
1835 a.properties.HideFromMake = true
1836}
1837
Jiyong Park956305c2020-01-09 12:32:06 +09001838func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1839 a.properties.IsCoverageVariant = coverage
1840}
1841
Jiyong Parkf653b052019-11-18 15:39:01 +09001842// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001843func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001844 // Decide the APEX-local directory by the multilib of the library
1845 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001847 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001848 case "lib32":
1849 dirInApex = "lib"
1850 case "lib64":
1851 dirInApex = "lib64"
1852 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001853 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001854 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001855 }
Jooyung Han35155c42020-02-06 17:33:20 +09001856 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001857 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001858 // Special case for Bionic libs and other libs installed with them. This is
1859 // to prevent those libs from being included in the search path
1860 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1861 // those libs in the Runtime APEX are available via the legacy paths in
1862 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1863 // to the legacy paths and thus will be loaded into the default linker
1864 // namespace (aka "platform" namespace). If the libs are directly in
1865 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1866 // into the runtime linker namespace, which will result in double loading of
1867 // them, which isn't supported.
1868 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001869 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001870
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001872 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001873}
1874
Jiyong Park1833cef2019-12-13 13:28:36 +09001875func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001876 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001877 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001878 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001879 }
Jooyung Han35155c42020-02-06 17:33:20 +09001880 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001882 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001883 af.symlinks = cc.Symlinks()
1884 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001885}
1886
Jiyong Park1833cef2019-12-13 13:28:36 +09001887func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001888 dirInApex := "bin"
1889 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001890 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001891}
Jiyong Park1833cef2019-12-13 13:28:36 +09001892func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001893 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001894 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1895 if err != nil {
1896 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001897 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001898 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001899 fileToCopy := android.PathForOutput(ctx, s)
1900 // NB: Since go binaries are static we don't need the module for anything here, which is
1901 // good since the go tool is a blueprint.Module not an android.Module like we would
1902 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001903 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001904}
1905
Jiyong Park1833cef2019-12-13 13:28:36 +09001906func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001907 dirInApex := filepath.Join("bin", sh.SubDir())
1908 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001909 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001910 af.symlinks = sh.Symlinks()
1911 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001912}
1913
Jooyung Han58f26ab2019-12-18 15:34:32 +09001914// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1915type javaLibrary interface {
1916 android.Module
1917 java.Dependency
1918}
1919
1920func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001921 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001922 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001923 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1924 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1925 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001926}
1927
Jiyong Park1833cef2019-12-13 13:28:36 +09001928func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001929 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1930 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001931 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001932}
1933
atrost6e126252020-01-27 17:01:16 +00001934func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1935 dirInApex := filepath.Join("etc", config.SubDir())
1936 fileToCopy := config.CompatConfig()
1937 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1938}
1939
Jiyong Park1833cef2019-12-13 13:28:36 +09001940func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001941 android.Module
1942 Privileged() bool
1943 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001944 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001945 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001946}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001947 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001948 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001949 appDir = "priv-app"
1950 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001951 dirInApex := filepath.Join(appDir, pkgName)
1952 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001953 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1954 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001955 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001956
1957 if app, ok := aapp.(interface {
1958 OverriddenManifestPackageName() string
1959 }); ok {
1960 af.overriddenPackageName = app.OverriddenManifestPackageName()
1961 }
Jiyong Park618922e2020-01-08 13:35:43 +09001962 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001963}
1964
Roland Levillain935639d2019-08-13 14:55:28 +01001965// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1966type flattenedApexContext struct {
1967 android.ModuleContext
1968}
1969
1970func (c *flattenedApexContext) InstallBypassMake() bool {
1971 return true
1972}
1973
Jiyong Park201cedd2020-02-07 17:25:49 +09001974// Visit dependencies that contributes to the payload of this APEX
1975func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1976 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001977 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1978 am, ok := child.(android.ApexModule)
1979 if !ok || !am.CanHaveApexVariants() {
1980 return false
1981 }
1982
1983 // Check for the direct dependencies that contribute to the payload
1984 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1985 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001986 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001987 return true
1988 }
1989 return false
1990 }
1991
1992 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001993 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001994 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001995 return true
1996 }
1997
Jiyong Park201cedd2020-02-07 17:25:49 +09001998 do(ctx, parent, am, true /* externalDep */)
1999
Jiyong Park0f80c182020-01-31 02:49:53 +09002000 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2001 return false
2002 })
2003}
2004
Jooyung Han03b51852020-02-26 22:45:42 +09002005func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
2006 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
2007 if ver != "current" {
2008 minSdkVersion, err := strconv.Atoi(ver)
2009 if err != nil {
2010 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
2011 }
2012 return minSdkVersion
2013 }
2014 return android.FutureApiLevel
2015}
2016
Jiyong Park201cedd2020-02-07 17:25:49 +09002017// Ensures that the dependencies are marked as available for this APEX
2018func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2019 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2020 if ctx.Host() || a.testApex || a.vndkApex {
2021 return
2022 }
2023
2024 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2025 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002026 fromName := ctx.OtherModuleName(from)
2027 toName := ctx.OtherModuleName(to)
2028 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002029 return
2030 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09002031 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09002032 })
2033}
2034
Jiyong Park678c8812020-02-07 17:25:49 +09002035// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2036func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2037 a.depInfos = make(map[string]depInfo)
2038 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2039 if from.Name() == to.Name() {
2040 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2041 return
2042 }
2043
2044 if info, exists := a.depInfos[to.Name()]; exists {
2045 if !android.InList(from.Name(), info.from) {
2046 info.from = append(info.from, from.Name())
2047 }
2048 info.isExternal = info.isExternal && externalDep
2049 a.depInfos[to.Name()] = info
2050 } else {
2051 a.depInfos[to.Name()] = depInfo{
2052 to: to.Name(),
2053 from: []string{from.Name()},
2054 isExternal: externalDep,
2055 }
2056 }
2057 })
2058}
2059
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002060func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002061 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2062 switch a.properties.ApexType {
2063 case imageApex:
2064 if buildFlattenedAsDefault {
2065 a.suffix = imageApexSuffix
2066 } else {
2067 a.suffix = ""
2068 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002069
2070 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002071 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002072 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002073 }
2074 case zipApex:
2075 if proptools.String(a.properties.Payload_type) == "zip" {
2076 a.suffix = ""
2077 a.primaryApexType = true
2078 } else {
2079 a.suffix = zipApexSuffix
2080 }
2081 case flattenedApex:
2082 if buildFlattenedAsDefault {
2083 a.suffix = ""
2084 a.primaryApexType = true
2085 } else {
2086 a.suffix = flattenedSuffix
2087 }
Alex Light5098a612018-11-29 17:12:15 -08002088 }
2089
Roland Levillain630846d2019-06-26 12:48:34 +01002090 if len(a.properties.Tests) > 0 && !a.testApex {
2091 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2092 return
2093 }
2094
Jiyong Park0f80c182020-01-31 02:49:53 +09002095 a.checkApexAvailability(ctx)
2096
Jiyong Park678c8812020-02-07 17:25:49 +09002097 a.collectDepsInfo(ctx)
2098
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002099 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2100
Jooyung Hane1633032019-08-01 17:41:43 +09002101 // native lib dependencies
2102 var provideNativeLibs []string
2103 var requireNativeLibs []string
2104
Jooyung Han5c998b92019-06-27 11:30:33 +09002105 // Check if "uses" requirements are met with dependent apexBundles
2106 var providedNativeSharedLibs []string
2107 useVendor := proptools.Bool(a.properties.Use_vendor)
2108 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2109 if ctx.OtherModuleDependencyTag(m) != usesTag {
2110 return
2111 }
2112 otherName := ctx.OtherModuleName(m)
2113 other, ok := m.(*apexBundle)
2114 if !ok {
2115 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2116 return
2117 }
2118 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2119 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2120 return
2121 }
2122 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2123 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2124 return
2125 }
2126 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2127 })
2128
Jiyong Parkf653b052019-11-18 15:39:01 +09002129 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002130 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002131 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002132 depTag := ctx.OtherModuleDependencyTag(child)
2133 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002134 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002135 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002136 case sharedLibTag, jniLibTag:
2137 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002138 if c, ok := child.(*cc.Module); ok {
2139 // bootstrap bionic libs are treated as provided by system
2140 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2141 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002142 }
Jooyung Han643adc42020-02-27 13:50:06 +09002143 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2144 fi.isJniLib = isJniLib
2145 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002146 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002147 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002148 propertyName := "native_shared_libs"
2149 if isJniLib {
2150 propertyName = "jni_libs"
2151 }
2152 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002153 }
2154 case executableTag:
2155 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002156 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002157 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002158 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002159 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002160 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002161 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002162 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002163 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002164 } else {
Alex Light778127a2019-02-27 14:19:50 -08002165 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002166 }
2167 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002168 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002169 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002170 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002171 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2172 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002173 filesInfo = append(filesInfo, af)
2174 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002175 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002176 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2177 af := apexFileForJavaLibrary(ctx, sdkLib)
2178 if !af.Ok() {
2179 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2180 return false
2181 }
2182 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002183 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002184 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002185 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002186 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002187 case androidAppTag:
2188 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2189 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002190 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002191 return true // track transitive dependencies
2192 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002193 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002194 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2195 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002196 } else {
2197 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2198 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002199 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002200 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002201 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002202 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2203 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002204 } else {
atrost6e126252020-01-27 17:01:16 +00002205 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002206 }
Roland Levillain630846d2019-06-26 12:48:34 +01002207 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002208 if ccTest, ok := child.(*cc.Module); ok {
2209 if ccTest.IsTestPerSrcAllTestsVariation() {
2210 // Multiple-output test module (where `test_per_src: true`).
2211 //
2212 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2213 // We do not add this variation to `filesInfo`, as it has no output;
2214 // however, we do add the other variations of this module as indirect
2215 // dependencies (see below).
2216 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002217 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002218 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002219 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002220 af.class = nativeTest
2221 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002222 }
Roland Levillain630846d2019-06-26 12:48:34 +01002223 } else {
2224 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2225 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002226 case keyTag:
2227 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002228 a.private_key_file = key.private_key_file
2229 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002230 } else {
2231 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002232 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002233 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002234 case certificateTag:
2235 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002236 a.container_certificate_file = dep.Certificate.Pem
2237 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002238 } else {
2239 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2240 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002241 case android.PrebuiltDepTag:
2242 // If the prebuilt is force disabled, remember to delete the prebuilt file
2243 // that might have been installed in the previous builds
2244 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2245 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2246 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002247 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002248 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002249 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002250 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002251 // We cannot use a switch statement on `depTag` here as the checked
2252 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002253 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002254 if cc, ok := child.(*cc.Module); ok {
2255 if android.InList(cc.Name(), providedNativeSharedLibs) {
2256 // If we're using a shared library which is provided from other APEX,
2257 // don't include it in this APEX
2258 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002259 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002260 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002261 // If the dependency is a stubs lib, don't include it in this APEX,
2262 // but make sure that the lib is installed on the device.
2263 // In case no APEX is having the lib, the lib is installed to the system
2264 // partition.
2265 //
2266 // Always include if we are a host-apex however since those won't have any
2267 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002268 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2269 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002270 }
Jooyung Hane1633032019-08-01 17:41:43 +09002271 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002272 // Don't track further
2273 return false
2274 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002275 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002276 af.transitiveDep = true
2277 filesInfo = append(filesInfo, af)
2278 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002279 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002280 } else if cc.IsTestPerSrcDepTag(depTag) {
2281 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002282 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002283 // Handle modules created as `test_per_src` variations of a single test module:
2284 // use the name of the generated test binary (`fileToCopy`) instead of the name
2285 // of the original test module (`depName`, shared by all `test_per_src`
2286 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002287 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002288 // these are not considered transitive dep
2289 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002290 filesInfo = append(filesInfo, af)
2291 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002292 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002293 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002294 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2295 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002296 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2297 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2298 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2299 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002300 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002301 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002302 }
2303 }
2304 }
2305 return false
2306 })
2307
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002308 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2309 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2310 // via the global boot image config.
2311 if a.artApex {
2312 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2313 dirInApex := filepath.Join("javalib", arch.String())
2314 for _, f := range files {
2315 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002316 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002317 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002318 }
2319 }
2320 }
2321
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002322 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002323 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2324 return
2325 }
2326
Jiyong Park8fd61922018-11-08 02:50:25 +09002327 // remove duplicates in filesInfo
2328 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002329 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002330 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002331 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002332 if e, ok := encountered[dest]; !ok {
2333 encountered[dest] = f
2334 } else {
2335 // If a module is directly included and also transitively depended on
2336 // consider it as directly included.
2337 e.transitiveDep = e.transitiveDep && f.transitiveDep
2338 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002339 }
2340 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002341 var result []apexFile
2342 for _, v := range encountered {
2343 result = append(result, v)
2344 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002345 return result
2346 }
2347 filesInfo = removeDup(filesInfo)
2348
2349 // to have consistent build rules
2350 sort.Slice(filesInfo, func(i, j int) bool {
2351 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2352 })
2353
Jiyong Park8fd61922018-11-08 02:50:25 +09002354 a.installDir = android.PathForModuleInstall(ctx, "apex")
2355 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002356
Jooyung Han54aca7b2019-11-20 02:26:02 +09002357 if a.properties.ApexType != zipApex {
2358 if a.properties.File_contexts == nil {
2359 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2360 } else {
2361 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2362 if a.Platform() {
2363 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2364 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2365 }
2366 }
2367 }
2368 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2369 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2370 return
2371 }
2372 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002373 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2374 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2375 // the same library in the system partition, thus effectively sharing the same libraries
2376 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2377 // in the APEX.
2378 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2379 a.installable() &&
2380 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002381
Jiyong Park9d677202020-02-19 16:29:35 +09002382 // We don't need the optimization for updatable APEXes, as it might give false signal
2383 // to the system health when the APEXes are still bundled (b/149805758)
2384 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2385 a.linkToSystemLib = false
2386 }
2387
Jiyong Park638d30e2020-02-26 18:27:19 +09002388 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2389 if ctx.Host() {
2390 a.linkToSystemLib = false
2391 }
2392
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002393 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002394 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2395
2396 a.setCertificateAndPrivateKey(ctx)
2397 if a.properties.ApexType == flattenedApex {
2398 a.buildFlattenedApex(ctx)
2399 } else {
2400 a.buildUnflattenedApex(ctx)
2401 }
2402
Jooyung Han002ab682020-01-08 01:57:58 +09002403 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002404
2405 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002406}
2407
Jooyung Han5e9013b2020-03-10 06:23:13 +09002408func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002409 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002410 moduleName = normalizeModuleName(moduleName)
2411
2412 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2413 return true
2414 }
2415
2416 key = android.AvailableToAnyApex
2417 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2418 return true
2419 }
2420
2421 return false
2422}
2423
2424func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002425 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2426 // system. Trim the prefix for the check since they are confusing
2427 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2428 if strings.HasPrefix(moduleName, "libclang_rt.") {
2429 // This module has many arch variants that depend on the product being built.
2430 // We don't want to list them all
2431 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002432 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002433 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002434}
2435
Jooyung Han344d5432019-08-23 11:17:39 +09002436func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002437 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002438 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002439 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002440 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002441 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002442 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2443 })
Alex Light5098a612018-11-29 17:12:15 -08002444 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002445 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002446 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002447 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002448 return module
2449}
Jiyong Park30ca9372019-02-07 16:27:23 +09002450
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002451func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002452 bundle := newApexBundle()
2453 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002454 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002455 return bundle
2456}
2457
Jiyong Parkfce0b422020-02-11 03:56:06 +09002458// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2459// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002460func testApexBundleFactory() android.Module {
2461 bundle := newApexBundle()
2462 bundle.testApex = true
2463 return bundle
2464}
2465
Jiyong Parkfce0b422020-02-11 03:56:06 +09002466// apex packages other modules into an APEX file which is a packaging format for system-level
2467// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002468func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002469 return newApexBundle()
2470}
2471
Jiyong Park30ca9372019-02-07 16:27:23 +09002472//
2473// Defaults
2474//
2475type Defaults struct {
2476 android.ModuleBase
2477 android.DefaultsModuleBase
2478}
2479
Jiyong Park30ca9372019-02-07 16:27:23 +09002480func defaultsFactory() android.Module {
2481 return DefaultsFactory()
2482}
2483
2484func DefaultsFactory(props ...interface{}) android.Module {
2485 module := &Defaults{}
2486
2487 module.AddProperties(props...)
2488 module.AddProperties(
2489 &apexBundleProperties{},
2490 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002491 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002492 )
2493
2494 android.InitDefaultsModule(module)
2495 return module
2496}
Jiyong Park5d790c32019-11-15 18:40:32 +09002497
2498//
2499// OverrideApex
2500//
2501type OverrideApex struct {
2502 android.ModuleBase
2503 android.OverrideModuleBase
2504}
2505
2506func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2507 // All the overrides happen in the base module.
2508}
2509
2510// override_apex is used to create an apex module based on another apex module
2511// by overriding some of its properties.
2512func overrideApexFactory() android.Module {
2513 m := &OverrideApex{}
2514 m.AddProperties(&overridableProperties{})
2515
2516 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2517 android.InitOverrideModule(m)
2518 return m
2519}