blob: 825a0ad6b1072530cc222c2545c15852ac308e73 [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",
97 "liblog",
98 "liblog_headers",
99 "libmdnssd",
100 "libminijail",
101 "libminijail_gen_constants",
102 "libminijail_gen_constants_obj",
103 "libminijail_gen_syscall",
104 "libminijail_gen_syscall_obj",
105 "libminijail_generated",
106 "libpackagelistparser",
107 "libpcre2",
108 "libprocessgroup_headers",
109 "libqemu_pipe",
110 "libselinux",
111 "libsystem_headers",
112 "libutils_headers",
113 }
114 //
115 // Module separator
116 //
117 m["com.android.appsearch"] = []string{
118 "icing-java-proto-lite",
119 "libprotobuf-java-lite",
120 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 //
122 // Module separator
123 //
124 m["com.android.art"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900125 "art_cmdlineparser_headers",
126 "art_disassembler_headers",
127 "art_libartbase_headers",
128 "bcm_object",
129 "bionic_libc_platform_headers",
130 "core-repackaged-icu4j",
131 "cpp-define-generator-asm-support",
132 "cpp-define-generator-definitions",
133 "crtbegin_dynamic",
134 "crtbegin_dynamic1",
135 "crtbegin_so1",
136 "crtbrand",
137 "conscrypt.module.intra.core.api.stubs",
138 "dex2oat_headers",
139 "dt_fd_forward_export",
140 "fmtlib",
141 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000142 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900143 "javavm_headers",
144 "jni_platform_headers",
145 "libPlatformProperties",
146 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000147 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900148 "libandroidicuinit",
149 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000150 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900151 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000152 "libbacktrace",
153 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000155 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900156 "libc++_static",
157 "libc++abi",
158 "libc++demangle",
159 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000160 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900161 "libdexfile_all_headers",
162 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000165 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900166 "libfdlibm",
167 "libgtest_prod",
168 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000169 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900170 "libicuuc_headers",
171 "libicuuc_stubdata",
172 "libjdwp_headers",
173 "liblog",
174 "liblog_headers",
175 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000176 "liblzma",
177 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libnativebridge-headers",
179 "libnativehelper_header_only",
180 "libnativeloader-headers",
181 "libnpt_headers",
182 "libopenjdkjvmti_headers",
183 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000184 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "libprotobuf-cpp-lite",
186 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900188 "libv8",
189 "libv8base",
190 "libv8gen",
191 "libv8platform",
192 "libv8sampler",
193 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000194 "libvixl",
195 "libvixld",
196 "libz",
197 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000199 }
200 //
201 // Module separator
202 //
203 m["com.android.bluetooth.updatable"] = []string{
204 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.hardware.bluetooth.a2dp@1.0",
206 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900207 "android.hardware.bluetooth@1.0",
208 "android.hardware.bluetooth@1.1",
209 "android.hardware.graphics.bufferqueue@1.0",
210 "android.hardware.graphics.bufferqueue@2.0",
211 "android.hardware.graphics.common@1.0",
212 "android.hardware.graphics.common@1.1",
213 "android.hardware.graphics.common@1.2",
214 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000215 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "android.hidl.token@1.0",
217 "android.hidl.token@1.0-utils",
218 "avrcp-target-service",
219 "avrcp_headers",
220 "bcm_object",
221 "bluetooth-protos-lite",
222 "bluetooth.mapsapi",
223 "com.android.vcard",
224 "fmtlib",
225 "guava",
226 "internal_include_headers",
227 "lib-bt-packets",
228 "lib-bt-packets-avrcp",
229 "lib-bt-packets-base",
230 "libFraunhoferAAC",
231 "libaudio-a2dp-hw-utils",
232 "libaudio-hearing-aid-hw-utils",
233 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000234 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900235 "libbase_headers",
236 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000237 "libbinderthreadstate",
238 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900239 "libbluetooth-types",
240 "libbluetooth-types-header",
241 "libbluetooth_gd",
242 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000243 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900244 "libbt-audio-hal-interface",
245 "libbt-bta",
246 "libbt-common",
247 "libbt-hci",
248 "libbt-platform-protos-lite",
249 "libbt-protos-lite",
250 "libbt-sbc-decoder",
251 "libbt-sbc-encoder",
252 "libbt-stack",
253 "libbt-utils",
254 "libbtcore",
255 "libbtdevice",
256 "libbte",
257 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 "libc++",
259 "libchrome",
260 "libcrypto",
261 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000263 "libevent",
264 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900265 "libg722codec",
266 "libgtest_prod",
267 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000268 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libhidlbase-impl-internal",
270 "libhidltransport-impl-internal",
271 "libhwbinder-impl-internal",
272 "libjsoncpp",
273 "liblog_headers",
274 "libmedia_headers",
275 "libmodpb64",
276 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000277 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900278 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000279 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "libprotobuf-java-lite",
281 "libprotobuf-java-micro",
282 "libstagefright_foundation_headers",
283 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000284 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900285 "libstatssocket",
286 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000287 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900288 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000289 "libutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000291 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900292 "media_plugin_headers",
293 "sap-api-java-static",
294 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000295 }
296 //
297 // Module separator
298 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000300 //
301 // Module separator
302 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 m["com.android.conscrypt"] = []string{
304 "bcm_object",
305 "boringssl_self_test",
306 "libc++",
307 "libcrypto",
308 "libnativehelper_header_only",
309 "libssl",
310 }
311 //
312 // Module separator
313 //
314 m["com.android.extservices"] = []string{
315 "flatbuffer_headers",
316 "liblua",
317 "libtextclassifier",
318 "libtextclassifier_hash_static",
319 "libtflite_static",
320 "libutf",
321 "libz_current",
322 "tensorflow_headers",
323 }
324 //
325 // Module separator
326 //
327 m["com.android.cronet"] = []string{
328 "cronet_impl_common_java",
329 "cronet_impl_native_java",
330 "cronet_impl_platform_java",
331 "libcronet.80.0.3986.0",
332 "org.chromium.net.cronet",
333 "prebuilt_libcronet.80.0.3986.0",
334 }
335 //
336 // Module separator
337 //
338 m["com.android.neuralnetworks"] = []string{
339 "android.hardware.neuralnetworks@1.0",
340 "android.hardware.neuralnetworks@1.1",
341 "android.hardware.neuralnetworks@1.2",
342 "android.hardware.neuralnetworks@1.3",
343 "android.hidl.allocator@1.0",
344 "android.hidl.memory.token@1.0",
345 "android.hidl.memory@1.0",
346 "android.hidl.safe_union@1.0",
347 "bcm_object",
348 "fmtlib",
349 "gemmlowp_headers",
350 "libarect",
351 "libbacktrace_headers",
352 "libbase",
353 "libbase_headers",
354 "libbinderthreadstate",
355 "libbuildversion",
356 "libc++",
357 "libcrypto",
358 "libcrypto_static",
359 "libcutils",
360 "libcutils_headers",
361 "libeigen",
362 "libfmq",
363 "libhidlbase",
364 "libhidlbase-impl-internal",
365 "libhidlmemory",
366 "libhidltransport-impl-internal",
367 "libhwbinder-impl-internal",
368 "libjsoncpp",
369 "liblog_headers",
370 "libmath",
371 "libneuralnetworks_common",
372 "libneuralnetworks_headers",
373 "libprocessgroup",
374 "libprocessgroup_headers",
375 "libprocpartition",
376 "libsync",
377 "libsystem_headers",
378 "libtextclassifier_hash",
379 "libtextclassifier_hash_headers",
380 "libtextclassifier_hash_static",
381 "libtflite_kernel_utils",
382 "libutils",
383 "libutils_headers",
384 "philox_random",
385 "philox_random_headers",
386 "tensorflow_headers",
387 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000388 //
389 // Module separator
390 //
391 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000392 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900393 "android.hardware.cas.native@1.0",
394 "android.hardware.cas@1.0",
395 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000396 "android.hardware.configstore@1.0",
397 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000398 "android.hardware.graphics.allocator@2.0",
399 "android.hardware.graphics.allocator@3.0",
400 "android.hardware.graphics.bufferqueue@1.0",
401 "android.hardware.graphics.bufferqueue@2.0",
402 "android.hardware.graphics.common@1.0",
403 "android.hardware.graphics.common@1.1",
404 "android.hardware.graphics.common@1.2",
405 "android.hardware.graphics.mapper@2.0",
406 "android.hardware.graphics.mapper@2.1",
407 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900408 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000409 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900410 "android.hidl.allocator@1.0",
411 "android.hidl.memory.token@1.0",
412 "android.hidl.memory@1.0",
413 "android.hidl.token@1.0",
414 "android.hidl.token@1.0-utils",
415 "bcm_object",
416 "bionic_libc_platform_headers",
417 "fmtlib",
418 "gl_headers",
419 "libEGL",
420 "libEGL_blobCache",
421 "libEGL_getProcAddress",
422 "libFLAC",
423 "libFLAC-config",
424 "libFLAC-headers",
425 "libGLESv2",
426 "libaacextractor",
427 "libamrextractor",
428 "libarect",
429 "libasync_safe",
430 "libaudio_system_headers",
431 "libaudioclient",
432 "libaudioclient_headers",
433 "libaudiofoundation",
434 "libaudiofoundation_headers",
435 "libaudiomanager",
436 "libaudiopolicy",
437 "libaudioutils",
438 "libaudioutils_fixedfft",
439 "libbacktrace",
440 "libbacktrace_headers",
441 "libbase",
442 "libbase_headers",
443 "libbinder_headers",
444 "libbinderthreadstate",
445 "libbluetooth-types-header",
446 "libbufferhub",
447 "libbufferhub_headers",
448 "libbufferhubqueue",
449 "libc++",
450 "libc_headers",
451 "libc_malloc_debug_backtrace",
452 "libcamera_client",
453 "libcamera_metadata",
454 "libcrypto",
455 "libcutils",
456 "libcutils_headers",
457 "libdexfile_external_headers",
458 "libdexfile_support",
459 "libdvr_headers",
460 "libexpat",
461 "libfifo",
462 "libflacextractor",
463 "libgrallocusage",
464 "libgraphicsenv",
465 "libgui",
466 "libgui_headers",
467 "libhardware_headers",
468 "libhidlbase",
469 "libhidlbase-impl-internal",
470 "libhidlmemory",
471 "libhidltransport-impl-internal",
472 "libhwbinder-impl-internal",
473 "libinput",
474 "libjsoncpp",
475 "liblog_headers",
476 "liblzma",
477 "libmath",
478 "libmedia",
479 "libmedia_codeclist",
480 "libmedia_headers",
481 "libmedia_helper",
482 "libmedia_helper_headers",
483 "libmedia_midiiowrapper",
484 "libmedia_omx",
485 "libmediautils",
486 "libmidiextractor",
487 "libmkvextractor",
488 "libmp3extractor",
489 "libmp4extractor",
490 "libmpeg2extractor",
491 "libnativebase_headers",
492 "libnativebridge-headers",
493 "libnativebridge_lazy",
494 "libnativeloader-headers",
495 "libnativeloader_lazy",
496 "libnativewindow_headers",
497 "libnblog",
498 "liboggextractor",
499 "libpackagelistparser",
500 "libpcre2",
501 "libpdx",
502 "libpdx_default_transport",
503 "libpdx_headers",
504 "libpdx_uds",
505 "libprocessgroup",
506 "libprocessgroup_headers",
507 "libprocinfo",
508 "libselinux",
509 "libsonivox",
510 "libspeexresampler",
511 "libspeexresampler",
512 "libstagefright_esds",
513 "libstagefright_flacdec",
514 "libstagefright_flacdec",
515 "libstagefright_foundation",
516 "libstagefright_foundation_headers",
517 "libstagefright_foundation_without_imemory",
518 "libstagefright_headers",
519 "libstagefright_id3",
520 "libstagefright_metadatautils",
521 "libstagefright_mpeg2extractor",
522 "libstagefright_mpeg2support",
523 "libsync",
524 "libsystem_headers",
525 "libui",
526 "libui_headers",
527 "libunwindstack",
528 "libutils",
529 "libutils_headers",
530 "libvibrator",
531 "libvorbisidec",
532 "libwavextractor",
533 "libwebm",
534 "media_ndk_headers",
535 "media_plugin_headers",
536 "updatable-media",
537 }
538 //
539 // Module separator
540 //
541 m["com.android.media.swcodec"] = []string{
542 "android.frameworks.bufferhub@1.0",
543 "android.hardware.common-ndk_platform",
544 "android.hardware.configstore-utils",
545 "android.hardware.configstore@1.0",
546 "android.hardware.configstore@1.1",
547 "android.hardware.graphics.allocator@2.0",
548 "android.hardware.graphics.allocator@3.0",
549 "android.hardware.graphics.bufferqueue@1.0",
550 "android.hardware.graphics.bufferqueue@2.0",
551 "android.hardware.graphics.common-ndk_platform",
552 "android.hardware.graphics.common@1.0",
553 "android.hardware.graphics.common@1.1",
554 "android.hardware.graphics.common@1.2",
555 "android.hardware.graphics.mapper@2.0",
556 "android.hardware.graphics.mapper@2.1",
557 "android.hardware.graphics.mapper@3.0",
558 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000559 "android.hardware.media.bufferpool@2.0",
560 "android.hardware.media.c2@1.0",
561 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "android.hardware.media@1.0",
563 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000566 "android.hidl.safe_union@1.0",
567 "android.hidl.token@1.0",
568 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900569 "fmtlib",
570 "libEGL",
571 "libFLAC",
572 "libFLAC-config",
573 "libFLAC-headers",
574 "libFraunhoferAAC",
575 "libarect",
576 "libasync_safe",
577 "libaudio_system_headers",
578 "libaudioutils",
579 "libaudioutils",
580 "libaudioutils_fixedfft",
581 "libavcdec",
582 "libavcenc",
583 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000584 "libavservices_minijail",
585 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900586 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000587 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900588 "libbase_headers",
589 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000590 "libbinderthreadstate",
Jiyong Park0f80c182020-01-31 02:49:53 +0900591 "libbluetooth-types-header",
592 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000593 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000595 "libcap",
596 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900597 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000598 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900599 "libcodec2_hidl@1.1",
600 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 "libcodec2_soft_aacdec",
602 "libcodec2_soft_aacenc",
603 "libcodec2_soft_amrnbdec",
604 "libcodec2_soft_amrnbenc",
605 "libcodec2_soft_amrwbdec",
606 "libcodec2_soft_amrwbenc",
607 "libcodec2_soft_av1dec_gav1",
608 "libcodec2_soft_avcdec",
609 "libcodec2_soft_avcenc",
610 "libcodec2_soft_common",
611 "libcodec2_soft_flacdec",
612 "libcodec2_soft_flacenc",
613 "libcodec2_soft_g711alawdec",
614 "libcodec2_soft_g711mlawdec",
615 "libcodec2_soft_gsmdec",
616 "libcodec2_soft_h263dec",
617 "libcodec2_soft_h263enc",
618 "libcodec2_soft_hevcdec",
619 "libcodec2_soft_hevcenc",
620 "libcodec2_soft_mp3dec",
621 "libcodec2_soft_mpeg2dec",
622 "libcodec2_soft_mpeg4dec",
623 "libcodec2_soft_mpeg4enc",
624 "libcodec2_soft_opusdec",
625 "libcodec2_soft_opusenc",
626 "libcodec2_soft_rawdec",
627 "libcodec2_soft_vorbisdec",
628 "libcodec2_soft_vp8dec",
629 "libcodec2_soft_vp8enc",
630 "libcodec2_soft_vp9dec",
631 "libcodec2_soft_vp9enc",
632 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000633 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000635 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900636 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000637 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900638 "libfmq",
639 "libgav1",
640 "libgralloctypes",
641 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000642 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900643 "libgsm",
644 "libgui_bufferqueue_static",
645 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000646 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "libhardware_headers",
648 "libhevcdec",
649 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000650 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libhidltransport-impl-internal",
654 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000655 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900656 "libjpeg",
657 "libjsoncpp",
658 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000659 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900660 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000663 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libminijail_gen_constants",
665 "libminijail_gen_constants_obj",
666 "libminijail_gen_syscall",
667 "libminijail_gen_syscall_obj",
668 "libminijail_generated",
669 "libmpeg2dec",
670 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000671 "libnativebridge_lazy",
672 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000674 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900675 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000676 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900677 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000678 "libscudo_wrapper",
679 "libsfplugin_ccodec_utils",
680 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libstagefright_amrnbdec",
682 "libstagefright_amrnbenc",
683 "libstagefright_amrwbdec",
684 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000685 "libstagefright_bufferpool@2.0.1",
686 "libstagefright_bufferqueue_helper",
687 "libstagefright_enc_common",
688 "libstagefright_flacdec",
689 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900690 "libstagefright_foundation_headers",
691 "libstagefright_headers",
692 "libstagefright_m4vh263dec",
693 "libstagefright_m4vh263enc",
694 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000695 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000697 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900698 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000699 "libunwindstack",
700 "libutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000702 "libvorbisidec",
703 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libyuv",
705 "libyuv_static",
706 "media_ndk_headers",
707 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000708 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 }
710 //
711 // Module separator
712 //
713 m["com.android.mediaprovider"] = []string{
714 "MediaProvider",
715 "MediaProviderGoogle",
716 "fmtlib_ndk",
717 "guava",
718 "libbase_ndk",
719 "libfuse",
720 "libfuse_jni",
721 "libnativehelper_header_only",
722 }
723 //
724 // Module separator
725 //
726 m["com.android.permission"] = []string{
727 "androidx.annotation_annotation",
728 "androidx.annotation_annotation-nodeps",
729 "androidx.lifecycle_lifecycle-common",
730 "androidx.lifecycle_lifecycle-common-java8",
731 "androidx.lifecycle_lifecycle-common-java8-nodeps",
732 "androidx.lifecycle_lifecycle-common-nodeps",
733 "kotlin-annotations",
734 "kotlin-stdlib",
735 "kotlin-stdlib-jdk7",
736 "kotlin-stdlib-jdk8",
737 "kotlinx-coroutines-android",
738 "kotlinx-coroutines-android-nodeps",
739 "kotlinx-coroutines-core",
740 "kotlinx-coroutines-core-nodeps",
741 "libprotobuf-java-lite",
742 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000743 }
744 //
745 // Module separator
746 //
747 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900748 "bionic_libc_platform_headers",
749 "fmtlib",
750 "libarm-optimized-routines-math",
751 "libasync_safe",
752 "libasync_safe_headers",
753 "libbacktrace_headers",
754 "libbase",
755 "libbase_headers",
756 "libc++",
757 "libc_aeabi",
758 "libc_bionic",
759 "libc_bionic_ndk",
760 "libc_bootstrap",
761 "libc_common",
762 "libc_common_shared",
763 "libc_common_static",
764 "libc_dns",
765 "libc_dynamic_dispatch",
766 "libc_fortify",
767 "libc_freebsd",
768 "libc_freebsd_large_stack",
769 "libc_gdtoa",
770 "libc_headers",
771 "libc_init_dynamic",
772 "libc_init_static",
773 "libc_jemalloc_wrapper",
774 "libc_netbsd",
775 "libc_nomalloc",
776 "libc_nopthread",
777 "libc_openbsd",
778 "libc_openbsd_large_stack",
779 "libc_openbsd_ndk",
780 "libc_pthread",
781 "libc_static_dispatch",
782 "libc_syscalls",
783 "libc_tzcode",
784 "libc_unwind_static",
785 "libcutils",
786 "libcutils_headers",
787 "libdebuggerd",
788 "libdebuggerd_common_headers",
789 "libdebuggerd_handler_core",
790 "libdebuggerd_handler_fallback",
791 "libdexfile_external_headers",
792 "libdexfile_support",
793 "libdexfile_support_static",
794 "libgtest_prod",
795 "libjemalloc5",
796 "liblinker_main",
797 "liblinker_malloc",
798 "liblog",
799 "liblog_headers",
800 "liblz4",
801 "liblzma",
802 "libprocessgroup_headers",
803 "libprocinfo",
804 "libpropertyinfoparser",
805 "libscudo",
806 "libstdc++",
807 "libsystem_headers",
808 "libsystemproperties",
809 "libtombstoned_client_static",
810 "libunwindstack",
811 "libutils_headers",
812 "libz",
813 "libziparchive",
814 }
815 //
816 // Module separator
817 //
818 m["com.android.resolv"] = []string{
819 "bcm_object",
820 "dnsresolver_aidl_interface-unstable-ndk_platform",
821 "fmtlib",
822 "libbacktrace_headers",
823 "libbase",
824 "libbase_headers",
825 "libc++",
826 "libcrypto",
827 "libcutils",
828 "libcutils_headers",
829 "libgtest_prod",
830 "libjsoncpp",
831 "liblog",
832 "liblog_headers",
833 "libnativehelper_header_only",
834 "libnetd_client_headers",
835 "libnetd_resolv",
836 "libnetdutils",
837 "libprocessgroup",
838 "libprocessgroup_headers",
839 "libprotobuf-cpp-lite",
840 "libssl",
841 "libstatslog_resolv",
842 "libstatspush_compat",
843 "libstatssocket",
844 "libstatssocket_headers",
845 "libsystem_headers",
846 "libsysutils",
847 "libutils",
848 "libutils_headers",
849 "netd_event_listener_interface-ndk_platform",
850 "server_configurable_flags",
851 "stats_proto",
852 }
853 //
854 // Module separator
855 //
856 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000857 "libbase",
858 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900859 "libnativehelper_compat_libc++",
860 "android.hardware.tetheroffload.config@1.0",
861 "fmtlib",
862 "libbacktrace_headers",
863 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000864 "libbinderthreadstate",
Jiyong Park0f80c182020-01-31 02:49:53 +0900865 "libcgrouprc",
866 "libcgrouprc_format",
867 "libcutils",
868 "libcutils_headers",
869 "libhidlbase",
870 "libhidlbase-impl-internal",
871 "libhidltransport-impl-internal",
872 "libhwbinder-impl-internal",
873 "libjsoncpp",
874 "liblog",
875 "liblog_headers",
876 "libprocessgroup",
877 "libprocessgroup_headers",
878 "libsystem_headers",
879 "libtetherutilsjni",
880 "libutils",
881 "libutils_headers",
882 "libvndksupport",
883 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000884 }
885 //
886 // Module separator
887 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900888 m["com.android.wifi"] = []string{
889 "PlatformProperties",
890 "android.hardware.wifi-V1.0-java",
891 "android.hardware.wifi-V1.1-java",
892 "android.hardware.wifi-V1.2-java",
893 "android.hardware.wifi-V1.3-java",
894 "android.hardware.wifi-V1.4-java",
895 "android.hardware.wifi.hostapd-V1.0-java",
896 "android.hardware.wifi.hostapd-V1.1-java",
897 "android.hardware.wifi.hostapd-V1.2-java",
898 "android.hardware.wifi.supplicant-V1.0-java",
899 "android.hardware.wifi.supplicant-V1.1-java",
900 "android.hardware.wifi.supplicant-V1.2-java",
901 "android.hardware.wifi.supplicant-V1.3-java",
902 "android.hidl.base-V1.0-java",
903 "android.hidl.manager-V1.0-java",
904 "android.hidl.manager-V1.1-java",
905 "android.hidl.manager-V1.2-java",
906 "androidx.annotation_annotation",
907 "androidx.annotation_annotation-nodeps",
908 "bouncycastle-unbundled",
909 "dnsresolver_aidl_interface-V2-java",
910 "error_prone_annotations",
911 "ipmemorystore-aidl-interfaces-V3-java",
912 "ipmemorystore-aidl-interfaces-java",
913 "ksoap2",
914 "libbacktrace_headers",
915 "libbase",
916 "libbase_headers",
917 "libc++",
918 "libcutils",
919 "libcutils_headers",
920 "liblog_headers",
921 "libnanohttpd",
922 "libprocessgroup",
923 "libprocessgroup_headers",
924 "libprotobuf-java-lite",
925 "libprotobuf-java-nano",
926 "libsystem_headers",
927 "libutils",
928 "libutils_headers",
929 "libwifi-jni",
930 "net-utils-services-common",
931 "netd_aidl_interface-V2-java",
932 "netd_aidl_interface-unstable-java",
933 "netd_event_listener_interface-java",
934 "netlink-client",
935 "networkstack-aidl-interfaces-unstable-java",
936 "networkstack-client",
937 "services.net",
938 "wifi-lite-protos",
939 "wifi-nano-protos",
940 "wifi-service-pre-jarjar",
941 "wifi-service-resources",
942 "prebuilt_androidx.annotation_annotation-nodeps",
943 }
944 //
945 // Module separator
946 //
947 m["com.android.sdkext"] = []string{
948 "fmtlib_ndk",
949 "libbase_ndk",
950 "libprotobuf-cpp-lite-ndk",
951 }
952 //
953 // Module separator
954 //
955 m["com.android.os.statsd"] = []string{
956 "libbacktrace_headers",
957 "libbase_headers",
958 "libc++",
959 "libcutils",
960 "libcutils_headers",
961 "liblog_headers",
962 "libprocessgroup_headers",
963 "libstatssocket",
964 "libsystem_headers",
965 "libutils_headers",
966 }
967 //
968 // Module separator
969 //
970 m["//any"] = []string{
971 "crtbegin_dynamic",
972 "crtbegin_dynamic1",
973 "crtbegin_so",
974 "crtbegin_so1",
975 "crtbegin_static",
976 "crtbrand",
977 "crtend_android",
978 "crtend_so",
979 "libatomic",
980 "libc++_static",
981 "libc++abi",
982 "libc++demangle",
983 "libc_headers",
984 "libclang_rt",
985 "libgcc_stripped",
986 "libprofile-clang-extras",
987 "libprofile-clang-extras_ndk",
988 "libprofile-extras",
989 "libprofile-extras_ndk",
990 "libunwind_llvm",
991 "ndk_crtbegin_dynamic.27",
992 "ndk_crtbegin_so.16",
993 "ndk_crtbegin_so.19",
994 "ndk_crtbegin_so.21",
995 "ndk_crtbegin_so.24",
996 "ndk_crtbegin_so.27",
997 "ndk_crtend_android.27",
998 "ndk_crtend_so.16",
999 "ndk_crtend_so.19",
1000 "ndk_crtend_so.21",
1001 "ndk_crtend_so.24",
1002 "ndk_crtend_so.27",
1003 "ndk_libandroid_support",
1004 "ndk_libc++_static",
1005 "ndk_libc++abi",
1006 "ndk_libunwind",
1007 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001008 return m
1009}
1010
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001012 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001013 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001014 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001015 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001016 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001017 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001018
Jooyung Han31c470b2019-10-18 16:26:59 +09001019 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001020 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001021
1022 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1023 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1024 sort.Strings(*apexFileContextsInfos)
1025 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1026 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001027}
1028
Jooyung Han31c470b2019-10-18 16:26:59 +09001029func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1030 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1031 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1032}
1033
Jiyong Parkd1063c12019-07-17 20:08:41 +09001034func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +09001035 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001036 ctx.BottomUp("apex", apexMutator).Parallel()
1037 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1038 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001039}
1040
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001041// Mark the direct and transitive dependencies of apex bundles so that they
1042// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +09001043func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00001044 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Colin Crossa4925902018-11-16 11:36:28 -08001045 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001046 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001047 depName := mctx.OtherModuleName(child)
1048 // If the parent is apexBundle, this child is directly depended.
1049 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -08001050 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -08001051 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
1052 // non-installable apex's cannot be installed and so should not prevent libraries from being
1053 // installed to the system.
1054 android.UpdateApexDependency(apexBundleName, depName, directDep)
1055 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001056
Jiyong Park3ff16992019-12-27 14:11:47 +09001057 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1058 (directDep || am.DepIsInSameApex(mctx, child)) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001059 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001060 return true
1061 } else {
1062 return false
1063 }
1064 })
1065 }
1066}
1067
1068// Create apex variations if a module is included in APEX(s).
1069func apexMutator(mctx android.BottomUpMutatorContext) {
1070 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001071 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001072 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001073 // apex bundle itself is mutated so that it and its modules have same
1074 // apex variant.
1075 apexBundleName := mctx.ModuleName()
1076 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001077 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1078 apexBundleName := o.GetOverriddenModuleName()
1079 if apexBundleName == "" {
1080 mctx.ModuleErrorf("base property is not set")
1081 return
1082 }
1083 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001084 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001085
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001086}
Sundong Ahne9b55722019-09-06 17:37:42 +09001087
Jooyung Han7a78a922019-10-08 21:59:58 +09001088var (
1089 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1090 apexFileContextsInfosMutex sync.Mutex
1091)
1092
1093func apexFileContextsInfos(config android.Config) *[]string {
1094 return config.Once(apexFileContextsInfosKey, func() interface{} {
1095 return &[]string{}
1096 }).(*[]string)
1097}
1098
Jooyung Han54aca7b2019-11-20 02:26:02 +09001099func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001100 apexFileContextsInfosMutex.Lock()
1101 defer apexFileContextsInfosMutex.Unlock()
1102 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001103 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001104}
1105
Sundong Ahne9b55722019-09-06 17:37:42 +09001106func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001107 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001108 var variants []string
1109 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1110 case "image":
1111 variants = append(variants, imageApexType, flattenedApexType)
1112 case "zip":
1113 variants = append(variants, zipApexType)
1114 case "both":
1115 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1116 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001117 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001118 return
1119 }
1120
1121 modules := mctx.CreateLocalVariations(variants...)
1122
1123 for i, v := range variants {
1124 switch v {
1125 case imageApexType:
1126 modules[i].(*apexBundle).properties.ApexType = imageApex
1127 case zipApexType:
1128 modules[i].(*apexBundle).properties.ApexType = zipApex
1129 case flattenedApexType:
1130 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001131 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001132 modules[i].(*apexBundle).MakeAsSystemExt()
1133 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001134 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001135 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001136 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1137 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001138 }
1139}
1140
Jooyung Han5c998b92019-06-27 11:30:33 +09001141func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1142 if ab, ok := mctx.Module().(*apexBundle); ok {
1143 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1144 }
1145}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001146
Jooyung Handc782442019-11-01 03:14:38 +09001147var (
1148 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1149)
1150
1151// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1152// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1153// which may cause compatibility issues. (e.g. libbinder)
1154// Even though libbinder restricts its availability via 'apex_available' property and relies on
1155// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1156// to avoid similar problems.
1157func useVendorWhitelist(config android.Config) []string {
1158 return config.Once(useVendorWhitelistKey, func() interface{} {
1159 return []string{
1160 // swcodec uses "vendor" variants for smaller size
1161 "com.android.media.swcodec",
1162 "test_com.android.media.swcodec",
1163 }
1164 }).([]string)
1165}
1166
1167// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1168// called before the first call to useVendorWhitelist()
1169func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1170 config.Once(useVendorWhitelistKey, func() interface{} {
1171 return whitelist
1172 })
1173}
1174
Alex Light9670d332019-01-29 18:07:33 -08001175type apexNativeDependencies struct {
1176 // List of native libraries
1177 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001178
Alex Light9670d332019-01-29 18:07:33 -08001179 // List of native executables
1180 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001181
Roland Levillain630846d2019-06-26 12:48:34 +01001182 // List of native tests
1183 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001184}
Jooyung Han344d5432019-08-23 11:17:39 +09001185
Alex Light9670d332019-01-29 18:07:33 -08001186type apexMultilibProperties struct {
1187 // Native dependencies whose compile_multilib is "first"
1188 First apexNativeDependencies
1189
1190 // Native dependencies whose compile_multilib is "both"
1191 Both apexNativeDependencies
1192
1193 // Native dependencies whose compile_multilib is "prefer32"
1194 Prefer32 apexNativeDependencies
1195
1196 // Native dependencies whose compile_multilib is "32"
1197 Lib32 apexNativeDependencies
1198
1199 // Native dependencies whose compile_multilib is "64"
1200 Lib64 apexNativeDependencies
1201}
1202
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001203type apexBundleProperties struct {
1204 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001205 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001206 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001207
Jiyong Park40e26a22019-02-08 02:53:06 +09001208 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1209 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001210 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001211
Roland Levillain411c5842019-09-19 16:37:20 +01001212 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1213 // device (/apex/<apex_name>).
1214 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001215 Apex_name *string
1216
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001217 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001218 // For platform APEXes, this should points to a file under /system/sepolicy
1219 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1220 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001221
1222 // List of native shared libs that are embedded inside this APEX bundle
1223 Native_shared_libs []string
1224
Roland Levillain630846d2019-06-26 12:48:34 +01001225 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001226 Binaries []string
1227
1228 // List of java libraries that are embedded inside this APEX bundle
1229 Java_libs []string
1230
1231 // List of prebuilt files that are embedded inside this APEX bundle
1232 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001233
Roland Levillain630846d2019-06-26 12:48:34 +01001234 // List of tests that are embedded inside this APEX bundle
1235 Tests []string
1236
Jiyong Parkff1458f2018-10-12 21:49:38 +09001237 // Name of the apex_key module that provides the private key to sign APEX
1238 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001239
Alex Light5098a612018-11-29 17:12:15 -08001240 // The type of APEX to build. Controls what the APEX payload is. Either
1241 // 'image', 'zip' or 'both'. Default: 'image'.
1242 Payload_type *string
1243
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001244 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1245 // or an android_app_certificate module name in the form ":module".
1246 Certificate *string
1247
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001248 // Whether this APEX is installable to one of the partitions. Default: true.
1249 Installable *bool
1250
Jiyong Parkda6eb592018-12-19 17:12:36 +09001251 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1252 // Default is false.
1253 Use_vendor *bool
1254
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001255 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1256 Ignore_system_library_special_case *bool
1257
Alex Light9670d332019-01-29 18:07:33 -08001258 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001259
Jiyong Parkf97782b2019-02-13 20:28:58 +09001260 // List of sanitizer names that this APEX is enabled for
1261 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001262
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001263 PreventInstall bool `blueprint:"mutated"`
1264
1265 HideFromMake bool `blueprint:"mutated"`
1266
Jooyung Han5c998b92019-06-27 11:30:33 +09001267 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1268 Provide_cpp_shared_libs *bool
1269
1270 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1271 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001272
1273 // A txt file containing list of files that are whitelisted to be included in this APEX.
1274 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001275
Sundong Ahnabb64432019-10-22 13:58:29 +09001276 // package format of this apex variant; could be non-flattened, flattened, or zip.
1277 // imageApex, zipApex or flattened
1278 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001279
Jiyong Parkd1063c12019-07-17 20:08:41 +09001280 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1281 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1282 // is implied. This value affects all modules included in this APEX. In other words, they are
1283 // also built with the SDKs specified here.
1284 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001285
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001286 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1287 // Should be only used in tests#.
1288 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001289
1290 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1291 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1292 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001293
1294 IsCoverageVariant bool `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -08001295}
1296
1297type apexTargetBundleProperties struct {
1298 Target struct {
1299 // Multilib properties only for android.
1300 Android struct {
1301 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001302 }
Jooyung Han344d5432019-08-23 11:17:39 +09001303
Alex Light9670d332019-01-29 18:07:33 -08001304 // Multilib properties only for host.
1305 Host struct {
1306 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001307 }
Jooyung Han344d5432019-08-23 11:17:39 +09001308
Alex Light9670d332019-01-29 18:07:33 -08001309 // Multilib properties only for host linux_bionic.
1310 Linux_bionic struct {
1311 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001312 }
Jooyung Han344d5432019-08-23 11:17:39 +09001313
Alex Light9670d332019-01-29 18:07:33 -08001314 // Multilib properties only for host linux_glibc.
1315 Linux_glibc struct {
1316 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001317 }
1318 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001319}
1320
Jiyong Park5d790c32019-11-15 18:40:32 +09001321type overridableProperties struct {
1322 // List of APKs to package inside APEX
1323 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001324
1325 // Names of modules to be overridden. Listed modules can only be other binaries
1326 // (in Make or Soong).
1327 // This does not completely prevent installation of the overridden binaries, but if both
1328 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1329 // from PRODUCT_PACKAGES.
1330 Overrides []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001331}
1332
Alex Light5098a612018-11-29 17:12:15 -08001333type apexPackaging int
1334
1335const (
1336 imageApex apexPackaging = iota
1337 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001338 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001339)
1340
Sundong Ahnabb64432019-10-22 13:58:29 +09001341// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001342func (a apexPackaging) suffix() string {
1343 switch a {
1344 case imageApex:
1345 return imageApexSuffix
1346 case zipApex:
1347 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001348 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001349 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001350 }
1351}
1352
1353func (a apexPackaging) name() string {
1354 switch a {
1355 case imageApex:
1356 return imageApexType
1357 case zipApex:
1358 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001359 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001360 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001361 }
1362}
1363
Jiyong Parkf653b052019-11-18 15:39:01 +09001364type apexFileClass int
1365
1366const (
1367 etc apexFileClass = iota
1368 nativeSharedLib
1369 nativeExecutable
1370 shBinary
1371 pyBinary
1372 goBinary
1373 javaSharedLib
1374 nativeTest
1375 app
1376)
1377
Jiyong Park8fd61922018-11-08 02:50:25 +09001378func (class apexFileClass) NameInMake() string {
1379 switch class {
1380 case etc:
1381 return "ETC"
1382 case nativeSharedLib:
1383 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001384 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001385 return "EXECUTABLES"
1386 case javaSharedLib:
1387 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001388 case nativeTest:
1389 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001390 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001391 // b/142537672 Why isn't this APP? We want to have full control over
1392 // the paths and file names of the apk file under the flattend APEX.
1393 // If this is set to APP, then the paths and file names are modified
1394 // by the Make build system. For example, it is installed to
1395 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1396 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1397 // appends module name (which is <apexname>.<Appname> to the path.
1398 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001399 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001400 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001401 }
1402}
1403
Jiyong Parkf653b052019-11-18 15:39:01 +09001404// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001405type apexFile struct {
1406 builtFile android.Path
1407 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001408 installDir string
1409 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001410 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001411 // list of symlinks that will be created in installDir that point to this apexFile
1412 symlinks []string
1413 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001414 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001415
1416 requiredModuleNames []string
1417 targetRequiredModuleNames []string
1418 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001419
Colin Cross503c1d02020-01-28 14:00:53 -08001420 jacocoReportClassesFile android.Path // only for javalibs and apps
1421 certificate java.Certificate // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001422}
1423
Jiyong Park1833cef2019-12-13 13:28:36 +09001424func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1425 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001426 builtFile: builtFile,
1427 moduleName: moduleName,
1428 installDir: installDir,
1429 class: class,
1430 module: module,
1431 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001432 if module != nil {
1433 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001434 ret.requiredModuleNames = module.RequiredModuleNames()
1435 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1436 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001437 }
1438 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001439}
1440
1441func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001442 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001443}
1444
Jiyong Park7cd10e32020-01-14 09:22:18 +09001445// Path() returns path of this apex file relative to the APEX root
1446func (af *apexFile) Path() string {
1447 return filepath.Join(af.installDir, af.builtFile.Base())
1448}
1449
1450// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1451func (af *apexFile) SymlinkPaths() []string {
1452 var ret []string
1453 for _, symlink := range af.symlinks {
1454 ret = append(ret, filepath.Join(af.installDir, symlink))
1455 }
1456 return ret
1457}
1458
1459func (af *apexFile) AvailableToPlatform() bool {
1460 if af.module == nil {
1461 return false
1462 }
1463 if am, ok := af.module.(android.ApexModule); ok {
1464 return am.AvailableFor(android.AvailableToPlatform)
1465 }
1466 return false
1467}
1468
Jiyong Park678c8812020-02-07 17:25:49 +09001469type depInfo struct {
1470 to string
1471 from []string
1472 isExternal bool
1473}
1474
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001475type apexBundle struct {
1476 android.ModuleBase
1477 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001478 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001479 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001480
Jiyong Park5d790c32019-11-15 18:40:32 +09001481 properties apexBundleProperties
1482 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001483 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001484
Jooyung Hanf21c7972019-12-16 22:32:06 +09001485 // specific to apex_vndk modules
1486 vndkProperties apexVndkProperties
1487
Colin Crossa4925902018-11-16 11:36:28 -08001488 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001489 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001490 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001491
Jiyong Park03b68dd2019-07-26 23:20:40 +09001492 prebuiltFileToDelete string
1493
Jiyong Park42cca6c2019-04-01 11:15:50 +09001494 public_key_file android.Path
1495 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001496
1497 container_certificate_file android.Path
1498 container_private_key_file android.Path
1499
Jooyung Han54aca7b2019-11-20 02:26:02 +09001500 fileContexts android.Path
1501
Jiyong Park8fd61922018-11-08 02:50:25 +09001502 // list of files to be included in this apex
1503 filesInfo []apexFile
1504
Jiyong Park956305c2020-01-09 12:32:06 +09001505 // list of module names that should be installed along with this APEX
1506 requiredDeps []string
1507
Jiyong Park956305c2020-01-09 12:32:06 +09001508 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001509 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001510
Sundong Ahnabb64432019-10-22 13:58:29 +09001511 testApex bool
1512 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001513 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001514 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001515
Jooyung Han214bf372019-11-12 13:03:50 +09001516 manifestJsonOut android.WritablePath
1517 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001518
Jooyung Han002ab682020-01-08 01:57:58 +09001519 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001520 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001521 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001522 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1523 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001524
1525 // Suffix of module name in Android.mk
1526 // ".flattened", ".apex", ".zipapex", or ""
1527 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001528
1529 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001530
1531 // Whether to create symlink to the system file instead of having a file
1532 // inside the apex or not
1533 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001534
1535 // Struct holding the merged notice file paths in different formats
1536 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001537}
1538
Jiyong Park397e55e2018-10-24 21:09:55 +09001539func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001540 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001541 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001542 // Use *FarVariation* to be able to depend on modules having
1543 // conflicting variations with this module. This is required since
1544 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1545 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001546 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001547 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001548 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001549 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001550 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001551
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001552 ctx.AddFarVariationDependencies(append(target.Variations(),
1553 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1554 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001555
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001556 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001557 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001558 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001559 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001560}
1561
Alex Light9670d332019-01-29 18:07:33 -08001562func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1563 if ctx.Os().Class == android.Device {
1564 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1565 } else {
1566 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1567 if ctx.Os().Bionic() {
1568 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1569 } else {
1570 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1571 }
1572 }
1573}
1574
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001575func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001576 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1577 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1578 }
1579
Jiyong Park397e55e2018-10-24 21:09:55 +09001580 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001581 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001582
1583 a.combineProperties(ctx)
1584
Jiyong Park397e55e2018-10-24 21:09:55 +09001585 has32BitTarget := false
1586 for _, target := range targets {
1587 if target.Arch.ArchType.Multilib == "lib32" {
1588 has32BitTarget = true
1589 }
1590 }
1591 for i, target := range targets {
1592 // When multilib.* is omitted for native_shared_libs, it implies
1593 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001594 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001595 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001596 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001597 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001598
Roland Levillain630846d2019-06-26 12:48:34 +01001599 // When multilib.* is omitted for tests, it implies
1600 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001601 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001602 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001603 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001604 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001605
Jiyong Park397e55e2018-10-24 21:09:55 +09001606 // Add native modules targetting both ABIs
1607 addDependenciesForNativeModules(ctx,
1608 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001609 a.properties.Multilib.Both.Binaries,
1610 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001611 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001612 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001613
Alex Light3d673592019-01-18 14:37:31 -08001614 isPrimaryAbi := i == 0
1615 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001616 // When multilib.* is omitted for binaries, it implies
1617 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001618 ctx.AddFarVariationDependencies(append(target.Variations(),
1619 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1620 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001621
1622 // Add native modules targetting the first ABI
1623 addDependenciesForNativeModules(ctx,
1624 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001625 a.properties.Multilib.First.Binaries,
1626 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001627 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001628 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001629 }
1630
1631 switch target.Arch.ArchType.Multilib {
1632 case "lib32":
1633 // Add native modules targetting 32-bit ABI
1634 addDependenciesForNativeModules(ctx,
1635 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001636 a.properties.Multilib.Lib32.Binaries,
1637 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001638 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001639 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001640
1641 addDependenciesForNativeModules(ctx,
1642 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001643 a.properties.Multilib.Prefer32.Binaries,
1644 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001645 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001646 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001647 case "lib64":
1648 // Add native modules targetting 64-bit ABI
1649 addDependenciesForNativeModules(ctx,
1650 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001651 a.properties.Multilib.Lib64.Binaries,
1652 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001653 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001654 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001655
1656 if !has32BitTarget {
1657 addDependenciesForNativeModules(ctx,
1658 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001659 a.properties.Multilib.Prefer32.Binaries,
1660 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001661 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001663 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001664
1665 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1666 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1667 if sanitizer == "hwaddress" {
1668 addDependenciesForNativeModules(ctx,
1669 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001670 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001671 break
1672 }
1673 }
1674 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001675 }
1676
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001677 }
1678
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001679 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1680 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1681 // b/144532908
1682 archForPrebuiltEtc := config.Arches()[0]
1683 for _, arch := range config.Arches() {
1684 // Prefer 64-bit arch if there is any
1685 if arch.ArchType.Multilib == "lib64" {
1686 archForPrebuiltEtc = arch
1687 break
1688 }
1689 }
1690 ctx.AddFarVariationDependencies([]blueprint.Variation{
1691 {Mutator: "os", Variation: ctx.Os().String()},
1692 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1693 }, prebuiltTag, a.properties.Prebuilts...)
1694
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001695 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1696 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001697
Ulya Trafimovich44561882020-01-03 13:25:54 +00001698 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1699 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1700 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1701 javaLibTag, "jacocoagent")
1702 }
1703
Jiyong Park23c52b02019-02-02 13:13:47 +09001704 if String(a.properties.Key) == "" {
1705 ctx.ModuleErrorf("key is missing")
1706 return
1707 }
1708 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001709
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001710 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001711 if cert != "" {
1712 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001713 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001714
1715 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1716 if len(a.properties.Uses_sdks) > 0 {
1717 sdkRefs := []android.SdkRef{}
1718 for _, str := range a.properties.Uses_sdks {
1719 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1720 sdkRefs = append(sdkRefs, parsed)
1721 }
1722 a.BuildWithSdks(sdkRefs)
1723 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001724}
1725
Jiyong Park5d790c32019-11-15 18:40:32 +09001726func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1727 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1728 androidAppTag, a.overridableProperties.Apps...)
1729}
1730
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001731func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1732 // direct deps of an APEX bundle are all part of the APEX bundle
1733 return true
1734}
1735
Colin Cross0ea8ba82019-06-06 14:33:29 -07001736func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001737 moduleName := ctx.ModuleName()
1738 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1739 // we check with the pseudo module name to see if its certificate is overridden.
1740 if a.vndkApex {
1741 moduleName = vndkApexName
1742 }
1743 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001744 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001745 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001746 }
1747 return String(a.properties.Certificate)
1748}
1749
Colin Cross41955e82019-05-29 14:40:35 -07001750func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1751 switch tag {
1752 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001753 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001754 default:
1755 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001756 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001757}
1758
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001759func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001760 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001761}
1762
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001763func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1764 return proptools.Bool(a.properties.Test_only_no_hashtree)
1765}
1766
Jiyong Park7c1dc612019-01-05 11:15:24 +09001767func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001768 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001769 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001770 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001771 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001772 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001773 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001774 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001775 }
1776}
1777
Jiyong Parkf97782b2019-02-13 20:28:58 +09001778func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1779 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1780 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1781 }
1782}
1783
Jiyong Park388ef3f2019-01-28 19:47:32 +09001784func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001785 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1786 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001787 }
1788
1789 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001790 globalSanitizerNames := []string{}
1791 if a.Host() {
1792 globalSanitizerNames = ctx.Config().SanitizeHost()
1793 } else {
1794 arches := ctx.Config().SanitizeDeviceArch()
1795 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1796 globalSanitizerNames = ctx.Config().SanitizeDevice()
1797 }
1798 }
1799 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001800}
1801
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001802func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001803 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001804}
1805
1806func (a *apexBundle) PreventInstall() {
1807 a.properties.PreventInstall = true
1808}
1809
1810func (a *apexBundle) HideFromMake() {
1811 a.properties.HideFromMake = true
1812}
1813
Jiyong Park956305c2020-01-09 12:32:06 +09001814func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1815 a.properties.IsCoverageVariant = coverage
1816}
1817
Jiyong Parkf653b052019-11-18 15:39:01 +09001818// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001819func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001820 // Decide the APEX-local directory by the multilib of the library
1821 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001822 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001823 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001824 case "lib32":
1825 dirInApex = "lib"
1826 case "lib64":
1827 dirInApex = "lib64"
1828 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001829 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001830 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001831 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001832 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001833 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001834 // Special case for Bionic libs and other libs installed with them. This is
1835 // to prevent those libs from being included in the search path
1836 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1837 // those libs in the Runtime APEX are available via the legacy paths in
1838 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1839 // to the legacy paths and thus will be loaded into the default linker
1840 // namespace (aka "platform" namespace). If the libs are directly in
1841 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1842 // into the runtime linker namespace, which will result in double loading of
1843 // them, which isn't supported.
1844 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001845 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001846
Jiyong Parkf653b052019-11-18 15:39:01 +09001847 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001848 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849}
1850
Jiyong Park1833cef2019-12-13 13:28:36 +09001851func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001852 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001853 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001854 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001855 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001856 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001857 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001858 af.symlinks = cc.Symlinks()
1859 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001860}
1861
Jiyong Park1833cef2019-12-13 13:28:36 +09001862func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001863 dirInApex := "bin"
1864 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001865 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001866}
Jiyong Park1833cef2019-12-13 13:28:36 +09001867func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001868 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001869 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1870 if err != nil {
1871 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001873 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001874 fileToCopy := android.PathForOutput(ctx, s)
1875 // NB: Since go binaries are static we don't need the module for anything here, which is
1876 // good since the go tool is a blueprint.Module not an android.Module like we would
1877 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001878 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001879}
1880
Jiyong Park1833cef2019-12-13 13:28:36 +09001881func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001882 dirInApex := filepath.Join("bin", sh.SubDir())
1883 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001884 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 af.symlinks = sh.Symlinks()
1886 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001887}
1888
Jooyung Han58f26ab2019-12-18 15:34:32 +09001889// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1890type javaLibrary interface {
1891 android.Module
1892 java.Dependency
1893}
1894
1895func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001896 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001897 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001898 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1899 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1900 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001901}
1902
Jiyong Park1833cef2019-12-13 13:28:36 +09001903func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1905 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001906 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001907}
1908
atrost6e126252020-01-27 17:01:16 +00001909func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1910 dirInApex := filepath.Join("etc", config.SubDir())
1911 fileToCopy := config.CompatConfig()
1912 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1913}
1914
Jiyong Park1833cef2019-12-13 13:28:36 +09001915func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 android.Module
1917 Privileged() bool
1918 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001919 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001920 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001921}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001922 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001923 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001924 appDir = "priv-app"
1925 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001926 dirInApex := filepath.Join(appDir, pkgName)
1927 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001928 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1929 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001930 af.certificate = aapp.Certificate()
Jiyong Park618922e2020-01-08 13:35:43 +09001931 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001932}
1933
Roland Levillain935639d2019-08-13 14:55:28 +01001934// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1935type flattenedApexContext struct {
1936 android.ModuleContext
1937}
1938
1939func (c *flattenedApexContext) InstallBypassMake() bool {
1940 return true
1941}
1942
Jiyong Park201cedd2020-02-07 17:25:49 +09001943// Visit dependencies that contributes to the payload of this APEX
1944func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1945 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001946 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1947 am, ok := child.(android.ApexModule)
1948 if !ok || !am.CanHaveApexVariants() {
1949 return false
1950 }
1951
1952 // Check for the direct dependencies that contribute to the payload
1953 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1954 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001955 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001956 return true
1957 }
1958 return false
1959 }
1960
1961 // Check for the indirect dependencies if it is considered as part of the APEX
1962 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001963 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001964 return true
1965 }
1966
Jiyong Park201cedd2020-02-07 17:25:49 +09001967 do(ctx, parent, am, true /* externalDep */)
1968
Jiyong Park0f80c182020-01-31 02:49:53 +09001969 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1970 return false
1971 })
1972}
1973
Jiyong Park201cedd2020-02-07 17:25:49 +09001974// Ensures that the dependencies are marked as available for this APEX
1975func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1976 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1977 if ctx.Host() || a.testApex || a.vndkApex {
1978 return
1979 }
1980
1981 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1982 apexName := ctx.ModuleName()
1983 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
1984 return
1985 }
1986 ctx.ModuleErrorf("requires %q that is not available for the APEX.", to.Name())
1987 })
1988}
1989
Jiyong Park678c8812020-02-07 17:25:49 +09001990// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1991func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1992 a.depInfos = make(map[string]depInfo)
1993 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1994 if from.Name() == to.Name() {
1995 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1996 return
1997 }
1998
1999 if info, exists := a.depInfos[to.Name()]; exists {
2000 if !android.InList(from.Name(), info.from) {
2001 info.from = append(info.from, from.Name())
2002 }
2003 info.isExternal = info.isExternal && externalDep
2004 a.depInfos[to.Name()] = info
2005 } else {
2006 a.depInfos[to.Name()] = depInfo{
2007 to: to.Name(),
2008 from: []string{from.Name()},
2009 isExternal: externalDep,
2010 }
2011 }
2012 })
2013}
2014
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002015func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002016 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2017 switch a.properties.ApexType {
2018 case imageApex:
2019 if buildFlattenedAsDefault {
2020 a.suffix = imageApexSuffix
2021 } else {
2022 a.suffix = ""
2023 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002024
2025 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002026 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002027 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002028 }
2029 case zipApex:
2030 if proptools.String(a.properties.Payload_type) == "zip" {
2031 a.suffix = ""
2032 a.primaryApexType = true
2033 } else {
2034 a.suffix = zipApexSuffix
2035 }
2036 case flattenedApex:
2037 if buildFlattenedAsDefault {
2038 a.suffix = ""
2039 a.primaryApexType = true
2040 } else {
2041 a.suffix = flattenedSuffix
2042 }
Alex Light5098a612018-11-29 17:12:15 -08002043 }
2044
Roland Levillain630846d2019-06-26 12:48:34 +01002045 if len(a.properties.Tests) > 0 && !a.testApex {
2046 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2047 return
2048 }
2049
Jiyong Park0f80c182020-01-31 02:49:53 +09002050 a.checkApexAvailability(ctx)
2051
Jiyong Park678c8812020-02-07 17:25:49 +09002052 a.collectDepsInfo(ctx)
2053
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002054 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2055
Jooyung Hane1633032019-08-01 17:41:43 +09002056 // native lib dependencies
2057 var provideNativeLibs []string
2058 var requireNativeLibs []string
2059
Jooyung Han5c998b92019-06-27 11:30:33 +09002060 // Check if "uses" requirements are met with dependent apexBundles
2061 var providedNativeSharedLibs []string
2062 useVendor := proptools.Bool(a.properties.Use_vendor)
2063 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2064 if ctx.OtherModuleDependencyTag(m) != usesTag {
2065 return
2066 }
2067 otherName := ctx.OtherModuleName(m)
2068 other, ok := m.(*apexBundle)
2069 if !ok {
2070 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2071 return
2072 }
2073 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2074 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2075 return
2076 }
2077 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2078 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2079 return
2080 }
2081 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2082 })
2083
Jiyong Parkf653b052019-11-18 15:39:01 +09002084 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002085 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002086 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002087 depTag := ctx.OtherModuleDependencyTag(child)
2088 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002089 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002090 switch depTag {
2091 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002092 if c, ok := child.(*cc.Module); ok {
2093 // bootstrap bionic libs are treated as provided by system
2094 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2095 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002096 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002097 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002098 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002099 } else {
2100 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002101 }
2102 case executableTag:
2103 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002104 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002105 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002106 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002107 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002108 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002109 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002110 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002111 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002112 } else {
Alex Light778127a2019-02-27 14:19:50 -08002113 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 +09002114 }
2115 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002116 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002117 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002118 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002119 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2120 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002121 filesInfo = append(filesInfo, af)
2122 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002123 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002124 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2125 af := apexFileForJavaLibrary(ctx, sdkLib)
2126 if !af.Ok() {
2127 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2128 return false
2129 }
2130 filesInfo = append(filesInfo, af)
2131
Jooyung Han624058e2019-12-24 18:38:06 +09002132 pf, _ := sdkLib.OutputFiles(".xml")
2133 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09002134 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
2135 return false
2136 }
Jooyung Han624058e2019-12-24 18:38:06 +09002137 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002138 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002139 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002140 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002141 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 case androidAppTag:
2143 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2144 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002145 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002146 return true // track transitive dependencies
2147 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002148 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002149 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2150 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002151 } else {
2152 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2153 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002154 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002155 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002156 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002157 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2158 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002159 } else {
atrost6e126252020-01-27 17:01:16 +00002160 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002161 }
Roland Levillain630846d2019-06-26 12:48:34 +01002162 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002163 if ccTest, ok := child.(*cc.Module); ok {
2164 if ccTest.IsTestPerSrcAllTestsVariation() {
2165 // Multiple-output test module (where `test_per_src: true`).
2166 //
2167 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2168 // We do not add this variation to `filesInfo`, as it has no output;
2169 // however, we do add the other variations of this module as indirect
2170 // dependencies (see below).
2171 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002172 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002173 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002174 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002175 af.class = nativeTest
2176 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002177 }
Roland Levillain630846d2019-06-26 12:48:34 +01002178 } else {
2179 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2180 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002181 case keyTag:
2182 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002183 a.private_key_file = key.private_key_file
2184 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002185 } else {
2186 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002187 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002188 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002189 case certificateTag:
2190 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002191 a.container_certificate_file = dep.Certificate.Pem
2192 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002193 } else {
2194 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2195 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002196 case android.PrebuiltDepTag:
2197 // If the prebuilt is force disabled, remember to delete the prebuilt file
2198 // that might have been installed in the previous builds
2199 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2200 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2201 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002202 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002203 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002204 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002205 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002206 // We cannot use a switch statement on `depTag` here as the checked
2207 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002208 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002209 if cc, ok := child.(*cc.Module); ok {
2210 if android.InList(cc.Name(), providedNativeSharedLibs) {
2211 // If we're using a shared library which is provided from other APEX,
2212 // don't include it in this APEX
2213 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002214 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002215 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002216 // If the dependency is a stubs lib, don't include it in this APEX,
2217 // but make sure that the lib is installed on the device.
2218 // In case no APEX is having the lib, the lib is installed to the system
2219 // partition.
2220 //
2221 // Always include if we are a host-apex however since those won't have any
2222 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002223 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2224 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002225 }
Jooyung Hane1633032019-08-01 17:41:43 +09002226 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002227 // Don't track further
2228 return false
2229 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002230 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002231 af.transitiveDep = true
2232 filesInfo = append(filesInfo, af)
2233 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002234 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002235 } else if cc.IsTestPerSrcDepTag(depTag) {
2236 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002237 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002238 // Handle modules created as `test_per_src` variations of a single test module:
2239 // use the name of the generated test binary (`fileToCopy`) instead of the name
2240 // of the original test module (`depName`, shared by all `test_per_src`
2241 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002242 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002243 // these are not considered transitive dep
2244 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002245 filesInfo = append(filesInfo, af)
2246 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002247 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002248 } else if java.IsJniDepTag(depTag) {
Jiyong Parkf653b052019-11-18 15:39:01 +09002249 return true
Jooyung Han9c80bae2019-08-20 17:30:57 +09002250 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002251 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002252 }
2253 }
2254 }
2255 return false
2256 })
2257
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002258 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2259 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2260 // via the global boot image config.
2261 if a.artApex {
2262 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2263 dirInApex := filepath.Join("javalib", arch.String())
2264 for _, f := range files {
2265 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002266 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002267 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002268 }
2269 }
2270 }
2271
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002272 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002273 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2274 return
2275 }
2276
Jiyong Park8fd61922018-11-08 02:50:25 +09002277 // remove duplicates in filesInfo
2278 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002279 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002280 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002281 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002282 if e, ok := encountered[dest]; !ok {
2283 encountered[dest] = f
2284 } else {
2285 // If a module is directly included and also transitively depended on
2286 // consider it as directly included.
2287 e.transitiveDep = e.transitiveDep && f.transitiveDep
2288 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002289 }
2290 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002291 var result []apexFile
2292 for _, v := range encountered {
2293 result = append(result, v)
2294 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002295 return result
2296 }
2297 filesInfo = removeDup(filesInfo)
2298
2299 // to have consistent build rules
2300 sort.Slice(filesInfo, func(i, j int) bool {
2301 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2302 })
2303
Jiyong Park8fd61922018-11-08 02:50:25 +09002304 a.installDir = android.PathForModuleInstall(ctx, "apex")
2305 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002306
Jooyung Han54aca7b2019-11-20 02:26:02 +09002307 if a.properties.ApexType != zipApex {
2308 if a.properties.File_contexts == nil {
2309 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2310 } else {
2311 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2312 if a.Platform() {
2313 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2314 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2315 }
2316 }
2317 }
2318 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2319 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2320 return
2321 }
2322 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002323 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2324 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2325 // the same library in the system partition, thus effectively sharing the same libraries
2326 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2327 // in the APEX.
2328 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2329 a.installable() &&
2330 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002331
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002332 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002333 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2334
2335 a.setCertificateAndPrivateKey(ctx)
2336 if a.properties.ApexType == flattenedApex {
2337 a.buildFlattenedApex(ctx)
2338 } else {
2339 a.buildUnflattenedApex(ctx)
2340 }
2341
Jooyung Han002ab682020-01-08 01:57:58 +09002342 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002343
2344 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002345}
2346
Jiyong Park0f80c182020-01-31 02:49:53 +09002347func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002348 key := apex
2349 key = strings.Replace(key, "test_", "", 1)
2350 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2351 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2352
2353 moduleName := module.Name()
Jiyong Park0f80c182020-01-31 02:49:53 +09002354 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2355 // system. Trim the prefix for the check since they are confusing
2356 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2357 if strings.HasPrefix(moduleName, "libclang_rt.") {
2358 // This module has many arch variants that depend on the product being built.
2359 // We don't want to list them all
2360 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002361 }
2362
2363 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2364 return true
2365 }
2366
Jiyong Park0f80c182020-01-31 02:49:53 +09002367 key = "//any"
2368 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2369 return true
2370 }
2371
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002372 return false
2373}
2374
Jooyung Han344d5432019-08-23 11:17:39 +09002375func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002376 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002377 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002378 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002379 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002380 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002381 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2382 })
Alex Light5098a612018-11-29 17:12:15 -08002383 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002384 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002385 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002386 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002387 return module
2388}
Jiyong Park30ca9372019-02-07 16:27:23 +09002389
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002390func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002391 bundle := newApexBundle()
2392 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002393 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002394 return bundle
2395}
2396
2397func testApexBundleFactory() android.Module {
2398 bundle := newApexBundle()
2399 bundle.testApex = true
2400 return bundle
2401}
2402
Jiyong Parkd1063c12019-07-17 20:08:41 +09002403func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002404 return newApexBundle()
2405}
2406
Jiyong Park30ca9372019-02-07 16:27:23 +09002407//
2408// Defaults
2409//
2410type Defaults struct {
2411 android.ModuleBase
2412 android.DefaultsModuleBase
2413}
2414
Jiyong Park30ca9372019-02-07 16:27:23 +09002415func defaultsFactory() android.Module {
2416 return DefaultsFactory()
2417}
2418
2419func DefaultsFactory(props ...interface{}) android.Module {
2420 module := &Defaults{}
2421
2422 module.AddProperties(props...)
2423 module.AddProperties(
2424 &apexBundleProperties{},
2425 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002426 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002427 )
2428
2429 android.InitDefaultsModule(module)
2430 return module
2431}
Jiyong Park5d790c32019-11-15 18:40:32 +09002432
2433//
2434// OverrideApex
2435//
2436type OverrideApex struct {
2437 android.ModuleBase
2438 android.OverrideModuleBase
2439}
2440
2441func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2442 // All the overrides happen in the base module.
2443}
2444
2445// override_apex is used to create an apex module based on another apex module
2446// by overriding some of its properties.
2447func overrideApexFactory() android.Module {
2448 m := &OverrideApex{}
2449 m.AddProperties(&overridableProperties{})
2450
2451 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2452 android.InitOverrideModule(m)
2453 return m
2454}