blob: bef4e42541606e4afe3bf493de492c21029f885e [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}
Jooyung Han643adc42020-02-27 13:50:06 +090055 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090056 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090065)
66
Anton Hanssoneec79eb2020-01-10 15:12:39 +000067// This is a map from apex to modules, which overrides the
68// apex_available setting for that particular module to make
69// it available for the apex regardless of its setting.
70// TODO(b/147364041): remove this
71func makeApexAvailableWhitelist() map[string][]string {
72 // The "Module separator"s below are employed to minimize merge conflicts.
73 m := make(map[string][]string)
74 //
75 // Module separator
76 //
Jiyong Park0f80c182020-01-31 02:49:53 +090077 m["com.android.adbd"] = []string{
78 "adbd",
79 "bcm_object",
80 "fmtlib",
81 "libadbconnection_server",
82 "libadbd",
83 "libadbd_auth",
84 "libadbd_core",
85 "libadbd_services",
86 "libasyncio",
87 "libbacktrace_headers",
88 "libbase",
89 "libbase_headers",
90 "libbuildversion",
91 "libc++",
92 "libcap",
93 "libcrypto",
94 "libcrypto_utils",
95 "libcutils",
96 "libcutils_headers",
97 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "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",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "liblog_headers",
174 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 "liblzma",
176 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900177 "libnativebridge-headers",
178 "libnativehelper_header_only",
179 "libnativeloader-headers",
180 "libnpt_headers",
181 "libopenjdkjvmti_headers",
182 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000183 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900184 "libprotobuf-cpp-lite",
185 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000186 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900187 "libv8",
188 "libv8base",
189 "libv8gen",
190 "libv8platform",
191 "libv8sampler",
192 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000193 "libvixl",
194 "libvixld",
195 "libz",
196 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000198 }
199 //
200 // Module separator
201 //
202 m["com.android.bluetooth.updatable"] = []string{
203 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000204 "android.hardware.bluetooth.a2dp@1.0",
205 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900206 "android.hardware.bluetooth@1.0",
207 "android.hardware.bluetooth@1.1",
208 "android.hardware.graphics.bufferqueue@1.0",
209 "android.hardware.graphics.bufferqueue@2.0",
210 "android.hardware.graphics.common@1.0",
211 "android.hardware.graphics.common@1.1",
212 "android.hardware.graphics.common@1.2",
213 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000214 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "android.hidl.token@1.0",
216 "android.hidl.token@1.0-utils",
217 "avrcp-target-service",
218 "avrcp_headers",
219 "bcm_object",
220 "bluetooth-protos-lite",
221 "bluetooth.mapsapi",
222 "com.android.vcard",
223 "fmtlib",
224 "guava",
225 "internal_include_headers",
226 "lib-bt-packets",
227 "lib-bt-packets-avrcp",
228 "lib-bt-packets-base",
229 "libFraunhoferAAC",
230 "libaudio-a2dp-hw-utils",
231 "libaudio-hearing-aid-hw-utils",
232 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000233 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900234 "libbase_headers",
235 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000236 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 "libbluetooth-types",
238 "libbluetooth-types-header",
239 "libbluetooth_gd",
240 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000241 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libbt-audio-hal-interface",
243 "libbt-bta",
244 "libbt-common",
245 "libbt-hci",
246 "libbt-platform-protos-lite",
247 "libbt-protos-lite",
248 "libbt-sbc-decoder",
249 "libbt-sbc-encoder",
250 "libbt-stack",
251 "libbt-utils",
252 "libbtcore",
253 "libbtdevice",
254 "libbte",
255 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000256 "libc++",
257 "libchrome",
258 "libcrypto",
259 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900260 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000261 "libevent",
262 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900263 "libg722codec",
264 "libgtest_prod",
265 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000266 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "libhidlbase-impl-internal",
268 "libhidltransport-impl-internal",
269 "libhwbinder-impl-internal",
270 "libjsoncpp",
271 "liblog_headers",
272 "libmedia_headers",
273 "libmodpb64",
274 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000275 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000277 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900278 "libprotobuf-java-lite",
279 "libprotobuf-java-micro",
280 "libstagefright_foundation_headers",
281 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000282 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900283 "libstatssocket",
284 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000285 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900286 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900287 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000288 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900289 "media_plugin_headers",
290 "sap-api-java-static",
291 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000292 }
293 //
294 // Module separator
295 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900296 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000297 //
298 // Module separator
299 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 m["com.android.conscrypt"] = []string{
301 "bcm_object",
302 "boringssl_self_test",
303 "libc++",
304 "libcrypto",
305 "libnativehelper_header_only",
306 "libssl",
307 }
308 //
309 // Module separator
310 //
311 m["com.android.extservices"] = []string{
312 "flatbuffer_headers",
313 "liblua",
314 "libtextclassifier",
315 "libtextclassifier_hash_static",
316 "libtflite_static",
317 "libutf",
318 "libz_current",
319 "tensorflow_headers",
320 }
321 //
322 // Module separator
323 //
324 m["com.android.cronet"] = []string{
325 "cronet_impl_common_java",
326 "cronet_impl_native_java",
327 "cronet_impl_platform_java",
328 "libcronet.80.0.3986.0",
329 "org.chromium.net.cronet",
330 "prebuilt_libcronet.80.0.3986.0",
331 }
332 //
333 // Module separator
334 //
335 m["com.android.neuralnetworks"] = []string{
336 "android.hardware.neuralnetworks@1.0",
337 "android.hardware.neuralnetworks@1.1",
338 "android.hardware.neuralnetworks@1.2",
339 "android.hardware.neuralnetworks@1.3",
340 "android.hidl.allocator@1.0",
341 "android.hidl.memory.token@1.0",
342 "android.hidl.memory@1.0",
343 "android.hidl.safe_union@1.0",
344 "bcm_object",
345 "fmtlib",
346 "gemmlowp_headers",
347 "libarect",
348 "libbacktrace_headers",
349 "libbase",
350 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900351 "libbuildversion",
352 "libc++",
353 "libcrypto",
354 "libcrypto_static",
355 "libcutils",
356 "libcutils_headers",
357 "libeigen",
358 "libfmq",
359 "libhidlbase",
360 "libhidlbase-impl-internal",
361 "libhidlmemory",
362 "libhidltransport-impl-internal",
363 "libhwbinder-impl-internal",
364 "libjsoncpp",
365 "liblog_headers",
366 "libmath",
367 "libneuralnetworks_common",
368 "libneuralnetworks_headers",
369 "libprocessgroup",
370 "libprocessgroup_headers",
371 "libprocpartition",
372 "libsync",
373 "libsystem_headers",
374 "libtextclassifier_hash",
375 "libtextclassifier_hash_headers",
376 "libtextclassifier_hash_static",
377 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libutils_headers",
379 "philox_random",
380 "philox_random_headers",
381 "tensorflow_headers",
382 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000383 //
384 // Module separator
385 //
386 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000387 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900388 "android.hardware.cas.native@1.0",
389 "android.hardware.cas@1.0",
390 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000391 "android.hardware.configstore@1.0",
392 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000393 "android.hardware.graphics.allocator@2.0",
394 "android.hardware.graphics.allocator@3.0",
395 "android.hardware.graphics.bufferqueue@1.0",
396 "android.hardware.graphics.bufferqueue@2.0",
397 "android.hardware.graphics.common@1.0",
398 "android.hardware.graphics.common@1.1",
399 "android.hardware.graphics.common@1.2",
400 "android.hardware.graphics.mapper@2.0",
401 "android.hardware.graphics.mapper@2.1",
402 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900403 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000404 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900405 "android.hidl.allocator@1.0",
406 "android.hidl.memory.token@1.0",
407 "android.hidl.memory@1.0",
408 "android.hidl.token@1.0",
409 "android.hidl.token@1.0-utils",
410 "bcm_object",
411 "bionic_libc_platform_headers",
412 "fmtlib",
413 "gl_headers",
414 "libEGL",
415 "libEGL_blobCache",
416 "libEGL_getProcAddress",
417 "libFLAC",
418 "libFLAC-config",
419 "libFLAC-headers",
420 "libGLESv2",
421 "libaacextractor",
422 "libamrextractor",
423 "libarect",
424 "libasync_safe",
425 "libaudio_system_headers",
426 "libaudioclient",
427 "libaudioclient_headers",
428 "libaudiofoundation",
429 "libaudiofoundation_headers",
430 "libaudiomanager",
431 "libaudiopolicy",
432 "libaudioutils",
433 "libaudioutils_fixedfft",
434 "libbacktrace",
435 "libbacktrace_headers",
436 "libbase",
437 "libbase_headers",
438 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900439 "libbluetooth-types-header",
440 "libbufferhub",
441 "libbufferhub_headers",
442 "libbufferhubqueue",
443 "libc++",
444 "libc_headers",
445 "libc_malloc_debug_backtrace",
446 "libcamera_client",
447 "libcamera_metadata",
448 "libcrypto",
449 "libcutils",
450 "libcutils_headers",
451 "libdexfile_external_headers",
452 "libdexfile_support",
453 "libdvr_headers",
454 "libexpat",
455 "libfifo",
456 "libflacextractor",
457 "libgrallocusage",
458 "libgraphicsenv",
459 "libgui",
460 "libgui_headers",
461 "libhardware_headers",
462 "libhidlbase",
463 "libhidlbase-impl-internal",
464 "libhidlmemory",
465 "libhidltransport-impl-internal",
466 "libhwbinder-impl-internal",
467 "libinput",
468 "libjsoncpp",
469 "liblog_headers",
470 "liblzma",
471 "libmath",
472 "libmedia",
473 "libmedia_codeclist",
474 "libmedia_headers",
475 "libmedia_helper",
476 "libmedia_helper_headers",
477 "libmedia_midiiowrapper",
478 "libmedia_omx",
479 "libmediautils",
480 "libmidiextractor",
481 "libmkvextractor",
482 "libmp3extractor",
483 "libmp4extractor",
484 "libmpeg2extractor",
485 "libnativebase_headers",
486 "libnativebridge-headers",
487 "libnativebridge_lazy",
488 "libnativeloader-headers",
489 "libnativeloader_lazy",
490 "libnativewindow_headers",
491 "libnblog",
492 "liboggextractor",
493 "libpackagelistparser",
494 "libpcre2",
495 "libpdx",
496 "libpdx_default_transport",
497 "libpdx_headers",
498 "libpdx_uds",
499 "libprocessgroup",
500 "libprocessgroup_headers",
501 "libprocinfo",
502 "libselinux",
503 "libsonivox",
504 "libspeexresampler",
505 "libspeexresampler",
506 "libstagefright_esds",
507 "libstagefright_flacdec",
508 "libstagefright_flacdec",
509 "libstagefright_foundation",
510 "libstagefright_foundation_headers",
511 "libstagefright_foundation_without_imemory",
512 "libstagefright_headers",
513 "libstagefright_id3",
514 "libstagefright_metadatautils",
515 "libstagefright_mpeg2extractor",
516 "libstagefright_mpeg2support",
517 "libsync",
518 "libsystem_headers",
519 "libui",
520 "libui_headers",
521 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900522 "libutils_headers",
523 "libvibrator",
524 "libvorbisidec",
525 "libwavextractor",
526 "libwebm",
527 "media_ndk_headers",
528 "media_plugin_headers",
529 "updatable-media",
530 }
531 //
532 // Module separator
533 //
534 m["com.android.media.swcodec"] = []string{
535 "android.frameworks.bufferhub@1.0",
536 "android.hardware.common-ndk_platform",
537 "android.hardware.configstore-utils",
538 "android.hardware.configstore@1.0",
539 "android.hardware.configstore@1.1",
540 "android.hardware.graphics.allocator@2.0",
541 "android.hardware.graphics.allocator@3.0",
542 "android.hardware.graphics.bufferqueue@1.0",
543 "android.hardware.graphics.bufferqueue@2.0",
544 "android.hardware.graphics.common-ndk_platform",
545 "android.hardware.graphics.common@1.0",
546 "android.hardware.graphics.common@1.1",
547 "android.hardware.graphics.common@1.2",
548 "android.hardware.graphics.mapper@2.0",
549 "android.hardware.graphics.mapper@2.1",
550 "android.hardware.graphics.mapper@3.0",
551 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000552 "android.hardware.media.bufferpool@2.0",
553 "android.hardware.media.c2@1.0",
554 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900555 "android.hardware.media@1.0",
556 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000557 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900558 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000559 "android.hidl.safe_union@1.0",
560 "android.hidl.token@1.0",
561 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "fmtlib",
563 "libEGL",
564 "libFLAC",
565 "libFLAC-config",
566 "libFLAC-headers",
567 "libFraunhoferAAC",
568 "libarect",
569 "libasync_safe",
570 "libaudio_system_headers",
571 "libaudioutils",
572 "libaudioutils",
573 "libaudioutils_fixedfft",
574 "libavcdec",
575 "libavcenc",
576 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000577 "libavservices_minijail",
578 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900579 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000580 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libbase_headers",
582 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900583 "libbluetooth-types-header",
584 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000585 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900586 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000587 "libcap",
588 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900589 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000590 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900591 "libcodec2_hidl@1.1",
592 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000593 "libcodec2_soft_aacdec",
594 "libcodec2_soft_aacenc",
595 "libcodec2_soft_amrnbdec",
596 "libcodec2_soft_amrnbenc",
597 "libcodec2_soft_amrwbdec",
598 "libcodec2_soft_amrwbenc",
599 "libcodec2_soft_av1dec_gav1",
600 "libcodec2_soft_avcdec",
601 "libcodec2_soft_avcenc",
602 "libcodec2_soft_common",
603 "libcodec2_soft_flacdec",
604 "libcodec2_soft_flacenc",
605 "libcodec2_soft_g711alawdec",
606 "libcodec2_soft_g711mlawdec",
607 "libcodec2_soft_gsmdec",
608 "libcodec2_soft_h263dec",
609 "libcodec2_soft_h263enc",
610 "libcodec2_soft_hevcdec",
611 "libcodec2_soft_hevcenc",
612 "libcodec2_soft_mp3dec",
613 "libcodec2_soft_mpeg2dec",
614 "libcodec2_soft_mpeg4dec",
615 "libcodec2_soft_mpeg4enc",
616 "libcodec2_soft_opusdec",
617 "libcodec2_soft_opusenc",
618 "libcodec2_soft_rawdec",
619 "libcodec2_soft_vorbisdec",
620 "libcodec2_soft_vp8dec",
621 "libcodec2_soft_vp8enc",
622 "libcodec2_soft_vp9dec",
623 "libcodec2_soft_vp9enc",
624 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000625 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900626 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000627 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900628 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000629 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900630 "libfmq",
631 "libgav1",
632 "libgralloctypes",
633 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000634 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900635 "libgsm",
636 "libgui_bufferqueue_static",
637 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000638 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "libhardware_headers",
640 "libhevcdec",
641 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000642 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900643 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000644 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900645 "libhidltransport-impl-internal",
646 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000647 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 "libjpeg",
649 "libjsoncpp",
650 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000651 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900652 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000653 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900654 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000655 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900656 "libminijail_gen_constants",
657 "libminijail_gen_constants_obj",
658 "libminijail_gen_syscall",
659 "libminijail_gen_syscall_obj",
660 "libminijail_generated",
661 "libmpeg2dec",
662 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000663 "libnativebridge_lazy",
664 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900665 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000666 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900667 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000668 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900669 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000670 "libscudo_wrapper",
671 "libsfplugin_ccodec_utils",
672 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "libstagefright_amrnbdec",
674 "libstagefright_amrnbenc",
675 "libstagefright_amrwbdec",
676 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000677 "libstagefright_bufferpool@2.0.1",
678 "libstagefright_bufferqueue_helper",
679 "libstagefright_enc_common",
680 "libstagefright_flacdec",
681 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900682 "libstagefright_foundation_headers",
683 "libstagefright_headers",
684 "libstagefright_m4vh263dec",
685 "libstagefright_m4vh263enc",
686 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000687 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900688 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000689 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900690 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000691 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900692 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000693 "libvorbisidec",
694 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900695 "libyuv",
696 "libyuv_static",
697 "media_ndk_headers",
698 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000699 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 }
701 //
702 // Module separator
703 //
704 m["com.android.mediaprovider"] = []string{
705 "MediaProvider",
706 "MediaProviderGoogle",
707 "fmtlib_ndk",
708 "guava",
709 "libbase_ndk",
710 "libfuse",
711 "libfuse_jni",
712 "libnativehelper_header_only",
713 }
714 //
715 // Module separator
716 //
717 m["com.android.permission"] = []string{
718 "androidx.annotation_annotation",
719 "androidx.annotation_annotation-nodeps",
720 "androidx.lifecycle_lifecycle-common",
721 "androidx.lifecycle_lifecycle-common-java8",
722 "androidx.lifecycle_lifecycle-common-java8-nodeps",
723 "androidx.lifecycle_lifecycle-common-nodeps",
724 "kotlin-annotations",
725 "kotlin-stdlib",
726 "kotlin-stdlib-jdk7",
727 "kotlin-stdlib-jdk8",
728 "kotlinx-coroutines-android",
729 "kotlinx-coroutines-android-nodeps",
730 "kotlinx-coroutines-core",
731 "kotlinx-coroutines-core-nodeps",
732 "libprotobuf-java-lite",
733 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000734 }
735 //
736 // Module separator
737 //
738 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900739 "bionic_libc_platform_headers",
740 "fmtlib",
741 "libarm-optimized-routines-math",
742 "libasync_safe",
743 "libasync_safe_headers",
744 "libbacktrace_headers",
745 "libbase",
746 "libbase_headers",
747 "libc++",
748 "libc_aeabi",
749 "libc_bionic",
750 "libc_bionic_ndk",
751 "libc_bootstrap",
752 "libc_common",
753 "libc_common_shared",
754 "libc_common_static",
755 "libc_dns",
756 "libc_dynamic_dispatch",
757 "libc_fortify",
758 "libc_freebsd",
759 "libc_freebsd_large_stack",
760 "libc_gdtoa",
761 "libc_headers",
762 "libc_init_dynamic",
763 "libc_init_static",
764 "libc_jemalloc_wrapper",
765 "libc_netbsd",
766 "libc_nomalloc",
767 "libc_nopthread",
768 "libc_openbsd",
769 "libc_openbsd_large_stack",
770 "libc_openbsd_ndk",
771 "libc_pthread",
772 "libc_static_dispatch",
773 "libc_syscalls",
774 "libc_tzcode",
775 "libc_unwind_static",
776 "libcutils",
777 "libcutils_headers",
778 "libdebuggerd",
779 "libdebuggerd_common_headers",
780 "libdebuggerd_handler_core",
781 "libdebuggerd_handler_fallback",
782 "libdexfile_external_headers",
783 "libdexfile_support",
784 "libdexfile_support_static",
785 "libgtest_prod",
786 "libjemalloc5",
787 "liblinker_main",
788 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900789 "liblog_headers",
790 "liblz4",
791 "liblzma",
792 "libprocessgroup_headers",
793 "libprocinfo",
794 "libpropertyinfoparser",
795 "libscudo",
796 "libstdc++",
797 "libsystem_headers",
798 "libsystemproperties",
799 "libtombstoned_client_static",
800 "libunwindstack",
801 "libutils_headers",
802 "libz",
803 "libziparchive",
804 }
805 //
806 // Module separator
807 //
808 m["com.android.resolv"] = []string{
809 "bcm_object",
810 "dnsresolver_aidl_interface-unstable-ndk_platform",
811 "fmtlib",
812 "libbacktrace_headers",
813 "libbase",
814 "libbase_headers",
815 "libc++",
816 "libcrypto",
817 "libcutils",
818 "libcutils_headers",
819 "libgtest_prod",
820 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900821 "liblog_headers",
822 "libnativehelper_header_only",
823 "libnetd_client_headers",
824 "libnetd_resolv",
825 "libnetdutils",
826 "libprocessgroup",
827 "libprocessgroup_headers",
828 "libprotobuf-cpp-lite",
829 "libssl",
830 "libstatslog_resolv",
831 "libstatspush_compat",
832 "libstatssocket",
833 "libstatssocket_headers",
834 "libsystem_headers",
835 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900836 "libutils_headers",
837 "netd_event_listener_interface-ndk_platform",
838 "server_configurable_flags",
839 "stats_proto",
840 }
841 //
842 // Module separator
843 //
844 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000845 "libbase",
846 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900847 "libnativehelper_compat_libc++",
848 "android.hardware.tetheroffload.config@1.0",
849 "fmtlib",
850 "libbacktrace_headers",
851 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900852 "libcgrouprc",
853 "libcgrouprc_format",
854 "libcutils",
855 "libcutils_headers",
856 "libhidlbase",
857 "libhidlbase-impl-internal",
858 "libhidltransport-impl-internal",
859 "libhwbinder-impl-internal",
860 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900861 "liblog_headers",
862 "libprocessgroup",
863 "libprocessgroup_headers",
864 "libsystem_headers",
865 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900866 "libutils_headers",
867 "libvndksupport",
868 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000869 }
870 //
871 // Module separator
872 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900873 m["com.android.wifi"] = []string{
874 "PlatformProperties",
875 "android.hardware.wifi-V1.0-java",
876 "android.hardware.wifi-V1.1-java",
877 "android.hardware.wifi-V1.2-java",
878 "android.hardware.wifi-V1.3-java",
879 "android.hardware.wifi-V1.4-java",
880 "android.hardware.wifi.hostapd-V1.0-java",
881 "android.hardware.wifi.hostapd-V1.1-java",
882 "android.hardware.wifi.hostapd-V1.2-java",
883 "android.hardware.wifi.supplicant-V1.0-java",
884 "android.hardware.wifi.supplicant-V1.1-java",
885 "android.hardware.wifi.supplicant-V1.2-java",
886 "android.hardware.wifi.supplicant-V1.3-java",
887 "android.hidl.base-V1.0-java",
888 "android.hidl.manager-V1.0-java",
889 "android.hidl.manager-V1.1-java",
890 "android.hidl.manager-V1.2-java",
891 "androidx.annotation_annotation",
892 "androidx.annotation_annotation-nodeps",
893 "bouncycastle-unbundled",
894 "dnsresolver_aidl_interface-V2-java",
895 "error_prone_annotations",
896 "ipmemorystore-aidl-interfaces-V3-java",
897 "ipmemorystore-aidl-interfaces-java",
898 "ksoap2",
899 "libbacktrace_headers",
900 "libbase",
901 "libbase_headers",
902 "libc++",
903 "libcutils",
904 "libcutils_headers",
905 "liblog_headers",
906 "libnanohttpd",
907 "libprocessgroup",
908 "libprocessgroup_headers",
909 "libprotobuf-java-lite",
910 "libprotobuf-java-nano",
911 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900912 "libutils_headers",
913 "libwifi-jni",
914 "net-utils-services-common",
915 "netd_aidl_interface-V2-java",
916 "netd_aidl_interface-unstable-java",
917 "netd_event_listener_interface-java",
918 "netlink-client",
919 "networkstack-aidl-interfaces-unstable-java",
920 "networkstack-client",
921 "services.net",
922 "wifi-lite-protos",
923 "wifi-nano-protos",
924 "wifi-service-pre-jarjar",
925 "wifi-service-resources",
926 "prebuilt_androidx.annotation_annotation-nodeps",
927 }
928 //
929 // Module separator
930 //
931 m["com.android.sdkext"] = []string{
932 "fmtlib_ndk",
933 "libbase_ndk",
934 "libprotobuf-cpp-lite-ndk",
935 }
936 //
937 // Module separator
938 //
939 m["com.android.os.statsd"] = []string{
940 "libbacktrace_headers",
941 "libbase_headers",
942 "libc++",
943 "libcutils",
944 "libcutils_headers",
945 "liblog_headers",
946 "libprocessgroup_headers",
947 "libstatssocket",
948 "libsystem_headers",
949 "libutils_headers",
950 }
951 //
952 // Module separator
953 //
954 m["//any"] = []string{
955 "crtbegin_dynamic",
956 "crtbegin_dynamic1",
957 "crtbegin_so",
958 "crtbegin_so1",
959 "crtbegin_static",
960 "crtbrand",
961 "crtend_android",
962 "crtend_so",
963 "libatomic",
964 "libc++_static",
965 "libc++abi",
966 "libc++demangle",
967 "libc_headers",
968 "libclang_rt",
969 "libgcc_stripped",
970 "libprofile-clang-extras",
971 "libprofile-clang-extras_ndk",
972 "libprofile-extras",
973 "libprofile-extras_ndk",
974 "libunwind_llvm",
975 "ndk_crtbegin_dynamic.27",
976 "ndk_crtbegin_so.16",
977 "ndk_crtbegin_so.19",
978 "ndk_crtbegin_so.21",
979 "ndk_crtbegin_so.24",
980 "ndk_crtbegin_so.27",
981 "ndk_crtend_android.27",
982 "ndk_crtend_so.16",
983 "ndk_crtend_so.19",
984 "ndk_crtend_so.21",
985 "ndk_crtend_so.24",
986 "ndk_crtend_so.27",
987 "ndk_libandroid_support",
988 "ndk_libc++_static",
989 "ndk_libc++abi",
990 "ndk_libunwind",
991 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000992 return m
993}
994
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900995func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900996 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800997 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900998 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900999 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001000 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001001 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001002
Jooyung Han31c470b2019-10-18 16:26:59 +09001003 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001004 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001005
1006 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1007 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1008 sort.Strings(*apexFileContextsInfos)
1009 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1010 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001011}
1012
Jooyung Han31c470b2019-10-18 16:26:59 +09001013func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1014 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1015 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1016}
1017
Jiyong Parkd1063c12019-07-17 20:08:41 +09001018func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001019 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001020 ctx.BottomUp("apex", apexMutator).Parallel()
1021 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1022 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001023}
1024
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001025// Mark the direct and transitive dependencies of apex bundles so that they
1026// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001027func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001028 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001029 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001030 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001031 apexBundles = []android.ApexInfo{{mctx.ModuleName(), proptools.Bool(a.properties.Legacy_android10_support)}}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001032 directDep = true
1033 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001034 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001035 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001036 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001037
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001038 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001039 return
1040 }
1041
1042 mctx.VisitDirectDeps(func(child android.Module) {
1043 depName := mctx.OtherModuleName(child)
1044 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1045 (directDep || am.DepIsInSameApex(mctx, child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001046 android.UpdateApexDependency(apexBundles, depName, directDep)
1047 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001048 }
1049 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001050}
1051
1052// Create apex variations if a module is included in APEX(s).
1053func apexMutator(mctx android.BottomUpMutatorContext) {
1054 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001055 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001056 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001057 // apex bundle itself is mutated so that it and its modules have same
1058 // apex variant.
1059 apexBundleName := mctx.ModuleName()
1060 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001061 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1062 apexBundleName := o.GetOverriddenModuleName()
1063 if apexBundleName == "" {
1064 mctx.ModuleErrorf("base property is not set")
1065 return
1066 }
1067 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001069
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001070}
Sundong Ahne9b55722019-09-06 17:37:42 +09001071
Jooyung Han7a78a922019-10-08 21:59:58 +09001072var (
1073 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1074 apexFileContextsInfosMutex sync.Mutex
1075)
1076
1077func apexFileContextsInfos(config android.Config) *[]string {
1078 return config.Once(apexFileContextsInfosKey, func() interface{} {
1079 return &[]string{}
1080 }).(*[]string)
1081}
1082
Jooyung Han54aca7b2019-11-20 02:26:02 +09001083func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001084 apexFileContextsInfosMutex.Lock()
1085 defer apexFileContextsInfosMutex.Unlock()
1086 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001087 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001088}
1089
Sundong Ahne9b55722019-09-06 17:37:42 +09001090func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001091 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001092 var variants []string
1093 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1094 case "image":
1095 variants = append(variants, imageApexType, flattenedApexType)
1096 case "zip":
1097 variants = append(variants, zipApexType)
1098 case "both":
1099 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1100 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001101 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001102 return
1103 }
1104
1105 modules := mctx.CreateLocalVariations(variants...)
1106
1107 for i, v := range variants {
1108 switch v {
1109 case imageApexType:
1110 modules[i].(*apexBundle).properties.ApexType = imageApex
1111 case zipApexType:
1112 modules[i].(*apexBundle).properties.ApexType = zipApex
1113 case flattenedApexType:
1114 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001115 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001116 modules[i].(*apexBundle).MakeAsSystemExt()
1117 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001118 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001119 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001120 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1121 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001122 }
1123}
1124
Jooyung Han5c998b92019-06-27 11:30:33 +09001125func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1126 if ab, ok := mctx.Module().(*apexBundle); ok {
1127 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1128 }
1129}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001130
Jooyung Handc782442019-11-01 03:14:38 +09001131var (
1132 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1133)
1134
1135// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1136// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1137// which may cause compatibility issues. (e.g. libbinder)
1138// Even though libbinder restricts its availability via 'apex_available' property and relies on
1139// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1140// to avoid similar problems.
1141func useVendorWhitelist(config android.Config) []string {
1142 return config.Once(useVendorWhitelistKey, func() interface{} {
1143 return []string{
1144 // swcodec uses "vendor" variants for smaller size
1145 "com.android.media.swcodec",
1146 "test_com.android.media.swcodec",
1147 }
1148 }).([]string)
1149}
1150
1151// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1152// called before the first call to useVendorWhitelist()
1153func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1154 config.Once(useVendorWhitelistKey, func() interface{} {
1155 return whitelist
1156 })
1157}
1158
Jooyung Han01a868d2020-02-27 13:40:44 +09001159type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001160 // List of native libraries
1161 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001162
Jooyung Han643adc42020-02-27 13:50:06 +09001163 // List of JNI libraries
1164 Jni_libs []string
1165
Alex Light9670d332019-01-29 18:07:33 -08001166 // List of native executables
1167 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001168
Roland Levillain630846d2019-06-26 12:48:34 +01001169 // List of native tests
1170 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001171}
Jooyung Han344d5432019-08-23 11:17:39 +09001172
Alex Light9670d332019-01-29 18:07:33 -08001173type apexMultilibProperties struct {
1174 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001175 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001176
1177 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001178 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001179
1180 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001181 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001182
1183 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001184 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001185
1186 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001187 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001188}
1189
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001190type apexBundleProperties struct {
1191 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001192 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001193 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001194
Jiyong Park40e26a22019-02-08 02:53:06 +09001195 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1196 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001197 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001198
Roland Levillain411c5842019-09-19 16:37:20 +01001199 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1200 // device (/apex/<apex_name>).
1201 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001202 Apex_name *string
1203
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001204 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001205 // For platform APEXes, this should points to a file under /system/sepolicy
1206 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1207 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001208
Jooyung Han01a868d2020-02-27 13:40:44 +09001209 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001210
1211 // List of java libraries that are embedded inside this APEX bundle
1212 Java_libs []string
1213
1214 // List of prebuilt files that are embedded inside this APEX bundle
1215 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001216
1217 // Name of the apex_key module that provides the private key to sign APEX
1218 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001219
Alex Light5098a612018-11-29 17:12:15 -08001220 // The type of APEX to build. Controls what the APEX payload is. Either
1221 // 'image', 'zip' or 'both'. Default: 'image'.
1222 Payload_type *string
1223
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001224 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1225 // or an android_app_certificate module name in the form ":module".
1226 Certificate *string
1227
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001228 // Whether this APEX is installable to one of the partitions. Default: true.
1229 Installable *bool
1230
Jiyong Parkda6eb592018-12-19 17:12:36 +09001231 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1232 // Default is false.
1233 Use_vendor *bool
1234
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001235 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1236 Ignore_system_library_special_case *bool
1237
Alex Light9670d332019-01-29 18:07:33 -08001238 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001239
Jiyong Parkf97782b2019-02-13 20:28:58 +09001240 // List of sanitizer names that this APEX is enabled for
1241 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001242
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001243 PreventInstall bool `blueprint:"mutated"`
1244
1245 HideFromMake bool `blueprint:"mutated"`
1246
Jooyung Han5c998b92019-06-27 11:30:33 +09001247 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1248 Provide_cpp_shared_libs *bool
1249
1250 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1251 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001252
1253 // A txt file containing list of files that are whitelisted to be included in this APEX.
1254 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001255
Sundong Ahnabb64432019-10-22 13:58:29 +09001256 // package format of this apex variant; could be non-flattened, flattened, or zip.
1257 // imageApex, zipApex or flattened
1258 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001259
Jiyong Parkd1063c12019-07-17 20:08:41 +09001260 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1261 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1262 // is implied. This value affects all modules included in this APEX. In other words, they are
1263 // also built with the SDKs specified here.
1264 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001265
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001266 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1267 // Should be only used in tests#.
1268 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001269
1270 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1271 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1272 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001273
1274 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001275
1276 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1277 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1278 // like symlinking to the system libs. Default is false.
1279 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001280
1281 // The minimum SDK version that this apex must be compatibile with.
1282 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001283}
1284
1285type apexTargetBundleProperties struct {
1286 Target struct {
1287 // Multilib properties only for android.
1288 Android struct {
1289 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001290 }
Jooyung Han344d5432019-08-23 11:17:39 +09001291
Alex Light9670d332019-01-29 18:07:33 -08001292 // Multilib properties only for host.
1293 Host struct {
1294 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001295 }
Jooyung Han344d5432019-08-23 11:17:39 +09001296
Alex Light9670d332019-01-29 18:07:33 -08001297 // Multilib properties only for host linux_bionic.
1298 Linux_bionic struct {
1299 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001300 }
Jooyung Han344d5432019-08-23 11:17:39 +09001301
Alex Light9670d332019-01-29 18:07:33 -08001302 // Multilib properties only for host linux_glibc.
1303 Linux_glibc struct {
1304 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001305 }
1306 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001307}
1308
Jiyong Park5d790c32019-11-15 18:40:32 +09001309type overridableProperties struct {
1310 // List of APKs to package inside APEX
1311 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001312
1313 // Names of modules to be overridden. Listed modules can only be other binaries
1314 // (in Make or Soong).
1315 // This does not completely prevent installation of the overridden binaries, but if both
1316 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1317 // from PRODUCT_PACKAGES.
1318 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001319
1320 // Logging Parent value
1321 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001322}
1323
Alex Light5098a612018-11-29 17:12:15 -08001324type apexPackaging int
1325
1326const (
1327 imageApex apexPackaging = iota
1328 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001329 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001330)
1331
Sundong Ahnabb64432019-10-22 13:58:29 +09001332// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001333func (a apexPackaging) suffix() string {
1334 switch a {
1335 case imageApex:
1336 return imageApexSuffix
1337 case zipApex:
1338 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001339 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001340 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001341 }
1342}
1343
1344func (a apexPackaging) name() string {
1345 switch a {
1346 case imageApex:
1347 return imageApexType
1348 case zipApex:
1349 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001350 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001351 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001352 }
1353}
1354
Jiyong Parkf653b052019-11-18 15:39:01 +09001355type apexFileClass int
1356
1357const (
1358 etc apexFileClass = iota
1359 nativeSharedLib
1360 nativeExecutable
1361 shBinary
1362 pyBinary
1363 goBinary
1364 javaSharedLib
1365 nativeTest
1366 app
1367)
1368
Jiyong Park8fd61922018-11-08 02:50:25 +09001369func (class apexFileClass) NameInMake() string {
1370 switch class {
1371 case etc:
1372 return "ETC"
1373 case nativeSharedLib:
1374 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001375 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001376 return "EXECUTABLES"
1377 case javaSharedLib:
1378 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001379 case nativeTest:
1380 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001381 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001382 // b/142537672 Why isn't this APP? We want to have full control over
1383 // the paths and file names of the apk file under the flattend APEX.
1384 // If this is set to APP, then the paths and file names are modified
1385 // by the Make build system. For example, it is installed to
1386 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1387 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1388 // appends module name (which is <apexname>.<Appname> to the path.
1389 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001390 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001391 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001392 }
1393}
1394
Jiyong Parkf653b052019-11-18 15:39:01 +09001395// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001396type apexFile struct {
1397 builtFile android.Path
1398 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001399 installDir string
1400 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001401 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001402 // list of symlinks that will be created in installDir that point to this apexFile
1403 symlinks []string
1404 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001405 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001406
1407 requiredModuleNames []string
1408 targetRequiredModuleNames []string
1409 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001410
Colin Cross503c1d02020-01-28 14:00:53 -08001411 jacocoReportClassesFile android.Path // only for javalibs and apps
1412 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001413 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001414
1415 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001416}
1417
Jiyong Park1833cef2019-12-13 13:28:36 +09001418func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1419 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001420 builtFile: builtFile,
1421 moduleName: moduleName,
1422 installDir: installDir,
1423 class: class,
1424 module: module,
1425 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001426 if module != nil {
1427 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001428 ret.requiredModuleNames = module.RequiredModuleNames()
1429 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1430 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001431 }
1432 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001433}
1434
1435func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001436 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001437}
1438
Jiyong Park7cd10e32020-01-14 09:22:18 +09001439// Path() returns path of this apex file relative to the APEX root
1440func (af *apexFile) Path() string {
1441 return filepath.Join(af.installDir, af.builtFile.Base())
1442}
1443
1444// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1445func (af *apexFile) SymlinkPaths() []string {
1446 var ret []string
1447 for _, symlink := range af.symlinks {
1448 ret = append(ret, filepath.Join(af.installDir, symlink))
1449 }
1450 return ret
1451}
1452
1453func (af *apexFile) AvailableToPlatform() bool {
1454 if af.module == nil {
1455 return false
1456 }
1457 if am, ok := af.module.(android.ApexModule); ok {
1458 return am.AvailableFor(android.AvailableToPlatform)
1459 }
1460 return false
1461}
1462
Jiyong Park678c8812020-02-07 17:25:49 +09001463type depInfo struct {
1464 to string
1465 from []string
1466 isExternal bool
1467}
1468
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001469type apexBundle struct {
1470 android.ModuleBase
1471 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001472 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001473 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001474
Jiyong Park5d790c32019-11-15 18:40:32 +09001475 properties apexBundleProperties
1476 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001477 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001478
Jooyung Hanf21c7972019-12-16 22:32:06 +09001479 // specific to apex_vndk modules
1480 vndkProperties apexVndkProperties
1481
Colin Crossa4925902018-11-16 11:36:28 -08001482 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001483 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001484 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001485
Jiyong Park03b68dd2019-07-26 23:20:40 +09001486 prebuiltFileToDelete string
1487
Jiyong Park42cca6c2019-04-01 11:15:50 +09001488 public_key_file android.Path
1489 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001490
1491 container_certificate_file android.Path
1492 container_private_key_file android.Path
1493
Jooyung Han54aca7b2019-11-20 02:26:02 +09001494 fileContexts android.Path
1495
Jiyong Park8fd61922018-11-08 02:50:25 +09001496 // list of files to be included in this apex
1497 filesInfo []apexFile
1498
Jiyong Park956305c2020-01-09 12:32:06 +09001499 // list of module names that should be installed along with this APEX
1500 requiredDeps []string
1501
Jiyong Park956305c2020-01-09 12:32:06 +09001502 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001503 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001504
Sundong Ahnabb64432019-10-22 13:58:29 +09001505 testApex bool
1506 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001507 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001508 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001509
Jooyung Han214bf372019-11-12 13:03:50 +09001510 manifestJsonOut android.WritablePath
1511 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001512
Jooyung Han002ab682020-01-08 01:57:58 +09001513 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001514 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001515 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001516 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1517 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001518
1519 // Suffix of module name in Android.mk
1520 // ".flattened", ".apex", ".zipapex", or ""
1521 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001522
1523 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001524
1525 // Whether to create symlink to the system file instead of having a file
1526 // inside the apex or not
1527 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001528
1529 // Struct holding the merged notice file paths in different formats
1530 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001531}
1532
Jiyong Park397e55e2018-10-24 21:09:55 +09001533func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001534 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001535 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001536 // Use *FarVariation* to be able to depend on modules having
1537 // conflicting variations with this module. This is required since
1538 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1539 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001540 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001541 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001542 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001543 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001544 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001545
Jooyung Han643adc42020-02-27 13:50:06 +09001546 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1547 {Mutator: "image", Variation: imageVariation},
1548 {Mutator: "link", Variation: "shared"},
1549 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1550 }...), jniLibTag, nativeModules.Jni_libs...)
1551
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001552 ctx.AddFarVariationDependencies(append(target.Variations(),
1553 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001554 executableTag, nativeModules.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
Jooyung Han01a868d2020-02-27 13:40:44 +09001559 }...), testTag, nativeModules.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 {
Jooyung Han643adc42020-02-27 13:50:06 +09001592 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001593 // multilib.both
1594 addDependenciesForNativeModules(ctx,
1595 ApexNativeDependencies{
1596 Native_shared_libs: a.properties.Native_shared_libs,
1597 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001598 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001599 Binaries: nil,
1600 },
1601 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001602
Jiyong Park397e55e2018-10-24 21:09:55 +09001603 // Add native modules targetting both ABIs
1604 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001605 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001606 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001607 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001608
Alex Light3d673592019-01-18 14:37:31 -08001609 isPrimaryAbi := i == 0
1610 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001611 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001612 // multilib.first
1613 addDependenciesForNativeModules(ctx,
1614 ApexNativeDependencies{
1615 Native_shared_libs: nil,
1616 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001617 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001618 Binaries: a.properties.Binaries,
1619 },
1620 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001621
1622 // Add native modules targetting the first ABI
1623 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001624 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001625 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001626 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001627 }
1628
1629 switch target.Arch.ArchType.Multilib {
1630 case "lib32":
1631 // Add native modules targetting 32-bit ABI
1632 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001633 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001634 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001635 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001636
1637 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001638 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001639 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001640 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001641 case "lib64":
1642 // Add native modules targetting 64-bit ABI
1643 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001644 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001645 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001646 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001647
1648 if !has32BitTarget {
1649 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001650 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001651 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001652 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001653 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001654
1655 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1656 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1657 if sanitizer == "hwaddress" {
1658 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001659 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001660 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001661 break
1662 }
1663 }
1664 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001665 }
1666
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667 }
1668
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001669 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1670 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1671 // b/144532908
1672 archForPrebuiltEtc := config.Arches()[0]
1673 for _, arch := range config.Arches() {
1674 // Prefer 64-bit arch if there is any
1675 if arch.ArchType.Multilib == "lib64" {
1676 archForPrebuiltEtc = arch
1677 break
1678 }
1679 }
1680 ctx.AddFarVariationDependencies([]blueprint.Variation{
1681 {Mutator: "os", Variation: ctx.Os().String()},
1682 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1683 }, prebuiltTag, a.properties.Prebuilts...)
1684
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001685 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1686 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001687
Ulya Trafimovich44561882020-01-03 13:25:54 +00001688 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1689 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1690 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1691 javaLibTag, "jacocoagent")
1692 }
1693
Jiyong Park23c52b02019-02-02 13:13:47 +09001694 if String(a.properties.Key) == "" {
1695 ctx.ModuleErrorf("key is missing")
1696 return
1697 }
1698 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001699
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001700 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001701 if cert != "" {
1702 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001703 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001704
1705 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1706 if len(a.properties.Uses_sdks) > 0 {
1707 sdkRefs := []android.SdkRef{}
1708 for _, str := range a.properties.Uses_sdks {
1709 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1710 sdkRefs = append(sdkRefs, parsed)
1711 }
1712 a.BuildWithSdks(sdkRefs)
1713 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001714}
1715
Jiyong Park5d790c32019-11-15 18:40:32 +09001716func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1717 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1718 androidAppTag, a.overridableProperties.Apps...)
1719}
1720
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001721func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1722 // direct deps of an APEX bundle are all part of the APEX bundle
1723 return true
1724}
1725
Colin Cross0ea8ba82019-06-06 14:33:29 -07001726func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001727 moduleName := ctx.ModuleName()
1728 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1729 // we check with the pseudo module name to see if its certificate is overridden.
1730 if a.vndkApex {
1731 moduleName = vndkApexName
1732 }
1733 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001734 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001735 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001736 }
1737 return String(a.properties.Certificate)
1738}
1739
Colin Cross41955e82019-05-29 14:40:35 -07001740func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1741 switch tag {
1742 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001743 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001744 default:
1745 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001746 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001747}
1748
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001749func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001750 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001751}
1752
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001753func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1754 return proptools.Bool(a.properties.Test_only_no_hashtree)
1755}
1756
Jiyong Park7c1dc612019-01-05 11:15:24 +09001757func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001758 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001759 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001760 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001761 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001762 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001763 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001764 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001765 }
1766}
1767
Jiyong Parkf97782b2019-02-13 20:28:58 +09001768func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1769 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1770 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1771 }
1772}
1773
Jiyong Park388ef3f2019-01-28 19:47:32 +09001774func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001775 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1776 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001777 }
1778
1779 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001780 globalSanitizerNames := []string{}
1781 if a.Host() {
1782 globalSanitizerNames = ctx.Config().SanitizeHost()
1783 } else {
1784 arches := ctx.Config().SanitizeDeviceArch()
1785 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1786 globalSanitizerNames = ctx.Config().SanitizeDevice()
1787 }
1788 }
1789 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001790}
1791
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001792func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001793 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001794}
1795
1796func (a *apexBundle) PreventInstall() {
1797 a.properties.PreventInstall = true
1798}
1799
1800func (a *apexBundle) HideFromMake() {
1801 a.properties.HideFromMake = true
1802}
1803
Jiyong Park956305c2020-01-09 12:32:06 +09001804func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1805 a.properties.IsCoverageVariant = coverage
1806}
1807
Jiyong Parkf653b052019-11-18 15:39:01 +09001808// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001809func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001810 // Decide the APEX-local directory by the multilib of the library
1811 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001812 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001813 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001814 case "lib32":
1815 dirInApex = "lib"
1816 case "lib64":
1817 dirInApex = "lib64"
1818 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001819 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001820 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001821 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001822 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001823 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001824 // Special case for Bionic libs and other libs installed with them. This is
1825 // to prevent those libs from being included in the search path
1826 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1827 // those libs in the Runtime APEX are available via the legacy paths in
1828 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1829 // to the legacy paths and thus will be loaded into the default linker
1830 // namespace (aka "platform" namespace). If the libs are directly in
1831 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1832 // into the runtime linker namespace, which will result in double loading of
1833 // them, which isn't supported.
1834 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001835 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001836
Jiyong Parkf653b052019-11-18 15:39:01 +09001837 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001838 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001839}
1840
Jiyong Park1833cef2019-12-13 13:28:36 +09001841func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001842 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001843 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001844 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001845 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001847 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001848 af.symlinks = cc.Symlinks()
1849 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001850}
1851
Jiyong Park1833cef2019-12-13 13:28:36 +09001852func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001853 dirInApex := "bin"
1854 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001855 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001856}
Jiyong Park1833cef2019-12-13 13:28:36 +09001857func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001858 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001859 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1860 if err != nil {
1861 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001863 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001864 fileToCopy := android.PathForOutput(ctx, s)
1865 // NB: Since go binaries are static we don't need the module for anything here, which is
1866 // good since the go tool is a blueprint.Module not an android.Module like we would
1867 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001868 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001869}
1870
Jiyong Park1833cef2019-12-13 13:28:36 +09001871func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 dirInApex := filepath.Join("bin", sh.SubDir())
1873 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001874 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001875 af.symlinks = sh.Symlinks()
1876 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001877}
1878
Jooyung Han58f26ab2019-12-18 15:34:32 +09001879// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1880type javaLibrary interface {
1881 android.Module
1882 java.Dependency
1883}
1884
1885func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001886 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001887 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001888 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1889 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1890 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001891}
1892
Jiyong Park1833cef2019-12-13 13:28:36 +09001893func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001894 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1895 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001896 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001897}
1898
atrost6e126252020-01-27 17:01:16 +00001899func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1900 dirInApex := filepath.Join("etc", config.SubDir())
1901 fileToCopy := config.CompatConfig()
1902 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1903}
1904
Jiyong Park1833cef2019-12-13 13:28:36 +09001905func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001906 android.Module
1907 Privileged() bool
1908 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001909 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001910 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001911}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001912 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001913 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001914 appDir = "priv-app"
1915 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 dirInApex := filepath.Join(appDir, pkgName)
1917 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001918 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1919 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001920 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001921
1922 if app, ok := aapp.(interface {
1923 OverriddenManifestPackageName() string
1924 }); ok {
1925 af.overriddenPackageName = app.OverriddenManifestPackageName()
1926 }
Jiyong Park618922e2020-01-08 13:35:43 +09001927 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001928}
1929
Roland Levillain935639d2019-08-13 14:55:28 +01001930// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1931type flattenedApexContext struct {
1932 android.ModuleContext
1933}
1934
1935func (c *flattenedApexContext) InstallBypassMake() bool {
1936 return true
1937}
1938
Jiyong Park201cedd2020-02-07 17:25:49 +09001939// Visit dependencies that contributes to the payload of this APEX
1940func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1941 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001942 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1943 am, ok := child.(android.ApexModule)
1944 if !ok || !am.CanHaveApexVariants() {
1945 return false
1946 }
1947
1948 // Check for the direct dependencies that contribute to the payload
1949 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1950 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001951 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001952 return true
1953 }
1954 return false
1955 }
1956
1957 // Check for the indirect dependencies if it is considered as part of the APEX
1958 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001959 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001960 return true
1961 }
1962
Jiyong Park201cedd2020-02-07 17:25:49 +09001963 do(ctx, parent, am, true /* externalDep */)
1964
Jiyong Park0f80c182020-01-31 02:49:53 +09001965 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1966 return false
1967 })
1968}
1969
Jiyong Park201cedd2020-02-07 17:25:49 +09001970// Ensures that the dependencies are marked as available for this APEX
1971func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1972 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1973 if ctx.Host() || a.testApex || a.vndkApex {
1974 return
1975 }
1976
1977 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1978 apexName := ctx.ModuleName()
1979 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
1980 return
1981 }
1982 ctx.ModuleErrorf("requires %q that is not available for the APEX.", to.Name())
1983 })
1984}
1985
Jiyong Park678c8812020-02-07 17:25:49 +09001986// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1987func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1988 a.depInfos = make(map[string]depInfo)
1989 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1990 if from.Name() == to.Name() {
1991 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1992 return
1993 }
1994
1995 if info, exists := a.depInfos[to.Name()]; exists {
1996 if !android.InList(from.Name(), info.from) {
1997 info.from = append(info.from, from.Name())
1998 }
1999 info.isExternal = info.isExternal && externalDep
2000 a.depInfos[to.Name()] = info
2001 } else {
2002 a.depInfos[to.Name()] = depInfo{
2003 to: to.Name(),
2004 from: []string{from.Name()},
2005 isExternal: externalDep,
2006 }
2007 }
2008 })
2009}
2010
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002011func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002012 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2013 switch a.properties.ApexType {
2014 case imageApex:
2015 if buildFlattenedAsDefault {
2016 a.suffix = imageApexSuffix
2017 } else {
2018 a.suffix = ""
2019 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002020
2021 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002022 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002023 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002024 }
2025 case zipApex:
2026 if proptools.String(a.properties.Payload_type) == "zip" {
2027 a.suffix = ""
2028 a.primaryApexType = true
2029 } else {
2030 a.suffix = zipApexSuffix
2031 }
2032 case flattenedApex:
2033 if buildFlattenedAsDefault {
2034 a.suffix = ""
2035 a.primaryApexType = true
2036 } else {
2037 a.suffix = flattenedSuffix
2038 }
Alex Light5098a612018-11-29 17:12:15 -08002039 }
2040
Roland Levillain630846d2019-06-26 12:48:34 +01002041 if len(a.properties.Tests) > 0 && !a.testApex {
2042 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2043 return
2044 }
2045
Jiyong Park0f80c182020-01-31 02:49:53 +09002046 a.checkApexAvailability(ctx)
2047
Jiyong Park678c8812020-02-07 17:25:49 +09002048 a.collectDepsInfo(ctx)
2049
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002050 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2051
Jooyung Hane1633032019-08-01 17:41:43 +09002052 // native lib dependencies
2053 var provideNativeLibs []string
2054 var requireNativeLibs []string
2055
Jooyung Han5c998b92019-06-27 11:30:33 +09002056 // Check if "uses" requirements are met with dependent apexBundles
2057 var providedNativeSharedLibs []string
2058 useVendor := proptools.Bool(a.properties.Use_vendor)
2059 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2060 if ctx.OtherModuleDependencyTag(m) != usesTag {
2061 return
2062 }
2063 otherName := ctx.OtherModuleName(m)
2064 other, ok := m.(*apexBundle)
2065 if !ok {
2066 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2067 return
2068 }
2069 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2070 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2071 return
2072 }
2073 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2074 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2075 return
2076 }
2077 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2078 })
2079
Jiyong Parkf653b052019-11-18 15:39:01 +09002080 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002081 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002082 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002083 depTag := ctx.OtherModuleDependencyTag(child)
2084 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002086 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002087 case sharedLibTag, jniLibTag:
2088 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002089 if c, ok := child.(*cc.Module); ok {
2090 // bootstrap bionic libs are treated as provided by system
2091 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2092 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002093 }
Jooyung Han643adc42020-02-27 13:50:06 +09002094 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2095 fi.isJniLib = isJniLib
2096 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002097 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002098 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002099 propertyName := "native_shared_libs"
2100 if isJniLib {
2101 propertyName = "jni_libs"
2102 }
2103 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002104 }
2105 case executableTag:
2106 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002107 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002108 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002109 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002110 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002111 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002112 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002113 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002114 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002115 } else {
Alex Light778127a2019-02-27 14:19:50 -08002116 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 +09002117 }
2118 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002119 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002120 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002121 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2123 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002124 filesInfo = append(filesInfo, af)
2125 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002126 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002127 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2128 af := apexFileForJavaLibrary(ctx, sdkLib)
2129 if !af.Ok() {
2130 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2131 return false
2132 }
2133 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002134 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002135 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002136 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002137 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002138 case androidAppTag:
2139 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2140 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002141 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 return true // track transitive dependencies
2143 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002144 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002145 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2146 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002147 } else {
2148 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2149 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002150 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002151 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002152 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002153 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2154 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002155 } else {
atrost6e126252020-01-27 17:01:16 +00002156 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002157 }
Roland Levillain630846d2019-06-26 12:48:34 +01002158 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002159 if ccTest, ok := child.(*cc.Module); ok {
2160 if ccTest.IsTestPerSrcAllTestsVariation() {
2161 // Multiple-output test module (where `test_per_src: true`).
2162 //
2163 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2164 // We do not add this variation to `filesInfo`, as it has no output;
2165 // however, we do add the other variations of this module as indirect
2166 // dependencies (see below).
2167 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002168 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002169 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002170 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002171 af.class = nativeTest
2172 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002173 }
Roland Levillain630846d2019-06-26 12:48:34 +01002174 } else {
2175 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2176 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002177 case keyTag:
2178 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002179 a.private_key_file = key.private_key_file
2180 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002181 } else {
2182 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002183 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002184 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002185 case certificateTag:
2186 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002187 a.container_certificate_file = dep.Certificate.Pem
2188 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002189 } else {
2190 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2191 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002192 case android.PrebuiltDepTag:
2193 // If the prebuilt is force disabled, remember to delete the prebuilt file
2194 // that might have been installed in the previous builds
2195 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2196 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2197 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002198 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002199 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002200 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002201 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002202 // We cannot use a switch statement on `depTag` here as the checked
2203 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002204 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002205 if cc, ok := child.(*cc.Module); ok {
2206 if android.InList(cc.Name(), providedNativeSharedLibs) {
2207 // If we're using a shared library which is provided from other APEX,
2208 // don't include it in this APEX
2209 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002210 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002211 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002212 // If the dependency is a stubs lib, don't include it in this APEX,
2213 // but make sure that the lib is installed on the device.
2214 // In case no APEX is having the lib, the lib is installed to the system
2215 // partition.
2216 //
2217 // Always include if we are a host-apex however since those won't have any
2218 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002219 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2220 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002221 }
Jooyung Hane1633032019-08-01 17:41:43 +09002222 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002223 // Don't track further
2224 return false
2225 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002226 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002227 af.transitiveDep = true
2228 filesInfo = append(filesInfo, af)
2229 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002230 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002231 } else if cc.IsTestPerSrcDepTag(depTag) {
2232 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002233 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002234 // Handle modules created as `test_per_src` variations of a single test module:
2235 // use the name of the generated test binary (`fileToCopy`) instead of the name
2236 // of the original test module (`depName`, shared by all `test_per_src`
2237 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002238 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002239 // these are not considered transitive dep
2240 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002241 filesInfo = append(filesInfo, af)
2242 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002243 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002244 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002245 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2246 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002247 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2248 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2249 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2250 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002251 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002252 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002253 }
2254 }
2255 }
2256 return false
2257 })
2258
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002259 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2260 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2261 // via the global boot image config.
2262 if a.artApex {
2263 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2264 dirInApex := filepath.Join("javalib", arch.String())
2265 for _, f := range files {
2266 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002267 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002268 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002269 }
2270 }
2271 }
2272
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002273 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002274 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2275 return
2276 }
2277
Jiyong Park8fd61922018-11-08 02:50:25 +09002278 // remove duplicates in filesInfo
2279 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002280 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002281 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002282 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002283 if e, ok := encountered[dest]; !ok {
2284 encountered[dest] = f
2285 } else {
2286 // If a module is directly included and also transitively depended on
2287 // consider it as directly included.
2288 e.transitiveDep = e.transitiveDep && f.transitiveDep
2289 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002290 }
2291 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002292 var result []apexFile
2293 for _, v := range encountered {
2294 result = append(result, v)
2295 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002296 return result
2297 }
2298 filesInfo = removeDup(filesInfo)
2299
2300 // to have consistent build rules
2301 sort.Slice(filesInfo, func(i, j int) bool {
2302 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2303 })
2304
Jiyong Park8fd61922018-11-08 02:50:25 +09002305 a.installDir = android.PathForModuleInstall(ctx, "apex")
2306 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002307
Jooyung Han54aca7b2019-11-20 02:26:02 +09002308 if a.properties.ApexType != zipApex {
2309 if a.properties.File_contexts == nil {
2310 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2311 } else {
2312 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2313 if a.Platform() {
2314 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2315 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2316 }
2317 }
2318 }
2319 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2320 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2321 return
2322 }
2323 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002324 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2325 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2326 // the same library in the system partition, thus effectively sharing the same libraries
2327 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2328 // in the APEX.
2329 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2330 a.installable() &&
2331 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002332
Jiyong Park9d677202020-02-19 16:29:35 +09002333 // We don't need the optimization for updatable APEXes, as it might give false signal
2334 // to the system health when the APEXes are still bundled (b/149805758)
2335 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2336 a.linkToSystemLib = false
2337 }
2338
Jiyong Park638d30e2020-02-26 18:27:19 +09002339 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2340 if ctx.Host() {
2341 a.linkToSystemLib = false
2342 }
2343
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002344 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002345 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2346
2347 a.setCertificateAndPrivateKey(ctx)
2348 if a.properties.ApexType == flattenedApex {
2349 a.buildFlattenedApex(ctx)
2350 } else {
2351 a.buildUnflattenedApex(ctx)
2352 }
2353
Jooyung Han002ab682020-01-08 01:57:58 +09002354 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002355
2356 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002357}
2358
Jiyong Park0f80c182020-01-31 02:49:53 +09002359func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002360 key := apex
2361 key = strings.Replace(key, "test_", "", 1)
2362 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2363 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2364
2365 moduleName := module.Name()
Jiyong Park0f80c182020-01-31 02:49:53 +09002366 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2367 // system. Trim the prefix for the check since they are confusing
2368 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2369 if strings.HasPrefix(moduleName, "libclang_rt.") {
2370 // This module has many arch variants that depend on the product being built.
2371 // We don't want to list them all
2372 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002373 }
2374
2375 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2376 return true
2377 }
2378
Jiyong Park0f80c182020-01-31 02:49:53 +09002379 key = "//any"
2380 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2381 return true
2382 }
2383
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002384 return false
2385}
2386
Jooyung Han344d5432019-08-23 11:17:39 +09002387func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002388 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002389 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002390 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002391 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002392 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002393 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2394 })
Alex Light5098a612018-11-29 17:12:15 -08002395 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002396 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002397 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002398 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002399 return module
2400}
Jiyong Park30ca9372019-02-07 16:27:23 +09002401
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002402func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002403 bundle := newApexBundle()
2404 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002405 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002406 return bundle
2407}
2408
Jiyong Parkfce0b422020-02-11 03:56:06 +09002409// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2410// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002411func testApexBundleFactory() android.Module {
2412 bundle := newApexBundle()
2413 bundle.testApex = true
2414 return bundle
2415}
2416
Jiyong Parkfce0b422020-02-11 03:56:06 +09002417// apex packages other modules into an APEX file which is a packaging format for system-level
2418// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002419func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002420 return newApexBundle()
2421}
2422
Jiyong Park30ca9372019-02-07 16:27:23 +09002423//
2424// Defaults
2425//
2426type Defaults struct {
2427 android.ModuleBase
2428 android.DefaultsModuleBase
2429}
2430
Jiyong Park30ca9372019-02-07 16:27:23 +09002431func defaultsFactory() android.Module {
2432 return DefaultsFactory()
2433}
2434
2435func DefaultsFactory(props ...interface{}) android.Module {
2436 module := &Defaults{}
2437
2438 module.AddProperties(props...)
2439 module.AddProperties(
2440 &apexBundleProperties{},
2441 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002442 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002443 )
2444
2445 android.InitDefaultsModule(module)
2446 return module
2447}
Jiyong Park5d790c32019-11-15 18:40:32 +09002448
2449//
2450// OverrideApex
2451//
2452type OverrideApex struct {
2453 android.ModuleBase
2454 android.OverrideModuleBase
2455}
2456
2457func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2458 // All the overrides happen in the base module.
2459}
2460
2461// override_apex is used to create an apex module based on another apex module
2462// by overriding some of its properties.
2463func overrideApexFactory() android.Module {
2464 m := &OverrideApex{}
2465 m.AddProperties(&overridableProperties{})
2466
2467 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2468 android.InitOverrideModule(m)
2469 return m
2470}