blob: af9fd82b974491c8dc0b80cdd5c89bead9b555a1 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090022 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090066)
67
Anton Hanssoneec79eb2020-01-10 15:12:39 +000068// This is a map from apex to modules, which overrides the
69// apex_available setting for that particular module to make
70// it available for the apex regardless of its setting.
71// TODO(b/147364041): remove this
72func makeApexAvailableWhitelist() map[string][]string {
73 // The "Module separator"s below are employed to minimize merge conflicts.
74 m := make(map[string][]string)
75 //
76 // Module separator
77 //
Jiyong Park0f80c182020-01-31 02:49:53 +090078 m["com.android.adbd"] = []string{
79 "adbd",
80 "bcm_object",
81 "fmtlib",
82 "libadbconnection_server",
83 "libadbd",
84 "libadbd_auth",
85 "libadbd_core",
86 "libadbd_services",
87 "libasyncio",
88 "libbacktrace_headers",
89 "libbase",
90 "libbase_headers",
91 "libbuildversion",
92 "libc++",
93 "libcap",
94 "libcrypto",
95 "libcrypto_utils",
96 "libcutils",
97 "libcutils_headers",
98 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "liblog_headers",
100 "libmdnssd",
101 "libminijail",
102 "libminijail_gen_constants",
103 "libminijail_gen_constants_obj",
104 "libminijail_gen_syscall",
105 "libminijail_gen_syscall_obj",
106 "libminijail_generated",
107 "libpackagelistparser",
108 "libpcre2",
109 "libprocessgroup_headers",
110 "libqemu_pipe",
111 "libselinux",
112 "libsystem_headers",
113 "libutils_headers",
114 }
115 //
116 // Module separator
117 //
118 m["com.android.appsearch"] = []string{
119 "icing-java-proto-lite",
120 "libprotobuf-java-lite",
121 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000122 //
123 // Module separator
124 //
125 m["com.android.art"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "art_cmdlineparser_headers",
127 "art_disassembler_headers",
128 "art_libartbase_headers",
129 "bcm_object",
130 "bionic_libc_platform_headers",
131 "core-repackaged-icu4j",
132 "cpp-define-generator-asm-support",
133 "cpp-define-generator-definitions",
134 "crtbegin_dynamic",
135 "crtbegin_dynamic1",
136 "crtbegin_so1",
137 "crtbrand",
138 "conscrypt.module.intra.core.api.stubs",
139 "dex2oat_headers",
140 "dt_fd_forward_export",
141 "fmtlib",
142 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000143 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900144 "javavm_headers",
145 "jni_platform_headers",
146 "libPlatformProperties",
147 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900149 "libandroidicuinit",
150 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000151 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 "libbacktrace",
154 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000156 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900157 "libc++_static",
158 "libc++abi",
159 "libc++demangle",
160 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libdexfile_all_headers",
163 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000166 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900167 "libfdlibm",
168 "libgtest_prod",
169 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900171 "libicuuc_headers",
172 "libicuuc_stubdata",
173 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 "liblog_headers",
175 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000176 "liblzma",
177 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libnativebridge-headers",
179 "libnativehelper_header_only",
180 "libnativeloader-headers",
181 "libnpt_headers",
182 "libopenjdkjvmti_headers",
183 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000184 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "libprotobuf-cpp-lite",
186 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900188 "libv8",
189 "libv8base",
190 "libv8gen",
191 "libv8platform",
192 "libv8sampler",
193 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000194 "libvixl",
195 "libvixld",
196 "libz",
197 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000199 }
200 //
201 // Module separator
202 //
203 m["com.android.bluetooth.updatable"] = []string{
204 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.hardware.bluetooth.a2dp@1.0",
206 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900207 "android.hardware.bluetooth@1.0",
208 "android.hardware.bluetooth@1.1",
209 "android.hardware.graphics.bufferqueue@1.0",
210 "android.hardware.graphics.bufferqueue@2.0",
211 "android.hardware.graphics.common@1.0",
212 "android.hardware.graphics.common@1.1",
213 "android.hardware.graphics.common@1.2",
214 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000215 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "android.hidl.token@1.0",
217 "android.hidl.token@1.0-utils",
218 "avrcp-target-service",
219 "avrcp_headers",
220 "bcm_object",
221 "bluetooth-protos-lite",
222 "bluetooth.mapsapi",
223 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900224 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "fmtlib",
226 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900227 "ipmemorystore-aidl-interfaces-V5-java",
228 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900229 "internal_include_headers",
230 "lib-bt-packets",
231 "lib-bt-packets-avrcp",
232 "lib-bt-packets-base",
233 "libFraunhoferAAC",
234 "libaudio-a2dp-hw-utils",
235 "libaudio-hearing-aid-hw-utils",
236 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000237 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "libbase_headers",
239 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libbluetooth-types",
242 "libbluetooth-types-header",
243 "libbluetooth_gd",
244 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000245 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900246 "libbt-audio-hal-interface",
247 "libbt-bta",
248 "libbt-common",
249 "libbt-hci",
250 "libbt-platform-protos-lite",
251 "libbt-protos-lite",
252 "libbt-sbc-decoder",
253 "libbt-sbc-encoder",
254 "libbt-stack",
255 "libbt-utils",
256 "libbtcore",
257 "libbtdevice",
258 "libbte",
259 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000260 "libc++",
261 "libchrome",
262 "libcrypto",
263 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900264 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000265 "libevent",
266 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "libg722codec",
268 "libgtest_prod",
269 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000270 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libhidlbase-impl-internal",
272 "libhidltransport-impl-internal",
273 "libhwbinder-impl-internal",
274 "libjsoncpp",
275 "liblog_headers",
276 "libmedia_headers",
277 "libmodpb64",
278 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000279 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000281 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900282 "libprotobuf-java-lite",
283 "libprotobuf-java-micro",
284 "libstagefright_foundation_headers",
285 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000286 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900287 "libstatssocket",
288 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000289 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900291 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000292 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900293 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900294 "net-utils-services-common",
295 "netd_aidl_interface-unstable-java",
296 "netd_event_listener_interface-java",
297 "netlink-client",
298 "networkstack-aidl-interfaces-unstable-java",
299 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 "sap-api-java-static",
301 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000302 }
303 //
304 // Module separator
305 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900306 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000307 //
308 // Module separator
309 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 m["com.android.conscrypt"] = []string{
311 "bcm_object",
312 "boringssl_self_test",
313 "libc++",
314 "libcrypto",
315 "libnativehelper_header_only",
316 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900317 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900318 }
319 //
320 // Module separator
321 //
322 m["com.android.extservices"] = []string{
323 "flatbuffer_headers",
324 "liblua",
325 "libtextclassifier",
326 "libtextclassifier_hash_static",
327 "libtflite_static",
328 "libutf",
329 "libz_current",
330 "tensorflow_headers",
331 }
332 //
333 // Module separator
334 //
335 m["com.android.cronet"] = []string{
336 "cronet_impl_common_java",
337 "cronet_impl_native_java",
338 "cronet_impl_platform_java",
339 "libcronet.80.0.3986.0",
340 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900341 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900342 "prebuilt_libcronet.80.0.3986.0",
343 }
344 //
345 // Module separator
346 //
347 m["com.android.neuralnetworks"] = []string{
348 "android.hardware.neuralnetworks@1.0",
349 "android.hardware.neuralnetworks@1.1",
350 "android.hardware.neuralnetworks@1.2",
351 "android.hardware.neuralnetworks@1.3",
352 "android.hidl.allocator@1.0",
353 "android.hidl.memory.token@1.0",
354 "android.hidl.memory@1.0",
355 "android.hidl.safe_union@1.0",
356 "bcm_object",
357 "fmtlib",
358 "gemmlowp_headers",
359 "libarect",
360 "libbacktrace_headers",
361 "libbase",
362 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900363 "libbuildversion",
364 "libc++",
365 "libcrypto",
366 "libcrypto_static",
367 "libcutils",
368 "libcutils_headers",
369 "libeigen",
370 "libfmq",
371 "libhidlbase",
372 "libhidlbase-impl-internal",
373 "libhidlmemory",
374 "libhidltransport-impl-internal",
375 "libhwbinder-impl-internal",
376 "libjsoncpp",
377 "liblog_headers",
378 "libmath",
379 "libneuralnetworks_common",
380 "libneuralnetworks_headers",
381 "libprocessgroup",
382 "libprocessgroup_headers",
383 "libprocpartition",
384 "libsync",
385 "libsystem_headers",
386 "libtextclassifier_hash",
387 "libtextclassifier_hash_headers",
388 "libtextclassifier_hash_static",
389 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900390 "libutils_headers",
391 "philox_random",
392 "philox_random_headers",
393 "tensorflow_headers",
394 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000395 //
396 // Module separator
397 //
398 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000399 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900400 "android.hardware.cas.native@1.0",
401 "android.hardware.cas@1.0",
402 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000403 "android.hardware.configstore@1.0",
404 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000405 "android.hardware.graphics.allocator@2.0",
406 "android.hardware.graphics.allocator@3.0",
407 "android.hardware.graphics.bufferqueue@1.0",
408 "android.hardware.graphics.bufferqueue@2.0",
409 "android.hardware.graphics.common@1.0",
410 "android.hardware.graphics.common@1.1",
411 "android.hardware.graphics.common@1.2",
412 "android.hardware.graphics.mapper@2.0",
413 "android.hardware.graphics.mapper@2.1",
414 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900415 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000416 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900417 "android.hidl.allocator@1.0",
418 "android.hidl.memory.token@1.0",
419 "android.hidl.memory@1.0",
420 "android.hidl.token@1.0",
421 "android.hidl.token@1.0-utils",
422 "bcm_object",
423 "bionic_libc_platform_headers",
424 "fmtlib",
425 "gl_headers",
426 "libEGL",
427 "libEGL_blobCache",
428 "libEGL_getProcAddress",
429 "libFLAC",
430 "libFLAC-config",
431 "libFLAC-headers",
432 "libGLESv2",
433 "libaacextractor",
434 "libamrextractor",
435 "libarect",
436 "libasync_safe",
437 "libaudio_system_headers",
438 "libaudioclient",
439 "libaudioclient_headers",
440 "libaudiofoundation",
441 "libaudiofoundation_headers",
442 "libaudiomanager",
443 "libaudiopolicy",
444 "libaudioutils",
445 "libaudioutils_fixedfft",
446 "libbacktrace",
447 "libbacktrace_headers",
448 "libbase",
449 "libbase_headers",
450 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900451 "libbluetooth-types-header",
452 "libbufferhub",
453 "libbufferhub_headers",
454 "libbufferhubqueue",
455 "libc++",
456 "libc_headers",
457 "libc_malloc_debug_backtrace",
458 "libcamera_client",
459 "libcamera_metadata",
460 "libcrypto",
461 "libcutils",
462 "libcutils_headers",
463 "libdexfile_external_headers",
464 "libdexfile_support",
465 "libdvr_headers",
466 "libexpat",
467 "libfifo",
468 "libflacextractor",
469 "libgrallocusage",
470 "libgraphicsenv",
471 "libgui",
472 "libgui_headers",
473 "libhardware_headers",
474 "libhidlbase",
475 "libhidlbase-impl-internal",
476 "libhidlmemory",
477 "libhidltransport-impl-internal",
478 "libhwbinder-impl-internal",
479 "libinput",
480 "libjsoncpp",
481 "liblog_headers",
482 "liblzma",
483 "libmath",
484 "libmedia",
485 "libmedia_codeclist",
486 "libmedia_headers",
487 "libmedia_helper",
488 "libmedia_helper_headers",
489 "libmedia_midiiowrapper",
490 "libmedia_omx",
491 "libmediautils",
492 "libmidiextractor",
493 "libmkvextractor",
494 "libmp3extractor",
495 "libmp4extractor",
496 "libmpeg2extractor",
497 "libnativebase_headers",
498 "libnativebridge-headers",
499 "libnativebridge_lazy",
500 "libnativeloader-headers",
501 "libnativeloader_lazy",
502 "libnativewindow_headers",
503 "libnblog",
504 "liboggextractor",
505 "libpackagelistparser",
506 "libpcre2",
507 "libpdx",
508 "libpdx_default_transport",
509 "libpdx_headers",
510 "libpdx_uds",
511 "libprocessgroup",
512 "libprocessgroup_headers",
513 "libprocinfo",
514 "libselinux",
515 "libsonivox",
516 "libspeexresampler",
517 "libspeexresampler",
518 "libstagefright_esds",
519 "libstagefright_flacdec",
520 "libstagefright_flacdec",
521 "libstagefright_foundation",
522 "libstagefright_foundation_headers",
523 "libstagefright_foundation_without_imemory",
524 "libstagefright_headers",
525 "libstagefright_id3",
526 "libstagefright_metadatautils",
527 "libstagefright_mpeg2extractor",
528 "libstagefright_mpeg2support",
529 "libsync",
530 "libsystem_headers",
531 "libui",
532 "libui_headers",
533 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900534 "libutils_headers",
535 "libvibrator",
536 "libvorbisidec",
537 "libwavextractor",
538 "libwebm",
539 "media_ndk_headers",
540 "media_plugin_headers",
541 "updatable-media",
542 }
543 //
544 // Module separator
545 //
546 m["com.android.media.swcodec"] = []string{
547 "android.frameworks.bufferhub@1.0",
548 "android.hardware.common-ndk_platform",
549 "android.hardware.configstore-utils",
550 "android.hardware.configstore@1.0",
551 "android.hardware.configstore@1.1",
552 "android.hardware.graphics.allocator@2.0",
553 "android.hardware.graphics.allocator@3.0",
554 "android.hardware.graphics.bufferqueue@1.0",
555 "android.hardware.graphics.bufferqueue@2.0",
556 "android.hardware.graphics.common-ndk_platform",
557 "android.hardware.graphics.common@1.0",
558 "android.hardware.graphics.common@1.1",
559 "android.hardware.graphics.common@1.2",
560 "android.hardware.graphics.mapper@2.0",
561 "android.hardware.graphics.mapper@2.1",
562 "android.hardware.graphics.mapper@3.0",
563 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000564 "android.hardware.media.bufferpool@2.0",
565 "android.hardware.media.c2@1.0",
566 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "android.hardware.media@1.0",
568 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000569 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900570 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000571 "android.hidl.safe_union@1.0",
572 "android.hidl.token@1.0",
573 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 "fmtlib",
575 "libEGL",
576 "libFLAC",
577 "libFLAC-config",
578 "libFLAC-headers",
579 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900580 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libarect",
582 "libasync_safe",
583 "libaudio_system_headers",
584 "libaudioutils",
585 "libaudioutils",
586 "libaudioutils_fixedfft",
587 "libavcdec",
588 "libavcenc",
589 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000590 "libavservices_minijail",
591 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000593 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libbase_headers",
595 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900596 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900597 "libbluetooth-types-header",
598 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000599 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900600 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 "libcap",
602 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900603 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000604 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libcodec2_hidl@1.1",
606 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000607 "libcodec2_soft_aacdec",
608 "libcodec2_soft_aacenc",
609 "libcodec2_soft_amrnbdec",
610 "libcodec2_soft_amrnbenc",
611 "libcodec2_soft_amrwbdec",
612 "libcodec2_soft_amrwbenc",
613 "libcodec2_soft_av1dec_gav1",
614 "libcodec2_soft_avcdec",
615 "libcodec2_soft_avcenc",
616 "libcodec2_soft_common",
617 "libcodec2_soft_flacdec",
618 "libcodec2_soft_flacenc",
619 "libcodec2_soft_g711alawdec",
620 "libcodec2_soft_g711mlawdec",
621 "libcodec2_soft_gsmdec",
622 "libcodec2_soft_h263dec",
623 "libcodec2_soft_h263enc",
624 "libcodec2_soft_hevcdec",
625 "libcodec2_soft_hevcenc",
626 "libcodec2_soft_mp3dec",
627 "libcodec2_soft_mpeg2dec",
628 "libcodec2_soft_mpeg4dec",
629 "libcodec2_soft_mpeg4enc",
630 "libcodec2_soft_opusdec",
631 "libcodec2_soft_opusenc",
632 "libcodec2_soft_rawdec",
633 "libcodec2_soft_vorbisdec",
634 "libcodec2_soft_vp8dec",
635 "libcodec2_soft_vp8enc",
636 "libcodec2_soft_vp9dec",
637 "libcodec2_soft_vp9enc",
638 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000639 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000641 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900642 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000643 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 "libfmq",
645 "libgav1",
646 "libgralloctypes",
647 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000648 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900649 "libgsm",
650 "libgui_bufferqueue_static",
651 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libhardware_headers",
654 "libhevcdec",
655 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000656 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900657 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000658 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900659 "libhidltransport-impl-internal",
660 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libjpeg",
663 "libjsoncpp",
664 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000665 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900666 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000667 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900668 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "libminijail_gen_constants",
671 "libminijail_gen_constants_obj",
672 "libminijail_gen_syscall",
673 "libminijail_gen_syscall_obj",
674 "libminijail_generated",
675 "libmpeg2dec",
676 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000677 "libnativebridge_lazy",
678 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900679 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000680 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000682 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900683 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000684 "libscudo_wrapper",
685 "libsfplugin_ccodec_utils",
686 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900687 "libstagefright_amrnbdec",
688 "libstagefright_amrnbenc",
689 "libstagefright_amrwbdec",
690 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000691 "libstagefright_bufferpool@2.0.1",
692 "libstagefright_bufferqueue_helper",
693 "libstagefright_enc_common",
694 "libstagefright_flacdec",
695 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libstagefright_foundation_headers",
697 "libstagefright_headers",
698 "libstagefright_m4vh263dec",
699 "libstagefright_m4vh263enc",
700 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000701 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900702 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000703 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900704 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000705 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900706 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000707 "libvorbisidec",
708 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libyuv",
710 "libyuv_static",
711 "media_ndk_headers",
712 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000713 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900714 }
715 //
716 // Module separator
717 //
718 m["com.android.mediaprovider"] = []string{
719 "MediaProvider",
720 "MediaProviderGoogle",
721 "fmtlib_ndk",
722 "guava",
723 "libbase_ndk",
724 "libfuse",
725 "libfuse_jni",
726 "libnativehelper_header_only",
727 }
728 //
729 // Module separator
730 //
731 m["com.android.permission"] = []string{
732 "androidx.annotation_annotation",
733 "androidx.annotation_annotation-nodeps",
734 "androidx.lifecycle_lifecycle-common",
735 "androidx.lifecycle_lifecycle-common-java8",
736 "androidx.lifecycle_lifecycle-common-java8-nodeps",
737 "androidx.lifecycle_lifecycle-common-nodeps",
738 "kotlin-annotations",
739 "kotlin-stdlib",
740 "kotlin-stdlib-jdk7",
741 "kotlin-stdlib-jdk8",
742 "kotlinx-coroutines-android",
743 "kotlinx-coroutines-android-nodeps",
744 "kotlinx-coroutines-core",
745 "kotlinx-coroutines-core-nodeps",
746 "libprotobuf-java-lite",
747 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000748 }
749 //
750 // Module separator
751 //
752 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900753 "bionic_libc_platform_headers",
754 "fmtlib",
755 "libarm-optimized-routines-math",
756 "libasync_safe",
757 "libasync_safe_headers",
758 "libbacktrace_headers",
759 "libbase",
760 "libbase_headers",
761 "libc++",
762 "libc_aeabi",
763 "libc_bionic",
764 "libc_bionic_ndk",
765 "libc_bootstrap",
766 "libc_common",
767 "libc_common_shared",
768 "libc_common_static",
769 "libc_dns",
770 "libc_dynamic_dispatch",
771 "libc_fortify",
772 "libc_freebsd",
773 "libc_freebsd_large_stack",
774 "libc_gdtoa",
775 "libc_headers",
776 "libc_init_dynamic",
777 "libc_init_static",
778 "libc_jemalloc_wrapper",
779 "libc_netbsd",
780 "libc_nomalloc",
781 "libc_nopthread",
782 "libc_openbsd",
783 "libc_openbsd_large_stack",
784 "libc_openbsd_ndk",
785 "libc_pthread",
786 "libc_static_dispatch",
787 "libc_syscalls",
788 "libc_tzcode",
789 "libc_unwind_static",
790 "libcutils",
791 "libcutils_headers",
792 "libdebuggerd",
793 "libdebuggerd_common_headers",
794 "libdebuggerd_handler_core",
795 "libdebuggerd_handler_fallback",
796 "libdexfile_external_headers",
797 "libdexfile_support",
798 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900799 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900800 "libgtest_prod",
801 "libjemalloc5",
802 "liblinker_main",
803 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900804 "liblog_headers",
805 "liblz4",
806 "liblzma",
807 "libprocessgroup_headers",
808 "libprocinfo",
809 "libpropertyinfoparser",
810 "libscudo",
811 "libstdc++",
812 "libsystem_headers",
813 "libsystemproperties",
814 "libtombstoned_client_static",
815 "libunwindstack",
816 "libutils_headers",
817 "libz",
818 "libziparchive",
819 }
820 //
821 // Module separator
822 //
823 m["com.android.resolv"] = []string{
824 "bcm_object",
825 "dnsresolver_aidl_interface-unstable-ndk_platform",
826 "fmtlib",
827 "libbacktrace_headers",
828 "libbase",
829 "libbase_headers",
830 "libc++",
831 "libcrypto",
832 "libcutils",
833 "libcutils_headers",
834 "libgtest_prod",
835 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900836 "liblog_headers",
837 "libnativehelper_header_only",
838 "libnetd_client_headers",
839 "libnetd_resolv",
840 "libnetdutils",
841 "libprocessgroup",
842 "libprocessgroup_headers",
843 "libprotobuf-cpp-lite",
844 "libssl",
845 "libstatslog_resolv",
846 "libstatspush_compat",
847 "libstatssocket",
848 "libstatssocket_headers",
849 "libsystem_headers",
850 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900851 "libutils_headers",
852 "netd_event_listener_interface-ndk_platform",
853 "server_configurable_flags",
854 "stats_proto",
855 }
856 //
857 // Module separator
858 //
859 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000860 "libbase",
861 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900862 "libnativehelper_compat_libc++",
863 "android.hardware.tetheroffload.config@1.0",
864 "fmtlib",
865 "libbacktrace_headers",
866 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900867 "libcgrouprc",
868 "libcgrouprc_format",
869 "libcutils",
870 "libcutils_headers",
871 "libhidlbase",
872 "libhidlbase-impl-internal",
873 "libhidltransport-impl-internal",
874 "libhwbinder-impl-internal",
875 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900876 "liblog_headers",
877 "libprocessgroup",
878 "libprocessgroup_headers",
879 "libsystem_headers",
880 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900881 "libutils_headers",
882 "libvndksupport",
883 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000884 }
885 //
886 // Module separator
887 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900888 m["com.android.wifi"] = []string{
889 "PlatformProperties",
890 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900891 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900892 "android.hardware.wifi-V1.1-java",
893 "android.hardware.wifi-V1.2-java",
894 "android.hardware.wifi-V1.3-java",
895 "android.hardware.wifi-V1.4-java",
896 "android.hardware.wifi.hostapd-V1.0-java",
897 "android.hardware.wifi.hostapd-V1.1-java",
898 "android.hardware.wifi.hostapd-V1.2-java",
899 "android.hardware.wifi.supplicant-V1.0-java",
900 "android.hardware.wifi.supplicant-V1.1-java",
901 "android.hardware.wifi.supplicant-V1.2-java",
902 "android.hardware.wifi.supplicant-V1.3-java",
903 "android.hidl.base-V1.0-java",
904 "android.hidl.manager-V1.0-java",
905 "android.hidl.manager-V1.1-java",
906 "android.hidl.manager-V1.2-java",
907 "androidx.annotation_annotation",
908 "androidx.annotation_annotation-nodeps",
909 "bouncycastle-unbundled",
910 "dnsresolver_aidl_interface-V2-java",
911 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900912 "framework-wifi-pre-jarjar",
913 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900914 "ipmemorystore-aidl-interfaces-V3-java",
915 "ipmemorystore-aidl-interfaces-java",
916 "ksoap2",
917 "libbacktrace_headers",
918 "libbase",
919 "libbase_headers",
920 "libc++",
921 "libcutils",
922 "libcutils_headers",
923 "liblog_headers",
924 "libnanohttpd",
925 "libprocessgroup",
926 "libprocessgroup_headers",
927 "libprotobuf-java-lite",
928 "libprotobuf-java-nano",
929 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900930 "libutils_headers",
931 "libwifi-jni",
932 "net-utils-services-common",
933 "netd_aidl_interface-V2-java",
934 "netd_aidl_interface-unstable-java",
935 "netd_event_listener_interface-java",
936 "netlink-client",
937 "networkstack-aidl-interfaces-unstable-java",
938 "networkstack-client",
939 "services.net",
940 "wifi-lite-protos",
941 "wifi-nano-protos",
942 "wifi-service-pre-jarjar",
943 "wifi-service-resources",
944 "prebuilt_androidx.annotation_annotation-nodeps",
945 }
946 //
947 // Module separator
948 //
949 m["com.android.sdkext"] = []string{
950 "fmtlib_ndk",
951 "libbase_ndk",
952 "libprotobuf-cpp-lite-ndk",
953 }
954 //
955 // Module separator
956 //
957 m["com.android.os.statsd"] = []string{
958 "libbacktrace_headers",
959 "libbase_headers",
960 "libc++",
961 "libcutils",
962 "libcutils_headers",
963 "liblog_headers",
964 "libprocessgroup_headers",
965 "libstatssocket",
966 "libsystem_headers",
967 "libutils_headers",
968 }
969 //
970 // Module separator
971 //
972 m["//any"] = []string{
973 "crtbegin_dynamic",
974 "crtbegin_dynamic1",
975 "crtbegin_so",
976 "crtbegin_so1",
977 "crtbegin_static",
978 "crtbrand",
979 "crtend_android",
980 "crtend_so",
981 "libatomic",
982 "libc++_static",
983 "libc++abi",
984 "libc++demangle",
985 "libc_headers",
986 "libclang_rt",
987 "libgcc_stripped",
988 "libprofile-clang-extras",
989 "libprofile-clang-extras_ndk",
990 "libprofile-extras",
991 "libprofile-extras_ndk",
992 "libunwind_llvm",
993 "ndk_crtbegin_dynamic.27",
994 "ndk_crtbegin_so.16",
995 "ndk_crtbegin_so.19",
996 "ndk_crtbegin_so.21",
997 "ndk_crtbegin_so.24",
998 "ndk_crtbegin_so.27",
999 "ndk_crtend_android.27",
1000 "ndk_crtend_so.16",
1001 "ndk_crtend_so.19",
1002 "ndk_crtend_so.21",
1003 "ndk_crtend_so.24",
1004 "ndk_crtend_so.27",
1005 "ndk_libandroid_support",
1006 "ndk_libc++_static",
1007 "ndk_libc++abi",
1008 "ndk_libunwind",
1009 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001010 return m
1011}
1012
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001013func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001014 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001015 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001016 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001017 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001018 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001019 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001020
Jooyung Han31c470b2019-10-18 16:26:59 +09001021 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001022 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001023
1024 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1025 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1026 sort.Strings(*apexFileContextsInfos)
1027 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1028 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001029}
1030
Jooyung Han31c470b2019-10-18 16:26:59 +09001031func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1032 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1033 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1034}
1035
Jiyong Parkd1063c12019-07-17 20:08:41 +09001036func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001037 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001038 ctx.BottomUp("apex", apexMutator).Parallel()
1039 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1040 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001041}
1042
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001043// Mark the direct and transitive dependencies of apex bundles so that they
1044// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001045func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001046 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001047 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001048 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han03b51852020-02-26 22:45:42 +09001049 minSdkVersion := a.minSdkVersion(mctx)
Jooyung Han5e9013b2020-03-10 06:23:13 +09001050 apexBundles = []android.ApexInfo{android.ApexInfo{
1051 ApexName: mctx.ModuleName(),
1052 LegacyAndroid10Support: proptools.Bool(a.properties.Legacy_android10_support),
1053 MinSdkVersion: minSdkVersion,
1054 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001055 directDep = true
1056 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001057 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001058 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001059 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001060
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001061 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001062 return
1063 }
1064
Jooyung Han5e9013b2020-03-10 06:23:13 +09001065 cur := mctx.Module().(interface {
1066 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1067 })
1068
Jiyong Parkf760cae2020-02-12 07:53:12 +09001069 mctx.VisitDirectDeps(func(child android.Module) {
1070 depName := mctx.OtherModuleName(child)
1071 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001072 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001073 android.UpdateApexDependency(apexBundles, depName, directDep)
1074 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001075 }
1076 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001077}
1078
1079// Create apex variations if a module is included in APEX(s).
1080func apexMutator(mctx android.BottomUpMutatorContext) {
1081 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001082 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001083 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001084 // apex bundle itself is mutated so that it and its modules have same
1085 // apex variant.
1086 apexBundleName := mctx.ModuleName()
1087 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001088 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1089 apexBundleName := o.GetOverriddenModuleName()
1090 if apexBundleName == "" {
1091 mctx.ModuleErrorf("base property is not set")
1092 return
1093 }
1094 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001095 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001096
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001097}
Sundong Ahne9b55722019-09-06 17:37:42 +09001098
Jooyung Han7a78a922019-10-08 21:59:58 +09001099var (
1100 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1101 apexFileContextsInfosMutex sync.Mutex
1102)
1103
1104func apexFileContextsInfos(config android.Config) *[]string {
1105 return config.Once(apexFileContextsInfosKey, func() interface{} {
1106 return &[]string{}
1107 }).(*[]string)
1108}
1109
Jooyung Han54aca7b2019-11-20 02:26:02 +09001110func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001111 apexFileContextsInfosMutex.Lock()
1112 defer apexFileContextsInfosMutex.Unlock()
1113 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001114 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001115}
1116
Sundong Ahne9b55722019-09-06 17:37:42 +09001117func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001118 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001119 var variants []string
1120 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1121 case "image":
1122 variants = append(variants, imageApexType, flattenedApexType)
1123 case "zip":
1124 variants = append(variants, zipApexType)
1125 case "both":
1126 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1127 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001128 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001129 return
1130 }
1131
1132 modules := mctx.CreateLocalVariations(variants...)
1133
1134 for i, v := range variants {
1135 switch v {
1136 case imageApexType:
1137 modules[i].(*apexBundle).properties.ApexType = imageApex
1138 case zipApexType:
1139 modules[i].(*apexBundle).properties.ApexType = zipApex
1140 case flattenedApexType:
1141 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001142 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001143 modules[i].(*apexBundle).MakeAsSystemExt()
1144 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001145 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001146 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001147 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1148 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001149 }
1150}
1151
Jooyung Han5c998b92019-06-27 11:30:33 +09001152func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1153 if ab, ok := mctx.Module().(*apexBundle); ok {
1154 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1155 }
1156}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001157
Jooyung Handc782442019-11-01 03:14:38 +09001158var (
1159 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1160)
1161
1162// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1163// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1164// which may cause compatibility issues. (e.g. libbinder)
1165// Even though libbinder restricts its availability via 'apex_available' property and relies on
1166// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1167// to avoid similar problems.
1168func useVendorWhitelist(config android.Config) []string {
1169 return config.Once(useVendorWhitelistKey, func() interface{} {
1170 return []string{
1171 // swcodec uses "vendor" variants for smaller size
1172 "com.android.media.swcodec",
1173 "test_com.android.media.swcodec",
1174 }
1175 }).([]string)
1176}
1177
1178// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1179// called before the first call to useVendorWhitelist()
1180func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1181 config.Once(useVendorWhitelistKey, func() interface{} {
1182 return whitelist
1183 })
1184}
1185
Jooyung Han01a868d2020-02-27 13:40:44 +09001186type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001187 // List of native libraries
1188 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001189
Jooyung Han643adc42020-02-27 13:50:06 +09001190 // List of JNI libraries
1191 Jni_libs []string
1192
Alex Light9670d332019-01-29 18:07:33 -08001193 // List of native executables
1194 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001195
Roland Levillain630846d2019-06-26 12:48:34 +01001196 // List of native tests
1197 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001198}
Jooyung Han344d5432019-08-23 11:17:39 +09001199
Alex Light9670d332019-01-29 18:07:33 -08001200type apexMultilibProperties struct {
1201 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001202 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001203
1204 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001205 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001206
1207 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001208 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001209
1210 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001211 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001212
1213 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001214 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001215}
1216
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001217type apexBundleProperties struct {
1218 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001219 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001220 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001221
Jiyong Park40e26a22019-02-08 02:53:06 +09001222 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1223 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001224 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001225
Roland Levillain411c5842019-09-19 16:37:20 +01001226 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1227 // device (/apex/<apex_name>).
1228 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001229 Apex_name *string
1230
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001231 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001232 // For platform APEXes, this should points to a file under /system/sepolicy
1233 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1234 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001235
Jooyung Han01a868d2020-02-27 13:40:44 +09001236 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001237
1238 // List of java libraries that are embedded inside this APEX bundle
1239 Java_libs []string
1240
1241 // List of prebuilt files that are embedded inside this APEX bundle
1242 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001243
1244 // Name of the apex_key module that provides the private key to sign APEX
1245 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001246
Alex Light5098a612018-11-29 17:12:15 -08001247 // The type of APEX to build. Controls what the APEX payload is. Either
1248 // 'image', 'zip' or 'both'. Default: 'image'.
1249 Payload_type *string
1250
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001251 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1252 // or an android_app_certificate module name in the form ":module".
1253 Certificate *string
1254
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001255 // Whether this APEX is installable to one of the partitions. Default: true.
1256 Installable *bool
1257
Jiyong Parkda6eb592018-12-19 17:12:36 +09001258 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1259 // Default is false.
1260 Use_vendor *bool
1261
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001262 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1263 Ignore_system_library_special_case *bool
1264
Alex Light9670d332019-01-29 18:07:33 -08001265 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001266
Jiyong Parkf97782b2019-02-13 20:28:58 +09001267 // List of sanitizer names that this APEX is enabled for
1268 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001269
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001270 PreventInstall bool `blueprint:"mutated"`
1271
1272 HideFromMake bool `blueprint:"mutated"`
1273
Jooyung Han5c998b92019-06-27 11:30:33 +09001274 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1275 Provide_cpp_shared_libs *bool
1276
1277 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1278 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001279
1280 // A txt file containing list of files that are whitelisted to be included in this APEX.
1281 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001282
Sundong Ahnabb64432019-10-22 13:58:29 +09001283 // package format of this apex variant; could be non-flattened, flattened, or zip.
1284 // imageApex, zipApex or flattened
1285 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001286
Jiyong Parkd1063c12019-07-17 20:08:41 +09001287 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1288 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1289 // is implied. This value affects all modules included in this APEX. In other words, they are
1290 // also built with the SDKs specified here.
1291 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001292
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001293 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1294 // Should be only used in tests#.
1295 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001296
1297 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1298 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1299 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001300
1301 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001302
1303 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1304 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1305 // like symlinking to the system libs. Default is false.
1306 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001307
1308 // The minimum SDK version that this apex must be compatibile with.
1309 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001310}
1311
1312type apexTargetBundleProperties struct {
1313 Target struct {
1314 // Multilib properties only for android.
1315 Android struct {
1316 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001317 }
Jooyung Han344d5432019-08-23 11:17:39 +09001318
Alex Light9670d332019-01-29 18:07:33 -08001319 // Multilib properties only for host.
1320 Host struct {
1321 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001322 }
Jooyung Han344d5432019-08-23 11:17:39 +09001323
Alex Light9670d332019-01-29 18:07:33 -08001324 // Multilib properties only for host linux_bionic.
1325 Linux_bionic struct {
1326 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001327 }
Jooyung Han344d5432019-08-23 11:17:39 +09001328
Alex Light9670d332019-01-29 18:07:33 -08001329 // Multilib properties only for host linux_glibc.
1330 Linux_glibc struct {
1331 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001332 }
1333 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001334}
1335
Jiyong Park5d790c32019-11-15 18:40:32 +09001336type overridableProperties struct {
1337 // List of APKs to package inside APEX
1338 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001339
1340 // Names of modules to be overridden. Listed modules can only be other binaries
1341 // (in Make or Soong).
1342 // This does not completely prevent installation of the overridden binaries, but if both
1343 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1344 // from PRODUCT_PACKAGES.
1345 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001346
1347 // Logging Parent value
1348 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001349}
1350
Alex Light5098a612018-11-29 17:12:15 -08001351type apexPackaging int
1352
1353const (
1354 imageApex apexPackaging = iota
1355 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001356 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001357)
1358
Sundong Ahnabb64432019-10-22 13:58:29 +09001359// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001360func (a apexPackaging) suffix() string {
1361 switch a {
1362 case imageApex:
1363 return imageApexSuffix
1364 case zipApex:
1365 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001366 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001367 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001368 }
1369}
1370
1371func (a apexPackaging) name() string {
1372 switch a {
1373 case imageApex:
1374 return imageApexType
1375 case zipApex:
1376 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001377 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001378 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001379 }
1380}
1381
Jiyong Parkf653b052019-11-18 15:39:01 +09001382type apexFileClass int
1383
1384const (
1385 etc apexFileClass = iota
1386 nativeSharedLib
1387 nativeExecutable
1388 shBinary
1389 pyBinary
1390 goBinary
1391 javaSharedLib
1392 nativeTest
1393 app
1394)
1395
Jiyong Park8fd61922018-11-08 02:50:25 +09001396func (class apexFileClass) NameInMake() string {
1397 switch class {
1398 case etc:
1399 return "ETC"
1400 case nativeSharedLib:
1401 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001402 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001403 return "EXECUTABLES"
1404 case javaSharedLib:
1405 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001406 case nativeTest:
1407 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001408 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001409 // b/142537672 Why isn't this APP? We want to have full control over
1410 // the paths and file names of the apk file under the flattend APEX.
1411 // If this is set to APP, then the paths and file names are modified
1412 // by the Make build system. For example, it is installed to
1413 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1414 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1415 // appends module name (which is <apexname>.<Appname> to the path.
1416 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001417 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001418 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001419 }
1420}
1421
Jiyong Parkf653b052019-11-18 15:39:01 +09001422// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001423type apexFile struct {
1424 builtFile android.Path
1425 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001426 installDir string
1427 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001428 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001429 // list of symlinks that will be created in installDir that point to this apexFile
1430 symlinks []string
1431 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001432 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001433
1434 requiredModuleNames []string
1435 targetRequiredModuleNames []string
1436 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001437
Colin Cross503c1d02020-01-28 14:00:53 -08001438 jacocoReportClassesFile android.Path // only for javalibs and apps
1439 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001440 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001441
1442 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001443}
1444
Jiyong Park1833cef2019-12-13 13:28:36 +09001445func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1446 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001447 builtFile: builtFile,
1448 moduleName: moduleName,
1449 installDir: installDir,
1450 class: class,
1451 module: module,
1452 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001453 if module != nil {
1454 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001455 ret.requiredModuleNames = module.RequiredModuleNames()
1456 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1457 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001458 }
1459 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001460}
1461
1462func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001463 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001464}
1465
Jiyong Park7cd10e32020-01-14 09:22:18 +09001466// Path() returns path of this apex file relative to the APEX root
1467func (af *apexFile) Path() string {
1468 return filepath.Join(af.installDir, af.builtFile.Base())
1469}
1470
1471// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1472func (af *apexFile) SymlinkPaths() []string {
1473 var ret []string
1474 for _, symlink := range af.symlinks {
1475 ret = append(ret, filepath.Join(af.installDir, symlink))
1476 }
1477 return ret
1478}
1479
1480func (af *apexFile) AvailableToPlatform() bool {
1481 if af.module == nil {
1482 return false
1483 }
1484 if am, ok := af.module.(android.ApexModule); ok {
1485 return am.AvailableFor(android.AvailableToPlatform)
1486 }
1487 return false
1488}
1489
Jiyong Park678c8812020-02-07 17:25:49 +09001490type depInfo struct {
1491 to string
1492 from []string
1493 isExternal bool
1494}
1495
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001496type apexBundle struct {
1497 android.ModuleBase
1498 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001499 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001500 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001501
Jiyong Park5d790c32019-11-15 18:40:32 +09001502 properties apexBundleProperties
1503 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001504 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001505
Jooyung Hanf21c7972019-12-16 22:32:06 +09001506 // specific to apex_vndk modules
1507 vndkProperties apexVndkProperties
1508
Colin Crossa4925902018-11-16 11:36:28 -08001509 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001510 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001511 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001512
Jiyong Park03b68dd2019-07-26 23:20:40 +09001513 prebuiltFileToDelete string
1514
Jiyong Park42cca6c2019-04-01 11:15:50 +09001515 public_key_file android.Path
1516 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001517
1518 container_certificate_file android.Path
1519 container_private_key_file android.Path
1520
Jooyung Han54aca7b2019-11-20 02:26:02 +09001521 fileContexts android.Path
1522
Jiyong Park8fd61922018-11-08 02:50:25 +09001523 // list of files to be included in this apex
1524 filesInfo []apexFile
1525
Jiyong Park956305c2020-01-09 12:32:06 +09001526 // list of module names that should be installed along with this APEX
1527 requiredDeps []string
1528
Jiyong Park956305c2020-01-09 12:32:06 +09001529 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001530 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001531
Sundong Ahnabb64432019-10-22 13:58:29 +09001532 testApex bool
1533 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001534 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001535 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001536
Jooyung Han214bf372019-11-12 13:03:50 +09001537 manifestJsonOut android.WritablePath
1538 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001539
Jooyung Han002ab682020-01-08 01:57:58 +09001540 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001541 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001542 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001543 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1544 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001545
1546 // Suffix of module name in Android.mk
1547 // ".flattened", ".apex", ".zipapex", or ""
1548 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001549
1550 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001551
1552 // Whether to create symlink to the system file instead of having a file
1553 // inside the apex or not
1554 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001555
1556 // Struct holding the merged notice file paths in different formats
1557 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001558}
1559
Jiyong Park397e55e2018-10-24 21:09:55 +09001560func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001561 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001562 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001563 // Use *FarVariation* to be able to depend on modules having
1564 // conflicting variations with this module. This is required since
1565 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1566 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001567 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001568 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001569 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001570 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001571 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001572
Jooyung Han643adc42020-02-27 13:50:06 +09001573 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1574 {Mutator: "image", Variation: imageVariation},
1575 {Mutator: "link", Variation: "shared"},
1576 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1577 }...), jniLibTag, nativeModules.Jni_libs...)
1578
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001579 ctx.AddFarVariationDependencies(append(target.Variations(),
1580 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001581 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001582
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001583 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001584 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001585 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001586 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001587}
1588
Alex Light9670d332019-01-29 18:07:33 -08001589func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1590 if ctx.Os().Class == android.Device {
1591 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1592 } else {
1593 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1594 if ctx.Os().Bionic() {
1595 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1596 } else {
1597 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1598 }
1599 }
1600}
1601
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001602func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001603 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1604 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1605 }
1606
Jiyong Park397e55e2018-10-24 21:09:55 +09001607 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001608 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001609
1610 a.combineProperties(ctx)
1611
Jiyong Park397e55e2018-10-24 21:09:55 +09001612 has32BitTarget := false
1613 for _, target := range targets {
1614 if target.Arch.ArchType.Multilib == "lib32" {
1615 has32BitTarget = true
1616 }
1617 }
1618 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001619 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001620 // multilib.both
1621 addDependenciesForNativeModules(ctx,
1622 ApexNativeDependencies{
1623 Native_shared_libs: a.properties.Native_shared_libs,
1624 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001625 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001626 Binaries: nil,
1627 },
1628 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001629
Jiyong Park397e55e2018-10-24 21:09:55 +09001630 // Add native modules targetting both ABIs
1631 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001632 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001633 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001634 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001635
Alex Light3d673592019-01-18 14:37:31 -08001636 isPrimaryAbi := i == 0
1637 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001638 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001639 // multilib.first
1640 addDependenciesForNativeModules(ctx,
1641 ApexNativeDependencies{
1642 Native_shared_libs: nil,
1643 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001644 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001645 Binaries: a.properties.Binaries,
1646 },
1647 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001648
1649 // Add native modules targetting the first ABI
1650 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001651 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001652 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001653 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001654 }
1655
1656 switch target.Arch.ArchType.Multilib {
1657 case "lib32":
1658 // Add native modules targetting 32-bit ABI
1659 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001660 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001661 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001663
1664 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001665 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001666 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001667 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001668 case "lib64":
1669 // Add native modules targetting 64-bit ABI
1670 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001671 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001672 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001673 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001674
1675 if !has32BitTarget {
1676 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001677 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001678 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001679 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001680 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001681
1682 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1683 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1684 if sanitizer == "hwaddress" {
1685 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001686 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001687 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001688 break
1689 }
1690 }
1691 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001692 }
1693
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001694 }
1695
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001696 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1697 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1698 // b/144532908
1699 archForPrebuiltEtc := config.Arches()[0]
1700 for _, arch := range config.Arches() {
1701 // Prefer 64-bit arch if there is any
1702 if arch.ArchType.Multilib == "lib64" {
1703 archForPrebuiltEtc = arch
1704 break
1705 }
1706 }
1707 ctx.AddFarVariationDependencies([]blueprint.Variation{
1708 {Mutator: "os", Variation: ctx.Os().String()},
1709 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1710 }, prebuiltTag, a.properties.Prebuilts...)
1711
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001712 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1713 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001714
Ulya Trafimovich44561882020-01-03 13:25:54 +00001715 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1716 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1717 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1718 javaLibTag, "jacocoagent")
1719 }
1720
Jiyong Park23c52b02019-02-02 13:13:47 +09001721 if String(a.properties.Key) == "" {
1722 ctx.ModuleErrorf("key is missing")
1723 return
1724 }
1725 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001726
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001727 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001728 if cert != "" {
1729 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001730 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001731
1732 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1733 if len(a.properties.Uses_sdks) > 0 {
1734 sdkRefs := []android.SdkRef{}
1735 for _, str := range a.properties.Uses_sdks {
1736 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1737 sdkRefs = append(sdkRefs, parsed)
1738 }
1739 a.BuildWithSdks(sdkRefs)
1740 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001741}
1742
Jiyong Park5d790c32019-11-15 18:40:32 +09001743func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1744 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1745 androidAppTag, a.overridableProperties.Apps...)
1746}
1747
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001748func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1749 // direct deps of an APEX bundle are all part of the APEX bundle
1750 return true
1751}
1752
Colin Cross0ea8ba82019-06-06 14:33:29 -07001753func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001754 moduleName := ctx.ModuleName()
1755 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1756 // we check with the pseudo module name to see if its certificate is overridden.
1757 if a.vndkApex {
1758 moduleName = vndkApexName
1759 }
1760 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001761 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001762 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001763 }
1764 return String(a.properties.Certificate)
1765}
1766
Colin Cross41955e82019-05-29 14:40:35 -07001767func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1768 switch tag {
1769 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001770 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001771 default:
1772 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001773 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001774}
1775
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001776func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001777 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001778}
1779
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001780func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1781 return proptools.Bool(a.properties.Test_only_no_hashtree)
1782}
1783
Jiyong Park7c1dc612019-01-05 11:15:24 +09001784func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001785 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001786 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001787 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001788 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001789 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001790 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001791 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001792 }
1793}
1794
Jiyong Parkf97782b2019-02-13 20:28:58 +09001795func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1796 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1797 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1798 }
1799}
1800
Jiyong Park388ef3f2019-01-28 19:47:32 +09001801func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001802 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1803 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001804 }
1805
1806 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001807 globalSanitizerNames := []string{}
1808 if a.Host() {
1809 globalSanitizerNames = ctx.Config().SanitizeHost()
1810 } else {
1811 arches := ctx.Config().SanitizeDeviceArch()
1812 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1813 globalSanitizerNames = ctx.Config().SanitizeDevice()
1814 }
1815 }
1816 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001817}
1818
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001819func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001820 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001821}
1822
1823func (a *apexBundle) PreventInstall() {
1824 a.properties.PreventInstall = true
1825}
1826
1827func (a *apexBundle) HideFromMake() {
1828 a.properties.HideFromMake = true
1829}
1830
Jiyong Park956305c2020-01-09 12:32:06 +09001831func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1832 a.properties.IsCoverageVariant = coverage
1833}
1834
Jiyong Parkf653b052019-11-18 15:39:01 +09001835// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001836func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001837 // Decide the APEX-local directory by the multilib of the library
1838 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001839 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001840 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001841 case "lib32":
1842 dirInApex = "lib"
1843 case "lib64":
1844 dirInApex = "lib64"
1845 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001846 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001847 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001848 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001850 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001851 // Special case for Bionic libs and other libs installed with them. This is
1852 // to prevent those libs from being included in the search path
1853 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1854 // those libs in the Runtime APEX are available via the legacy paths in
1855 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1856 // to the legacy paths and thus will be loaded into the default linker
1857 // namespace (aka "platform" namespace). If the libs are directly in
1858 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1859 // into the runtime linker namespace, which will result in double loading of
1860 // them, which isn't supported.
1861 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001862 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001863
Jiyong Parkf653b052019-11-18 15:39:01 +09001864 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001865 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001866}
1867
Jiyong Park1833cef2019-12-13 13:28:36 +09001868func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001869 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001870 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001871 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001872 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001874 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001875 af.symlinks = cc.Symlinks()
1876 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001877}
1878
Jiyong Park1833cef2019-12-13 13:28:36 +09001879func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001880 dirInApex := "bin"
1881 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001882 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001883}
Jiyong Park1833cef2019-12-13 13:28:36 +09001884func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001886 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1887 if err != nil {
1888 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001889 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001890 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001891 fileToCopy := android.PathForOutput(ctx, s)
1892 // NB: Since go binaries are static we don't need the module for anything here, which is
1893 // good since the go tool is a blueprint.Module not an android.Module like we would
1894 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001895 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001896}
1897
Jiyong Park1833cef2019-12-13 13:28:36 +09001898func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001899 dirInApex := filepath.Join("bin", sh.SubDir())
1900 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001901 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001902 af.symlinks = sh.Symlinks()
1903 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001904}
1905
Jooyung Han58f26ab2019-12-18 15:34:32 +09001906// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1907type javaLibrary interface {
1908 android.Module
1909 java.Dependency
1910}
1911
1912func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001913 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001914 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001915 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1916 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1917 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001918}
1919
Jiyong Park1833cef2019-12-13 13:28:36 +09001920func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001921 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1922 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001923 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001924}
1925
atrost6e126252020-01-27 17:01:16 +00001926func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1927 dirInApex := filepath.Join("etc", config.SubDir())
1928 fileToCopy := config.CompatConfig()
1929 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1930}
1931
Jiyong Park1833cef2019-12-13 13:28:36 +09001932func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001933 android.Module
1934 Privileged() bool
1935 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001936 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001937 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001938}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001939 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001940 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001941 appDir = "priv-app"
1942 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001943 dirInApex := filepath.Join(appDir, pkgName)
1944 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001945 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1946 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001947 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001948
1949 if app, ok := aapp.(interface {
1950 OverriddenManifestPackageName() string
1951 }); ok {
1952 af.overriddenPackageName = app.OverriddenManifestPackageName()
1953 }
Jiyong Park618922e2020-01-08 13:35:43 +09001954 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001955}
1956
Roland Levillain935639d2019-08-13 14:55:28 +01001957// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1958type flattenedApexContext struct {
1959 android.ModuleContext
1960}
1961
1962func (c *flattenedApexContext) InstallBypassMake() bool {
1963 return true
1964}
1965
Jiyong Park201cedd2020-02-07 17:25:49 +09001966// Visit dependencies that contributes to the payload of this APEX
1967func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1968 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001969 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1970 am, ok := child.(android.ApexModule)
1971 if !ok || !am.CanHaveApexVariants() {
1972 return false
1973 }
1974
1975 // Check for the direct dependencies that contribute to the payload
1976 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1977 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001978 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001979 return true
1980 }
1981 return false
1982 }
1983
1984 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001985 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001986 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001987 return true
1988 }
1989
Jiyong Park201cedd2020-02-07 17:25:49 +09001990 do(ctx, parent, am, true /* externalDep */)
1991
Jiyong Park0f80c182020-01-31 02:49:53 +09001992 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1993 return false
1994 })
1995}
1996
Jooyung Han03b51852020-02-26 22:45:42 +09001997func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1998 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1999 if ver != "current" {
2000 minSdkVersion, err := strconv.Atoi(ver)
2001 if err != nil {
2002 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
2003 }
2004 return minSdkVersion
2005 }
2006 return android.FutureApiLevel
2007}
2008
Jiyong Park201cedd2020-02-07 17:25:49 +09002009// Ensures that the dependencies are marked as available for this APEX
2010func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2011 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2012 if ctx.Host() || a.testApex || a.vndkApex {
2013 return
2014 }
2015
2016 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2017 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002018 fromName := ctx.OtherModuleName(from)
2019 toName := ctx.OtherModuleName(to)
2020 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002021 return
2022 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09002023 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09002024 })
2025}
2026
Jiyong Park678c8812020-02-07 17:25:49 +09002027// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2028func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2029 a.depInfos = make(map[string]depInfo)
2030 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2031 if from.Name() == to.Name() {
2032 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2033 return
2034 }
2035
2036 if info, exists := a.depInfos[to.Name()]; exists {
2037 if !android.InList(from.Name(), info.from) {
2038 info.from = append(info.from, from.Name())
2039 }
2040 info.isExternal = info.isExternal && externalDep
2041 a.depInfos[to.Name()] = info
2042 } else {
2043 a.depInfos[to.Name()] = depInfo{
2044 to: to.Name(),
2045 from: []string{from.Name()},
2046 isExternal: externalDep,
2047 }
2048 }
2049 })
2050}
2051
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002052func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002053 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2054 switch a.properties.ApexType {
2055 case imageApex:
2056 if buildFlattenedAsDefault {
2057 a.suffix = imageApexSuffix
2058 } else {
2059 a.suffix = ""
2060 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002061
2062 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002063 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002064 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002065 }
2066 case zipApex:
2067 if proptools.String(a.properties.Payload_type) == "zip" {
2068 a.suffix = ""
2069 a.primaryApexType = true
2070 } else {
2071 a.suffix = zipApexSuffix
2072 }
2073 case flattenedApex:
2074 if buildFlattenedAsDefault {
2075 a.suffix = ""
2076 a.primaryApexType = true
2077 } else {
2078 a.suffix = flattenedSuffix
2079 }
Alex Light5098a612018-11-29 17:12:15 -08002080 }
2081
Roland Levillain630846d2019-06-26 12:48:34 +01002082 if len(a.properties.Tests) > 0 && !a.testApex {
2083 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2084 return
2085 }
2086
Jiyong Park0f80c182020-01-31 02:49:53 +09002087 a.checkApexAvailability(ctx)
2088
Jiyong Park678c8812020-02-07 17:25:49 +09002089 a.collectDepsInfo(ctx)
2090
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002091 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2092
Jooyung Hane1633032019-08-01 17:41:43 +09002093 // native lib dependencies
2094 var provideNativeLibs []string
2095 var requireNativeLibs []string
2096
Jooyung Han5c998b92019-06-27 11:30:33 +09002097 // Check if "uses" requirements are met with dependent apexBundles
2098 var providedNativeSharedLibs []string
2099 useVendor := proptools.Bool(a.properties.Use_vendor)
2100 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2101 if ctx.OtherModuleDependencyTag(m) != usesTag {
2102 return
2103 }
2104 otherName := ctx.OtherModuleName(m)
2105 other, ok := m.(*apexBundle)
2106 if !ok {
2107 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2108 return
2109 }
2110 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2111 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2112 return
2113 }
2114 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2115 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2116 return
2117 }
2118 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2119 })
2120
Jiyong Parkf653b052019-11-18 15:39:01 +09002121 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002122 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002123 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002124 depTag := ctx.OtherModuleDependencyTag(child)
2125 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002126 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002127 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002128 case sharedLibTag, jniLibTag:
2129 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002130 if c, ok := child.(*cc.Module); ok {
2131 // bootstrap bionic libs are treated as provided by system
2132 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2133 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002134 }
Jooyung Han643adc42020-02-27 13:50:06 +09002135 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2136 fi.isJniLib = isJniLib
2137 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002138 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002139 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002140 propertyName := "native_shared_libs"
2141 if isJniLib {
2142 propertyName = "jni_libs"
2143 }
2144 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002145 }
2146 case executableTag:
2147 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002148 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002149 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002150 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002151 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002152 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002153 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002154 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002155 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002156 } else {
Alex Light778127a2019-02-27 14:19:50 -08002157 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 +09002158 }
2159 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002160 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002161 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002162 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002163 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2164 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002165 filesInfo = append(filesInfo, af)
2166 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002167 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002168 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2169 af := apexFileForJavaLibrary(ctx, sdkLib)
2170 if !af.Ok() {
2171 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2172 return false
2173 }
2174 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002175 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002176 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002177 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002178 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002179 case androidAppTag:
2180 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2181 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002182 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002183 return true // track transitive dependencies
2184 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002185 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002186 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2187 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002188 } else {
2189 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2190 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002191 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002192 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002193 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002194 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2195 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002196 } else {
atrost6e126252020-01-27 17:01:16 +00002197 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002198 }
Roland Levillain630846d2019-06-26 12:48:34 +01002199 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002200 if ccTest, ok := child.(*cc.Module); ok {
2201 if ccTest.IsTestPerSrcAllTestsVariation() {
2202 // Multiple-output test module (where `test_per_src: true`).
2203 //
2204 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2205 // We do not add this variation to `filesInfo`, as it has no output;
2206 // however, we do add the other variations of this module as indirect
2207 // dependencies (see below).
2208 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002209 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002210 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002211 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002212 af.class = nativeTest
2213 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002214 }
Roland Levillain630846d2019-06-26 12:48:34 +01002215 } else {
2216 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2217 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002218 case keyTag:
2219 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002220 a.private_key_file = key.private_key_file
2221 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002222 } else {
2223 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002224 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002225 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002226 case certificateTag:
2227 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002228 a.container_certificate_file = dep.Certificate.Pem
2229 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002230 } else {
2231 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2232 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002233 case android.PrebuiltDepTag:
2234 // If the prebuilt is force disabled, remember to delete the prebuilt file
2235 // that might have been installed in the previous builds
2236 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2237 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2238 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002239 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002240 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002241 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002242 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002243 // We cannot use a switch statement on `depTag` here as the checked
2244 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002245 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002246 if cc, ok := child.(*cc.Module); ok {
2247 if android.InList(cc.Name(), providedNativeSharedLibs) {
2248 // If we're using a shared library which is provided from other APEX,
2249 // don't include it in this APEX
2250 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002251 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002252 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002253 // If the dependency is a stubs lib, don't include it in this APEX,
2254 // but make sure that the lib is installed on the device.
2255 // In case no APEX is having the lib, the lib is installed to the system
2256 // partition.
2257 //
2258 // Always include if we are a host-apex however since those won't have any
2259 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002260 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2261 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002262 }
Jooyung Hane1633032019-08-01 17:41:43 +09002263 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002264 // Don't track further
2265 return false
2266 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002267 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002268 af.transitiveDep = true
2269 filesInfo = append(filesInfo, af)
2270 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002271 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002272 } else if cc.IsTestPerSrcDepTag(depTag) {
2273 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002274 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002275 // Handle modules created as `test_per_src` variations of a single test module:
2276 // use the name of the generated test binary (`fileToCopy`) instead of the name
2277 // of the original test module (`depName`, shared by all `test_per_src`
2278 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002279 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002280 // these are not considered transitive dep
2281 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002282 filesInfo = append(filesInfo, af)
2283 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002284 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002285 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002286 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2287 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002288 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2289 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2290 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2291 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002292 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002293 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002294 }
2295 }
2296 }
2297 return false
2298 })
2299
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002300 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2301 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2302 // via the global boot image config.
2303 if a.artApex {
2304 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2305 dirInApex := filepath.Join("javalib", arch.String())
2306 for _, f := range files {
2307 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002308 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002309 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002310 }
2311 }
2312 }
2313
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002314 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002315 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2316 return
2317 }
2318
Jiyong Park8fd61922018-11-08 02:50:25 +09002319 // remove duplicates in filesInfo
2320 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002321 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002322 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002323 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002324 if e, ok := encountered[dest]; !ok {
2325 encountered[dest] = f
2326 } else {
2327 // If a module is directly included and also transitively depended on
2328 // consider it as directly included.
2329 e.transitiveDep = e.transitiveDep && f.transitiveDep
2330 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002331 }
2332 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002333 var result []apexFile
2334 for _, v := range encountered {
2335 result = append(result, v)
2336 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002337 return result
2338 }
2339 filesInfo = removeDup(filesInfo)
2340
2341 // to have consistent build rules
2342 sort.Slice(filesInfo, func(i, j int) bool {
2343 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2344 })
2345
Jiyong Park8fd61922018-11-08 02:50:25 +09002346 a.installDir = android.PathForModuleInstall(ctx, "apex")
2347 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002348
Jooyung Han54aca7b2019-11-20 02:26:02 +09002349 if a.properties.ApexType != zipApex {
2350 if a.properties.File_contexts == nil {
2351 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2352 } else {
2353 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2354 if a.Platform() {
2355 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2356 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2357 }
2358 }
2359 }
2360 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2361 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2362 return
2363 }
2364 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002365 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2366 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2367 // the same library in the system partition, thus effectively sharing the same libraries
2368 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2369 // in the APEX.
2370 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2371 a.installable() &&
2372 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002373
Jiyong Park9d677202020-02-19 16:29:35 +09002374 // We don't need the optimization for updatable APEXes, as it might give false signal
2375 // to the system health when the APEXes are still bundled (b/149805758)
2376 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2377 a.linkToSystemLib = false
2378 }
2379
Jiyong Park638d30e2020-02-26 18:27:19 +09002380 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2381 if ctx.Host() {
2382 a.linkToSystemLib = false
2383 }
2384
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002385 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002386 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2387
2388 a.setCertificateAndPrivateKey(ctx)
2389 if a.properties.ApexType == flattenedApex {
2390 a.buildFlattenedApex(ctx)
2391 } else {
2392 a.buildUnflattenedApex(ctx)
2393 }
2394
Jooyung Han002ab682020-01-08 01:57:58 +09002395 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002396
2397 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002398}
2399
Jooyung Han5e9013b2020-03-10 06:23:13 +09002400func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002401 key := apex
2402 key = strings.Replace(key, "test_", "", 1)
2403 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2404 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2405
Jiyong Park0f80c182020-01-31 02:49:53 +09002406 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2407 // system. Trim the prefix for the check since they are confusing
2408 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2409 if strings.HasPrefix(moduleName, "libclang_rt.") {
2410 // This module has many arch variants that depend on the product being built.
2411 // We don't want to list them all
2412 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002413 }
2414
2415 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2416 return true
2417 }
2418
Jiyong Park0f80c182020-01-31 02:49:53 +09002419 key = "//any"
2420 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2421 return true
2422 }
2423
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002424 return false
2425}
2426
Jooyung Han344d5432019-08-23 11:17:39 +09002427func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002428 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002429 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002430 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002431 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002432 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002433 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2434 })
Alex Light5098a612018-11-29 17:12:15 -08002435 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002436 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002437 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002438 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002439 return module
2440}
Jiyong Park30ca9372019-02-07 16:27:23 +09002441
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002442func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002443 bundle := newApexBundle()
2444 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002445 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002446 return bundle
2447}
2448
Jiyong Parkfce0b422020-02-11 03:56:06 +09002449// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2450// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002451func testApexBundleFactory() android.Module {
2452 bundle := newApexBundle()
2453 bundle.testApex = true
2454 return bundle
2455}
2456
Jiyong Parkfce0b422020-02-11 03:56:06 +09002457// apex packages other modules into an APEX file which is a packaging format for system-level
2458// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002459func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002460 return newApexBundle()
2461}
2462
Jiyong Park30ca9372019-02-07 16:27:23 +09002463//
2464// Defaults
2465//
2466type Defaults struct {
2467 android.ModuleBase
2468 android.DefaultsModuleBase
2469}
2470
Jiyong Park30ca9372019-02-07 16:27:23 +09002471func defaultsFactory() android.Module {
2472 return DefaultsFactory()
2473}
2474
2475func DefaultsFactory(props ...interface{}) android.Module {
2476 module := &Defaults{}
2477
2478 module.AddProperties(props...)
2479 module.AddProperties(
2480 &apexBundleProperties{},
2481 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002482 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002483 )
2484
2485 android.InitDefaultsModule(module)
2486 return module
2487}
Jiyong Park5d790c32019-11-15 18:40:32 +09002488
2489//
2490// OverrideApex
2491//
2492type OverrideApex struct {
2493 android.ModuleBase
2494 android.OverrideModuleBase
2495}
2496
2497func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2498 // All the overrides happen in the base module.
2499}
2500
2501// override_apex is used to create an apex module based on another apex module
2502// by overriding some of its properties.
2503func overrideApexFactory() android.Module {
2504 m := &OverrideApex{}
2505 m.AddProperties(&overridableProperties{})
2506
2507 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2508 android.InitOverrideModule(m)
2509 return m
2510}