blob: 852985a7e620873f5e2ab5be4669ae626449d55e [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()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090066)
67
Anton Hanssoneec79eb2020-01-10 15:12:39 +000068// This is a map from apex to modules, which overrides the
69// apex_available setting for that particular module to make
70// it available for the apex regardless of its setting.
71// TODO(b/147364041): remove this
72func makeApexAvailableWhitelist() map[string][]string {
73 // The "Module separator"s below are employed to minimize merge conflicts.
74 m := make(map[string][]string)
75 //
76 // Module separator
77 //
Jiyong Park0f80c182020-01-31 02:49:53 +090078 m["com.android.adbd"] = []string{
79 "adbd",
80 "bcm_object",
81 "fmtlib",
82 "libadbconnection_server",
83 "libadbd",
84 "libadbd_auth",
85 "libadbd_core",
86 "libadbd_services",
87 "libasyncio",
88 "libbacktrace_headers",
89 "libbase",
90 "libbase_headers",
91 "libbuildversion",
92 "libc++",
93 "libcap",
94 "libcrypto",
95 "libcrypto_utils",
96 "libcutils",
97 "libcutils_headers",
98 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "liblog_headers",
100 "libmdnssd",
101 "libminijail",
102 "libminijail_gen_constants",
103 "libminijail_gen_constants_obj",
104 "libminijail_gen_syscall",
105 "libminijail_gen_syscall_obj",
106 "libminijail_generated",
107 "libpackagelistparser",
108 "libpcre2",
109 "libprocessgroup_headers",
110 "libqemu_pipe",
111 "libselinux",
112 "libsystem_headers",
113 "libutils_headers",
114 }
115 //
116 // Module separator
117 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000118 m["com.android.art"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "art_cmdlineparser_headers",
120 "art_disassembler_headers",
121 "art_libartbase_headers",
122 "bcm_object",
123 "bionic_libc_platform_headers",
124 "core-repackaged-icu4j",
125 "cpp-define-generator-asm-support",
126 "cpp-define-generator-definitions",
127 "crtbegin_dynamic",
128 "crtbegin_dynamic1",
129 "crtbegin_so1",
130 "crtbrand",
131 "conscrypt.module.intra.core.api.stubs",
132 "dex2oat_headers",
133 "dt_fd_forward_export",
134 "fmtlib",
135 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000136 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "javavm_headers",
138 "jni_platform_headers",
139 "libPlatformProperties",
140 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libandroidicuinit",
143 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000144 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900145 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000146 "libbacktrace",
147 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900148 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900150 "libc++_static",
151 "libc++abi",
152 "libc++demangle",
153 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libdexfile_all_headers",
156 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000157 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900158 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libfdlibm",
161 "libgtest_prod",
162 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libicuuc_headers",
165 "libicuuc_stubdata",
166 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900167 "liblog_headers",
168 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000169 "liblzma",
170 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900171 "libnativebridge-headers",
172 "libnativehelper_header_only",
173 "libnativeloader-headers",
174 "libnpt_headers",
175 "libopenjdkjvmti_headers",
176 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libprotobuf-cpp-lite",
179 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000180 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900181 "libv8",
182 "libv8base",
183 "libv8gen",
184 "libv8platform",
185 "libv8sampler",
186 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "libvixl",
188 "libvixld",
189 "libz",
190 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900191 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000192 }
193 //
194 // Module separator
195 //
196 m["com.android.bluetooth.updatable"] = []string{
197 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000198 "android.hardware.bluetooth.a2dp@1.0",
199 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900200 "android.hardware.bluetooth@1.0",
201 "android.hardware.bluetooth@1.1",
202 "android.hardware.graphics.bufferqueue@1.0",
203 "android.hardware.graphics.bufferqueue@2.0",
204 "android.hardware.graphics.common@1.0",
205 "android.hardware.graphics.common@1.1",
206 "android.hardware.graphics.common@1.2",
207 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000208 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900209 "android.hidl.token@1.0",
210 "android.hidl.token@1.0-utils",
211 "avrcp-target-service",
212 "avrcp_headers",
213 "bcm_object",
214 "bluetooth-protos-lite",
215 "bluetooth.mapsapi",
216 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900217 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900218 "fmtlib",
219 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900220 "ipmemorystore-aidl-interfaces-V5-java",
221 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900222 "internal_include_headers",
223 "lib-bt-packets",
224 "lib-bt-packets-avrcp",
225 "lib-bt-packets-base",
226 "libFraunhoferAAC",
227 "libaudio-a2dp-hw-utils",
228 "libaudio-hearing-aid-hw-utils",
229 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000230 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "libbase_headers",
232 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900234 "libbluetooth-types",
235 "libbluetooth-types-header",
236 "libbluetooth_gd",
237 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000238 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900239 "libbt-audio-hal-interface",
240 "libbt-bta",
241 "libbt-common",
242 "libbt-hci",
243 "libbt-platform-protos-lite",
244 "libbt-protos-lite",
245 "libbt-sbc-decoder",
246 "libbt-sbc-encoder",
247 "libbt-stack",
248 "libbt-utils",
249 "libbtcore",
250 "libbtdevice",
251 "libbte",
252 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000253 "libc++",
254 "libchrome",
255 "libcrypto",
256 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 "libevent",
259 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900260 "libg722codec",
261 "libgtest_prod",
262 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000263 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900264 "libhidlbase-impl-internal",
265 "libhidltransport-impl-internal",
266 "libhwbinder-impl-internal",
267 "libjsoncpp",
268 "liblog_headers",
269 "libmedia_headers",
270 "libmodpb64",
271 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000272 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900273 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000274 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900275 "libprotobuf-java-lite",
276 "libprotobuf-java-micro",
277 "libstagefright_foundation_headers",
278 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000279 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "libstatssocket",
281 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000282 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900283 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900284 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000285 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900286 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900287 "net-utils-services-common",
288 "netd_aidl_interface-unstable-java",
289 "netd_event_listener_interface-java",
290 "netlink-client",
291 "networkstack-aidl-interfaces-unstable-java",
292 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900293 "sap-api-java-static",
294 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000295 }
296 //
297 // Module separator
298 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000300 //
301 // Module separator
302 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 m["com.android.conscrypt"] = []string{
304 "bcm_object",
305 "boringssl_self_test",
306 "libc++",
307 "libcrypto",
308 "libnativehelper_header_only",
309 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900310 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 }
312 //
313 // Module separator
314 //
315 m["com.android.extservices"] = []string{
316 "flatbuffer_headers",
317 "liblua",
318 "libtextclassifier",
319 "libtextclassifier_hash_static",
320 "libtflite_static",
321 "libutf",
322 "libz_current",
323 "tensorflow_headers",
324 }
325 //
326 // Module separator
327 //
328 m["com.android.cronet"] = []string{
329 "cronet_impl_common_java",
330 "cronet_impl_native_java",
331 "cronet_impl_platform_java",
332 "libcronet.80.0.3986.0",
333 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900334 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900335 "prebuilt_libcronet.80.0.3986.0",
336 }
337 //
338 // Module separator
339 //
340 m["com.android.neuralnetworks"] = []string{
341 "android.hardware.neuralnetworks@1.0",
342 "android.hardware.neuralnetworks@1.1",
343 "android.hardware.neuralnetworks@1.2",
344 "android.hardware.neuralnetworks@1.3",
345 "android.hidl.allocator@1.0",
346 "android.hidl.memory.token@1.0",
347 "android.hidl.memory@1.0",
348 "android.hidl.safe_union@1.0",
349 "bcm_object",
350 "fmtlib",
351 "gemmlowp_headers",
352 "libarect",
353 "libbacktrace_headers",
354 "libbase",
355 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "libbuildversion",
357 "libc++",
358 "libcrypto",
359 "libcrypto_static",
360 "libcutils",
361 "libcutils_headers",
362 "libeigen",
363 "libfmq",
364 "libhidlbase",
365 "libhidlbase-impl-internal",
366 "libhidlmemory",
367 "libhidltransport-impl-internal",
368 "libhwbinder-impl-internal",
369 "libjsoncpp",
370 "liblog_headers",
371 "libmath",
372 "libneuralnetworks_common",
373 "libneuralnetworks_headers",
374 "libprocessgroup",
375 "libprocessgroup_headers",
376 "libprocpartition",
377 "libsync",
378 "libsystem_headers",
379 "libtextclassifier_hash",
380 "libtextclassifier_hash_headers",
381 "libtextclassifier_hash_static",
382 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900383 "libutils_headers",
384 "philox_random",
385 "philox_random_headers",
386 "tensorflow_headers",
387 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000388 //
389 // Module separator
390 //
391 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000392 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900393 "android.hardware.cas.native@1.0",
394 "android.hardware.cas@1.0",
395 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000396 "android.hardware.configstore@1.0",
397 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000398 "android.hardware.graphics.allocator@2.0",
399 "android.hardware.graphics.allocator@3.0",
400 "android.hardware.graphics.bufferqueue@1.0",
401 "android.hardware.graphics.bufferqueue@2.0",
402 "android.hardware.graphics.common@1.0",
403 "android.hardware.graphics.common@1.1",
404 "android.hardware.graphics.common@1.2",
405 "android.hardware.graphics.mapper@2.0",
406 "android.hardware.graphics.mapper@2.1",
407 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900408 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000409 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900410 "android.hidl.allocator@1.0",
411 "android.hidl.memory.token@1.0",
412 "android.hidl.memory@1.0",
413 "android.hidl.token@1.0",
414 "android.hidl.token@1.0-utils",
415 "bcm_object",
416 "bionic_libc_platform_headers",
417 "fmtlib",
418 "gl_headers",
419 "libEGL",
420 "libEGL_blobCache",
421 "libEGL_getProcAddress",
422 "libFLAC",
423 "libFLAC-config",
424 "libFLAC-headers",
425 "libGLESv2",
426 "libaacextractor",
427 "libamrextractor",
428 "libarect",
429 "libasync_safe",
430 "libaudio_system_headers",
431 "libaudioclient",
432 "libaudioclient_headers",
433 "libaudiofoundation",
434 "libaudiofoundation_headers",
435 "libaudiomanager",
436 "libaudiopolicy",
437 "libaudioutils",
438 "libaudioutils_fixedfft",
439 "libbacktrace",
440 "libbacktrace_headers",
441 "libbase",
442 "libbase_headers",
443 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900444 "libbluetooth-types-header",
445 "libbufferhub",
446 "libbufferhub_headers",
447 "libbufferhubqueue",
448 "libc++",
449 "libc_headers",
450 "libc_malloc_debug_backtrace",
451 "libcamera_client",
452 "libcamera_metadata",
453 "libcrypto",
454 "libcutils",
455 "libcutils_headers",
456 "libdexfile_external_headers",
457 "libdexfile_support",
458 "libdvr_headers",
459 "libexpat",
460 "libfifo",
461 "libflacextractor",
462 "libgrallocusage",
463 "libgraphicsenv",
464 "libgui",
465 "libgui_headers",
466 "libhardware_headers",
467 "libhidlbase",
468 "libhidlbase-impl-internal",
469 "libhidlmemory",
470 "libhidltransport-impl-internal",
471 "libhwbinder-impl-internal",
472 "libinput",
473 "libjsoncpp",
474 "liblog_headers",
475 "liblzma",
476 "libmath",
477 "libmedia",
478 "libmedia_codeclist",
479 "libmedia_headers",
480 "libmedia_helper",
481 "libmedia_helper_headers",
482 "libmedia_midiiowrapper",
483 "libmedia_omx",
484 "libmediautils",
485 "libmidiextractor",
486 "libmkvextractor",
487 "libmp3extractor",
488 "libmp4extractor",
489 "libmpeg2extractor",
490 "libnativebase_headers",
491 "libnativebridge-headers",
492 "libnativebridge_lazy",
493 "libnativeloader-headers",
494 "libnativeloader_lazy",
495 "libnativewindow_headers",
496 "libnblog",
497 "liboggextractor",
498 "libpackagelistparser",
499 "libpcre2",
500 "libpdx",
501 "libpdx_default_transport",
502 "libpdx_headers",
503 "libpdx_uds",
504 "libprocessgroup",
505 "libprocessgroup_headers",
506 "libprocinfo",
507 "libselinux",
508 "libsonivox",
509 "libspeexresampler",
510 "libspeexresampler",
511 "libstagefright_esds",
512 "libstagefright_flacdec",
513 "libstagefright_flacdec",
514 "libstagefright_foundation",
515 "libstagefright_foundation_headers",
516 "libstagefright_foundation_without_imemory",
517 "libstagefright_headers",
518 "libstagefright_id3",
519 "libstagefright_metadatautils",
520 "libstagefright_mpeg2extractor",
521 "libstagefright_mpeg2support",
522 "libsync",
523 "libsystem_headers",
524 "libui",
525 "libui_headers",
526 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900527 "libutils_headers",
528 "libvibrator",
529 "libvorbisidec",
530 "libwavextractor",
531 "libwebm",
532 "media_ndk_headers",
533 "media_plugin_headers",
534 "updatable-media",
535 }
536 //
537 // Module separator
538 //
539 m["com.android.media.swcodec"] = []string{
540 "android.frameworks.bufferhub@1.0",
541 "android.hardware.common-ndk_platform",
542 "android.hardware.configstore-utils",
543 "android.hardware.configstore@1.0",
544 "android.hardware.configstore@1.1",
545 "android.hardware.graphics.allocator@2.0",
546 "android.hardware.graphics.allocator@3.0",
547 "android.hardware.graphics.bufferqueue@1.0",
548 "android.hardware.graphics.bufferqueue@2.0",
549 "android.hardware.graphics.common-ndk_platform",
550 "android.hardware.graphics.common@1.0",
551 "android.hardware.graphics.common@1.1",
552 "android.hardware.graphics.common@1.2",
553 "android.hardware.graphics.mapper@2.0",
554 "android.hardware.graphics.mapper@2.1",
555 "android.hardware.graphics.mapper@3.0",
556 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000557 "android.hardware.media.bufferpool@2.0",
558 "android.hardware.media.c2@1.0",
559 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900560 "android.hardware.media@1.0",
561 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000562 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900563 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "android.hidl.safe_union@1.0",
565 "android.hidl.token@1.0",
566 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "fmtlib",
568 "libEGL",
569 "libFLAC",
570 "libFLAC-config",
571 "libFLAC-headers",
572 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900573 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 "libarect",
575 "libasync_safe",
576 "libaudio_system_headers",
577 "libaudioutils",
578 "libaudioutils",
579 "libaudioutils_fixedfft",
580 "libavcdec",
581 "libavcenc",
582 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000583 "libavservices_minijail",
584 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900585 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000586 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "libbase_headers",
588 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900589 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900590 "libbluetooth-types-header",
591 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000592 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900593 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000594 "libcap",
595 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900596 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000597 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900598 "libcodec2_hidl@1.1",
599 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000600 "libcodec2_soft_aacdec",
601 "libcodec2_soft_aacenc",
602 "libcodec2_soft_amrnbdec",
603 "libcodec2_soft_amrnbenc",
604 "libcodec2_soft_amrwbdec",
605 "libcodec2_soft_amrwbenc",
606 "libcodec2_soft_av1dec_gav1",
607 "libcodec2_soft_avcdec",
608 "libcodec2_soft_avcenc",
609 "libcodec2_soft_common",
610 "libcodec2_soft_flacdec",
611 "libcodec2_soft_flacenc",
612 "libcodec2_soft_g711alawdec",
613 "libcodec2_soft_g711mlawdec",
614 "libcodec2_soft_gsmdec",
615 "libcodec2_soft_h263dec",
616 "libcodec2_soft_h263enc",
617 "libcodec2_soft_hevcdec",
618 "libcodec2_soft_hevcenc",
619 "libcodec2_soft_mp3dec",
620 "libcodec2_soft_mpeg2dec",
621 "libcodec2_soft_mpeg4dec",
622 "libcodec2_soft_mpeg4enc",
623 "libcodec2_soft_opusdec",
624 "libcodec2_soft_opusenc",
625 "libcodec2_soft_rawdec",
626 "libcodec2_soft_vorbisdec",
627 "libcodec2_soft_vp8dec",
628 "libcodec2_soft_vp8enc",
629 "libcodec2_soft_vp9dec",
630 "libcodec2_soft_vp9enc",
631 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000632 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900633 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000634 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000636 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libfmq",
638 "libgav1",
639 "libgralloctypes",
640 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900642 "libgsm",
643 "libgui_bufferqueue_static",
644 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000645 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900646 "libhardware_headers",
647 "libhevcdec",
648 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000649 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900650 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000651 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900652 "libhidltransport-impl-internal",
653 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libjpeg",
656 "libjsoncpp",
657 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000658 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900659 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000660 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900661 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000662 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900663 "libminijail_gen_constants",
664 "libminijail_gen_constants_obj",
665 "libminijail_gen_syscall",
666 "libminijail_gen_syscall_obj",
667 "libminijail_generated",
668 "libmpeg2dec",
669 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000670 "libnativebridge_lazy",
671 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000673 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000675 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000677 "libscudo_wrapper",
678 "libsfplugin_ccodec_utils",
679 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900680 "libstagefright_amrnbdec",
681 "libstagefright_amrnbenc",
682 "libstagefright_amrwbdec",
683 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000684 "libstagefright_bufferpool@2.0.1",
685 "libstagefright_bufferqueue_helper",
686 "libstagefright_enc_common",
687 "libstagefright_flacdec",
688 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900689 "libstagefright_foundation_headers",
690 "libstagefright_headers",
691 "libstagefright_m4vh263dec",
692 "libstagefright_m4vh263enc",
693 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000694 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900695 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000696 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900697 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000698 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900699 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000700 "libvorbisidec",
701 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900702 "libyuv",
703 "libyuv_static",
704 "media_ndk_headers",
705 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000706 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 }
708 //
709 // Module separator
710 //
711 m["com.android.mediaprovider"] = []string{
712 "MediaProvider",
713 "MediaProviderGoogle",
714 "fmtlib_ndk",
715 "guava",
716 "libbase_ndk",
717 "libfuse",
718 "libfuse_jni",
719 "libnativehelper_header_only",
720 }
721 //
722 // Module separator
723 //
724 m["com.android.permission"] = []string{
725 "androidx.annotation_annotation",
726 "androidx.annotation_annotation-nodeps",
727 "androidx.lifecycle_lifecycle-common",
728 "androidx.lifecycle_lifecycle-common-java8",
729 "androidx.lifecycle_lifecycle-common-java8-nodeps",
730 "androidx.lifecycle_lifecycle-common-nodeps",
731 "kotlin-annotations",
732 "kotlin-stdlib",
733 "kotlin-stdlib-jdk7",
734 "kotlin-stdlib-jdk8",
735 "kotlinx-coroutines-android",
736 "kotlinx-coroutines-android-nodeps",
737 "kotlinx-coroutines-core",
738 "kotlinx-coroutines-core-nodeps",
739 "libprotobuf-java-lite",
740 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000741 }
742 //
743 // Module separator
744 //
745 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900746 "bionic_libc_platform_headers",
747 "fmtlib",
748 "libarm-optimized-routines-math",
749 "libasync_safe",
750 "libasync_safe_headers",
751 "libbacktrace_headers",
752 "libbase",
753 "libbase_headers",
754 "libc++",
755 "libc_aeabi",
756 "libc_bionic",
757 "libc_bionic_ndk",
758 "libc_bootstrap",
759 "libc_common",
760 "libc_common_shared",
761 "libc_common_static",
762 "libc_dns",
763 "libc_dynamic_dispatch",
764 "libc_fortify",
765 "libc_freebsd",
766 "libc_freebsd_large_stack",
767 "libc_gdtoa",
768 "libc_headers",
769 "libc_init_dynamic",
770 "libc_init_static",
771 "libc_jemalloc_wrapper",
772 "libc_netbsd",
773 "libc_nomalloc",
774 "libc_nopthread",
775 "libc_openbsd",
776 "libc_openbsd_large_stack",
777 "libc_openbsd_ndk",
778 "libc_pthread",
779 "libc_static_dispatch",
780 "libc_syscalls",
781 "libc_tzcode",
782 "libc_unwind_static",
783 "libcutils",
784 "libcutils_headers",
785 "libdebuggerd",
786 "libdebuggerd_common_headers",
787 "libdebuggerd_handler_core",
788 "libdebuggerd_handler_fallback",
789 "libdexfile_external_headers",
790 "libdexfile_support",
791 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900792 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900793 "libgtest_prod",
794 "libjemalloc5",
795 "liblinker_main",
796 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900797 "liblog_headers",
798 "liblz4",
799 "liblzma",
800 "libprocessgroup_headers",
801 "libprocinfo",
802 "libpropertyinfoparser",
803 "libscudo",
804 "libstdc++",
805 "libsystem_headers",
806 "libsystemproperties",
807 "libtombstoned_client_static",
808 "libunwindstack",
809 "libutils_headers",
810 "libz",
811 "libziparchive",
812 }
813 //
814 // Module separator
815 //
816 m["com.android.resolv"] = []string{
817 "bcm_object",
818 "dnsresolver_aidl_interface-unstable-ndk_platform",
819 "fmtlib",
820 "libbacktrace_headers",
821 "libbase",
822 "libbase_headers",
823 "libc++",
824 "libcrypto",
825 "libcutils",
826 "libcutils_headers",
827 "libgtest_prod",
828 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900829 "liblog_headers",
830 "libnativehelper_header_only",
831 "libnetd_client_headers",
832 "libnetd_resolv",
833 "libnetdutils",
834 "libprocessgroup",
835 "libprocessgroup_headers",
836 "libprotobuf-cpp-lite",
837 "libssl",
838 "libstatslog_resolv",
839 "libstatspush_compat",
840 "libstatssocket",
841 "libstatssocket_headers",
842 "libsystem_headers",
843 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900844 "libutils_headers",
845 "netd_event_listener_interface-ndk_platform",
846 "server_configurable_flags",
847 "stats_proto",
848 }
849 //
850 // Module separator
851 //
852 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000853 "libbase",
854 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900855 "libnativehelper_compat_libc++",
856 "android.hardware.tetheroffload.config@1.0",
857 "fmtlib",
858 "libbacktrace_headers",
859 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900860 "libcgrouprc",
861 "libcgrouprc_format",
862 "libcutils",
863 "libcutils_headers",
864 "libhidlbase",
865 "libhidlbase-impl-internal",
866 "libhidltransport-impl-internal",
867 "libhwbinder-impl-internal",
868 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900869 "liblog_headers",
870 "libprocessgroup",
871 "libprocessgroup_headers",
872 "libsystem_headers",
873 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900874 "libutils_headers",
875 "libvndksupport",
876 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000877 }
878 //
879 // Module separator
880 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900881 m["com.android.wifi"] = []string{
882 "PlatformProperties",
883 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900884 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900885 "android.hardware.wifi-V1.1-java",
886 "android.hardware.wifi-V1.2-java",
887 "android.hardware.wifi-V1.3-java",
888 "android.hardware.wifi-V1.4-java",
889 "android.hardware.wifi.hostapd-V1.0-java",
890 "android.hardware.wifi.hostapd-V1.1-java",
891 "android.hardware.wifi.hostapd-V1.2-java",
892 "android.hardware.wifi.supplicant-V1.0-java",
893 "android.hardware.wifi.supplicant-V1.1-java",
894 "android.hardware.wifi.supplicant-V1.2-java",
895 "android.hardware.wifi.supplicant-V1.3-java",
896 "android.hidl.base-V1.0-java",
897 "android.hidl.manager-V1.0-java",
898 "android.hidl.manager-V1.1-java",
899 "android.hidl.manager-V1.2-java",
900 "androidx.annotation_annotation",
901 "androidx.annotation_annotation-nodeps",
902 "bouncycastle-unbundled",
903 "dnsresolver_aidl_interface-V2-java",
904 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900905 "framework-wifi-pre-jarjar",
906 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900907 "ipmemorystore-aidl-interfaces-V3-java",
908 "ipmemorystore-aidl-interfaces-java",
909 "ksoap2",
910 "libbacktrace_headers",
911 "libbase",
912 "libbase_headers",
913 "libc++",
914 "libcutils",
915 "libcutils_headers",
916 "liblog_headers",
917 "libnanohttpd",
918 "libprocessgroup",
919 "libprocessgroup_headers",
920 "libprotobuf-java-lite",
921 "libprotobuf-java-nano",
922 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900923 "libutils_headers",
924 "libwifi-jni",
925 "net-utils-services-common",
926 "netd_aidl_interface-V2-java",
927 "netd_aidl_interface-unstable-java",
928 "netd_event_listener_interface-java",
929 "netlink-client",
930 "networkstack-aidl-interfaces-unstable-java",
931 "networkstack-client",
932 "services.net",
933 "wifi-lite-protos",
934 "wifi-nano-protos",
935 "wifi-service-pre-jarjar",
936 "wifi-service-resources",
937 "prebuilt_androidx.annotation_annotation-nodeps",
938 }
939 //
940 // Module separator
941 //
942 m["com.android.sdkext"] = []string{
943 "fmtlib_ndk",
944 "libbase_ndk",
945 "libprotobuf-cpp-lite-ndk",
946 }
947 //
948 // Module separator
949 //
950 m["com.android.os.statsd"] = []string{
951 "libbacktrace_headers",
952 "libbase_headers",
953 "libc++",
954 "libcutils",
955 "libcutils_headers",
956 "liblog_headers",
957 "libprocessgroup_headers",
958 "libstatssocket",
959 "libsystem_headers",
960 "libutils_headers",
961 }
962 //
963 // Module separator
964 //
965 m["//any"] = []string{
966 "crtbegin_dynamic",
967 "crtbegin_dynamic1",
968 "crtbegin_so",
969 "crtbegin_so1",
970 "crtbegin_static",
971 "crtbrand",
972 "crtend_android",
973 "crtend_so",
974 "libatomic",
975 "libc++_static",
976 "libc++abi",
977 "libc++demangle",
978 "libc_headers",
979 "libclang_rt",
980 "libgcc_stripped",
981 "libprofile-clang-extras",
982 "libprofile-clang-extras_ndk",
983 "libprofile-extras",
984 "libprofile-extras_ndk",
985 "libunwind_llvm",
986 "ndk_crtbegin_dynamic.27",
987 "ndk_crtbegin_so.16",
988 "ndk_crtbegin_so.19",
989 "ndk_crtbegin_so.21",
990 "ndk_crtbegin_so.24",
991 "ndk_crtbegin_so.27",
992 "ndk_crtend_android.27",
993 "ndk_crtend_so.16",
994 "ndk_crtend_so.19",
995 "ndk_crtend_so.21",
996 "ndk_crtend_so.24",
997 "ndk_crtend_so.27",
998 "ndk_libandroid_support",
999 "ndk_libc++_static",
1000 "ndk_libc++abi",
1001 "ndk_libunwind",
1002 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001003 return m
1004}
1005
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001006func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001007 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001008 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001009 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001010 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001011 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001012 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001013
Jooyung Han31c470b2019-10-18 16:26:59 +09001014 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001015 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001016
1017 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1018 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1019 sort.Strings(*apexFileContextsInfos)
1020 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1021 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001022}
1023
Jooyung Han31c470b2019-10-18 16:26:59 +09001024func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1025 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1026 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1027}
1028
Jiyong Parkd1063c12019-07-17 20:08:41 +09001029func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001030 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001031 ctx.BottomUp("apex", apexMutator).Parallel()
1032 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1033 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001034}
1035
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036// Mark the direct and transitive dependencies of apex bundles so that they
1037// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001038func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001039 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001040 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001041 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han03b51852020-02-26 22:45:42 +09001042 minSdkVersion := a.minSdkVersion(mctx)
Jooyung Han5e9013b2020-03-10 06:23:13 +09001043 apexBundles = []android.ApexInfo{android.ApexInfo{
1044 ApexName: mctx.ModuleName(),
1045 LegacyAndroid10Support: proptools.Bool(a.properties.Legacy_android10_support),
1046 MinSdkVersion: minSdkVersion,
1047 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001048 directDep = true
1049 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001050 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001051 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001052 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001053
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001054 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001055 return
1056 }
1057
Jooyung Han5e9013b2020-03-10 06:23:13 +09001058 cur := mctx.Module().(interface {
1059 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1060 })
1061
Jiyong Parkf760cae2020-02-12 07:53:12 +09001062 mctx.VisitDirectDeps(func(child android.Module) {
1063 depName := mctx.OtherModuleName(child)
1064 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001065 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001066 android.UpdateApexDependency(apexBundles, depName, directDep)
1067 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001068 }
1069 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070}
1071
1072// Create apex variations if a module is included in APEX(s).
1073func apexMutator(mctx android.BottomUpMutatorContext) {
1074 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001075 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001076 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001077 // apex bundle itself is mutated so that it and its modules have same
1078 // apex variant.
1079 apexBundleName := mctx.ModuleName()
1080 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001081 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1082 apexBundleName := o.GetOverriddenModuleName()
1083 if apexBundleName == "" {
1084 mctx.ModuleErrorf("base property is not set")
1085 return
1086 }
1087 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001088 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001089
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001090}
Sundong Ahne9b55722019-09-06 17:37:42 +09001091
Jooyung Han7a78a922019-10-08 21:59:58 +09001092var (
1093 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1094 apexFileContextsInfosMutex sync.Mutex
1095)
1096
1097func apexFileContextsInfos(config android.Config) *[]string {
1098 return config.Once(apexFileContextsInfosKey, func() interface{} {
1099 return &[]string{}
1100 }).(*[]string)
1101}
1102
Jooyung Han54aca7b2019-11-20 02:26:02 +09001103func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001104 apexFileContextsInfosMutex.Lock()
1105 defer apexFileContextsInfosMutex.Unlock()
1106 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001107 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001108}
1109
Sundong Ahne9b55722019-09-06 17:37:42 +09001110func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001111 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001112 var variants []string
1113 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1114 case "image":
1115 variants = append(variants, imageApexType, flattenedApexType)
1116 case "zip":
1117 variants = append(variants, zipApexType)
1118 case "both":
1119 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1120 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001121 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001122 return
1123 }
1124
1125 modules := mctx.CreateLocalVariations(variants...)
1126
1127 for i, v := range variants {
1128 switch v {
1129 case imageApexType:
1130 modules[i].(*apexBundle).properties.ApexType = imageApex
1131 case zipApexType:
1132 modules[i].(*apexBundle).properties.ApexType = zipApex
1133 case flattenedApexType:
1134 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001135 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001136 modules[i].(*apexBundle).MakeAsSystemExt()
1137 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001138 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001139 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001140 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1141 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001142 }
1143}
1144
Jooyung Han5c998b92019-06-27 11:30:33 +09001145func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1146 if ab, ok := mctx.Module().(*apexBundle); ok {
1147 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1148 }
1149}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001150
Jooyung Handc782442019-11-01 03:14:38 +09001151var (
1152 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1153)
1154
1155// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1156// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1157// which may cause compatibility issues. (e.g. libbinder)
1158// Even though libbinder restricts its availability via 'apex_available' property and relies on
1159// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1160// to avoid similar problems.
1161func useVendorWhitelist(config android.Config) []string {
1162 return config.Once(useVendorWhitelistKey, func() interface{} {
1163 return []string{
1164 // swcodec uses "vendor" variants for smaller size
1165 "com.android.media.swcodec",
1166 "test_com.android.media.swcodec",
1167 }
1168 }).([]string)
1169}
1170
1171// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1172// called before the first call to useVendorWhitelist()
1173func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1174 config.Once(useVendorWhitelistKey, func() interface{} {
1175 return whitelist
1176 })
1177}
1178
Jooyung Han01a868d2020-02-27 13:40:44 +09001179type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001180 // List of native libraries
1181 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001182
Jooyung Han643adc42020-02-27 13:50:06 +09001183 // List of JNI libraries
1184 Jni_libs []string
1185
Alex Light9670d332019-01-29 18:07:33 -08001186 // List of native executables
1187 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001188
Roland Levillain630846d2019-06-26 12:48:34 +01001189 // List of native tests
1190 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001191}
Jooyung Han344d5432019-08-23 11:17:39 +09001192
Alex Light9670d332019-01-29 18:07:33 -08001193type apexMultilibProperties struct {
1194 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001195 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001196
1197 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001198 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001199
1200 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001201 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001202
1203 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001204 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001205
1206 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001207 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001208}
1209
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001210type apexBundleProperties struct {
1211 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001212 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001213 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001214
Jiyong Park40e26a22019-02-08 02:53:06 +09001215 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1216 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001217 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001218
Roland Levillain411c5842019-09-19 16:37:20 +01001219 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1220 // device (/apex/<apex_name>).
1221 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001222 Apex_name *string
1223
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001224 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001225 // For platform APEXes, this should points to a file under /system/sepolicy
1226 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1227 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001228
Jooyung Han01a868d2020-02-27 13:40:44 +09001229 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001230
1231 // List of java libraries that are embedded inside this APEX bundle
1232 Java_libs []string
1233
1234 // List of prebuilt files that are embedded inside this APEX bundle
1235 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001236
1237 // Name of the apex_key module that provides the private key to sign APEX
1238 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001239
Alex Light5098a612018-11-29 17:12:15 -08001240 // The type of APEX to build. Controls what the APEX payload is. Either
1241 // 'image', 'zip' or 'both'. Default: 'image'.
1242 Payload_type *string
1243
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001244 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1245 // or an android_app_certificate module name in the form ":module".
1246 Certificate *string
1247
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001248 // Whether this APEX is installable to one of the partitions. Default: true.
1249 Installable *bool
1250
Jiyong Parkda6eb592018-12-19 17:12:36 +09001251 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1252 // Default is false.
1253 Use_vendor *bool
1254
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001255 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1256 Ignore_system_library_special_case *bool
1257
Alex Light9670d332019-01-29 18:07:33 -08001258 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001259
Jiyong Parkf97782b2019-02-13 20:28:58 +09001260 // List of sanitizer names that this APEX is enabled for
1261 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001262
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001263 PreventInstall bool `blueprint:"mutated"`
1264
1265 HideFromMake bool `blueprint:"mutated"`
1266
Jooyung Han5c998b92019-06-27 11:30:33 +09001267 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1268 Provide_cpp_shared_libs *bool
1269
1270 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1271 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001272
1273 // A txt file containing list of files that are whitelisted to be included in this APEX.
1274 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001275
Sundong Ahnabb64432019-10-22 13:58:29 +09001276 // package format of this apex variant; could be non-flattened, flattened, or zip.
1277 // imageApex, zipApex or flattened
1278 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001279
Jiyong Parkd1063c12019-07-17 20:08:41 +09001280 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1281 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1282 // is implied. This value affects all modules included in this APEX. In other words, they are
1283 // also built with the SDKs specified here.
1284 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001285
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001286 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1287 // Should be only used in tests#.
1288 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001289
1290 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1291 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1292 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001293
1294 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001295
1296 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1297 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1298 // like symlinking to the system libs. Default is false.
1299 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001300
1301 // The minimum SDK version that this apex must be compatibile with.
1302 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001303}
1304
1305type apexTargetBundleProperties struct {
1306 Target struct {
1307 // Multilib properties only for android.
1308 Android struct {
1309 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001310 }
Jooyung Han344d5432019-08-23 11:17:39 +09001311
Alex Light9670d332019-01-29 18:07:33 -08001312 // Multilib properties only for host.
1313 Host struct {
1314 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001315 }
Jooyung Han344d5432019-08-23 11:17:39 +09001316
Alex Light9670d332019-01-29 18:07:33 -08001317 // Multilib properties only for host linux_bionic.
1318 Linux_bionic struct {
1319 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001320 }
Jooyung Han344d5432019-08-23 11:17:39 +09001321
Alex Light9670d332019-01-29 18:07:33 -08001322 // Multilib properties only for host linux_glibc.
1323 Linux_glibc struct {
1324 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001325 }
1326 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001327}
1328
Jiyong Park5d790c32019-11-15 18:40:32 +09001329type overridableProperties struct {
1330 // List of APKs to package inside APEX
1331 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001332
1333 // Names of modules to be overridden. Listed modules can only be other binaries
1334 // (in Make or Soong).
1335 // This does not completely prevent installation of the overridden binaries, but if both
1336 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1337 // from PRODUCT_PACKAGES.
1338 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001339
1340 // Logging Parent value
1341 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001342}
1343
Alex Light5098a612018-11-29 17:12:15 -08001344type apexPackaging int
1345
1346const (
1347 imageApex apexPackaging = iota
1348 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001349 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001350)
1351
Sundong Ahnabb64432019-10-22 13:58:29 +09001352// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001353func (a apexPackaging) suffix() string {
1354 switch a {
1355 case imageApex:
1356 return imageApexSuffix
1357 case zipApex:
1358 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001359 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001360 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001361 }
1362}
1363
1364func (a apexPackaging) name() string {
1365 switch a {
1366 case imageApex:
1367 return imageApexType
1368 case zipApex:
1369 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001370 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001371 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001372 }
1373}
1374
Jiyong Parkf653b052019-11-18 15:39:01 +09001375type apexFileClass int
1376
1377const (
1378 etc apexFileClass = iota
1379 nativeSharedLib
1380 nativeExecutable
1381 shBinary
1382 pyBinary
1383 goBinary
1384 javaSharedLib
1385 nativeTest
1386 app
1387)
1388
Jiyong Park8fd61922018-11-08 02:50:25 +09001389func (class apexFileClass) NameInMake() string {
1390 switch class {
1391 case etc:
1392 return "ETC"
1393 case nativeSharedLib:
1394 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001395 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001396 return "EXECUTABLES"
1397 case javaSharedLib:
1398 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001399 case nativeTest:
1400 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001401 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001402 // b/142537672 Why isn't this APP? We want to have full control over
1403 // the paths and file names of the apk file under the flattend APEX.
1404 // If this is set to APP, then the paths and file names are modified
1405 // by the Make build system. For example, it is installed to
1406 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1407 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1408 // appends module name (which is <apexname>.<Appname> to the path.
1409 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001410 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001411 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001412 }
1413}
1414
Jiyong Parkf653b052019-11-18 15:39:01 +09001415// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001416type apexFile struct {
1417 builtFile android.Path
1418 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001419 installDir string
1420 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001421 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001422 // list of symlinks that will be created in installDir that point to this apexFile
1423 symlinks []string
1424 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001425 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001426
1427 requiredModuleNames []string
1428 targetRequiredModuleNames []string
1429 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001430
Colin Cross503c1d02020-01-28 14:00:53 -08001431 jacocoReportClassesFile android.Path // only for javalibs and apps
1432 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001433 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001434
1435 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001436}
1437
Jiyong Park1833cef2019-12-13 13:28:36 +09001438func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1439 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001440 builtFile: builtFile,
1441 moduleName: moduleName,
1442 installDir: installDir,
1443 class: class,
1444 module: module,
1445 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001446 if module != nil {
1447 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001448 ret.requiredModuleNames = module.RequiredModuleNames()
1449 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1450 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001451 }
1452 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001453}
1454
1455func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001456 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001457}
1458
Jiyong Park7cd10e32020-01-14 09:22:18 +09001459// Path() returns path of this apex file relative to the APEX root
1460func (af *apexFile) Path() string {
1461 return filepath.Join(af.installDir, af.builtFile.Base())
1462}
1463
1464// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1465func (af *apexFile) SymlinkPaths() []string {
1466 var ret []string
1467 for _, symlink := range af.symlinks {
1468 ret = append(ret, filepath.Join(af.installDir, symlink))
1469 }
1470 return ret
1471}
1472
1473func (af *apexFile) AvailableToPlatform() bool {
1474 if af.module == nil {
1475 return false
1476 }
1477 if am, ok := af.module.(android.ApexModule); ok {
1478 return am.AvailableFor(android.AvailableToPlatform)
1479 }
1480 return false
1481}
1482
Jiyong Park678c8812020-02-07 17:25:49 +09001483type depInfo struct {
1484 to string
1485 from []string
1486 isExternal bool
1487}
1488
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001489type apexBundle struct {
1490 android.ModuleBase
1491 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001492 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001493 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001494
Jiyong Park5d790c32019-11-15 18:40:32 +09001495 properties apexBundleProperties
1496 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001497 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001498
Jooyung Hanf21c7972019-12-16 22:32:06 +09001499 // specific to apex_vndk modules
1500 vndkProperties apexVndkProperties
1501
Colin Crossa4925902018-11-16 11:36:28 -08001502 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001503 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001504 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001505
Jiyong Park03b68dd2019-07-26 23:20:40 +09001506 prebuiltFileToDelete string
1507
Jiyong Park42cca6c2019-04-01 11:15:50 +09001508 public_key_file android.Path
1509 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001510
1511 container_certificate_file android.Path
1512 container_private_key_file android.Path
1513
Jooyung Han54aca7b2019-11-20 02:26:02 +09001514 fileContexts android.Path
1515
Jiyong Park8fd61922018-11-08 02:50:25 +09001516 // list of files to be included in this apex
1517 filesInfo []apexFile
1518
Jiyong Park956305c2020-01-09 12:32:06 +09001519 // list of module names that should be installed along with this APEX
1520 requiredDeps []string
1521
Jiyong Park956305c2020-01-09 12:32:06 +09001522 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001523 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001524
Sundong Ahnabb64432019-10-22 13:58:29 +09001525 testApex bool
1526 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001527 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001528 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001529
Jooyung Han214bf372019-11-12 13:03:50 +09001530 manifestJsonOut android.WritablePath
1531 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001532
Jooyung Han002ab682020-01-08 01:57:58 +09001533 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001534 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001535 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001536 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1537 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001538
1539 // Suffix of module name in Android.mk
1540 // ".flattened", ".apex", ".zipapex", or ""
1541 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001542
1543 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001544
1545 // Whether to create symlink to the system file instead of having a file
1546 // inside the apex or not
1547 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001548
1549 // Struct holding the merged notice file paths in different formats
1550 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001551}
1552
Jiyong Park397e55e2018-10-24 21:09:55 +09001553func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001554 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001555 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001556 // Use *FarVariation* to be able to depend on modules having
1557 // conflicting variations with this module. This is required since
1558 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1559 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001560 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001561 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001562 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001563 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001564 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001565
Jooyung Han643adc42020-02-27 13:50:06 +09001566 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1567 {Mutator: "image", Variation: imageVariation},
1568 {Mutator: "link", Variation: "shared"},
1569 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1570 }...), jniLibTag, nativeModules.Jni_libs...)
1571
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001572 ctx.AddFarVariationDependencies(append(target.Variations(),
1573 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001574 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001575
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001576 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001577 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001578 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001579 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001580}
1581
Alex Light9670d332019-01-29 18:07:33 -08001582func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1583 if ctx.Os().Class == android.Device {
1584 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1585 } else {
1586 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1587 if ctx.Os().Bionic() {
1588 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1589 } else {
1590 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1591 }
1592 }
1593}
1594
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001595func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001596 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1597 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1598 }
1599
Jiyong Park397e55e2018-10-24 21:09:55 +09001600 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001601 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001602
1603 a.combineProperties(ctx)
1604
Jiyong Park397e55e2018-10-24 21:09:55 +09001605 has32BitTarget := false
1606 for _, target := range targets {
1607 if target.Arch.ArchType.Multilib == "lib32" {
1608 has32BitTarget = true
1609 }
1610 }
1611 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001612 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001613 // multilib.both
1614 addDependenciesForNativeModules(ctx,
1615 ApexNativeDependencies{
1616 Native_shared_libs: a.properties.Native_shared_libs,
1617 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001618 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001619 Binaries: nil,
1620 },
1621 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001622
Jiyong Park397e55e2018-10-24 21:09:55 +09001623 // Add native modules targetting both ABIs
1624 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001625 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001626 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001627 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001628
Alex Light3d673592019-01-18 14:37:31 -08001629 isPrimaryAbi := i == 0
1630 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001631 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001632 // multilib.first
1633 addDependenciesForNativeModules(ctx,
1634 ApexNativeDependencies{
1635 Native_shared_libs: nil,
1636 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001637 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001638 Binaries: a.properties.Binaries,
1639 },
1640 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001641
1642 // Add native modules targetting the first ABI
1643 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001644 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001645 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001646 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001647 }
1648
1649 switch target.Arch.ArchType.Multilib {
1650 case "lib32":
1651 // Add native modules targetting 32-bit ABI
1652 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001653 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001654 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001655 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001656
1657 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001658 a.properties.Multilib.Prefer32,
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 case "lib64":
1662 // Add native modules targetting 64-bit ABI
1663 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001664 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001665 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001666 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001667
1668 if !has32BitTarget {
1669 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001670 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001671 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001672 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001673 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001674
1675 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1676 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1677 if sanitizer == "hwaddress" {
1678 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001679 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001680 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001681 break
1682 }
1683 }
1684 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001685 }
1686
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001687 }
1688
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001689 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1690 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1691 // b/144532908
1692 archForPrebuiltEtc := config.Arches()[0]
1693 for _, arch := range config.Arches() {
1694 // Prefer 64-bit arch if there is any
1695 if arch.ArchType.Multilib == "lib64" {
1696 archForPrebuiltEtc = arch
1697 break
1698 }
1699 }
1700 ctx.AddFarVariationDependencies([]blueprint.Variation{
1701 {Mutator: "os", Variation: ctx.Os().String()},
1702 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1703 }, prebuiltTag, a.properties.Prebuilts...)
1704
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001705 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1706 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001707
Ulya Trafimovich44561882020-01-03 13:25:54 +00001708 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1709 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1710 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1711 javaLibTag, "jacocoagent")
1712 }
1713
Jiyong Park23c52b02019-02-02 13:13:47 +09001714 if String(a.properties.Key) == "" {
1715 ctx.ModuleErrorf("key is missing")
1716 return
1717 }
1718 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001719
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001720 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001721 if cert != "" {
1722 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001723 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001724
1725 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1726 if len(a.properties.Uses_sdks) > 0 {
1727 sdkRefs := []android.SdkRef{}
1728 for _, str := range a.properties.Uses_sdks {
1729 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1730 sdkRefs = append(sdkRefs, parsed)
1731 }
1732 a.BuildWithSdks(sdkRefs)
1733 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001734}
1735
Jiyong Park5d790c32019-11-15 18:40:32 +09001736func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1737 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1738 androidAppTag, a.overridableProperties.Apps...)
1739}
1740
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001741func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1742 // direct deps of an APEX bundle are all part of the APEX bundle
1743 return true
1744}
1745
Colin Cross0ea8ba82019-06-06 14:33:29 -07001746func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001747 moduleName := ctx.ModuleName()
1748 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1749 // we check with the pseudo module name to see if its certificate is overridden.
1750 if a.vndkApex {
1751 moduleName = vndkApexName
1752 }
1753 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001754 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001755 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001756 }
1757 return String(a.properties.Certificate)
1758}
1759
Colin Cross41955e82019-05-29 14:40:35 -07001760func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1761 switch tag {
1762 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001763 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001764 default:
1765 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001766 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001767}
1768
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001769func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001770 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001771}
1772
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001773func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1774 return proptools.Bool(a.properties.Test_only_no_hashtree)
1775}
1776
Jiyong Park7c1dc612019-01-05 11:15:24 +09001777func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001778 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001779 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001780 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001781 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001782 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001783 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001784 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001785 }
1786}
1787
Jiyong Parkf97782b2019-02-13 20:28:58 +09001788func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1789 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1790 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1791 }
1792}
1793
Jiyong Park388ef3f2019-01-28 19:47:32 +09001794func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001795 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1796 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001797 }
1798
1799 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001800 globalSanitizerNames := []string{}
1801 if a.Host() {
1802 globalSanitizerNames = ctx.Config().SanitizeHost()
1803 } else {
1804 arches := ctx.Config().SanitizeDeviceArch()
1805 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1806 globalSanitizerNames = ctx.Config().SanitizeDevice()
1807 }
1808 }
1809 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001810}
1811
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001812func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001813 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001814}
1815
1816func (a *apexBundle) PreventInstall() {
1817 a.properties.PreventInstall = true
1818}
1819
1820func (a *apexBundle) HideFromMake() {
1821 a.properties.HideFromMake = true
1822}
1823
Jiyong Park956305c2020-01-09 12:32:06 +09001824func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1825 a.properties.IsCoverageVariant = coverage
1826}
1827
Jiyong Parkf653b052019-11-18 15:39:01 +09001828// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001829func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001830 // Decide the APEX-local directory by the multilib of the library
1831 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001832 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001833 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001834 case "lib32":
1835 dirInApex = "lib"
1836 case "lib64":
1837 dirInApex = "lib64"
1838 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001839 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001840 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001841 }
Jooyung Han35155c42020-02-06 17:33:20 +09001842 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001843 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001844 // Special case for Bionic libs and other libs installed with them. This is
1845 // to prevent those libs from being included in the search path
1846 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1847 // those libs in the Runtime APEX are available via the legacy paths in
1848 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1849 // to the legacy paths and thus will be loaded into the default linker
1850 // namespace (aka "platform" namespace). If the libs are directly in
1851 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1852 // into the runtime linker namespace, which will result in double loading of
1853 // them, which isn't supported.
1854 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001855 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001856
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001858 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001859}
1860
Jiyong Park1833cef2019-12-13 13:28:36 +09001861func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001862 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001863 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001864 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001865 }
Jooyung Han35155c42020-02-06 17:33:20 +09001866 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001867 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001868 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001869 af.symlinks = cc.Symlinks()
1870 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001871}
1872
Jiyong Park1833cef2019-12-13 13:28:36 +09001873func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001874 dirInApex := "bin"
1875 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001876 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001877}
Jiyong Park1833cef2019-12-13 13:28:36 +09001878func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001879 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001880 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1881 if err != nil {
1882 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001883 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001884 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 fileToCopy := android.PathForOutput(ctx, s)
1886 // NB: Since go binaries are static we don't need the module for anything here, which is
1887 // good since the go tool is a blueprint.Module not an android.Module like we would
1888 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001889 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001890}
1891
Jiyong Park1833cef2019-12-13 13:28:36 +09001892func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001893 dirInApex := filepath.Join("bin", sh.SubDir())
1894 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001895 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001896 af.symlinks = sh.Symlinks()
1897 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001898}
1899
Jooyung Han58f26ab2019-12-18 15:34:32 +09001900// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1901type javaLibrary interface {
1902 android.Module
1903 java.Dependency
1904}
1905
1906func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001907 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001908 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001909 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1910 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1911 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001912}
1913
Jiyong Park1833cef2019-12-13 13:28:36 +09001914func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001915 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1916 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001917 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001918}
1919
atrost6e126252020-01-27 17:01:16 +00001920func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1921 dirInApex := filepath.Join("etc", config.SubDir())
1922 fileToCopy := config.CompatConfig()
1923 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1924}
1925
Jiyong Park1833cef2019-12-13 13:28:36 +09001926func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001927 android.Module
1928 Privileged() bool
1929 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001930 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001931 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001932}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001933 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001934 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001935 appDir = "priv-app"
1936 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001937 dirInApex := filepath.Join(appDir, pkgName)
1938 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001939 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1940 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001941 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001942
1943 if app, ok := aapp.(interface {
1944 OverriddenManifestPackageName() string
1945 }); ok {
1946 af.overriddenPackageName = app.OverriddenManifestPackageName()
1947 }
Jiyong Park618922e2020-01-08 13:35:43 +09001948 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001949}
1950
Roland Levillain935639d2019-08-13 14:55:28 +01001951// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1952type flattenedApexContext struct {
1953 android.ModuleContext
1954}
1955
1956func (c *flattenedApexContext) InstallBypassMake() bool {
1957 return true
1958}
1959
Jiyong Park201cedd2020-02-07 17:25:49 +09001960// Visit dependencies that contributes to the payload of this APEX
1961func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1962 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001963 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1964 am, ok := child.(android.ApexModule)
1965 if !ok || !am.CanHaveApexVariants() {
1966 return false
1967 }
1968
1969 // Check for the direct dependencies that contribute to the payload
1970 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1971 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001972 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001973 return true
1974 }
1975 return false
1976 }
1977
1978 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001979 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001980 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001981 return true
1982 }
1983
Jiyong Park201cedd2020-02-07 17:25:49 +09001984 do(ctx, parent, am, true /* externalDep */)
1985
Jiyong Park0f80c182020-01-31 02:49:53 +09001986 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1987 return false
1988 })
1989}
1990
Jooyung Han03b51852020-02-26 22:45:42 +09001991func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1992 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1993 if ver != "current" {
1994 minSdkVersion, err := strconv.Atoi(ver)
1995 if err != nil {
1996 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1997 }
1998 return minSdkVersion
1999 }
2000 return android.FutureApiLevel
2001}
2002
Jiyong Park201cedd2020-02-07 17:25:49 +09002003// Ensures that the dependencies are marked as available for this APEX
2004func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2005 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2006 if ctx.Host() || a.testApex || a.vndkApex {
2007 return
2008 }
2009
2010 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2011 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002012 fromName := ctx.OtherModuleName(from)
2013 toName := ctx.OtherModuleName(to)
2014 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002015 return
2016 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09002017 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09002018 })
2019}
2020
Jiyong Park678c8812020-02-07 17:25:49 +09002021// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2022func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2023 a.depInfos = make(map[string]depInfo)
2024 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2025 if from.Name() == to.Name() {
2026 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2027 return
2028 }
2029
2030 if info, exists := a.depInfos[to.Name()]; exists {
2031 if !android.InList(from.Name(), info.from) {
2032 info.from = append(info.from, from.Name())
2033 }
2034 info.isExternal = info.isExternal && externalDep
2035 a.depInfos[to.Name()] = info
2036 } else {
2037 a.depInfos[to.Name()] = depInfo{
2038 to: to.Name(),
2039 from: []string{from.Name()},
2040 isExternal: externalDep,
2041 }
2042 }
2043 })
2044}
2045
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002046func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002047 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2048 switch a.properties.ApexType {
2049 case imageApex:
2050 if buildFlattenedAsDefault {
2051 a.suffix = imageApexSuffix
2052 } else {
2053 a.suffix = ""
2054 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002055
2056 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002057 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002058 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002059 }
2060 case zipApex:
2061 if proptools.String(a.properties.Payload_type) == "zip" {
2062 a.suffix = ""
2063 a.primaryApexType = true
2064 } else {
2065 a.suffix = zipApexSuffix
2066 }
2067 case flattenedApex:
2068 if buildFlattenedAsDefault {
2069 a.suffix = ""
2070 a.primaryApexType = true
2071 } else {
2072 a.suffix = flattenedSuffix
2073 }
Alex Light5098a612018-11-29 17:12:15 -08002074 }
2075
Roland Levillain630846d2019-06-26 12:48:34 +01002076 if len(a.properties.Tests) > 0 && !a.testApex {
2077 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2078 return
2079 }
2080
Jiyong Park0f80c182020-01-31 02:49:53 +09002081 a.checkApexAvailability(ctx)
2082
Jiyong Park678c8812020-02-07 17:25:49 +09002083 a.collectDepsInfo(ctx)
2084
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002085 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2086
Jooyung Hane1633032019-08-01 17:41:43 +09002087 // native lib dependencies
2088 var provideNativeLibs []string
2089 var requireNativeLibs []string
2090
Jooyung Han5c998b92019-06-27 11:30:33 +09002091 // Check if "uses" requirements are met with dependent apexBundles
2092 var providedNativeSharedLibs []string
2093 useVendor := proptools.Bool(a.properties.Use_vendor)
2094 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2095 if ctx.OtherModuleDependencyTag(m) != usesTag {
2096 return
2097 }
2098 otherName := ctx.OtherModuleName(m)
2099 other, ok := m.(*apexBundle)
2100 if !ok {
2101 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2102 return
2103 }
2104 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2105 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2106 return
2107 }
2108 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2109 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2110 return
2111 }
2112 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2113 })
2114
Jiyong Parkf653b052019-11-18 15:39:01 +09002115 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002116 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002117 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002118 depTag := ctx.OtherModuleDependencyTag(child)
2119 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002120 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002121 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002122 case sharedLibTag, jniLibTag:
2123 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002124 if c, ok := child.(*cc.Module); ok {
2125 // bootstrap bionic libs are treated as provided by system
2126 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2127 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002128 }
Jooyung Han643adc42020-02-27 13:50:06 +09002129 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2130 fi.isJniLib = isJniLib
2131 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002132 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002133 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002134 propertyName := "native_shared_libs"
2135 if isJniLib {
2136 propertyName = "jni_libs"
2137 }
2138 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002139 }
2140 case executableTag:
2141 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002142 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002143 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002144 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002145 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002146 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002147 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002148 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002149 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002150 } else {
Alex Light778127a2019-02-27 14:19:50 -08002151 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 +09002152 }
2153 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002154 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002155 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002156 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002157 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2158 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002159 filesInfo = append(filesInfo, af)
2160 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002161 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002162 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2163 af := apexFileForJavaLibrary(ctx, sdkLib)
2164 if !af.Ok() {
2165 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2166 return false
2167 }
2168 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002169 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002170 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002171 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002172 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002173 case androidAppTag:
2174 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2175 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002176 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002177 return true // track transitive dependencies
2178 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002179 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002180 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2181 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002182 } else {
2183 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2184 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002185 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002186 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002187 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002188 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2189 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002190 } else {
atrost6e126252020-01-27 17:01:16 +00002191 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002192 }
Roland Levillain630846d2019-06-26 12:48:34 +01002193 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002194 if ccTest, ok := child.(*cc.Module); ok {
2195 if ccTest.IsTestPerSrcAllTestsVariation() {
2196 // Multiple-output test module (where `test_per_src: true`).
2197 //
2198 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2199 // We do not add this variation to `filesInfo`, as it has no output;
2200 // however, we do add the other variations of this module as indirect
2201 // dependencies (see below).
2202 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002203 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002204 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002205 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002206 af.class = nativeTest
2207 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002208 }
Roland Levillain630846d2019-06-26 12:48:34 +01002209 } else {
2210 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2211 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002212 case keyTag:
2213 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002214 a.private_key_file = key.private_key_file
2215 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002216 } else {
2217 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002218 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002219 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002220 case certificateTag:
2221 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002222 a.container_certificate_file = dep.Certificate.Pem
2223 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002224 } else {
2225 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2226 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002227 case android.PrebuiltDepTag:
2228 // If the prebuilt is force disabled, remember to delete the prebuilt file
2229 // that might have been installed in the previous builds
2230 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2231 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2232 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002233 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002234 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002235 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002236 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002237 // We cannot use a switch statement on `depTag` here as the checked
2238 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002239 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002240 if cc, ok := child.(*cc.Module); ok {
2241 if android.InList(cc.Name(), providedNativeSharedLibs) {
2242 // If we're using a shared library which is provided from other APEX,
2243 // don't include it in this APEX
2244 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002245 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002246 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002247 // If the dependency is a stubs lib, don't include it in this APEX,
2248 // but make sure that the lib is installed on the device.
2249 // In case no APEX is having the lib, the lib is installed to the system
2250 // partition.
2251 //
2252 // Always include if we are a host-apex however since those won't have any
2253 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002254 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2255 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002256 }
Jooyung Hane1633032019-08-01 17:41:43 +09002257 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002258 // Don't track further
2259 return false
2260 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002261 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002262 af.transitiveDep = true
2263 filesInfo = append(filesInfo, af)
2264 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002265 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002266 } else if cc.IsTestPerSrcDepTag(depTag) {
2267 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002268 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002269 // Handle modules created as `test_per_src` variations of a single test module:
2270 // use the name of the generated test binary (`fileToCopy`) instead of the name
2271 // of the original test module (`depName`, shared by all `test_per_src`
2272 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002273 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002274 // these are not considered transitive dep
2275 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002276 filesInfo = append(filesInfo, af)
2277 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002278 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002279 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002280 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2281 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002282 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2283 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2284 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2285 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002286 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002287 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002288 }
2289 }
2290 }
2291 return false
2292 })
2293
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002294 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2295 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2296 // via the global boot image config.
2297 if a.artApex {
2298 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2299 dirInApex := filepath.Join("javalib", arch.String())
2300 for _, f := range files {
2301 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002302 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002303 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002304 }
2305 }
2306 }
2307
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002308 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002309 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2310 return
2311 }
2312
Jiyong Park8fd61922018-11-08 02:50:25 +09002313 // remove duplicates in filesInfo
2314 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002315 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002316 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002317 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002318 if e, ok := encountered[dest]; !ok {
2319 encountered[dest] = f
2320 } else {
2321 // If a module is directly included and also transitively depended on
2322 // consider it as directly included.
2323 e.transitiveDep = e.transitiveDep && f.transitiveDep
2324 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002325 }
2326 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002327 var result []apexFile
2328 for _, v := range encountered {
2329 result = append(result, v)
2330 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002331 return result
2332 }
2333 filesInfo = removeDup(filesInfo)
2334
2335 // to have consistent build rules
2336 sort.Slice(filesInfo, func(i, j int) bool {
2337 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2338 })
2339
Jiyong Park8fd61922018-11-08 02:50:25 +09002340 a.installDir = android.PathForModuleInstall(ctx, "apex")
2341 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002342
Jooyung Han54aca7b2019-11-20 02:26:02 +09002343 if a.properties.ApexType != zipApex {
2344 if a.properties.File_contexts == nil {
2345 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2346 } else {
2347 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2348 if a.Platform() {
2349 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2350 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2351 }
2352 }
2353 }
2354 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2355 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2356 return
2357 }
2358 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002359 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2360 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2361 // the same library in the system partition, thus effectively sharing the same libraries
2362 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2363 // in the APEX.
2364 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2365 a.installable() &&
2366 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002367
Jiyong Park9d677202020-02-19 16:29:35 +09002368 // We don't need the optimization for updatable APEXes, as it might give false signal
2369 // to the system health when the APEXes are still bundled (b/149805758)
2370 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2371 a.linkToSystemLib = false
2372 }
2373
Jiyong Park638d30e2020-02-26 18:27:19 +09002374 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2375 if ctx.Host() {
2376 a.linkToSystemLib = false
2377 }
2378
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002379 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002380 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2381
2382 a.setCertificateAndPrivateKey(ctx)
2383 if a.properties.ApexType == flattenedApex {
2384 a.buildFlattenedApex(ctx)
2385 } else {
2386 a.buildUnflattenedApex(ctx)
2387 }
2388
Jooyung Han002ab682020-01-08 01:57:58 +09002389 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002390
2391 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002392}
2393
Jooyung Han5e9013b2020-03-10 06:23:13 +09002394func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002395 key := apex
2396 key = strings.Replace(key, "test_", "", 1)
2397 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2398 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2399
Jiyong Park0f80c182020-01-31 02:49:53 +09002400 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2401 // system. Trim the prefix for the check since they are confusing
2402 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2403 if strings.HasPrefix(moduleName, "libclang_rt.") {
2404 // This module has many arch variants that depend on the product being built.
2405 // We don't want to list them all
2406 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002407 }
2408
2409 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2410 return true
2411 }
2412
Jiyong Park0f80c182020-01-31 02:49:53 +09002413 key = "//any"
2414 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2415 return true
2416 }
2417
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002418 return false
2419}
2420
Jooyung Han344d5432019-08-23 11:17:39 +09002421func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002422 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002423 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002424 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002425 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002426 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002427 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2428 })
Alex Light5098a612018-11-29 17:12:15 -08002429 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002430 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002431 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002432 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002433 return module
2434}
Jiyong Park30ca9372019-02-07 16:27:23 +09002435
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002436func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002437 bundle := newApexBundle()
2438 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002439 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002440 return bundle
2441}
2442
Jiyong Parkfce0b422020-02-11 03:56:06 +09002443// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2444// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002445func testApexBundleFactory() android.Module {
2446 bundle := newApexBundle()
2447 bundle.testApex = true
2448 return bundle
2449}
2450
Jiyong Parkfce0b422020-02-11 03:56:06 +09002451// apex packages other modules into an APEX file which is a packaging format for system-level
2452// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002453func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002454 return newApexBundle()
2455}
2456
Jiyong Park30ca9372019-02-07 16:27:23 +09002457//
2458// Defaults
2459//
2460type Defaults struct {
2461 android.ModuleBase
2462 android.DefaultsModuleBase
2463}
2464
Jiyong Park30ca9372019-02-07 16:27:23 +09002465func defaultsFactory() android.Module {
2466 return DefaultsFactory()
2467}
2468
2469func DefaultsFactory(props ...interface{}) android.Module {
2470 module := &Defaults{}
2471
2472 module.AddProperties(props...)
2473 module.AddProperties(
2474 &apexBundleProperties{},
2475 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002476 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002477 )
2478
2479 android.InitDefaultsModule(module)
2480 return module
2481}
Jiyong Park5d790c32019-11-15 18:40:32 +09002482
2483//
2484// OverrideApex
2485//
2486type OverrideApex struct {
2487 android.ModuleBase
2488 android.OverrideModuleBase
2489}
2490
2491func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2492 // All the overrides happen in the base module.
2493}
2494
2495// override_apex is used to create an apex module based on another apex module
2496// by overriding some of its properties.
2497func overrideApexFactory() android.Module {
2498 m := &OverrideApex{}
2499 m.AddProperties(&overridableProperties{})
2500
2501 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2502 android.InitOverrideModule(m)
2503 return m
2504}