blob: a4467f60e5a5acc0c1b77905b72df90722a18c22 [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 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000118 artApexContents := []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 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000193 m["com.android.art.debug"] = artApexContents
194 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 //
196 // Module separator
197 //
198 m["com.android.bluetooth.updatable"] = []string{
199 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000200 "android.hardware.bluetooth.a2dp@1.0",
201 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900202 "android.hardware.bluetooth@1.0",
203 "android.hardware.bluetooth@1.1",
204 "android.hardware.graphics.bufferqueue@1.0",
205 "android.hardware.graphics.bufferqueue@2.0",
206 "android.hardware.graphics.common@1.0",
207 "android.hardware.graphics.common@1.1",
208 "android.hardware.graphics.common@1.2",
209 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900211 "android.hidl.token@1.0",
212 "android.hidl.token@1.0-utils",
213 "avrcp-target-service",
214 "avrcp_headers",
215 "bcm_object",
216 "bluetooth-protos-lite",
217 "bluetooth.mapsapi",
218 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900219 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900220 "fmtlib",
221 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900222 "ipmemorystore-aidl-interfaces-V5-java",
223 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900224 "internal_include_headers",
225 "lib-bt-packets",
226 "lib-bt-packets-avrcp",
227 "lib-bt-packets-base",
228 "libFraunhoferAAC",
229 "libaudio-a2dp-hw-utils",
230 "libaudio-hearing-aid-hw-utils",
231 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000232 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900233 "libbase_headers",
234 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000235 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900236 "libbluetooth-types",
237 "libbluetooth-types-header",
238 "libbluetooth_gd",
239 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libbt-audio-hal-interface",
242 "libbt-bta",
243 "libbt-common",
244 "libbt-hci",
245 "libbt-platform-protos-lite",
246 "libbt-protos-lite",
247 "libbt-sbc-decoder",
248 "libbt-sbc-encoder",
249 "libbt-stack",
250 "libbt-utils",
251 "libbtcore",
252 "libbtdevice",
253 "libbte",
254 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000255 "libc++",
256 "libchrome",
257 "libcrypto",
258 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000260 "libevent",
261 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 "libg722codec",
263 "libgtest_prod",
264 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000265 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900266 "libhidlbase-impl-internal",
267 "libhidltransport-impl-internal",
268 "libhwbinder-impl-internal",
269 "libjsoncpp",
270 "liblog_headers",
271 "libmedia_headers",
272 "libmodpb64",
273 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000274 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900275 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000276 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900277 "libprotobuf-java-lite",
278 "libprotobuf-java-micro",
279 "libstagefright_foundation_headers",
280 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000281 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900282 "libstatssocket",
283 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000284 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900285 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900286 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000287 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900288 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900289 "net-utils-services-common",
290 "netd_aidl_interface-unstable-java",
291 "netd_event_listener_interface-java",
292 "netlink-client",
293 "networkstack-aidl-interfaces-unstable-java",
294 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "sap-api-java-static",
296 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000297 }
298 //
299 // Module separator
300 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900301 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000302 //
303 // Module separator
304 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900305 m["com.android.conscrypt"] = []string{
306 "bcm_object",
307 "boringssl_self_test",
308 "libc++",
309 "libcrypto",
310 "libnativehelper_header_only",
311 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900312 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 }
314 //
315 // Module separator
316 //
317 m["com.android.extservices"] = []string{
318 "flatbuffer_headers",
319 "liblua",
320 "libtextclassifier",
321 "libtextclassifier_hash_static",
322 "libtflite_static",
323 "libutf",
324 "libz_current",
325 "tensorflow_headers",
326 }
327 //
328 // Module separator
329 //
330 m["com.android.cronet"] = []string{
331 "cronet_impl_common_java",
332 "cronet_impl_native_java",
333 "cronet_impl_platform_java",
334 "libcronet.80.0.3986.0",
335 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900336 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900337 "prebuilt_libcronet.80.0.3986.0",
338 }
339 //
340 // Module separator
341 //
342 m["com.android.neuralnetworks"] = []string{
343 "android.hardware.neuralnetworks@1.0",
344 "android.hardware.neuralnetworks@1.1",
345 "android.hardware.neuralnetworks@1.2",
346 "android.hardware.neuralnetworks@1.3",
347 "android.hidl.allocator@1.0",
348 "android.hidl.memory.token@1.0",
349 "android.hidl.memory@1.0",
350 "android.hidl.safe_union@1.0",
351 "bcm_object",
352 "fmtlib",
353 "gemmlowp_headers",
354 "libarect",
355 "libbacktrace_headers",
356 "libbase",
357 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900358 "libbuildversion",
359 "libc++",
360 "libcrypto",
361 "libcrypto_static",
362 "libcutils",
363 "libcutils_headers",
364 "libeigen",
365 "libfmq",
366 "libhidlbase",
367 "libhidlbase-impl-internal",
368 "libhidlmemory",
369 "libhidltransport-impl-internal",
370 "libhwbinder-impl-internal",
371 "libjsoncpp",
372 "liblog_headers",
373 "libmath",
374 "libneuralnetworks_common",
375 "libneuralnetworks_headers",
376 "libprocessgroup",
377 "libprocessgroup_headers",
378 "libprocpartition",
379 "libsync",
380 "libsystem_headers",
381 "libtextclassifier_hash",
382 "libtextclassifier_hash_headers",
383 "libtextclassifier_hash_static",
384 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900385 "libutils_headers",
386 "philox_random",
387 "philox_random_headers",
388 "tensorflow_headers",
389 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000390 //
391 // Module separator
392 //
393 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000394 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900395 "android.hardware.cas.native@1.0",
396 "android.hardware.cas@1.0",
397 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000398 "android.hardware.configstore@1.0",
399 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000400 "android.hardware.graphics.allocator@2.0",
401 "android.hardware.graphics.allocator@3.0",
402 "android.hardware.graphics.bufferqueue@1.0",
403 "android.hardware.graphics.bufferqueue@2.0",
404 "android.hardware.graphics.common@1.0",
405 "android.hardware.graphics.common@1.1",
406 "android.hardware.graphics.common@1.2",
407 "android.hardware.graphics.mapper@2.0",
408 "android.hardware.graphics.mapper@2.1",
409 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900410 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000411 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900412 "android.hidl.allocator@1.0",
413 "android.hidl.memory.token@1.0",
414 "android.hidl.memory@1.0",
415 "android.hidl.token@1.0",
416 "android.hidl.token@1.0-utils",
417 "bcm_object",
418 "bionic_libc_platform_headers",
419 "fmtlib",
420 "gl_headers",
421 "libEGL",
422 "libEGL_blobCache",
423 "libEGL_getProcAddress",
424 "libFLAC",
425 "libFLAC-config",
426 "libFLAC-headers",
427 "libGLESv2",
428 "libaacextractor",
429 "libamrextractor",
430 "libarect",
431 "libasync_safe",
432 "libaudio_system_headers",
433 "libaudioclient",
434 "libaudioclient_headers",
435 "libaudiofoundation",
436 "libaudiofoundation_headers",
437 "libaudiomanager",
438 "libaudiopolicy",
439 "libaudioutils",
440 "libaudioutils_fixedfft",
441 "libbacktrace",
442 "libbacktrace_headers",
443 "libbase",
444 "libbase_headers",
445 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libbluetooth-types-header",
447 "libbufferhub",
448 "libbufferhub_headers",
449 "libbufferhubqueue",
450 "libc++",
451 "libc_headers",
452 "libc_malloc_debug_backtrace",
453 "libcamera_client",
454 "libcamera_metadata",
455 "libcrypto",
456 "libcutils",
457 "libcutils_headers",
458 "libdexfile_external_headers",
459 "libdexfile_support",
460 "libdvr_headers",
461 "libexpat",
462 "libfifo",
463 "libflacextractor",
464 "libgrallocusage",
465 "libgraphicsenv",
466 "libgui",
467 "libgui_headers",
468 "libhardware_headers",
469 "libhidlbase",
470 "libhidlbase-impl-internal",
471 "libhidlmemory",
472 "libhidltransport-impl-internal",
473 "libhwbinder-impl-internal",
474 "libinput",
475 "libjsoncpp",
476 "liblog_headers",
477 "liblzma",
478 "libmath",
479 "libmedia",
480 "libmedia_codeclist",
481 "libmedia_headers",
482 "libmedia_helper",
483 "libmedia_helper_headers",
484 "libmedia_midiiowrapper",
485 "libmedia_omx",
486 "libmediautils",
487 "libmidiextractor",
488 "libmkvextractor",
489 "libmp3extractor",
490 "libmp4extractor",
491 "libmpeg2extractor",
492 "libnativebase_headers",
493 "libnativebridge-headers",
494 "libnativebridge_lazy",
495 "libnativeloader-headers",
496 "libnativeloader_lazy",
497 "libnativewindow_headers",
498 "libnblog",
499 "liboggextractor",
500 "libpackagelistparser",
501 "libpcre2",
502 "libpdx",
503 "libpdx_default_transport",
504 "libpdx_headers",
505 "libpdx_uds",
506 "libprocessgroup",
507 "libprocessgroup_headers",
508 "libprocinfo",
509 "libselinux",
510 "libsonivox",
511 "libspeexresampler",
512 "libspeexresampler",
513 "libstagefright_esds",
514 "libstagefright_flacdec",
515 "libstagefright_flacdec",
516 "libstagefright_foundation",
517 "libstagefright_foundation_headers",
518 "libstagefright_foundation_without_imemory",
519 "libstagefright_headers",
520 "libstagefright_id3",
521 "libstagefright_metadatautils",
522 "libstagefright_mpeg2extractor",
523 "libstagefright_mpeg2support",
524 "libsync",
525 "libsystem_headers",
526 "libui",
527 "libui_headers",
528 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900529 "libutils_headers",
530 "libvibrator",
531 "libvorbisidec",
532 "libwavextractor",
533 "libwebm",
534 "media_ndk_headers",
535 "media_plugin_headers",
536 "updatable-media",
537 }
538 //
539 // Module separator
540 //
541 m["com.android.media.swcodec"] = []string{
542 "android.frameworks.bufferhub@1.0",
543 "android.hardware.common-ndk_platform",
544 "android.hardware.configstore-utils",
545 "android.hardware.configstore@1.0",
546 "android.hardware.configstore@1.1",
547 "android.hardware.graphics.allocator@2.0",
548 "android.hardware.graphics.allocator@3.0",
549 "android.hardware.graphics.bufferqueue@1.0",
550 "android.hardware.graphics.bufferqueue@2.0",
551 "android.hardware.graphics.common-ndk_platform",
552 "android.hardware.graphics.common@1.0",
553 "android.hardware.graphics.common@1.1",
554 "android.hardware.graphics.common@1.2",
555 "android.hardware.graphics.mapper@2.0",
556 "android.hardware.graphics.mapper@2.1",
557 "android.hardware.graphics.mapper@3.0",
558 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000559 "android.hardware.media.bufferpool@2.0",
560 "android.hardware.media.c2@1.0",
561 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "android.hardware.media@1.0",
563 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000566 "android.hidl.safe_union@1.0",
567 "android.hidl.token@1.0",
568 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900569 "fmtlib",
570 "libEGL",
571 "libFLAC",
572 "libFLAC-config",
573 "libFLAC-headers",
574 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900575 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900576 "libarect",
577 "libasync_safe",
578 "libaudio_system_headers",
579 "libaudioutils",
580 "libaudioutils",
581 "libaudioutils_fixedfft",
582 "libavcdec",
583 "libavcenc",
584 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000585 "libavservices_minijail",
586 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000588 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900589 "libbase_headers",
590 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900591 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libbluetooth-types-header",
593 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000594 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000596 "libcap",
597 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900598 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000599 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900600 "libcodec2_hidl@1.1",
601 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000602 "libcodec2_soft_aacdec",
603 "libcodec2_soft_aacenc",
604 "libcodec2_soft_amrnbdec",
605 "libcodec2_soft_amrnbenc",
606 "libcodec2_soft_amrwbdec",
607 "libcodec2_soft_amrwbenc",
608 "libcodec2_soft_av1dec_gav1",
609 "libcodec2_soft_avcdec",
610 "libcodec2_soft_avcenc",
611 "libcodec2_soft_common",
612 "libcodec2_soft_flacdec",
613 "libcodec2_soft_flacenc",
614 "libcodec2_soft_g711alawdec",
615 "libcodec2_soft_g711mlawdec",
616 "libcodec2_soft_gsmdec",
617 "libcodec2_soft_h263dec",
618 "libcodec2_soft_h263enc",
619 "libcodec2_soft_hevcdec",
620 "libcodec2_soft_hevcenc",
621 "libcodec2_soft_mp3dec",
622 "libcodec2_soft_mpeg2dec",
623 "libcodec2_soft_mpeg4dec",
624 "libcodec2_soft_mpeg4enc",
625 "libcodec2_soft_opusdec",
626 "libcodec2_soft_opusenc",
627 "libcodec2_soft_rawdec",
628 "libcodec2_soft_vorbisdec",
629 "libcodec2_soft_vp8dec",
630 "libcodec2_soft_vp8enc",
631 "libcodec2_soft_vp9dec",
632 "libcodec2_soft_vp9enc",
633 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000634 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000636 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000638 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "libfmq",
640 "libgav1",
641 "libgralloctypes",
642 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 "libgsm",
645 "libgui_bufferqueue_static",
646 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000647 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "libhardware_headers",
649 "libhevcdec",
650 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000651 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900652 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000653 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900654 "libhidltransport-impl-internal",
655 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000656 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900657 "libjpeg",
658 "libjsoncpp",
659 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000660 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900661 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000662 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900663 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000664 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900665 "libminijail_gen_constants",
666 "libminijail_gen_constants_obj",
667 "libminijail_gen_syscall",
668 "libminijail_gen_syscall_obj",
669 "libminijail_generated",
670 "libmpeg2dec",
671 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000672 "libnativebridge_lazy",
673 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000675 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000677 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900678 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000679 "libscudo_wrapper",
680 "libsfplugin_ccodec_utils",
681 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900682 "libstagefright_amrnbdec",
683 "libstagefright_amrnbenc",
684 "libstagefright_amrwbdec",
685 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000686 "libstagefright_bufferpool@2.0.1",
687 "libstagefright_bufferqueue_helper",
688 "libstagefright_enc_common",
689 "libstagefright_flacdec",
690 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900691 "libstagefright_foundation_headers",
692 "libstagefright_headers",
693 "libstagefright_m4vh263dec",
694 "libstagefright_m4vh263enc",
695 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000696 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900697 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000698 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900699 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000700 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000702 "libvorbisidec",
703 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libyuv",
705 "libyuv_static",
706 "media_ndk_headers",
707 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000708 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 }
710 //
711 // Module separator
712 //
713 m["com.android.mediaprovider"] = []string{
714 "MediaProvider",
715 "MediaProviderGoogle",
716 "fmtlib_ndk",
717 "guava",
718 "libbase_ndk",
719 "libfuse",
720 "libfuse_jni",
721 "libnativehelper_header_only",
722 }
723 //
724 // Module separator
725 //
726 m["com.android.permission"] = []string{
727 "androidx.annotation_annotation",
728 "androidx.annotation_annotation-nodeps",
729 "androidx.lifecycle_lifecycle-common",
730 "androidx.lifecycle_lifecycle-common-java8",
731 "androidx.lifecycle_lifecycle-common-java8-nodeps",
732 "androidx.lifecycle_lifecycle-common-nodeps",
733 "kotlin-annotations",
734 "kotlin-stdlib",
735 "kotlin-stdlib-jdk7",
736 "kotlin-stdlib-jdk8",
737 "kotlinx-coroutines-android",
738 "kotlinx-coroutines-android-nodeps",
739 "kotlinx-coroutines-core",
740 "kotlinx-coroutines-core-nodeps",
741 "libprotobuf-java-lite",
742 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000743 }
744 //
745 // Module separator
746 //
747 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900748 "bionic_libc_platform_headers",
749 "fmtlib",
750 "libarm-optimized-routines-math",
751 "libasync_safe",
752 "libasync_safe_headers",
753 "libbacktrace_headers",
754 "libbase",
755 "libbase_headers",
756 "libc++",
757 "libc_aeabi",
758 "libc_bionic",
759 "libc_bionic_ndk",
760 "libc_bootstrap",
761 "libc_common",
762 "libc_common_shared",
763 "libc_common_static",
764 "libc_dns",
765 "libc_dynamic_dispatch",
766 "libc_fortify",
767 "libc_freebsd",
768 "libc_freebsd_large_stack",
769 "libc_gdtoa",
770 "libc_headers",
771 "libc_init_dynamic",
772 "libc_init_static",
773 "libc_jemalloc_wrapper",
774 "libc_netbsd",
775 "libc_nomalloc",
776 "libc_nopthread",
777 "libc_openbsd",
778 "libc_openbsd_large_stack",
779 "libc_openbsd_ndk",
780 "libc_pthread",
781 "libc_static_dispatch",
782 "libc_syscalls",
783 "libc_tzcode",
784 "libc_unwind_static",
785 "libcutils",
786 "libcutils_headers",
787 "libdebuggerd",
788 "libdebuggerd_common_headers",
789 "libdebuggerd_handler_core",
790 "libdebuggerd_handler_fallback",
791 "libdexfile_external_headers",
792 "libdexfile_support",
793 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900794 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900795 "libgtest_prod",
796 "libjemalloc5",
797 "liblinker_main",
798 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900799 "liblog_headers",
800 "liblz4",
801 "liblzma",
802 "libprocessgroup_headers",
803 "libprocinfo",
804 "libpropertyinfoparser",
805 "libscudo",
806 "libstdc++",
807 "libsystem_headers",
808 "libsystemproperties",
809 "libtombstoned_client_static",
810 "libunwindstack",
811 "libutils_headers",
812 "libz",
813 "libziparchive",
814 }
815 //
816 // Module separator
817 //
818 m["com.android.resolv"] = []string{
819 "bcm_object",
820 "dnsresolver_aidl_interface-unstable-ndk_platform",
821 "fmtlib",
822 "libbacktrace_headers",
823 "libbase",
824 "libbase_headers",
825 "libc++",
826 "libcrypto",
827 "libcutils",
828 "libcutils_headers",
829 "libgtest_prod",
830 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900831 "liblog_headers",
832 "libnativehelper_header_only",
833 "libnetd_client_headers",
834 "libnetd_resolv",
835 "libnetdutils",
836 "libprocessgroup",
837 "libprocessgroup_headers",
838 "libprotobuf-cpp-lite",
839 "libssl",
840 "libstatslog_resolv",
841 "libstatspush_compat",
842 "libstatssocket",
843 "libstatssocket_headers",
844 "libsystem_headers",
845 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900846 "libutils_headers",
847 "netd_event_listener_interface-ndk_platform",
848 "server_configurable_flags",
849 "stats_proto",
850 }
851 //
852 // Module separator
853 //
854 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000855 "libbase",
856 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900857 "libnativehelper_compat_libc++",
858 "android.hardware.tetheroffload.config@1.0",
859 "fmtlib",
860 "libbacktrace_headers",
861 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900862 "libcgrouprc",
863 "libcgrouprc_format",
864 "libcutils",
865 "libcutils_headers",
866 "libhidlbase",
867 "libhidlbase-impl-internal",
868 "libhidltransport-impl-internal",
869 "libhwbinder-impl-internal",
870 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900871 "liblog_headers",
872 "libprocessgroup",
873 "libprocessgroup_headers",
874 "libsystem_headers",
875 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900876 "libutils_headers",
877 "libvndksupport",
878 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000879 }
880 //
881 // Module separator
882 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900883 m["com.android.wifi"] = []string{
884 "PlatformProperties",
885 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900886 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900887 "android.hardware.wifi-V1.1-java",
888 "android.hardware.wifi-V1.2-java",
889 "android.hardware.wifi-V1.3-java",
890 "android.hardware.wifi-V1.4-java",
891 "android.hardware.wifi.hostapd-V1.0-java",
892 "android.hardware.wifi.hostapd-V1.1-java",
893 "android.hardware.wifi.hostapd-V1.2-java",
894 "android.hardware.wifi.supplicant-V1.0-java",
895 "android.hardware.wifi.supplicant-V1.1-java",
896 "android.hardware.wifi.supplicant-V1.2-java",
897 "android.hardware.wifi.supplicant-V1.3-java",
898 "android.hidl.base-V1.0-java",
899 "android.hidl.manager-V1.0-java",
900 "android.hidl.manager-V1.1-java",
901 "android.hidl.manager-V1.2-java",
902 "androidx.annotation_annotation",
903 "androidx.annotation_annotation-nodeps",
904 "bouncycastle-unbundled",
905 "dnsresolver_aidl_interface-V2-java",
906 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900907 "framework-wifi-pre-jarjar",
908 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900909 "ipmemorystore-aidl-interfaces-V3-java",
910 "ipmemorystore-aidl-interfaces-java",
911 "ksoap2",
912 "libbacktrace_headers",
913 "libbase",
914 "libbase_headers",
915 "libc++",
916 "libcutils",
917 "libcutils_headers",
918 "liblog_headers",
919 "libnanohttpd",
920 "libprocessgroup",
921 "libprocessgroup_headers",
922 "libprotobuf-java-lite",
923 "libprotobuf-java-nano",
924 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900925 "libutils_headers",
926 "libwifi-jni",
927 "net-utils-services-common",
928 "netd_aidl_interface-V2-java",
929 "netd_aidl_interface-unstable-java",
930 "netd_event_listener_interface-java",
931 "netlink-client",
932 "networkstack-aidl-interfaces-unstable-java",
933 "networkstack-client",
934 "services.net",
935 "wifi-lite-protos",
936 "wifi-nano-protos",
937 "wifi-service-pre-jarjar",
938 "wifi-service-resources",
939 "prebuilt_androidx.annotation_annotation-nodeps",
940 }
941 //
942 // Module separator
943 //
944 m["com.android.sdkext"] = []string{
945 "fmtlib_ndk",
946 "libbase_ndk",
947 "libprotobuf-cpp-lite-ndk",
948 }
949 //
950 // Module separator
951 //
952 m["com.android.os.statsd"] = []string{
953 "libbacktrace_headers",
954 "libbase_headers",
955 "libc++",
956 "libcutils",
957 "libcutils_headers",
958 "liblog_headers",
959 "libprocessgroup_headers",
960 "libstatssocket",
961 "libsystem_headers",
962 "libutils_headers",
963 }
964 //
965 // Module separator
966 //
967 m["//any"] = []string{
968 "crtbegin_dynamic",
969 "crtbegin_dynamic1",
970 "crtbegin_so",
971 "crtbegin_so1",
972 "crtbegin_static",
973 "crtbrand",
974 "crtend_android",
975 "crtend_so",
976 "libatomic",
977 "libc++_static",
978 "libc++abi",
979 "libc++demangle",
980 "libc_headers",
981 "libclang_rt",
982 "libgcc_stripped",
983 "libprofile-clang-extras",
984 "libprofile-clang-extras_ndk",
985 "libprofile-extras",
986 "libprofile-extras_ndk",
987 "libunwind_llvm",
988 "ndk_crtbegin_dynamic.27",
989 "ndk_crtbegin_so.16",
990 "ndk_crtbegin_so.19",
991 "ndk_crtbegin_so.21",
992 "ndk_crtbegin_so.24",
993 "ndk_crtbegin_so.27",
994 "ndk_crtend_android.27",
995 "ndk_crtend_so.16",
996 "ndk_crtend_so.19",
997 "ndk_crtend_so.21",
998 "ndk_crtend_so.24",
999 "ndk_crtend_so.27",
1000 "ndk_libandroid_support",
1001 "ndk_libc++_static",
1002 "ndk_libc++abi",
1003 "ndk_libunwind",
1004 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001005 return m
1006}
1007
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001008func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001009 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001010 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001011 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001012 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001013 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001014 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015
Jooyung Han31c470b2019-10-18 16:26:59 +09001016 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001017 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001018
1019 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1020 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1021 sort.Strings(*apexFileContextsInfos)
1022 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1023 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001024}
1025
Jooyung Han31c470b2019-10-18 16:26:59 +09001026func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1027 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1028 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1029}
1030
Jiyong Parkd1063c12019-07-17 20:08:41 +09001031func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001032 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001033 ctx.BottomUp("apex", apexMutator).Parallel()
1034 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1035 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036}
1037
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001038// Mark the direct and transitive dependencies of apex bundles so that they
1039// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001040func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001041 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001042 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001043 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han03b51852020-02-26 22:45:42 +09001044 minSdkVersion := a.minSdkVersion(mctx)
Jooyung Han5e9013b2020-03-10 06:23:13 +09001045 apexBundles = []android.ApexInfo{android.ApexInfo{
1046 ApexName: mctx.ModuleName(),
1047 LegacyAndroid10Support: proptools.Bool(a.properties.Legacy_android10_support),
1048 MinSdkVersion: minSdkVersion,
1049 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001050 directDep = true
1051 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001052 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001053 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001055
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001056 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001057 return
1058 }
1059
Jooyung Han5e9013b2020-03-10 06:23:13 +09001060 cur := mctx.Module().(interface {
1061 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1062 })
1063
Jiyong Parkf760cae2020-02-12 07:53:12 +09001064 mctx.VisitDirectDeps(func(child android.Module) {
1065 depName := mctx.OtherModuleName(child)
1066 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001067 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001068 android.UpdateApexDependency(apexBundles, depName, directDep)
1069 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001070 }
1071 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001072}
1073
1074// Create apex variations if a module is included in APEX(s).
1075func apexMutator(mctx android.BottomUpMutatorContext) {
1076 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001077 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001078 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001079 // apex bundle itself is mutated so that it and its modules have same
1080 // apex variant.
1081 apexBundleName := mctx.ModuleName()
1082 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001083 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1084 apexBundleName := o.GetOverriddenModuleName()
1085 if apexBundleName == "" {
1086 mctx.ModuleErrorf("base property is not set")
1087 return
1088 }
1089 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001090 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001091
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001092}
Sundong Ahne9b55722019-09-06 17:37:42 +09001093
Jooyung Han7a78a922019-10-08 21:59:58 +09001094var (
1095 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1096 apexFileContextsInfosMutex sync.Mutex
1097)
1098
1099func apexFileContextsInfos(config android.Config) *[]string {
1100 return config.Once(apexFileContextsInfosKey, func() interface{} {
1101 return &[]string{}
1102 }).(*[]string)
1103}
1104
Jooyung Han54aca7b2019-11-20 02:26:02 +09001105func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001106 apexFileContextsInfosMutex.Lock()
1107 defer apexFileContextsInfosMutex.Unlock()
1108 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001109 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001110}
1111
Sundong Ahne9b55722019-09-06 17:37:42 +09001112func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001113 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001114 var variants []string
1115 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1116 case "image":
1117 variants = append(variants, imageApexType, flattenedApexType)
1118 case "zip":
1119 variants = append(variants, zipApexType)
1120 case "both":
1121 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1122 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001123 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001124 return
1125 }
1126
1127 modules := mctx.CreateLocalVariations(variants...)
1128
1129 for i, v := range variants {
1130 switch v {
1131 case imageApexType:
1132 modules[i].(*apexBundle).properties.ApexType = imageApex
1133 case zipApexType:
1134 modules[i].(*apexBundle).properties.ApexType = zipApex
1135 case flattenedApexType:
1136 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001137 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001138 modules[i].(*apexBundle).MakeAsSystemExt()
1139 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001140 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001141 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001142 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1143 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001144 }
1145}
1146
Jooyung Han5c998b92019-06-27 11:30:33 +09001147func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1148 if ab, ok := mctx.Module().(*apexBundle); ok {
1149 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1150 }
1151}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001152
Jooyung Handc782442019-11-01 03:14:38 +09001153var (
1154 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1155)
1156
1157// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1158// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1159// which may cause compatibility issues. (e.g. libbinder)
1160// Even though libbinder restricts its availability via 'apex_available' property and relies on
1161// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1162// to avoid similar problems.
1163func useVendorWhitelist(config android.Config) []string {
1164 return config.Once(useVendorWhitelistKey, func() interface{} {
1165 return []string{
1166 // swcodec uses "vendor" variants for smaller size
1167 "com.android.media.swcodec",
1168 "test_com.android.media.swcodec",
1169 }
1170 }).([]string)
1171}
1172
1173// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1174// called before the first call to useVendorWhitelist()
1175func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1176 config.Once(useVendorWhitelistKey, func() interface{} {
1177 return whitelist
1178 })
1179}
1180
Jooyung Han01a868d2020-02-27 13:40:44 +09001181type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001182 // List of native libraries
1183 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001184
Jooyung Han643adc42020-02-27 13:50:06 +09001185 // List of JNI libraries
1186 Jni_libs []string
1187
Alex Light9670d332019-01-29 18:07:33 -08001188 // List of native executables
1189 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001190
Roland Levillain630846d2019-06-26 12:48:34 +01001191 // List of native tests
1192 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001193}
Jooyung Han344d5432019-08-23 11:17:39 +09001194
Alex Light9670d332019-01-29 18:07:33 -08001195type apexMultilibProperties struct {
1196 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001197 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001198
1199 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001200 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001201
1202 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001203 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001204
1205 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001206 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001207
1208 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001209 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001210}
1211
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001212type apexBundleProperties struct {
1213 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001214 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001215 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001216
Jiyong Park40e26a22019-02-08 02:53:06 +09001217 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1218 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001219 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001220
Roland Levillain411c5842019-09-19 16:37:20 +01001221 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1222 // device (/apex/<apex_name>).
1223 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001224 Apex_name *string
1225
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001226 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001227 // For platform APEXes, this should points to a file under /system/sepolicy
1228 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1229 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001230
Jooyung Han01a868d2020-02-27 13:40:44 +09001231 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001232
1233 // List of java libraries that are embedded inside this APEX bundle
1234 Java_libs []string
1235
1236 // List of prebuilt files that are embedded inside this APEX bundle
1237 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001238
1239 // Name of the apex_key module that provides the private key to sign APEX
1240 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001241
Alex Light5098a612018-11-29 17:12:15 -08001242 // The type of APEX to build. Controls what the APEX payload is. Either
1243 // 'image', 'zip' or 'both'. Default: 'image'.
1244 Payload_type *string
1245
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001246 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1247 // or an android_app_certificate module name in the form ":module".
1248 Certificate *string
1249
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001250 // Whether this APEX is installable to one of the partitions. Default: true.
1251 Installable *bool
1252
Jiyong Parkda6eb592018-12-19 17:12:36 +09001253 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1254 // Default is false.
1255 Use_vendor *bool
1256
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001257 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1258 Ignore_system_library_special_case *bool
1259
Alex Light9670d332019-01-29 18:07:33 -08001260 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001261
Jiyong Parkf97782b2019-02-13 20:28:58 +09001262 // List of sanitizer names that this APEX is enabled for
1263 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001264
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001265 PreventInstall bool `blueprint:"mutated"`
1266
1267 HideFromMake bool `blueprint:"mutated"`
1268
Jooyung Han5c998b92019-06-27 11:30:33 +09001269 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1270 Provide_cpp_shared_libs *bool
1271
1272 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1273 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001274
1275 // A txt file containing list of files that are whitelisted to be included in this APEX.
1276 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001277
Sundong Ahnabb64432019-10-22 13:58:29 +09001278 // package format of this apex variant; could be non-flattened, flattened, or zip.
1279 // imageApex, zipApex or flattened
1280 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001281
Jiyong Parkd1063c12019-07-17 20:08:41 +09001282 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1283 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1284 // is implied. This value affects all modules included in this APEX. In other words, they are
1285 // also built with the SDKs specified here.
1286 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001287
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001288 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1289 // Should be only used in tests#.
1290 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001291
1292 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1293 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1294 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001295
1296 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001297
1298 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1299 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1300 // like symlinking to the system libs. Default is false.
1301 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001302
1303 // The minimum SDK version that this apex must be compatibile with.
1304 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001305}
1306
1307type apexTargetBundleProperties struct {
1308 Target struct {
1309 // Multilib properties only for android.
1310 Android struct {
1311 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001312 }
Jooyung Han344d5432019-08-23 11:17:39 +09001313
Alex Light9670d332019-01-29 18:07:33 -08001314 // Multilib properties only for host.
1315 Host struct {
1316 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001317 }
Jooyung Han344d5432019-08-23 11:17:39 +09001318
Alex Light9670d332019-01-29 18:07:33 -08001319 // Multilib properties only for host linux_bionic.
1320 Linux_bionic struct {
1321 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001322 }
Jooyung Han344d5432019-08-23 11:17:39 +09001323
Alex Light9670d332019-01-29 18:07:33 -08001324 // Multilib properties only for host linux_glibc.
1325 Linux_glibc struct {
1326 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001327 }
1328 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001329}
1330
Jiyong Park5d790c32019-11-15 18:40:32 +09001331type overridableProperties struct {
1332 // List of APKs to package inside APEX
1333 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001334
1335 // Names of modules to be overridden. Listed modules can only be other binaries
1336 // (in Make or Soong).
1337 // This does not completely prevent installation of the overridden binaries, but if both
1338 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1339 // from PRODUCT_PACKAGES.
1340 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001341
1342 // Logging Parent value
1343 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001344}
1345
Alex Light5098a612018-11-29 17:12:15 -08001346type apexPackaging int
1347
1348const (
1349 imageApex apexPackaging = iota
1350 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001351 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001352)
1353
Sundong Ahnabb64432019-10-22 13:58:29 +09001354// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001355func (a apexPackaging) suffix() string {
1356 switch a {
1357 case imageApex:
1358 return imageApexSuffix
1359 case zipApex:
1360 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001361 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001362 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001363 }
1364}
1365
1366func (a apexPackaging) name() string {
1367 switch a {
1368 case imageApex:
1369 return imageApexType
1370 case zipApex:
1371 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001372 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001373 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001374 }
1375}
1376
Jiyong Parkf653b052019-11-18 15:39:01 +09001377type apexFileClass int
1378
1379const (
1380 etc apexFileClass = iota
1381 nativeSharedLib
1382 nativeExecutable
1383 shBinary
1384 pyBinary
1385 goBinary
1386 javaSharedLib
1387 nativeTest
1388 app
1389)
1390
Jiyong Park8fd61922018-11-08 02:50:25 +09001391func (class apexFileClass) NameInMake() string {
1392 switch class {
1393 case etc:
1394 return "ETC"
1395 case nativeSharedLib:
1396 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001397 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001398 return "EXECUTABLES"
1399 case javaSharedLib:
1400 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001401 case nativeTest:
1402 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001403 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001404 // b/142537672 Why isn't this APP? We want to have full control over
1405 // the paths and file names of the apk file under the flattend APEX.
1406 // If this is set to APP, then the paths and file names are modified
1407 // by the Make build system. For example, it is installed to
1408 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1409 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1410 // appends module name (which is <apexname>.<Appname> to the path.
1411 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001412 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001413 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001414 }
1415}
1416
Jiyong Parkf653b052019-11-18 15:39:01 +09001417// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001418type apexFile struct {
1419 builtFile android.Path
1420 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001421 installDir string
1422 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001423 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001424 // list of symlinks that will be created in installDir that point to this apexFile
1425 symlinks []string
1426 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001427 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001428
1429 requiredModuleNames []string
1430 targetRequiredModuleNames []string
1431 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001432
Colin Cross503c1d02020-01-28 14:00:53 -08001433 jacocoReportClassesFile android.Path // only for javalibs and apps
1434 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001435 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001436
1437 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001438}
1439
Jiyong Park1833cef2019-12-13 13:28:36 +09001440func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1441 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001442 builtFile: builtFile,
1443 moduleName: moduleName,
1444 installDir: installDir,
1445 class: class,
1446 module: module,
1447 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001448 if module != nil {
1449 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001450 ret.requiredModuleNames = module.RequiredModuleNames()
1451 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1452 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001453 }
1454 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001455}
1456
1457func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001458 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001459}
1460
Jiyong Park7cd10e32020-01-14 09:22:18 +09001461// Path() returns path of this apex file relative to the APEX root
1462func (af *apexFile) Path() string {
1463 return filepath.Join(af.installDir, af.builtFile.Base())
1464}
1465
1466// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1467func (af *apexFile) SymlinkPaths() []string {
1468 var ret []string
1469 for _, symlink := range af.symlinks {
1470 ret = append(ret, filepath.Join(af.installDir, symlink))
1471 }
1472 return ret
1473}
1474
1475func (af *apexFile) AvailableToPlatform() bool {
1476 if af.module == nil {
1477 return false
1478 }
1479 if am, ok := af.module.(android.ApexModule); ok {
1480 return am.AvailableFor(android.AvailableToPlatform)
1481 }
1482 return false
1483}
1484
Jiyong Park678c8812020-02-07 17:25:49 +09001485type depInfo struct {
1486 to string
1487 from []string
1488 isExternal bool
1489}
1490
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001491type apexBundle struct {
1492 android.ModuleBase
1493 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001494 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001495 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001496
Jiyong Park5d790c32019-11-15 18:40:32 +09001497 properties apexBundleProperties
1498 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001499 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001500
Jooyung Hanf21c7972019-12-16 22:32:06 +09001501 // specific to apex_vndk modules
1502 vndkProperties apexVndkProperties
1503
Colin Crossa4925902018-11-16 11:36:28 -08001504 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001505 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001506 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001507
Jiyong Park03b68dd2019-07-26 23:20:40 +09001508 prebuiltFileToDelete string
1509
Jiyong Park42cca6c2019-04-01 11:15:50 +09001510 public_key_file android.Path
1511 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001512
1513 container_certificate_file android.Path
1514 container_private_key_file android.Path
1515
Jooyung Han54aca7b2019-11-20 02:26:02 +09001516 fileContexts android.Path
1517
Jiyong Park8fd61922018-11-08 02:50:25 +09001518 // list of files to be included in this apex
1519 filesInfo []apexFile
1520
Jiyong Park956305c2020-01-09 12:32:06 +09001521 // list of module names that should be installed along with this APEX
1522 requiredDeps []string
1523
Jiyong Park956305c2020-01-09 12:32:06 +09001524 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001525 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001526
Sundong Ahnabb64432019-10-22 13:58:29 +09001527 testApex bool
1528 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001529 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001530 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001531
Jooyung Han214bf372019-11-12 13:03:50 +09001532 manifestJsonOut android.WritablePath
1533 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001534
Jooyung Han002ab682020-01-08 01:57:58 +09001535 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001536 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001537 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001538 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1539 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001540
1541 // Suffix of module name in Android.mk
1542 // ".flattened", ".apex", ".zipapex", or ""
1543 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001544
1545 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001546
1547 // Whether to create symlink to the system file instead of having a file
1548 // inside the apex or not
1549 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001550
1551 // Struct holding the merged notice file paths in different formats
1552 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001553}
1554
Jiyong Park397e55e2018-10-24 21:09:55 +09001555func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001556 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001557 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001558 // Use *FarVariation* to be able to depend on modules having
1559 // conflicting variations with this module. This is required since
1560 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1561 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001562 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001563 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001564 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001565 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001566 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001567
Jooyung Han643adc42020-02-27 13:50:06 +09001568 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1569 {Mutator: "image", Variation: imageVariation},
1570 {Mutator: "link", Variation: "shared"},
1571 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1572 }...), jniLibTag, nativeModules.Jni_libs...)
1573
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001574 ctx.AddFarVariationDependencies(append(target.Variations(),
1575 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001576 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001577
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001578 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001579 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001580 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001581 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001582}
1583
Alex Light9670d332019-01-29 18:07:33 -08001584func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1585 if ctx.Os().Class == android.Device {
1586 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1587 } else {
1588 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1589 if ctx.Os().Bionic() {
1590 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1591 } else {
1592 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1593 }
1594 }
1595}
1596
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001597func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001598 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1599 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1600 }
1601
Jiyong Park397e55e2018-10-24 21:09:55 +09001602 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001603 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001604
1605 a.combineProperties(ctx)
1606
Jiyong Park397e55e2018-10-24 21:09:55 +09001607 has32BitTarget := false
1608 for _, target := range targets {
1609 if target.Arch.ArchType.Multilib == "lib32" {
1610 has32BitTarget = true
1611 }
1612 }
1613 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001614 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001615 // multilib.both
1616 addDependenciesForNativeModules(ctx,
1617 ApexNativeDependencies{
1618 Native_shared_libs: a.properties.Native_shared_libs,
1619 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001620 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001621 Binaries: nil,
1622 },
1623 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001624
Jiyong Park397e55e2018-10-24 21:09:55 +09001625 // Add native modules targetting both ABIs
1626 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001627 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001628 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001629 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001630
Alex Light3d673592019-01-18 14:37:31 -08001631 isPrimaryAbi := i == 0
1632 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001633 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001634 // multilib.first
1635 addDependenciesForNativeModules(ctx,
1636 ApexNativeDependencies{
1637 Native_shared_libs: nil,
1638 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001639 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001640 Binaries: a.properties.Binaries,
1641 },
1642 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001643
1644 // Add native modules targetting the first ABI
1645 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001646 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001647 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001648 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001649 }
1650
1651 switch target.Arch.ArchType.Multilib {
1652 case "lib32":
1653 // Add native modules targetting 32-bit ABI
1654 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001655 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001656 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001657 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001658
1659 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001660 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001661 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001663 case "lib64":
1664 // Add native modules targetting 64-bit ABI
1665 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001666 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001667 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001668 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001669
1670 if !has32BitTarget {
1671 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001672 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001673 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001674 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001675 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001676
1677 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1678 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1679 if sanitizer == "hwaddress" {
1680 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001681 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001682 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001683 break
1684 }
1685 }
1686 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001687 }
1688
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001689 }
1690
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001691 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1692 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1693 // b/144532908
1694 archForPrebuiltEtc := config.Arches()[0]
1695 for _, arch := range config.Arches() {
1696 // Prefer 64-bit arch if there is any
1697 if arch.ArchType.Multilib == "lib64" {
1698 archForPrebuiltEtc = arch
1699 break
1700 }
1701 }
1702 ctx.AddFarVariationDependencies([]blueprint.Variation{
1703 {Mutator: "os", Variation: ctx.Os().String()},
1704 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1705 }, prebuiltTag, a.properties.Prebuilts...)
1706
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001707 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1708 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001709
Ulya Trafimovich44561882020-01-03 13:25:54 +00001710 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1711 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1712 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1713 javaLibTag, "jacocoagent")
1714 }
1715
Jiyong Park23c52b02019-02-02 13:13:47 +09001716 if String(a.properties.Key) == "" {
1717 ctx.ModuleErrorf("key is missing")
1718 return
1719 }
1720 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001721
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001722 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001723 if cert != "" {
1724 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001725 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001726
1727 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1728 if len(a.properties.Uses_sdks) > 0 {
1729 sdkRefs := []android.SdkRef{}
1730 for _, str := range a.properties.Uses_sdks {
1731 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1732 sdkRefs = append(sdkRefs, parsed)
1733 }
1734 a.BuildWithSdks(sdkRefs)
1735 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001736}
1737
Jiyong Park5d790c32019-11-15 18:40:32 +09001738func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1739 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1740 androidAppTag, a.overridableProperties.Apps...)
1741}
1742
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001743func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1744 // direct deps of an APEX bundle are all part of the APEX bundle
1745 return true
1746}
1747
Colin Cross0ea8ba82019-06-06 14:33:29 -07001748func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001749 moduleName := ctx.ModuleName()
1750 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1751 // we check with the pseudo module name to see if its certificate is overridden.
1752 if a.vndkApex {
1753 moduleName = vndkApexName
1754 }
1755 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001756 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001757 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001758 }
1759 return String(a.properties.Certificate)
1760}
1761
Colin Cross41955e82019-05-29 14:40:35 -07001762func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1763 switch tag {
1764 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001765 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001766 default:
1767 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001768 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001769}
1770
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001771func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001772 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001773}
1774
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001775func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1776 return proptools.Bool(a.properties.Test_only_no_hashtree)
1777}
1778
Jiyong Park7c1dc612019-01-05 11:15:24 +09001779func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001780 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001781 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001782 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001783 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001784 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001785 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001786 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001787 }
1788}
1789
Jiyong Parkf97782b2019-02-13 20:28:58 +09001790func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1791 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1792 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1793 }
1794}
1795
Jiyong Park388ef3f2019-01-28 19:47:32 +09001796func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001797 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1798 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001799 }
1800
1801 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001802 globalSanitizerNames := []string{}
1803 if a.Host() {
1804 globalSanitizerNames = ctx.Config().SanitizeHost()
1805 } else {
1806 arches := ctx.Config().SanitizeDeviceArch()
1807 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1808 globalSanitizerNames = ctx.Config().SanitizeDevice()
1809 }
1810 }
1811 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001812}
1813
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001814func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001815 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001816}
1817
1818func (a *apexBundle) PreventInstall() {
1819 a.properties.PreventInstall = true
1820}
1821
1822func (a *apexBundle) HideFromMake() {
1823 a.properties.HideFromMake = true
1824}
1825
Jiyong Park956305c2020-01-09 12:32:06 +09001826func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1827 a.properties.IsCoverageVariant = coverage
1828}
1829
Jiyong Parkf653b052019-11-18 15:39:01 +09001830// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001831func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001832 // Decide the APEX-local directory by the multilib of the library
1833 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001834 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001835 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001836 case "lib32":
1837 dirInApex = "lib"
1838 case "lib64":
1839 dirInApex = "lib64"
1840 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001841 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001842 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001843 }
Jooyung Han35155c42020-02-06 17:33:20 +09001844 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001845 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001846 // Special case for Bionic libs and other libs installed with them. This is
1847 // to prevent those libs from being included in the search path
1848 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1849 // those libs in the Runtime APEX are available via the legacy paths in
1850 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1851 // to the legacy paths and thus will be loaded into the default linker
1852 // namespace (aka "platform" namespace). If the libs are directly in
1853 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1854 // into the runtime linker namespace, which will result in double loading of
1855 // them, which isn't supported.
1856 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001857 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001858
Jiyong Parkf653b052019-11-18 15:39:01 +09001859 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001860 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001861}
1862
Jiyong Park1833cef2019-12-13 13:28:36 +09001863func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001864 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001865 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001866 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001867 }
Jooyung Han35155c42020-02-06 17:33:20 +09001868 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001869 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001870 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 af.symlinks = cc.Symlinks()
1872 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001873}
1874
Jiyong Park1833cef2019-12-13 13:28:36 +09001875func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001876 dirInApex := "bin"
1877 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001878 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001879}
Jiyong Park1833cef2019-12-13 13:28:36 +09001880func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001882 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1883 if err != nil {
1884 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001886 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001887 fileToCopy := android.PathForOutput(ctx, s)
1888 // NB: Since go binaries are static we don't need the module for anything here, which is
1889 // good since the go tool is a blueprint.Module not an android.Module like we would
1890 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001891 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001892}
1893
Jiyong Park1833cef2019-12-13 13:28:36 +09001894func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 dirInApex := filepath.Join("bin", sh.SubDir())
1896 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001897 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001898 af.symlinks = sh.Symlinks()
1899 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001900}
1901
Jooyung Han58f26ab2019-12-18 15:34:32 +09001902// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1903type javaLibrary interface {
1904 android.Module
1905 java.Dependency
1906}
1907
1908func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001910 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001911 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1912 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1913 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001914}
1915
Jiyong Park1833cef2019-12-13 13:28:36 +09001916func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001917 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1918 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001919 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001920}
1921
atrost6e126252020-01-27 17:01:16 +00001922func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1923 dirInApex := filepath.Join("etc", config.SubDir())
1924 fileToCopy := config.CompatConfig()
1925 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1926}
1927
Jiyong Park1833cef2019-12-13 13:28:36 +09001928func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001929 android.Module
1930 Privileged() bool
1931 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001932 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001933 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001934}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001935 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001936 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001937 appDir = "priv-app"
1938 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 dirInApex := filepath.Join(appDir, pkgName)
1940 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001941 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1942 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001943 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001944
1945 if app, ok := aapp.(interface {
1946 OverriddenManifestPackageName() string
1947 }); ok {
1948 af.overriddenPackageName = app.OverriddenManifestPackageName()
1949 }
Jiyong Park618922e2020-01-08 13:35:43 +09001950 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001951}
1952
Roland Levillain935639d2019-08-13 14:55:28 +01001953// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1954type flattenedApexContext struct {
1955 android.ModuleContext
1956}
1957
1958func (c *flattenedApexContext) InstallBypassMake() bool {
1959 return true
1960}
1961
Jiyong Park201cedd2020-02-07 17:25:49 +09001962// Visit dependencies that contributes to the payload of this APEX
1963func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1964 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001965 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1966 am, ok := child.(android.ApexModule)
1967 if !ok || !am.CanHaveApexVariants() {
1968 return false
1969 }
1970
1971 // Check for the direct dependencies that contribute to the payload
1972 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1973 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001974 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001975 return true
1976 }
1977 return false
1978 }
1979
1980 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001981 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001982 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001983 return true
1984 }
1985
Jiyong Park201cedd2020-02-07 17:25:49 +09001986 do(ctx, parent, am, true /* externalDep */)
1987
Jiyong Park0f80c182020-01-31 02:49:53 +09001988 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1989 return false
1990 })
1991}
1992
Jooyung Han03b51852020-02-26 22:45:42 +09001993func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1994 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1995 if ver != "current" {
1996 minSdkVersion, err := strconv.Atoi(ver)
1997 if err != nil {
1998 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1999 }
2000 return minSdkVersion
2001 }
2002 return android.FutureApiLevel
2003}
2004
Jiyong Park201cedd2020-02-07 17:25:49 +09002005// Ensures that the dependencies are marked as available for this APEX
2006func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2007 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2008 if ctx.Host() || a.testApex || a.vndkApex {
2009 return
2010 }
2011
2012 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2013 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002014 fromName := ctx.OtherModuleName(from)
2015 toName := ctx.OtherModuleName(to)
2016 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002017 return
2018 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09002019 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09002020 })
2021}
2022
Jiyong Park678c8812020-02-07 17:25:49 +09002023// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2024func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2025 a.depInfos = make(map[string]depInfo)
2026 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2027 if from.Name() == to.Name() {
2028 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2029 return
2030 }
2031
2032 if info, exists := a.depInfos[to.Name()]; exists {
2033 if !android.InList(from.Name(), info.from) {
2034 info.from = append(info.from, from.Name())
2035 }
2036 info.isExternal = info.isExternal && externalDep
2037 a.depInfos[to.Name()] = info
2038 } else {
2039 a.depInfos[to.Name()] = depInfo{
2040 to: to.Name(),
2041 from: []string{from.Name()},
2042 isExternal: externalDep,
2043 }
2044 }
2045 })
2046}
2047
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002049 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2050 switch a.properties.ApexType {
2051 case imageApex:
2052 if buildFlattenedAsDefault {
2053 a.suffix = imageApexSuffix
2054 } else {
2055 a.suffix = ""
2056 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002057
2058 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002059 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002060 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002061 }
2062 case zipApex:
2063 if proptools.String(a.properties.Payload_type) == "zip" {
2064 a.suffix = ""
2065 a.primaryApexType = true
2066 } else {
2067 a.suffix = zipApexSuffix
2068 }
2069 case flattenedApex:
2070 if buildFlattenedAsDefault {
2071 a.suffix = ""
2072 a.primaryApexType = true
2073 } else {
2074 a.suffix = flattenedSuffix
2075 }
Alex Light5098a612018-11-29 17:12:15 -08002076 }
2077
Roland Levillain630846d2019-06-26 12:48:34 +01002078 if len(a.properties.Tests) > 0 && !a.testApex {
2079 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2080 return
2081 }
2082
Jiyong Park0f80c182020-01-31 02:49:53 +09002083 a.checkApexAvailability(ctx)
2084
Jiyong Park678c8812020-02-07 17:25:49 +09002085 a.collectDepsInfo(ctx)
2086
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002087 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2088
Jooyung Hane1633032019-08-01 17:41:43 +09002089 // native lib dependencies
2090 var provideNativeLibs []string
2091 var requireNativeLibs []string
2092
Jooyung Han5c998b92019-06-27 11:30:33 +09002093 // Check if "uses" requirements are met with dependent apexBundles
2094 var providedNativeSharedLibs []string
2095 useVendor := proptools.Bool(a.properties.Use_vendor)
2096 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2097 if ctx.OtherModuleDependencyTag(m) != usesTag {
2098 return
2099 }
2100 otherName := ctx.OtherModuleName(m)
2101 other, ok := m.(*apexBundle)
2102 if !ok {
2103 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2104 return
2105 }
2106 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2107 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2108 return
2109 }
2110 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2111 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2112 return
2113 }
2114 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2115 })
2116
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002118 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002119 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002120 depTag := ctx.OtherModuleDependencyTag(child)
2121 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002122 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002123 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002124 case sharedLibTag, jniLibTag:
2125 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002126 if c, ok := child.(*cc.Module); ok {
2127 // bootstrap bionic libs are treated as provided by system
2128 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2129 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002130 }
Jooyung Han643adc42020-02-27 13:50:06 +09002131 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2132 fi.isJniLib = isJniLib
2133 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002134 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002135 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002136 propertyName := "native_shared_libs"
2137 if isJniLib {
2138 propertyName = "jni_libs"
2139 }
2140 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002141 }
2142 case executableTag:
2143 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002144 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002145 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002146 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002147 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002148 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002149 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002150 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002151 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002152 } else {
Alex Light778127a2019-02-27 14:19:50 -08002153 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 +09002154 }
2155 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002156 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002157 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002158 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002159 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2160 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002161 filesInfo = append(filesInfo, af)
2162 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002163 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002164 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2165 af := apexFileForJavaLibrary(ctx, sdkLib)
2166 if !af.Ok() {
2167 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2168 return false
2169 }
2170 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002171 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002172 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002173 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002174 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002175 case androidAppTag:
2176 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2177 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002178 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002179 return true // track transitive dependencies
2180 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002181 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002182 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2183 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002184 } else {
2185 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2186 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002187 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002188 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002189 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002190 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2191 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002192 } else {
atrost6e126252020-01-27 17:01:16 +00002193 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002194 }
Roland Levillain630846d2019-06-26 12:48:34 +01002195 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002196 if ccTest, ok := child.(*cc.Module); ok {
2197 if ccTest.IsTestPerSrcAllTestsVariation() {
2198 // Multiple-output test module (where `test_per_src: true`).
2199 //
2200 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2201 // We do not add this variation to `filesInfo`, as it has no output;
2202 // however, we do add the other variations of this module as indirect
2203 // dependencies (see below).
2204 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002205 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002206 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002207 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002208 af.class = nativeTest
2209 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002210 }
Roland Levillain630846d2019-06-26 12:48:34 +01002211 } else {
2212 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2213 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002214 case keyTag:
2215 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002216 a.private_key_file = key.private_key_file
2217 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002218 } else {
2219 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002220 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002221 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002222 case certificateTag:
2223 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002224 a.container_certificate_file = dep.Certificate.Pem
2225 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002226 } else {
2227 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2228 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002229 case android.PrebuiltDepTag:
2230 // If the prebuilt is force disabled, remember to delete the prebuilt file
2231 // that might have been installed in the previous builds
2232 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2233 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2234 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002235 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002236 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002237 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002238 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002239 // We cannot use a switch statement on `depTag` here as the checked
2240 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002241 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002242 if cc, ok := child.(*cc.Module); ok {
2243 if android.InList(cc.Name(), providedNativeSharedLibs) {
2244 // If we're using a shared library which is provided from other APEX,
2245 // don't include it in this APEX
2246 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002247 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002248 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002249 // If the dependency is a stubs lib, don't include it in this APEX,
2250 // but make sure that the lib is installed on the device.
2251 // In case no APEX is having the lib, the lib is installed to the system
2252 // partition.
2253 //
2254 // Always include if we are a host-apex however since those won't have any
2255 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002256 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2257 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002258 }
Jooyung Hane1633032019-08-01 17:41:43 +09002259 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002260 // Don't track further
2261 return false
2262 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002263 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002264 af.transitiveDep = true
2265 filesInfo = append(filesInfo, af)
2266 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002267 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002268 } else if cc.IsTestPerSrcDepTag(depTag) {
2269 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002270 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002271 // Handle modules created as `test_per_src` variations of a single test module:
2272 // use the name of the generated test binary (`fileToCopy`) instead of the name
2273 // of the original test module (`depName`, shared by all `test_per_src`
2274 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002275 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002276 // these are not considered transitive dep
2277 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002278 filesInfo = append(filesInfo, af)
2279 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002280 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002281 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002282 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2283 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002284 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2285 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2286 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2287 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002288 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002289 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002290 }
2291 }
2292 }
2293 return false
2294 })
2295
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002296 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2297 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2298 // via the global boot image config.
2299 if a.artApex {
2300 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2301 dirInApex := filepath.Join("javalib", arch.String())
2302 for _, f := range files {
2303 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002304 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002305 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002306 }
2307 }
2308 }
2309
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002310 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002311 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2312 return
2313 }
2314
Jiyong Park8fd61922018-11-08 02:50:25 +09002315 // remove duplicates in filesInfo
2316 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002317 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002318 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002319 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002320 if e, ok := encountered[dest]; !ok {
2321 encountered[dest] = f
2322 } else {
2323 // If a module is directly included and also transitively depended on
2324 // consider it as directly included.
2325 e.transitiveDep = e.transitiveDep && f.transitiveDep
2326 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002327 }
2328 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002329 var result []apexFile
2330 for _, v := range encountered {
2331 result = append(result, v)
2332 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002333 return result
2334 }
2335 filesInfo = removeDup(filesInfo)
2336
2337 // to have consistent build rules
2338 sort.Slice(filesInfo, func(i, j int) bool {
2339 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2340 })
2341
Jiyong Park8fd61922018-11-08 02:50:25 +09002342 a.installDir = android.PathForModuleInstall(ctx, "apex")
2343 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002344
Jooyung Han54aca7b2019-11-20 02:26:02 +09002345 if a.properties.ApexType != zipApex {
2346 if a.properties.File_contexts == nil {
2347 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2348 } else {
2349 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2350 if a.Platform() {
2351 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2352 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2353 }
2354 }
2355 }
2356 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2357 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2358 return
2359 }
2360 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002361 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2362 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2363 // the same library in the system partition, thus effectively sharing the same libraries
2364 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2365 // in the APEX.
2366 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2367 a.installable() &&
2368 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002369
Jiyong Park9d677202020-02-19 16:29:35 +09002370 // We don't need the optimization for updatable APEXes, as it might give false signal
2371 // to the system health when the APEXes are still bundled (b/149805758)
2372 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2373 a.linkToSystemLib = false
2374 }
2375
Jiyong Park638d30e2020-02-26 18:27:19 +09002376 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2377 if ctx.Host() {
2378 a.linkToSystemLib = false
2379 }
2380
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002381 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002382 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2383
2384 a.setCertificateAndPrivateKey(ctx)
2385 if a.properties.ApexType == flattenedApex {
2386 a.buildFlattenedApex(ctx)
2387 } else {
2388 a.buildUnflattenedApex(ctx)
2389 }
2390
Jooyung Han002ab682020-01-08 01:57:58 +09002391 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002392
2393 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002394}
2395
Jooyung Han5e9013b2020-03-10 06:23:13 +09002396func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002397 key := apex
Jiyong Park0f80c182020-01-31 02:49:53 +09002398 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2399 // system. Trim the prefix for the check since they are confusing
2400 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2401 if strings.HasPrefix(moduleName, "libclang_rt.") {
2402 // This module has many arch variants that depend on the product being built.
2403 // We don't want to list them all
2404 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002405 }
2406
2407 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2408 return true
2409 }
2410
Jiyong Park0f80c182020-01-31 02:49:53 +09002411 key = "//any"
2412 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2413 return true
2414 }
2415
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002416 return false
2417}
2418
Jooyung Han344d5432019-08-23 11:17:39 +09002419func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002420 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002421 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002422 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002423 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002424 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002425 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2426 })
Alex Light5098a612018-11-29 17:12:15 -08002427 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002428 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002429 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002430 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002431 return module
2432}
Jiyong Park30ca9372019-02-07 16:27:23 +09002433
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002434func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002435 bundle := newApexBundle()
2436 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002437 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002438 return bundle
2439}
2440
Jiyong Parkfce0b422020-02-11 03:56:06 +09002441// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2442// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002443func testApexBundleFactory() android.Module {
2444 bundle := newApexBundle()
2445 bundle.testApex = true
2446 return bundle
2447}
2448
Jiyong Parkfce0b422020-02-11 03:56:06 +09002449// apex packages other modules into an APEX file which is a packaging format for system-level
2450// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002451func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002452 return newApexBundle()
2453}
2454
Jiyong Park30ca9372019-02-07 16:27:23 +09002455//
2456// Defaults
2457//
2458type Defaults struct {
2459 android.ModuleBase
2460 android.DefaultsModuleBase
2461}
2462
Jiyong Park30ca9372019-02-07 16:27:23 +09002463func defaultsFactory() android.Module {
2464 return DefaultsFactory()
2465}
2466
2467func DefaultsFactory(props ...interface{}) android.Module {
2468 module := &Defaults{}
2469
2470 module.AddProperties(props...)
2471 module.AddProperties(
2472 &apexBundleProperties{},
2473 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002474 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002475 )
2476
2477 android.InitDefaultsModule(module)
2478 return module
2479}
Jiyong Park5d790c32019-11-15 18:40:32 +09002480
2481//
2482// OverrideApex
2483//
2484type OverrideApex struct {
2485 android.ModuleBase
2486 android.OverrideModuleBase
2487}
2488
2489func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2490 // All the overrides happen in the base module.
2491}
2492
2493// override_apex is used to create an apex module based on another apex module
2494// by overriding some of its properties.
2495func overrideApexFactory() android.Module {
2496 m := &OverrideApex{}
2497 m.AddProperties(&overridableProperties{})
2498
2499 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2500 android.InitOverrideModule(m)
2501 return m
2502}