blob: 452e831f46cb59acec56a6d7b99a6f890f35fffb [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"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Park0f80c182020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
55 executableTag = dependencyTag{name: "executable", payload: true}
56 javaLibTag = dependencyTag{name: "javaLib", payload: true}
57 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
58 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090059 keyTag = dependencyTag{name: "key"}
60 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090061 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090062 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000063 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090064)
65
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066// This is a map from apex to modules, which overrides the
67// apex_available setting for that particular module to make
68// it available for the apex regardless of its setting.
69// TODO(b/147364041): remove this
70func makeApexAvailableWhitelist() map[string][]string {
71 // The "Module separator"s below are employed to minimize merge conflicts.
72 m := make(map[string][]string)
73 //
74 // Module separator
75 //
Jiyong Park0f80c182020-01-31 02:49:53 +090076 m["com.android.adbd"] = []string{
77 "adbd",
78 "bcm_object",
79 "fmtlib",
80 "libadbconnection_server",
81 "libadbd",
82 "libadbd_auth",
83 "libadbd_core",
84 "libadbd_services",
85 "libasyncio",
86 "libbacktrace_headers",
87 "libbase",
88 "libbase_headers",
89 "libbuildversion",
90 "libc++",
91 "libcap",
92 "libcrypto",
93 "libcrypto_utils",
94 "libcutils",
95 "libcutils_headers",
96 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +090097 "liblog_headers",
98 "libmdnssd",
99 "libminijail",
100 "libminijail_gen_constants",
101 "libminijail_gen_constants_obj",
102 "libminijail_gen_syscall",
103 "libminijail_gen_syscall_obj",
104 "libminijail_generated",
105 "libpackagelistparser",
106 "libpcre2",
107 "libprocessgroup_headers",
108 "libqemu_pipe",
109 "libselinux",
110 "libsystem_headers",
111 "libutils_headers",
112 }
113 //
114 // Module separator
115 //
116 m["com.android.appsearch"] = []string{
117 "icing-java-proto-lite",
118 "libprotobuf-java-lite",
119 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000120 //
121 // Module separator
122 //
123 m["com.android.art"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900124 "art_cmdlineparser_headers",
125 "art_disassembler_headers",
126 "art_libartbase_headers",
127 "bcm_object",
128 "bionic_libc_platform_headers",
129 "core-repackaged-icu4j",
130 "cpp-define-generator-asm-support",
131 "cpp-define-generator-definitions",
132 "crtbegin_dynamic",
133 "crtbegin_dynamic1",
134 "crtbegin_so1",
135 "crtbrand",
136 "conscrypt.module.intra.core.api.stubs",
137 "dex2oat_headers",
138 "dt_fd_forward_export",
139 "fmtlib",
140 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "javavm_headers",
143 "jni_platform_headers",
144 "libPlatformProperties",
145 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000146 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900147 "libandroidicuinit",
148 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900150 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "libbacktrace",
152 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libc++_static",
156 "libc++abi",
157 "libc++demangle",
158 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libdexfile_all_headers",
161 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libfdlibm",
166 "libgtest_prod",
167 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000168 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900169 "libicuuc_headers",
170 "libicuuc_stubdata",
171 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "liblog_headers",
173 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000174 "liblzma",
175 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "libnativebridge-headers",
177 "libnativehelper_header_only",
178 "libnativeloader-headers",
179 "libnpt_headers",
180 "libopenjdkjvmti_headers",
181 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000182 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900183 "libprotobuf-cpp-lite",
184 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000185 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900186 "libv8",
187 "libv8base",
188 "libv8gen",
189 "libv8platform",
190 "libv8sampler",
191 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000192 "libvixl",
193 "libvixld",
194 "libz",
195 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000197 }
198 //
199 // Module separator
200 //
201 m["com.android.bluetooth.updatable"] = []string{
202 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000203 "android.hardware.bluetooth.a2dp@1.0",
204 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900205 "android.hardware.bluetooth@1.0",
206 "android.hardware.bluetooth@1.1",
207 "android.hardware.graphics.bufferqueue@1.0",
208 "android.hardware.graphics.bufferqueue@2.0",
209 "android.hardware.graphics.common@1.0",
210 "android.hardware.graphics.common@1.1",
211 "android.hardware.graphics.common@1.2",
212 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000213 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "android.hidl.token@1.0",
215 "android.hidl.token@1.0-utils",
216 "avrcp-target-service",
217 "avrcp_headers",
218 "bcm_object",
219 "bluetooth-protos-lite",
220 "bluetooth.mapsapi",
221 "com.android.vcard",
222 "fmtlib",
223 "guava",
224 "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",
289 "sap-api-java-static",
290 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000291 }
292 //
293 // Module separator
294 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000296 //
297 // Module separator
298 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 m["com.android.conscrypt"] = []string{
300 "bcm_object",
301 "boringssl_self_test",
302 "libc++",
303 "libcrypto",
304 "libnativehelper_header_only",
305 "libssl",
306 }
307 //
308 // Module separator
309 //
310 m["com.android.extservices"] = []string{
311 "flatbuffer_headers",
312 "liblua",
313 "libtextclassifier",
314 "libtextclassifier_hash_static",
315 "libtflite_static",
316 "libutf",
317 "libz_current",
318 "tensorflow_headers",
319 }
320 //
321 // Module separator
322 //
323 m["com.android.cronet"] = []string{
324 "cronet_impl_common_java",
325 "cronet_impl_native_java",
326 "cronet_impl_platform_java",
327 "libcronet.80.0.3986.0",
328 "org.chromium.net.cronet",
329 "prebuilt_libcronet.80.0.3986.0",
330 }
331 //
332 // Module separator
333 //
334 m["com.android.neuralnetworks"] = []string{
335 "android.hardware.neuralnetworks@1.0",
336 "android.hardware.neuralnetworks@1.1",
337 "android.hardware.neuralnetworks@1.2",
338 "android.hardware.neuralnetworks@1.3",
339 "android.hidl.allocator@1.0",
340 "android.hidl.memory.token@1.0",
341 "android.hidl.memory@1.0",
342 "android.hidl.safe_union@1.0",
343 "bcm_object",
344 "fmtlib",
345 "gemmlowp_headers",
346 "libarect",
347 "libbacktrace_headers",
348 "libbase",
349 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900350 "libbuildversion",
351 "libc++",
352 "libcrypto",
353 "libcrypto_static",
354 "libcutils",
355 "libcutils_headers",
356 "libeigen",
357 "libfmq",
358 "libhidlbase",
359 "libhidlbase-impl-internal",
360 "libhidlmemory",
361 "libhidltransport-impl-internal",
362 "libhwbinder-impl-internal",
363 "libjsoncpp",
364 "liblog_headers",
365 "libmath",
366 "libneuralnetworks_common",
367 "libneuralnetworks_headers",
368 "libprocessgroup",
369 "libprocessgroup_headers",
370 "libprocpartition",
371 "libsync",
372 "libsystem_headers",
373 "libtextclassifier_hash",
374 "libtextclassifier_hash_headers",
375 "libtextclassifier_hash_static",
376 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libutils_headers",
378 "philox_random",
379 "philox_random_headers",
380 "tensorflow_headers",
381 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000382 //
383 // Module separator
384 //
385 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000386 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900387 "android.hardware.cas.native@1.0",
388 "android.hardware.cas@1.0",
389 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000390 "android.hardware.configstore@1.0",
391 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000392 "android.hardware.graphics.allocator@2.0",
393 "android.hardware.graphics.allocator@3.0",
394 "android.hardware.graphics.bufferqueue@1.0",
395 "android.hardware.graphics.bufferqueue@2.0",
396 "android.hardware.graphics.common@1.0",
397 "android.hardware.graphics.common@1.1",
398 "android.hardware.graphics.common@1.2",
399 "android.hardware.graphics.mapper@2.0",
400 "android.hardware.graphics.mapper@2.1",
401 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900402 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000403 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900404 "android.hidl.allocator@1.0",
405 "android.hidl.memory.token@1.0",
406 "android.hidl.memory@1.0",
407 "android.hidl.token@1.0",
408 "android.hidl.token@1.0-utils",
409 "bcm_object",
410 "bionic_libc_platform_headers",
411 "fmtlib",
412 "gl_headers",
413 "libEGL",
414 "libEGL_blobCache",
415 "libEGL_getProcAddress",
416 "libFLAC",
417 "libFLAC-config",
418 "libFLAC-headers",
419 "libGLESv2",
420 "libaacextractor",
421 "libamrextractor",
422 "libarect",
423 "libasync_safe",
424 "libaudio_system_headers",
425 "libaudioclient",
426 "libaudioclient_headers",
427 "libaudiofoundation",
428 "libaudiofoundation_headers",
429 "libaudiomanager",
430 "libaudiopolicy",
431 "libaudioutils",
432 "libaudioutils_fixedfft",
433 "libbacktrace",
434 "libbacktrace_headers",
435 "libbase",
436 "libbase_headers",
437 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900438 "libbluetooth-types-header",
439 "libbufferhub",
440 "libbufferhub_headers",
441 "libbufferhubqueue",
442 "libc++",
443 "libc_headers",
444 "libc_malloc_debug_backtrace",
445 "libcamera_client",
446 "libcamera_metadata",
447 "libcrypto",
448 "libcutils",
449 "libcutils_headers",
450 "libdexfile_external_headers",
451 "libdexfile_support",
452 "libdvr_headers",
453 "libexpat",
454 "libfifo",
455 "libflacextractor",
456 "libgrallocusage",
457 "libgraphicsenv",
458 "libgui",
459 "libgui_headers",
460 "libhardware_headers",
461 "libhidlbase",
462 "libhidlbase-impl-internal",
463 "libhidlmemory",
464 "libhidltransport-impl-internal",
465 "libhwbinder-impl-internal",
466 "libinput",
467 "libjsoncpp",
468 "liblog_headers",
469 "liblzma",
470 "libmath",
471 "libmedia",
472 "libmedia_codeclist",
473 "libmedia_headers",
474 "libmedia_helper",
475 "libmedia_helper_headers",
476 "libmedia_midiiowrapper",
477 "libmedia_omx",
478 "libmediautils",
479 "libmidiextractor",
480 "libmkvextractor",
481 "libmp3extractor",
482 "libmp4extractor",
483 "libmpeg2extractor",
484 "libnativebase_headers",
485 "libnativebridge-headers",
486 "libnativebridge_lazy",
487 "libnativeloader-headers",
488 "libnativeloader_lazy",
489 "libnativewindow_headers",
490 "libnblog",
491 "liboggextractor",
492 "libpackagelistparser",
493 "libpcre2",
494 "libpdx",
495 "libpdx_default_transport",
496 "libpdx_headers",
497 "libpdx_uds",
498 "libprocessgroup",
499 "libprocessgroup_headers",
500 "libprocinfo",
501 "libselinux",
502 "libsonivox",
503 "libspeexresampler",
504 "libspeexresampler",
505 "libstagefright_esds",
506 "libstagefright_flacdec",
507 "libstagefright_flacdec",
508 "libstagefright_foundation",
509 "libstagefright_foundation_headers",
510 "libstagefright_foundation_without_imemory",
511 "libstagefright_headers",
512 "libstagefright_id3",
513 "libstagefright_metadatautils",
514 "libstagefright_mpeg2extractor",
515 "libstagefright_mpeg2support",
516 "libsync",
517 "libsystem_headers",
518 "libui",
519 "libui_headers",
520 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900521 "libutils_headers",
522 "libvibrator",
523 "libvorbisidec",
524 "libwavextractor",
525 "libwebm",
526 "media_ndk_headers",
527 "media_plugin_headers",
528 "updatable-media",
529 }
530 //
531 // Module separator
532 //
533 m["com.android.media.swcodec"] = []string{
534 "android.frameworks.bufferhub@1.0",
535 "android.hardware.common-ndk_platform",
536 "android.hardware.configstore-utils",
537 "android.hardware.configstore@1.0",
538 "android.hardware.configstore@1.1",
539 "android.hardware.graphics.allocator@2.0",
540 "android.hardware.graphics.allocator@3.0",
541 "android.hardware.graphics.bufferqueue@1.0",
542 "android.hardware.graphics.bufferqueue@2.0",
543 "android.hardware.graphics.common-ndk_platform",
544 "android.hardware.graphics.common@1.0",
545 "android.hardware.graphics.common@1.1",
546 "android.hardware.graphics.common@1.2",
547 "android.hardware.graphics.mapper@2.0",
548 "android.hardware.graphics.mapper@2.1",
549 "android.hardware.graphics.mapper@3.0",
550 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000551 "android.hardware.media.bufferpool@2.0",
552 "android.hardware.media.c2@1.0",
553 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 "android.hardware.media@1.0",
555 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000556 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900557 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000558 "android.hidl.safe_union@1.0",
559 "android.hidl.token@1.0",
560 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "fmtlib",
562 "libEGL",
563 "libFLAC",
564 "libFLAC-config",
565 "libFLAC-headers",
566 "libFraunhoferAAC",
567 "libarect",
568 "libasync_safe",
569 "libaudio_system_headers",
570 "libaudioutils",
571 "libaudioutils",
572 "libaudioutils_fixedfft",
573 "libavcdec",
574 "libavcenc",
575 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000576 "libavservices_minijail",
577 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000579 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libbase_headers",
581 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900582 "libbluetooth-types-header",
583 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000584 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900585 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000586 "libcap",
587 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900588 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000589 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900590 "libcodec2_hidl@1.1",
591 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000592 "libcodec2_soft_aacdec",
593 "libcodec2_soft_aacenc",
594 "libcodec2_soft_amrnbdec",
595 "libcodec2_soft_amrnbenc",
596 "libcodec2_soft_amrwbdec",
597 "libcodec2_soft_amrwbenc",
598 "libcodec2_soft_av1dec_gav1",
599 "libcodec2_soft_avcdec",
600 "libcodec2_soft_avcenc",
601 "libcodec2_soft_common",
602 "libcodec2_soft_flacdec",
603 "libcodec2_soft_flacenc",
604 "libcodec2_soft_g711alawdec",
605 "libcodec2_soft_g711mlawdec",
606 "libcodec2_soft_gsmdec",
607 "libcodec2_soft_h263dec",
608 "libcodec2_soft_h263enc",
609 "libcodec2_soft_hevcdec",
610 "libcodec2_soft_hevcenc",
611 "libcodec2_soft_mp3dec",
612 "libcodec2_soft_mpeg2dec",
613 "libcodec2_soft_mpeg4dec",
614 "libcodec2_soft_mpeg4enc",
615 "libcodec2_soft_opusdec",
616 "libcodec2_soft_opusenc",
617 "libcodec2_soft_rawdec",
618 "libcodec2_soft_vorbisdec",
619 "libcodec2_soft_vp8dec",
620 "libcodec2_soft_vp8enc",
621 "libcodec2_soft_vp9dec",
622 "libcodec2_soft_vp9enc",
623 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000624 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900625 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000626 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900627 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000628 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "libfmq",
630 "libgav1",
631 "libgralloctypes",
632 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000633 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 "libgsm",
635 "libgui_bufferqueue_static",
636 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000637 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libhardware_headers",
639 "libhevcdec",
640 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900642 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 "libhidltransport-impl-internal",
645 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000646 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "libjpeg",
648 "libjsoncpp",
649 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000650 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libminijail_gen_constants",
656 "libminijail_gen_constants_obj",
657 "libminijail_gen_syscall",
658 "libminijail_gen_syscall_obj",
659 "libminijail_generated",
660 "libmpeg2dec",
661 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000662 "libnativebridge_lazy",
663 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000665 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900666 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000667 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900668 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libscudo_wrapper",
670 "libsfplugin_ccodec_utils",
671 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "libstagefright_amrnbdec",
673 "libstagefright_amrnbenc",
674 "libstagefright_amrwbdec",
675 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000676 "libstagefright_bufferpool@2.0.1",
677 "libstagefright_bufferqueue_helper",
678 "libstagefright_enc_common",
679 "libstagefright_flacdec",
680 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libstagefright_foundation_headers",
682 "libstagefright_headers",
683 "libstagefright_m4vh263dec",
684 "libstagefright_m4vh263enc",
685 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000686 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900687 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000688 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900689 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000690 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900691 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000692 "libvorbisidec",
693 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libyuv",
695 "libyuv_static",
696 "media_ndk_headers",
697 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000698 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900699 }
700 //
701 // Module separator
702 //
703 m["com.android.mediaprovider"] = []string{
704 "MediaProvider",
705 "MediaProviderGoogle",
706 "fmtlib_ndk",
707 "guava",
708 "libbase_ndk",
709 "libfuse",
710 "libfuse_jni",
711 "libnativehelper_header_only",
712 }
713 //
714 // Module separator
715 //
716 m["com.android.permission"] = []string{
717 "androidx.annotation_annotation",
718 "androidx.annotation_annotation-nodeps",
719 "androidx.lifecycle_lifecycle-common",
720 "androidx.lifecycle_lifecycle-common-java8",
721 "androidx.lifecycle_lifecycle-common-java8-nodeps",
722 "androidx.lifecycle_lifecycle-common-nodeps",
723 "kotlin-annotations",
724 "kotlin-stdlib",
725 "kotlin-stdlib-jdk7",
726 "kotlin-stdlib-jdk8",
727 "kotlinx-coroutines-android",
728 "kotlinx-coroutines-android-nodeps",
729 "kotlinx-coroutines-core",
730 "kotlinx-coroutines-core-nodeps",
731 "libprotobuf-java-lite",
732 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000733 }
734 //
735 // Module separator
736 //
737 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900738 "bionic_libc_platform_headers",
739 "fmtlib",
740 "libarm-optimized-routines-math",
741 "libasync_safe",
742 "libasync_safe_headers",
743 "libbacktrace_headers",
744 "libbase",
745 "libbase_headers",
746 "libc++",
747 "libc_aeabi",
748 "libc_bionic",
749 "libc_bionic_ndk",
750 "libc_bootstrap",
751 "libc_common",
752 "libc_common_shared",
753 "libc_common_static",
754 "libc_dns",
755 "libc_dynamic_dispatch",
756 "libc_fortify",
757 "libc_freebsd",
758 "libc_freebsd_large_stack",
759 "libc_gdtoa",
760 "libc_headers",
761 "libc_init_dynamic",
762 "libc_init_static",
763 "libc_jemalloc_wrapper",
764 "libc_netbsd",
765 "libc_nomalloc",
766 "libc_nopthread",
767 "libc_openbsd",
768 "libc_openbsd_large_stack",
769 "libc_openbsd_ndk",
770 "libc_pthread",
771 "libc_static_dispatch",
772 "libc_syscalls",
773 "libc_tzcode",
774 "libc_unwind_static",
775 "libcutils",
776 "libcutils_headers",
777 "libdebuggerd",
778 "libdebuggerd_common_headers",
779 "libdebuggerd_handler_core",
780 "libdebuggerd_handler_fallback",
781 "libdexfile_external_headers",
782 "libdexfile_support",
783 "libdexfile_support_static",
784 "libgtest_prod",
785 "libjemalloc5",
786 "liblinker_main",
787 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900788 "liblog_headers",
789 "liblz4",
790 "liblzma",
791 "libprocessgroup_headers",
792 "libprocinfo",
793 "libpropertyinfoparser",
794 "libscudo",
795 "libstdc++",
796 "libsystem_headers",
797 "libsystemproperties",
798 "libtombstoned_client_static",
799 "libunwindstack",
800 "libutils_headers",
801 "libz",
802 "libziparchive",
803 }
804 //
805 // Module separator
806 //
807 m["com.android.resolv"] = []string{
808 "bcm_object",
809 "dnsresolver_aidl_interface-unstable-ndk_platform",
810 "fmtlib",
811 "libbacktrace_headers",
812 "libbase",
813 "libbase_headers",
814 "libc++",
815 "libcrypto",
816 "libcutils",
817 "libcutils_headers",
818 "libgtest_prod",
819 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900820 "liblog_headers",
821 "libnativehelper_header_only",
822 "libnetd_client_headers",
823 "libnetd_resolv",
824 "libnetdutils",
825 "libprocessgroup",
826 "libprocessgroup_headers",
827 "libprotobuf-cpp-lite",
828 "libssl",
829 "libstatslog_resolv",
830 "libstatspush_compat",
831 "libstatssocket",
832 "libstatssocket_headers",
833 "libsystem_headers",
834 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900835 "libutils_headers",
836 "netd_event_listener_interface-ndk_platform",
837 "server_configurable_flags",
838 "stats_proto",
839 }
840 //
841 // Module separator
842 //
843 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000844 "libbase",
845 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900846 "libnativehelper_compat_libc++",
847 "android.hardware.tetheroffload.config@1.0",
848 "fmtlib",
849 "libbacktrace_headers",
850 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900851 "libcgrouprc",
852 "libcgrouprc_format",
853 "libcutils",
854 "libcutils_headers",
855 "libhidlbase",
856 "libhidlbase-impl-internal",
857 "libhidltransport-impl-internal",
858 "libhwbinder-impl-internal",
859 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900860 "liblog_headers",
861 "libprocessgroup",
862 "libprocessgroup_headers",
863 "libsystem_headers",
864 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900865 "libutils_headers",
866 "libvndksupport",
867 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000868 }
869 //
870 // Module separator
871 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900872 m["com.android.wifi"] = []string{
873 "PlatformProperties",
874 "android.hardware.wifi-V1.0-java",
875 "android.hardware.wifi-V1.1-java",
876 "android.hardware.wifi-V1.2-java",
877 "android.hardware.wifi-V1.3-java",
878 "android.hardware.wifi-V1.4-java",
879 "android.hardware.wifi.hostapd-V1.0-java",
880 "android.hardware.wifi.hostapd-V1.1-java",
881 "android.hardware.wifi.hostapd-V1.2-java",
882 "android.hardware.wifi.supplicant-V1.0-java",
883 "android.hardware.wifi.supplicant-V1.1-java",
884 "android.hardware.wifi.supplicant-V1.2-java",
885 "android.hardware.wifi.supplicant-V1.3-java",
886 "android.hidl.base-V1.0-java",
887 "android.hidl.manager-V1.0-java",
888 "android.hidl.manager-V1.1-java",
889 "android.hidl.manager-V1.2-java",
890 "androidx.annotation_annotation",
891 "androidx.annotation_annotation-nodeps",
892 "bouncycastle-unbundled",
893 "dnsresolver_aidl_interface-V2-java",
894 "error_prone_annotations",
895 "ipmemorystore-aidl-interfaces-V3-java",
896 "ipmemorystore-aidl-interfaces-java",
897 "ksoap2",
898 "libbacktrace_headers",
899 "libbase",
900 "libbase_headers",
901 "libc++",
902 "libcutils",
903 "libcutils_headers",
904 "liblog_headers",
905 "libnanohttpd",
906 "libprocessgroup",
907 "libprocessgroup_headers",
908 "libprotobuf-java-lite",
909 "libprotobuf-java-nano",
910 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900911 "libutils_headers",
912 "libwifi-jni",
913 "net-utils-services-common",
914 "netd_aidl_interface-V2-java",
915 "netd_aidl_interface-unstable-java",
916 "netd_event_listener_interface-java",
917 "netlink-client",
918 "networkstack-aidl-interfaces-unstable-java",
919 "networkstack-client",
920 "services.net",
921 "wifi-lite-protos",
922 "wifi-nano-protos",
923 "wifi-service-pre-jarjar",
924 "wifi-service-resources",
925 "prebuilt_androidx.annotation_annotation-nodeps",
926 }
927 //
928 // Module separator
929 //
930 m["com.android.sdkext"] = []string{
931 "fmtlib_ndk",
932 "libbase_ndk",
933 "libprotobuf-cpp-lite-ndk",
934 }
935 //
936 // Module separator
937 //
938 m["com.android.os.statsd"] = []string{
939 "libbacktrace_headers",
940 "libbase_headers",
941 "libc++",
942 "libcutils",
943 "libcutils_headers",
944 "liblog_headers",
945 "libprocessgroup_headers",
946 "libstatssocket",
947 "libsystem_headers",
948 "libutils_headers",
949 }
950 //
951 // Module separator
952 //
953 m["//any"] = []string{
954 "crtbegin_dynamic",
955 "crtbegin_dynamic1",
956 "crtbegin_so",
957 "crtbegin_so1",
958 "crtbegin_static",
959 "crtbrand",
960 "crtend_android",
961 "crtend_so",
962 "libatomic",
963 "libc++_static",
964 "libc++abi",
965 "libc++demangle",
966 "libc_headers",
967 "libclang_rt",
968 "libgcc_stripped",
969 "libprofile-clang-extras",
970 "libprofile-clang-extras_ndk",
971 "libprofile-extras",
972 "libprofile-extras_ndk",
973 "libunwind_llvm",
974 "ndk_crtbegin_dynamic.27",
975 "ndk_crtbegin_so.16",
976 "ndk_crtbegin_so.19",
977 "ndk_crtbegin_so.21",
978 "ndk_crtbegin_so.24",
979 "ndk_crtbegin_so.27",
980 "ndk_crtend_android.27",
981 "ndk_crtend_so.16",
982 "ndk_crtend_so.19",
983 "ndk_crtend_so.21",
984 "ndk_crtend_so.24",
985 "ndk_crtend_so.27",
986 "ndk_libandroid_support",
987 "ndk_libc++_static",
988 "ndk_libc++abi",
989 "ndk_libunwind",
990 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000991 return m
992}
993
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900994func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900995 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800996 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900997 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900998 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700999 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001000 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001001
Jooyung Han31c470b2019-10-18 16:26:59 +09001002 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001003 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001004
1005 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1006 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1007 sort.Strings(*apexFileContextsInfos)
1008 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1009 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001010}
1011
Jooyung Han31c470b2019-10-18 16:26:59 +09001012func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1013 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1014 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1015}
1016
Jiyong Parkd1063c12019-07-17 20:08:41 +09001017func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001018 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001019 ctx.BottomUp("apex", apexMutator).Parallel()
1020 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1021 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001022}
1023
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001024// Mark the direct and transitive dependencies of apex bundles so that they
1025// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001026func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001027 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001028 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001029 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001030 apexBundles = []android.ApexInfo{{mctx.ModuleName(), proptools.Bool(a.properties.Legacy_android10_support)}}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001031 directDep = true
1032 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001033 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001034 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001035 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001036
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001037 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001038 return
1039 }
1040
1041 mctx.VisitDirectDeps(func(child android.Module) {
1042 depName := mctx.OtherModuleName(child)
1043 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1044 (directDep || am.DepIsInSameApex(mctx, child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001045 android.UpdateApexDependency(apexBundles, depName, directDep)
1046 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001047 }
1048 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049}
1050
1051// Create apex variations if a module is included in APEX(s).
1052func apexMutator(mctx android.BottomUpMutatorContext) {
1053 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001054 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001055 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 // apex bundle itself is mutated so that it and its modules have same
1057 // apex variant.
1058 apexBundleName := mctx.ModuleName()
1059 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001060 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1061 apexBundleName := o.GetOverriddenModuleName()
1062 if apexBundleName == "" {
1063 mctx.ModuleErrorf("base property is not set")
1064 return
1065 }
1066 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001067 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001068
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001069}
Sundong Ahne9b55722019-09-06 17:37:42 +09001070
Jooyung Han7a78a922019-10-08 21:59:58 +09001071var (
1072 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1073 apexFileContextsInfosMutex sync.Mutex
1074)
1075
1076func apexFileContextsInfos(config android.Config) *[]string {
1077 return config.Once(apexFileContextsInfosKey, func() interface{} {
1078 return &[]string{}
1079 }).(*[]string)
1080}
1081
Jooyung Han54aca7b2019-11-20 02:26:02 +09001082func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001083 apexFileContextsInfosMutex.Lock()
1084 defer apexFileContextsInfosMutex.Unlock()
1085 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001086 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001087}
1088
Sundong Ahne9b55722019-09-06 17:37:42 +09001089func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001090 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001091 var variants []string
1092 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1093 case "image":
1094 variants = append(variants, imageApexType, flattenedApexType)
1095 case "zip":
1096 variants = append(variants, zipApexType)
1097 case "both":
1098 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1099 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001100 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001101 return
1102 }
1103
1104 modules := mctx.CreateLocalVariations(variants...)
1105
1106 for i, v := range variants {
1107 switch v {
1108 case imageApexType:
1109 modules[i].(*apexBundle).properties.ApexType = imageApex
1110 case zipApexType:
1111 modules[i].(*apexBundle).properties.ApexType = zipApex
1112 case flattenedApexType:
1113 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001114 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001115 modules[i].(*apexBundle).MakeAsSystemExt()
1116 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001117 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001118 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001119 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1120 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001121 }
1122}
1123
Jooyung Han5c998b92019-06-27 11:30:33 +09001124func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1125 if ab, ok := mctx.Module().(*apexBundle); ok {
1126 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1127 }
1128}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001129
Jooyung Handc782442019-11-01 03:14:38 +09001130var (
1131 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1132)
1133
1134// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1135// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1136// which may cause compatibility issues. (e.g. libbinder)
1137// Even though libbinder restricts its availability via 'apex_available' property and relies on
1138// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1139// to avoid similar problems.
1140func useVendorWhitelist(config android.Config) []string {
1141 return config.Once(useVendorWhitelistKey, func() interface{} {
1142 return []string{
1143 // swcodec uses "vendor" variants for smaller size
1144 "com.android.media.swcodec",
1145 "test_com.android.media.swcodec",
1146 }
1147 }).([]string)
1148}
1149
1150// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1151// called before the first call to useVendorWhitelist()
1152func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1153 config.Once(useVendorWhitelistKey, func() interface{} {
1154 return whitelist
1155 })
1156}
1157
Jooyung Han01a868d2020-02-27 13:40:44 +09001158type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001159 // List of native libraries
1160 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001161
Alex Light9670d332019-01-29 18:07:33 -08001162 // List of native executables
1163 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001164
Roland Levillain630846d2019-06-26 12:48:34 +01001165 // List of native tests
1166 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001167}
Jooyung Han344d5432019-08-23 11:17:39 +09001168
Alex Light9670d332019-01-29 18:07:33 -08001169type apexMultilibProperties struct {
1170 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001171 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001172
1173 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001174 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001175
1176 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001177 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001178
1179 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001180 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001181
1182 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001183 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001184}
1185
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001186type apexBundleProperties struct {
1187 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001188 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001189 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001190
Jiyong Park40e26a22019-02-08 02:53:06 +09001191 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1192 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001193 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001194
Roland Levillain411c5842019-09-19 16:37:20 +01001195 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1196 // device (/apex/<apex_name>).
1197 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001198 Apex_name *string
1199
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001200 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001201 // For platform APEXes, this should points to a file under /system/sepolicy
1202 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1203 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001204
Jooyung Han01a868d2020-02-27 13:40:44 +09001205 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001206
1207 // List of java libraries that are embedded inside this APEX bundle
1208 Java_libs []string
1209
1210 // List of prebuilt files that are embedded inside this APEX bundle
1211 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001212
1213 // Name of the apex_key module that provides the private key to sign APEX
1214 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001215
Alex Light5098a612018-11-29 17:12:15 -08001216 // The type of APEX to build. Controls what the APEX payload is. Either
1217 // 'image', 'zip' or 'both'. Default: 'image'.
1218 Payload_type *string
1219
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001220 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1221 // or an android_app_certificate module name in the form ":module".
1222 Certificate *string
1223
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001224 // Whether this APEX is installable to one of the partitions. Default: true.
1225 Installable *bool
1226
Jiyong Parkda6eb592018-12-19 17:12:36 +09001227 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1228 // Default is false.
1229 Use_vendor *bool
1230
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001231 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1232 Ignore_system_library_special_case *bool
1233
Alex Light9670d332019-01-29 18:07:33 -08001234 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001235
Jiyong Parkf97782b2019-02-13 20:28:58 +09001236 // List of sanitizer names that this APEX is enabled for
1237 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001238
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001239 PreventInstall bool `blueprint:"mutated"`
1240
1241 HideFromMake bool `blueprint:"mutated"`
1242
Jooyung Han5c998b92019-06-27 11:30:33 +09001243 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1244 Provide_cpp_shared_libs *bool
1245
1246 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1247 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001248
1249 // A txt file containing list of files that are whitelisted to be included in this APEX.
1250 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001251
Sundong Ahnabb64432019-10-22 13:58:29 +09001252 // package format of this apex variant; could be non-flattened, flattened, or zip.
1253 // imageApex, zipApex or flattened
1254 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001255
Jiyong Parkd1063c12019-07-17 20:08:41 +09001256 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1257 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1258 // is implied. This value affects all modules included in this APEX. In other words, they are
1259 // also built with the SDKs specified here.
1260 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001261
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001262 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1263 // Should be only used in tests#.
1264 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001265
1266 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1267 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1268 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001269
1270 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001271
1272 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1273 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1274 // like symlinking to the system libs. Default is false.
1275 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001276
1277 // The minimum SDK version that this apex must be compatibile with.
1278 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001279}
1280
1281type apexTargetBundleProperties struct {
1282 Target struct {
1283 // Multilib properties only for android.
1284 Android struct {
1285 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001286 }
Jooyung Han344d5432019-08-23 11:17:39 +09001287
Alex Light9670d332019-01-29 18:07:33 -08001288 // Multilib properties only for host.
1289 Host struct {
1290 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001291 }
Jooyung Han344d5432019-08-23 11:17:39 +09001292
Alex Light9670d332019-01-29 18:07:33 -08001293 // Multilib properties only for host linux_bionic.
1294 Linux_bionic struct {
1295 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001296 }
Jooyung Han344d5432019-08-23 11:17:39 +09001297
Alex Light9670d332019-01-29 18:07:33 -08001298 // Multilib properties only for host linux_glibc.
1299 Linux_glibc struct {
1300 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001301 }
1302 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001303}
1304
Jiyong Park5d790c32019-11-15 18:40:32 +09001305type overridableProperties struct {
1306 // List of APKs to package inside APEX
1307 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001308
1309 // Names of modules to be overridden. Listed modules can only be other binaries
1310 // (in Make or Soong).
1311 // This does not completely prevent installation of the overridden binaries, but if both
1312 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1313 // from PRODUCT_PACKAGES.
1314 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001315
1316 // Logging Parent value
1317 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001318}
1319
Alex Light5098a612018-11-29 17:12:15 -08001320type apexPackaging int
1321
1322const (
1323 imageApex apexPackaging = iota
1324 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001325 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001326)
1327
Sundong Ahnabb64432019-10-22 13:58:29 +09001328// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001329func (a apexPackaging) suffix() string {
1330 switch a {
1331 case imageApex:
1332 return imageApexSuffix
1333 case zipApex:
1334 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001335 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001336 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001337 }
1338}
1339
1340func (a apexPackaging) name() string {
1341 switch a {
1342 case imageApex:
1343 return imageApexType
1344 case zipApex:
1345 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001346 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001347 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001348 }
1349}
1350
Jiyong Parkf653b052019-11-18 15:39:01 +09001351type apexFileClass int
1352
1353const (
1354 etc apexFileClass = iota
1355 nativeSharedLib
1356 nativeExecutable
1357 shBinary
1358 pyBinary
1359 goBinary
1360 javaSharedLib
1361 nativeTest
1362 app
1363)
1364
Jiyong Park8fd61922018-11-08 02:50:25 +09001365func (class apexFileClass) NameInMake() string {
1366 switch class {
1367 case etc:
1368 return "ETC"
1369 case nativeSharedLib:
1370 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001371 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001372 return "EXECUTABLES"
1373 case javaSharedLib:
1374 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001375 case nativeTest:
1376 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001377 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001378 // b/142537672 Why isn't this APP? We want to have full control over
1379 // the paths and file names of the apk file under the flattend APEX.
1380 // If this is set to APP, then the paths and file names are modified
1381 // by the Make build system. For example, it is installed to
1382 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1383 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1384 // appends module name (which is <apexname>.<Appname> to the path.
1385 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001386 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001387 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001388 }
1389}
1390
Jiyong Parkf653b052019-11-18 15:39:01 +09001391// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001392type apexFile struct {
1393 builtFile android.Path
1394 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001395 installDir string
1396 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001397 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001398 // list of symlinks that will be created in installDir that point to this apexFile
1399 symlinks []string
1400 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001401 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001402
1403 requiredModuleNames []string
1404 targetRequiredModuleNames []string
1405 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001406
Colin Cross503c1d02020-01-28 14:00:53 -08001407 jacocoReportClassesFile android.Path // only for javalibs and apps
1408 certificate java.Certificate // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001409}
1410
Jiyong Park1833cef2019-12-13 13:28:36 +09001411func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1412 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001413 builtFile: builtFile,
1414 moduleName: moduleName,
1415 installDir: installDir,
1416 class: class,
1417 module: module,
1418 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001419 if module != nil {
1420 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001421 ret.requiredModuleNames = module.RequiredModuleNames()
1422 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1423 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001424 }
1425 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001426}
1427
1428func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001429 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001430}
1431
Jiyong Park7cd10e32020-01-14 09:22:18 +09001432// Path() returns path of this apex file relative to the APEX root
1433func (af *apexFile) Path() string {
1434 return filepath.Join(af.installDir, af.builtFile.Base())
1435}
1436
1437// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1438func (af *apexFile) SymlinkPaths() []string {
1439 var ret []string
1440 for _, symlink := range af.symlinks {
1441 ret = append(ret, filepath.Join(af.installDir, symlink))
1442 }
1443 return ret
1444}
1445
1446func (af *apexFile) AvailableToPlatform() bool {
1447 if af.module == nil {
1448 return false
1449 }
1450 if am, ok := af.module.(android.ApexModule); ok {
1451 return am.AvailableFor(android.AvailableToPlatform)
1452 }
1453 return false
1454}
1455
Jiyong Park678c8812020-02-07 17:25:49 +09001456type depInfo struct {
1457 to string
1458 from []string
1459 isExternal bool
1460}
1461
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001462type apexBundle struct {
1463 android.ModuleBase
1464 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001465 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001466 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001467
Jiyong Park5d790c32019-11-15 18:40:32 +09001468 properties apexBundleProperties
1469 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001470 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001471
Jooyung Hanf21c7972019-12-16 22:32:06 +09001472 // specific to apex_vndk modules
1473 vndkProperties apexVndkProperties
1474
Colin Crossa4925902018-11-16 11:36:28 -08001475 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001476 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001477 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001478
Jiyong Park03b68dd2019-07-26 23:20:40 +09001479 prebuiltFileToDelete string
1480
Jiyong Park42cca6c2019-04-01 11:15:50 +09001481 public_key_file android.Path
1482 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001483
1484 container_certificate_file android.Path
1485 container_private_key_file android.Path
1486
Jooyung Han54aca7b2019-11-20 02:26:02 +09001487 fileContexts android.Path
1488
Jiyong Park8fd61922018-11-08 02:50:25 +09001489 // list of files to be included in this apex
1490 filesInfo []apexFile
1491
Jiyong Park956305c2020-01-09 12:32:06 +09001492 // list of module names that should be installed along with this APEX
1493 requiredDeps []string
1494
Jiyong Park956305c2020-01-09 12:32:06 +09001495 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001496 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001497
Sundong Ahnabb64432019-10-22 13:58:29 +09001498 testApex bool
1499 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001500 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001501 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001502
Jooyung Han214bf372019-11-12 13:03:50 +09001503 manifestJsonOut android.WritablePath
1504 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001505
Jooyung Han002ab682020-01-08 01:57:58 +09001506 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001507 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001508 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001509 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1510 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001511
1512 // Suffix of module name in Android.mk
1513 // ".flattened", ".apex", ".zipapex", or ""
1514 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001515
1516 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001517
1518 // Whether to create symlink to the system file instead of having a file
1519 // inside the apex or not
1520 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001521
1522 // Struct holding the merged notice file paths in different formats
1523 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001524}
1525
Jiyong Park397e55e2018-10-24 21:09:55 +09001526func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001527 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001528 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001529 // Use *FarVariation* to be able to depend on modules having
1530 // conflicting variations with this module. This is required since
1531 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1532 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001533 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001534 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001535 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001536 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001537 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001538
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001539 ctx.AddFarVariationDependencies(append(target.Variations(),
1540 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001541 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001542
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001543 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001544 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001545 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001546 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001547}
1548
Alex Light9670d332019-01-29 18:07:33 -08001549func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1550 if ctx.Os().Class == android.Device {
1551 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1552 } else {
1553 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1554 if ctx.Os().Bionic() {
1555 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1556 } else {
1557 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1558 }
1559 }
1560}
1561
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001562func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001563 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1564 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1565 }
1566
Jiyong Park397e55e2018-10-24 21:09:55 +09001567 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001568 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001569
1570 a.combineProperties(ctx)
1571
Jiyong Park397e55e2018-10-24 21:09:55 +09001572 has32BitTarget := false
1573 for _, target := range targets {
1574 if target.Arch.ArchType.Multilib == "lib32" {
1575 has32BitTarget = true
1576 }
1577 }
1578 for i, target := range targets {
Jooyung Han01a868d2020-02-27 13:40:44 +09001579 // When multilib.* is omitted for native_shared_libs/tests, it implies
1580 // multilib.both
1581 addDependenciesForNativeModules(ctx,
1582 ApexNativeDependencies{
1583 Native_shared_libs: a.properties.Native_shared_libs,
1584 Tests: a.properties.Tests,
1585 Binaries: nil,
1586 },
1587 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001588
Jiyong Park397e55e2018-10-24 21:09:55 +09001589 // Add native modules targetting both ABIs
1590 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001591 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001592 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001593 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001594
Alex Light3d673592019-01-18 14:37:31 -08001595 isPrimaryAbi := i == 0
1596 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001597 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001598 // multilib.first
1599 addDependenciesForNativeModules(ctx,
1600 ApexNativeDependencies{
1601 Native_shared_libs: nil,
1602 Tests: nil,
1603 Binaries: a.properties.Binaries,
1604 },
1605 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001606
1607 // Add native modules targetting the first ABI
1608 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001609 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001610 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001611 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001612 }
1613
1614 switch target.Arch.ArchType.Multilib {
1615 case "lib32":
1616 // Add native modules targetting 32-bit ABI
1617 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001618 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001619 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001620 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001621
1622 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001623 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001624 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001625 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001626 case "lib64":
1627 // Add native modules targetting 64-bit ABI
1628 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001629 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001630 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001631 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001632
1633 if !has32BitTarget {
1634 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001635 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001636 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001637 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001638 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001639
1640 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1641 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1642 if sanitizer == "hwaddress" {
1643 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001644 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil},
1645 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001646 break
1647 }
1648 }
1649 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001650 }
1651
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001652 }
1653
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001654 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1655 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1656 // b/144532908
1657 archForPrebuiltEtc := config.Arches()[0]
1658 for _, arch := range config.Arches() {
1659 // Prefer 64-bit arch if there is any
1660 if arch.ArchType.Multilib == "lib64" {
1661 archForPrebuiltEtc = arch
1662 break
1663 }
1664 }
1665 ctx.AddFarVariationDependencies([]blueprint.Variation{
1666 {Mutator: "os", Variation: ctx.Os().String()},
1667 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1668 }, prebuiltTag, a.properties.Prebuilts...)
1669
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001670 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1671 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001672
Ulya Trafimovich44561882020-01-03 13:25:54 +00001673 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1674 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1675 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1676 javaLibTag, "jacocoagent")
1677 }
1678
Jiyong Park23c52b02019-02-02 13:13:47 +09001679 if String(a.properties.Key) == "" {
1680 ctx.ModuleErrorf("key is missing")
1681 return
1682 }
1683 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001684
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001685 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001686 if cert != "" {
1687 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001688 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001689
1690 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1691 if len(a.properties.Uses_sdks) > 0 {
1692 sdkRefs := []android.SdkRef{}
1693 for _, str := range a.properties.Uses_sdks {
1694 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1695 sdkRefs = append(sdkRefs, parsed)
1696 }
1697 a.BuildWithSdks(sdkRefs)
1698 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001699}
1700
Jiyong Park5d790c32019-11-15 18:40:32 +09001701func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1702 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1703 androidAppTag, a.overridableProperties.Apps...)
1704}
1705
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001706func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1707 // direct deps of an APEX bundle are all part of the APEX bundle
1708 return true
1709}
1710
Colin Cross0ea8ba82019-06-06 14:33:29 -07001711func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001712 moduleName := ctx.ModuleName()
1713 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1714 // we check with the pseudo module name to see if its certificate is overridden.
1715 if a.vndkApex {
1716 moduleName = vndkApexName
1717 }
1718 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001719 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001720 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001721 }
1722 return String(a.properties.Certificate)
1723}
1724
Colin Cross41955e82019-05-29 14:40:35 -07001725func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1726 switch tag {
1727 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001728 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001729 default:
1730 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001731 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001732}
1733
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001734func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001735 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001736}
1737
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001738func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1739 return proptools.Bool(a.properties.Test_only_no_hashtree)
1740}
1741
Jiyong Park7c1dc612019-01-05 11:15:24 +09001742func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001743 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001744 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001745 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001746 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001747 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001748 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001749 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001750 }
1751}
1752
Jiyong Parkf97782b2019-02-13 20:28:58 +09001753func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1754 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1755 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1756 }
1757}
1758
Jiyong Park388ef3f2019-01-28 19:47:32 +09001759func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001760 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1761 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001762 }
1763
1764 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001765 globalSanitizerNames := []string{}
1766 if a.Host() {
1767 globalSanitizerNames = ctx.Config().SanitizeHost()
1768 } else {
1769 arches := ctx.Config().SanitizeDeviceArch()
1770 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1771 globalSanitizerNames = ctx.Config().SanitizeDevice()
1772 }
1773 }
1774 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001775}
1776
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001777func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001778 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001779}
1780
1781func (a *apexBundle) PreventInstall() {
1782 a.properties.PreventInstall = true
1783}
1784
1785func (a *apexBundle) HideFromMake() {
1786 a.properties.HideFromMake = true
1787}
1788
Jiyong Park956305c2020-01-09 12:32:06 +09001789func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1790 a.properties.IsCoverageVariant = coverage
1791}
1792
Jiyong Parkf653b052019-11-18 15:39:01 +09001793// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001794func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001795 // Decide the APEX-local directory by the multilib of the library
1796 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001797 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001798 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001799 case "lib32":
1800 dirInApex = "lib"
1801 case "lib64":
1802 dirInApex = "lib64"
1803 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001804 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001805 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001806 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001807 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001808 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001809 // Special case for Bionic libs and other libs installed with them. This is
1810 // to prevent those libs from being included in the search path
1811 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1812 // those libs in the Runtime APEX are available via the legacy paths in
1813 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1814 // to the legacy paths and thus will be loaded into the default linker
1815 // namespace (aka "platform" namespace). If the libs are directly in
1816 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1817 // into the runtime linker namespace, which will result in double loading of
1818 // them, which isn't supported.
1819 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001820 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001821
Jiyong Parkf653b052019-11-18 15:39:01 +09001822 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001823 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001824}
1825
Jiyong Park1833cef2019-12-13 13:28:36 +09001826func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001827 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001828 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001829 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001830 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001831 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001832 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001833 af.symlinks = cc.Symlinks()
1834 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001835}
1836
Jiyong Park1833cef2019-12-13 13:28:36 +09001837func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001838 dirInApex := "bin"
1839 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001840 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001841}
Jiyong Park1833cef2019-12-13 13:28:36 +09001842func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001843 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001844 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1845 if err != nil {
1846 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001847 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001848 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001849 fileToCopy := android.PathForOutput(ctx, s)
1850 // NB: Since go binaries are static we don't need the module for anything here, which is
1851 // good since the go tool is a blueprint.Module not an android.Module like we would
1852 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001853 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001854}
1855
Jiyong Park1833cef2019-12-13 13:28:36 +09001856func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 dirInApex := filepath.Join("bin", sh.SubDir())
1858 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001859 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001860 af.symlinks = sh.Symlinks()
1861 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001862}
1863
Jooyung Han58f26ab2019-12-18 15:34:32 +09001864// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1865type javaLibrary interface {
1866 android.Module
1867 java.Dependency
1868}
1869
1870func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001872 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001873 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1874 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1875 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001876}
1877
Jiyong Park1833cef2019-12-13 13:28:36 +09001878func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001879 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1880 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001881 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001882}
1883
atrost6e126252020-01-27 17:01:16 +00001884func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1885 dirInApex := filepath.Join("etc", config.SubDir())
1886 fileToCopy := config.CompatConfig()
1887 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1888}
1889
Jiyong Park1833cef2019-12-13 13:28:36 +09001890func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001891 android.Module
1892 Privileged() bool
1893 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001894 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001895 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001896}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001897 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001898 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001899 appDir = "priv-app"
1900 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001901 dirInApex := filepath.Join(appDir, pkgName)
1902 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001903 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1904 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001905 af.certificate = aapp.Certificate()
Jiyong Park618922e2020-01-08 13:35:43 +09001906 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001907}
1908
Roland Levillain935639d2019-08-13 14:55:28 +01001909// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1910type flattenedApexContext struct {
1911 android.ModuleContext
1912}
1913
1914func (c *flattenedApexContext) InstallBypassMake() bool {
1915 return true
1916}
1917
Jiyong Park201cedd2020-02-07 17:25:49 +09001918// Visit dependencies that contributes to the payload of this APEX
1919func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1920 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001921 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1922 am, ok := child.(android.ApexModule)
1923 if !ok || !am.CanHaveApexVariants() {
1924 return false
1925 }
1926
1927 // Check for the direct dependencies that contribute to the payload
1928 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1929 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001930 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001931 return true
1932 }
1933 return false
1934 }
1935
1936 // Check for the indirect dependencies if it is considered as part of the APEX
1937 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001938 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001939 return true
1940 }
1941
Jiyong Park201cedd2020-02-07 17:25:49 +09001942 do(ctx, parent, am, true /* externalDep */)
1943
Jiyong Park0f80c182020-01-31 02:49:53 +09001944 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1945 return false
1946 })
1947}
1948
Jiyong Park201cedd2020-02-07 17:25:49 +09001949// Ensures that the dependencies are marked as available for this APEX
1950func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1951 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1952 if ctx.Host() || a.testApex || a.vndkApex {
1953 return
1954 }
1955
1956 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1957 apexName := ctx.ModuleName()
1958 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
1959 return
1960 }
1961 ctx.ModuleErrorf("requires %q that is not available for the APEX.", to.Name())
1962 })
1963}
1964
Jiyong Park678c8812020-02-07 17:25:49 +09001965// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1966func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1967 a.depInfos = make(map[string]depInfo)
1968 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1969 if from.Name() == to.Name() {
1970 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1971 return
1972 }
1973
1974 if info, exists := a.depInfos[to.Name()]; exists {
1975 if !android.InList(from.Name(), info.from) {
1976 info.from = append(info.from, from.Name())
1977 }
1978 info.isExternal = info.isExternal && externalDep
1979 a.depInfos[to.Name()] = info
1980 } else {
1981 a.depInfos[to.Name()] = depInfo{
1982 to: to.Name(),
1983 from: []string{from.Name()},
1984 isExternal: externalDep,
1985 }
1986 }
1987 })
1988}
1989
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001990func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001991 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1992 switch a.properties.ApexType {
1993 case imageApex:
1994 if buildFlattenedAsDefault {
1995 a.suffix = imageApexSuffix
1996 } else {
1997 a.suffix = ""
1998 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001999
2000 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002001 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002002 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002003 }
2004 case zipApex:
2005 if proptools.String(a.properties.Payload_type) == "zip" {
2006 a.suffix = ""
2007 a.primaryApexType = true
2008 } else {
2009 a.suffix = zipApexSuffix
2010 }
2011 case flattenedApex:
2012 if buildFlattenedAsDefault {
2013 a.suffix = ""
2014 a.primaryApexType = true
2015 } else {
2016 a.suffix = flattenedSuffix
2017 }
Alex Light5098a612018-11-29 17:12:15 -08002018 }
2019
Roland Levillain630846d2019-06-26 12:48:34 +01002020 if len(a.properties.Tests) > 0 && !a.testApex {
2021 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2022 return
2023 }
2024
Jiyong Park0f80c182020-01-31 02:49:53 +09002025 a.checkApexAvailability(ctx)
2026
Jiyong Park678c8812020-02-07 17:25:49 +09002027 a.collectDepsInfo(ctx)
2028
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002029 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2030
Jooyung Hane1633032019-08-01 17:41:43 +09002031 // native lib dependencies
2032 var provideNativeLibs []string
2033 var requireNativeLibs []string
2034
Jooyung Han5c998b92019-06-27 11:30:33 +09002035 // Check if "uses" requirements are met with dependent apexBundles
2036 var providedNativeSharedLibs []string
2037 useVendor := proptools.Bool(a.properties.Use_vendor)
2038 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2039 if ctx.OtherModuleDependencyTag(m) != usesTag {
2040 return
2041 }
2042 otherName := ctx.OtherModuleName(m)
2043 other, ok := m.(*apexBundle)
2044 if !ok {
2045 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2046 return
2047 }
2048 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2049 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2050 return
2051 }
2052 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2053 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2054 return
2055 }
2056 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2057 })
2058
Jiyong Parkf653b052019-11-18 15:39:01 +09002059 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002060 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002061 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 depTag := ctx.OtherModuleDependencyTag(child)
2063 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002064 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002065 switch depTag {
2066 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002067 if c, ok := child.(*cc.Module); ok {
2068 // bootstrap bionic libs are treated as provided by system
2069 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2070 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002071 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002072 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002073 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002074 } else {
2075 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002076 }
2077 case executableTag:
2078 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002079 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002080 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002081 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002082 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002083 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002085 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002086 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002087 } else {
Alex Light778127a2019-02-27 14:19:50 -08002088 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 +09002089 }
2090 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002091 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002092 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002093 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002094 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2095 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002096 filesInfo = append(filesInfo, af)
2097 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002098 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002099 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2100 af := apexFileForJavaLibrary(ctx, sdkLib)
2101 if !af.Ok() {
2102 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2103 return false
2104 }
2105 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002106 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002107 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002108 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002109 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002110 case androidAppTag:
2111 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2112 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002113 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002114 return true // track transitive dependencies
2115 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002116 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002117 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2118 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002119 } else {
2120 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2121 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002122 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002123 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002124 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002125 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2126 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002127 } else {
atrost6e126252020-01-27 17:01:16 +00002128 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002129 }
Roland Levillain630846d2019-06-26 12:48:34 +01002130 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002131 if ccTest, ok := child.(*cc.Module); ok {
2132 if ccTest.IsTestPerSrcAllTestsVariation() {
2133 // Multiple-output test module (where `test_per_src: true`).
2134 //
2135 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2136 // We do not add this variation to `filesInfo`, as it has no output;
2137 // however, we do add the other variations of this module as indirect
2138 // dependencies (see below).
2139 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002140 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002141 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002142 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002143 af.class = nativeTest
2144 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002145 }
Roland Levillain630846d2019-06-26 12:48:34 +01002146 } else {
2147 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2148 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002149 case keyTag:
2150 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002151 a.private_key_file = key.private_key_file
2152 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002153 } else {
2154 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002155 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002156 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002157 case certificateTag:
2158 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002159 a.container_certificate_file = dep.Certificate.Pem
2160 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002161 } else {
2162 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2163 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002164 case android.PrebuiltDepTag:
2165 // If the prebuilt is force disabled, remember to delete the prebuilt file
2166 // that might have been installed in the previous builds
2167 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2168 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2169 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002170 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002171 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002172 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002173 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002174 // We cannot use a switch statement on `depTag` here as the checked
2175 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002176 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002177 if cc, ok := child.(*cc.Module); ok {
2178 if android.InList(cc.Name(), providedNativeSharedLibs) {
2179 // If we're using a shared library which is provided from other APEX,
2180 // don't include it in this APEX
2181 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002182 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002183 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002184 // If the dependency is a stubs lib, don't include it in this APEX,
2185 // but make sure that the lib is installed on the device.
2186 // In case no APEX is having the lib, the lib is installed to the system
2187 // partition.
2188 //
2189 // Always include if we are a host-apex however since those won't have any
2190 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002191 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2192 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002193 }
Jooyung Hane1633032019-08-01 17:41:43 +09002194 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002195 // Don't track further
2196 return false
2197 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002198 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002199 af.transitiveDep = true
2200 filesInfo = append(filesInfo, af)
2201 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002202 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002203 } else if cc.IsTestPerSrcDepTag(depTag) {
2204 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002205 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002206 // Handle modules created as `test_per_src` variations of a single test module:
2207 // use the name of the generated test binary (`fileToCopy`) instead of the name
2208 // of the original test module (`depName`, shared by all `test_per_src`
2209 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002210 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002211 // these are not considered transitive dep
2212 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002213 filesInfo = append(filesInfo, af)
2214 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002215 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002216 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002217 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2218 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002219 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2220 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2221 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2222 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002223 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002224 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002225 }
2226 }
2227 }
2228 return false
2229 })
2230
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002231 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2232 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2233 // via the global boot image config.
2234 if a.artApex {
2235 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2236 dirInApex := filepath.Join("javalib", arch.String())
2237 for _, f := range files {
2238 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002239 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002240 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002241 }
2242 }
2243 }
2244
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002245 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002246 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2247 return
2248 }
2249
Jiyong Park8fd61922018-11-08 02:50:25 +09002250 // remove duplicates in filesInfo
2251 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002252 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002253 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002254 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002255 if e, ok := encountered[dest]; !ok {
2256 encountered[dest] = f
2257 } else {
2258 // If a module is directly included and also transitively depended on
2259 // consider it as directly included.
2260 e.transitiveDep = e.transitiveDep && f.transitiveDep
2261 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002262 }
2263 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002264 var result []apexFile
2265 for _, v := range encountered {
2266 result = append(result, v)
2267 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002268 return result
2269 }
2270 filesInfo = removeDup(filesInfo)
2271
2272 // to have consistent build rules
2273 sort.Slice(filesInfo, func(i, j int) bool {
2274 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2275 })
2276
Jiyong Park8fd61922018-11-08 02:50:25 +09002277 a.installDir = android.PathForModuleInstall(ctx, "apex")
2278 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002279
Jooyung Han54aca7b2019-11-20 02:26:02 +09002280 if a.properties.ApexType != zipApex {
2281 if a.properties.File_contexts == nil {
2282 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2283 } else {
2284 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2285 if a.Platform() {
2286 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2287 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2288 }
2289 }
2290 }
2291 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2292 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2293 return
2294 }
2295 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002296 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2297 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2298 // the same library in the system partition, thus effectively sharing the same libraries
2299 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2300 // in the APEX.
2301 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2302 a.installable() &&
2303 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002304
Jiyong Park9d677202020-02-19 16:29:35 +09002305 // We don't need the optimization for updatable APEXes, as it might give false signal
2306 // to the system health when the APEXes are still bundled (b/149805758)
2307 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2308 a.linkToSystemLib = false
2309 }
2310
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002311 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002312 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2313
2314 a.setCertificateAndPrivateKey(ctx)
2315 if a.properties.ApexType == flattenedApex {
2316 a.buildFlattenedApex(ctx)
2317 } else {
2318 a.buildUnflattenedApex(ctx)
2319 }
2320
Jooyung Han002ab682020-01-08 01:57:58 +09002321 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002322
2323 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002324}
2325
Jiyong Park0f80c182020-01-31 02:49:53 +09002326func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002327 key := apex
2328 key = strings.Replace(key, "test_", "", 1)
2329 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2330 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2331
2332 moduleName := module.Name()
Jiyong Park0f80c182020-01-31 02:49:53 +09002333 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2334 // system. Trim the prefix for the check since they are confusing
2335 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2336 if strings.HasPrefix(moduleName, "libclang_rt.") {
2337 // This module has many arch variants that depend on the product being built.
2338 // We don't want to list them all
2339 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002340 }
2341
2342 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2343 return true
2344 }
2345
Jiyong Park0f80c182020-01-31 02:49:53 +09002346 key = "//any"
2347 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2348 return true
2349 }
2350
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002351 return false
2352}
2353
Jooyung Han344d5432019-08-23 11:17:39 +09002354func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002355 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002356 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002357 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002358 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002359 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002360 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2361 })
Alex Light5098a612018-11-29 17:12:15 -08002362 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002363 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002364 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002365 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002366 return module
2367}
Jiyong Park30ca9372019-02-07 16:27:23 +09002368
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002369func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002370 bundle := newApexBundle()
2371 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002372 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002373 return bundle
2374}
2375
Jiyong Parkfce0b422020-02-11 03:56:06 +09002376// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2377// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002378func testApexBundleFactory() android.Module {
2379 bundle := newApexBundle()
2380 bundle.testApex = true
2381 return bundle
2382}
2383
Jiyong Parkfce0b422020-02-11 03:56:06 +09002384// apex packages other modules into an APEX file which is a packaging format for system-level
2385// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002386func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002387 return newApexBundle()
2388}
2389
Jiyong Park30ca9372019-02-07 16:27:23 +09002390//
2391// Defaults
2392//
2393type Defaults struct {
2394 android.ModuleBase
2395 android.DefaultsModuleBase
2396}
2397
Jiyong Park30ca9372019-02-07 16:27:23 +09002398func defaultsFactory() android.Module {
2399 return DefaultsFactory()
2400}
2401
2402func DefaultsFactory(props ...interface{}) android.Module {
2403 module := &Defaults{}
2404
2405 module.AddProperties(props...)
2406 module.AddProperties(
2407 &apexBundleProperties{},
2408 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002409 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002410 )
2411
2412 android.InitDefaultsModule(module)
2413 return module
2414}
Jiyong Park5d790c32019-11-15 18:40:32 +09002415
2416//
2417// OverrideApex
2418//
2419type OverrideApex struct {
2420 android.ModuleBase
2421 android.OverrideModuleBase
2422}
2423
2424func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2425 // All the overrides happen in the base module.
2426}
2427
2428// override_apex is used to create an apex module based on another apex module
2429// by overriding some of its properties.
2430func overrideApexFactory() android.Module {
2431 m := &OverrideApex{}
2432 m.AddProperties(&overridableProperties{})
2433
2434 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2435 android.InitOverrideModule(m)
2436 return m
2437}