blob: ed7cb3f2dd2357b2b8ef7de18b5540738cb70aac [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Parkfa899442020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
55 executableTag = dependencyTag{name: "executable", payload: true}
56 javaLibTag = dependencyTag{name: "javaLib", payload: true}
57 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
58 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090059 keyTag = dependencyTag{name: "key"}
60 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090061 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090062 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000063 apexAvailWl = makeApexAvailableWhitelist()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090064)
65
Anton Hansson5053c292020-01-10 15:12:39 +000066// This is a map from apex to modules, which overrides the
67// apex_available setting for that particular module to make
68// it available for the apex regardless of its setting.
69// TODO(b/147364041): remove this
70func makeApexAvailableWhitelist() map[string][]string {
71 // The "Module separator"s below are employed to minimize merge conflicts.
72 m := make(map[string][]string)
73 //
74 // Module separator
75 //
Jiyong Parkfa899442020-01-31 02:49:53 +090076 m["com.android.adbd"] = []string{
77 "adbd",
78 "bcm_object",
79 "fmtlib",
80 "libadbconnection_server",
81 "libadbd",
82 "libadbd_auth",
83 "libadbd_core",
84 "libadbd_services",
85 "libasyncio",
86 "libbacktrace_headers",
87 "libbase",
88 "libbase_headers",
89 "libbuildversion",
90 "libc++",
91 "libcap",
92 "libcrypto",
93 "libcrypto_utils",
94 "libcutils",
95 "libcutils_headers",
96 "libdiagnose_usb",
Jiyong Parkfa899442020-01-31 02:49:53 +090097 "liblog_headers",
98 "libmdnssd",
99 "libminijail",
100 "libminijail_gen_constants",
101 "libminijail_gen_constants_obj",
102 "libminijail_gen_syscall",
103 "libminijail_gen_syscall_obj",
104 "libminijail_generated",
105 "libpackagelistparser",
106 "libpcre2",
107 "libprocessgroup_headers",
108 "libqemu_pipe",
109 "libselinux",
110 "libsystem_headers",
111 "libutils_headers",
112 }
113 //
114 // Module separator
115 //
116 m["com.android.appsearch"] = []string{
117 "icing-java-proto-lite",
118 "libprotobuf-java-lite",
119 }
Anton Hansson5053c292020-01-10 15:12:39 +0000120 //
121 // Module separator
122 //
123 m["com.android.art"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "art_cmdlineparser_headers",
125 "art_disassembler_headers",
126 "art_libartbase_headers",
127 "bcm_object",
128 "bionic_libc_platform_headers",
129 "core-repackaged-icu4j",
130 "cpp-define-generator-asm-support",
131 "cpp-define-generator-definitions",
132 "crtbegin_dynamic",
133 "crtbegin_dynamic1",
134 "crtbegin_so1",
135 "crtbrand",
136 "conscrypt.module.intra.core.api.stubs",
137 "dex2oat_headers",
138 "dt_fd_forward_export",
139 "fmtlib",
140 "icu4c_extra_headers",
Anton Hanssonf17f2482020-01-16 09:11:57 +0000141 "jacocoagent",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "javavm_headers",
143 "jni_platform_headers",
144 "libPlatformProperties",
145 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000146 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900147 "libandroidicuinit",
148 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000149 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900150 "libasync_safe",
Anton Hansson5053c292020-01-10 15:12:39 +0000151 "libbacktrace",
152 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900153 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000154 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900155 "libc++_static",
156 "libc++abi",
157 "libc++demangle",
158 "libc_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000159 "libcrypto",
Jiyong Parkfa899442020-01-31 02:49:53 +0900160 "libdexfile_all_headers",
161 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000162 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900163 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000164 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900165 "libfdlibm",
166 "libgtest_prod",
167 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000168 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900169 "libicuuc_headers",
170 "libicuuc_stubdata",
171 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900172 "liblog_headers",
173 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000174 "liblzma",
175 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900176 "libnativebridge-headers",
177 "libnativehelper_header_only",
178 "libnativeloader-headers",
179 "libnpt_headers",
180 "libopenjdkjvmti_headers",
181 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000182 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900183 "libprotobuf-cpp-lite",
184 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000185 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900186 "libv8",
187 "libv8base",
188 "libv8gen",
189 "libv8platform",
190 "libv8sampler",
191 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000192 "libvixl",
193 "libvixld",
194 "libz",
195 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900196 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000197 }
198 //
199 // Module separator
200 //
201 m["com.android.bluetooth.updatable"] = []string{
202 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000203 "android.hardware.bluetooth.a2dp@1.0",
204 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900205 "android.hardware.bluetooth@1.0",
206 "android.hardware.bluetooth@1.1",
207 "android.hardware.graphics.bufferqueue@1.0",
208 "android.hardware.graphics.bufferqueue@2.0",
209 "android.hardware.graphics.common@1.0",
210 "android.hardware.graphics.common@1.1",
211 "android.hardware.graphics.common@1.2",
212 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000213 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "android.hidl.token@1.0",
215 "android.hidl.token@1.0-utils",
216 "avrcp-target-service",
217 "avrcp_headers",
218 "bcm_object",
219 "bluetooth-protos-lite",
220 "bluetooth.mapsapi",
221 "com.android.vcard",
222 "fmtlib",
223 "guava",
224 "internal_include_headers",
225 "lib-bt-packets",
226 "lib-bt-packets-avrcp",
227 "lib-bt-packets-base",
228 "libFraunhoferAAC",
229 "libaudio-a2dp-hw-utils",
230 "libaudio-hearing-aid-hw-utils",
231 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000232 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900233 "libbase_headers",
234 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000235 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900236 "libbluetooth-types",
237 "libbluetooth-types-header",
238 "libbluetooth_gd",
239 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000240 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900241 "libbt-audio-hal-interface",
242 "libbt-bta",
243 "libbt-common",
244 "libbt-hci",
245 "libbt-platform-protos-lite",
246 "libbt-protos-lite",
247 "libbt-sbc-decoder",
248 "libbt-sbc-encoder",
249 "libbt-stack",
250 "libbt-utils",
251 "libbtcore",
252 "libbtdevice",
253 "libbte",
254 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000255 "libc++",
256 "libchrome",
257 "libcrypto",
258 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900259 "libcutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000260 "libevent",
261 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900262 "libg722codec",
263 "libgtest_prod",
264 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000265 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "libhidlbase-impl-internal",
267 "libhidltransport-impl-internal",
268 "libhwbinder-impl-internal",
269 "libjsoncpp",
270 "liblog_headers",
271 "libmedia_headers",
272 "libmodpb64",
273 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000274 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900275 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000276 "libprotobuf-cpp-lite",
Jiyong Parkfa899442020-01-31 02:49:53 +0900277 "libprotobuf-java-lite",
278 "libprotobuf-java-micro",
279 "libstagefright_foundation_headers",
280 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000281 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900282 "libstatssocket",
283 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000284 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900285 "libudrv-uipc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900286 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000287 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "media_plugin_headers",
289 "sap-api-java-static",
290 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000291 }
292 //
293 // Module separator
294 //
295 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
296 //
297 // Module separator
298 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900299 m["com.android.conscrypt"] = []string{
300 "bcm_object",
301 "boringssl_self_test",
302 "libc++",
303 "libcrypto",
304 "libnativehelper_header_only",
305 "libssl",
306 }
Anton Hansson5053c292020-01-10 15:12:39 +0000307 //
308 // Module separator
309 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900310 m["com.android.extservices"] = []string{
311 "flatbuffer_headers",
312 "liblua",
313 "libtextclassifier",
314 "libtextclassifier_hash_static",
315 "libtflite_static",
316 "libutf",
317 "libz_current",
318 "tensorflow_headers",
319 }
320 //
321 // Module separator
322 //
323 m["com.android.cronet"] = []string{
324 "cronet_impl_common_java",
325 "cronet_impl_native_java",
326 "cronet_impl_platform_java",
327 "libcronet.80.0.3986.0",
328 "org.chromium.net.cronet",
329 "prebuilt_libcronet.80.0.3986.0",
330 }
331 //
332 // Module separator
333 //
334 m["com.android.neuralnetworks"] = []string{
335 "android.hardware.neuralnetworks@1.0",
336 "android.hardware.neuralnetworks@1.1",
337 "android.hardware.neuralnetworks@1.2",
338 "android.hardware.neuralnetworks@1.3",
339 "android.hidl.allocator@1.0",
340 "android.hidl.memory.token@1.0",
341 "android.hidl.memory@1.0",
342 "android.hidl.safe_union@1.0",
343 "bcm_object",
344 "fmtlib",
345 "gemmlowp_headers",
346 "libarect",
347 "libbacktrace_headers",
348 "libbase",
349 "libbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900350 "libbuildversion",
351 "libc++",
352 "libcrypto",
353 "libcrypto_static",
354 "libcutils",
355 "libcutils_headers",
356 "libeigen",
357 "libfmq",
358 "libhidlbase",
359 "libhidlbase-impl-internal",
360 "libhidlmemory",
361 "libhidltransport-impl-internal",
362 "libhwbinder-impl-internal",
363 "libjsoncpp",
364 "liblog_headers",
365 "libmath",
366 "libneuralnetworks_common",
367 "libneuralnetworks_headers",
368 "libprocessgroup",
369 "libprocessgroup_headers",
370 "libprocpartition",
371 "libsync",
372 "libsystem_headers",
373 "libtextclassifier_hash",
374 "libtextclassifier_hash_headers",
375 "libtextclassifier_hash_static",
376 "libtflite_kernel_utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "libutils_headers",
378 "philox_random",
379 "philox_random_headers",
380 "tensorflow_headers",
381 }
Anton Hansson5053c292020-01-10 15:12:39 +0000382 //
383 // Module separator
384 //
Anton Hansson5053c292020-01-10 15:12:39 +0000385 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900386 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000387 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900388 "android.hardware.cas@1.0",
389 "android.hardware.configstore-utils",
390 "android.hardware.configstore@1.0",
391 "android.hardware.configstore@1.1",
392 "android.hardware.graphics.allocator@2.0",
393 "android.hardware.graphics.allocator@3.0",
394 "android.hardware.graphics.bufferqueue@1.0",
395 "android.hardware.graphics.bufferqueue@2.0",
396 "android.hardware.graphics.common@1.0",
397 "android.hardware.graphics.common@1.1",
398 "android.hardware.graphics.common@1.2",
399 "android.hardware.graphics.mapper@2.0",
400 "android.hardware.graphics.mapper@2.1",
401 "android.hardware.graphics.mapper@3.0",
402 "android.hardware.media.omx@1.0",
403 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000404 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000407 "android.hidl.token@1.0",
408 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900409 "bcm_object",
410 "bionic_libc_platform_headers",
411 "fmtlib",
412 "gl_headers",
413 "libEGL",
414 "libEGL_blobCache",
415 "libEGL_getProcAddress",
416 "libFLAC",
417 "libFLAC-config",
418 "libFLAC-headers",
419 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000420 "libaacextractor",
421 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900422 "libarect",
423 "libasync_safe",
424 "libaudio_system_headers",
425 "libaudioclient",
426 "libaudioclient_headers",
427 "libaudiofoundation",
428 "libaudiofoundation_headers",
429 "libaudiomanager",
430 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000431 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900432 "libaudioutils_fixedfft",
433 "libbacktrace",
434 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libbase_headers",
437 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libbluetooth-types-header",
439 "libbufferhub",
440 "libbufferhub_headers",
441 "libbufferhubqueue",
Anton Hansson5053c292020-01-10 15:12:39 +0000442 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900443 "libc_headers",
444 "libc_malloc_debug_backtrace",
445 "libcamera_client",
446 "libcamera_metadata",
Anton Hansson5053c292020-01-10 15:12:39 +0000447 "libcrypto",
448 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900449 "libcutils_headers",
450 "libdexfile_external_headers",
451 "libdexfile_support",
452 "libdvr_headers",
453 "libexpat",
454 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000455 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "libgrallocusage",
457 "libgraphicsenv",
458 "libgui",
459 "libgui_headers",
460 "libhardware_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000461 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900462 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900464 "libhidltransport-impl-internal",
465 "libhwbinder-impl-internal",
466 "libinput",
467 "libjsoncpp",
468 "liblog_headers",
469 "liblzma",
470 "libmath",
471 "libmedia",
472 "libmedia_codeclist",
473 "libmedia_headers",
474 "libmedia_helper",
475 "libmedia_helper_headers",
476 "libmedia_midiiowrapper",
477 "libmedia_omx",
478 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000479 "libmidiextractor",
480 "libmkvextractor",
481 "libmp3extractor",
482 "libmp4extractor",
483 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900484 "libnativebase_headers",
485 "libnativebridge-headers",
486 "libnativebridge_lazy",
487 "libnativeloader-headers",
488 "libnativeloader_lazy",
489 "libnativewindow_headers",
490 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000491 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libpackagelistparser",
493 "libpcre2",
494 "libpdx",
495 "libpdx_default_transport",
496 "libpdx_headers",
497 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libprocessgroup_headers",
500 "libprocinfo",
501 "libselinux",
502 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000503 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900504 "libspeexresampler",
505 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000506 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900507 "libstagefright_flacdec",
508 "libstagefright_foundation",
509 "libstagefright_foundation_headers",
510 "libstagefright_foundation_without_imemory",
511 "libstagefright_headers",
512 "libstagefright_id3",
513 "libstagefright_metadatautils",
514 "libstagefright_mpeg2extractor",
515 "libstagefright_mpeg2support",
516 "libsync",
517 "libsystem_headers",
518 "libui",
519 "libui_headers",
520 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900521 "libutils_headers",
522 "libvibrator",
523 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000524 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900525 "libwebm",
526 "media_ndk_headers",
527 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000528 "updatable-media",
529 }
530 //
531 // Module separator
532 //
533 m["com.android.media.swcodec"] = []string{
534 "android.frameworks.bufferhub@1.0",
535 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "android.hardware.configstore-utils",
537 "android.hardware.configstore@1.0",
538 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000539 "android.hardware.graphics.allocator@2.0",
540 "android.hardware.graphics.allocator@3.0",
541 "android.hardware.graphics.allocator@4.0",
542 "android.hardware.graphics.bufferqueue@1.0",
543 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900544 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000545 "android.hardware.graphics.common@1.0",
546 "android.hardware.graphics.common@1.1",
547 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000548 "android.hardware.graphics.mapper@2.0",
549 "android.hardware.graphics.mapper@2.1",
550 "android.hardware.graphics.mapper@3.0",
551 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000552 "android.hardware.media.bufferpool@2.0",
553 "android.hardware.media.c2@1.0",
554 "android.hardware.media.c2@1.1",
555 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900556 "android.hardware.media@1.0",
557 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000558 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900559 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000560 "android.hidl.safe_union@1.0",
561 "android.hidl.token@1.0",
562 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900563 "fmtlib",
564 "libEGL",
565 "libFLAC",
566 "libFLAC-config",
567 "libFLAC-headers",
568 "libFraunhoferAAC",
569 "libarect",
570 "libasync_safe",
571 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000572 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libaudioutils",
574 "libaudioutils_fixedfft",
575 "libavcdec",
576 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900578 "libavservices_minijail",
579 "libbacktrace",
580 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000581 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libbase_headers",
583 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900584 "libbluetooth-types-header",
585 "libbufferhub_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000586 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900587 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000588 "libcap",
589 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900590 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000591 "libcodec2_hidl@1.0",
592 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000594 "libcodec2_soft_aacdec",
595 "libcodec2_soft_aacenc",
596 "libcodec2_soft_amrnbdec",
597 "libcodec2_soft_amrnbenc",
598 "libcodec2_soft_amrwbdec",
599 "libcodec2_soft_amrwbenc",
600 "libcodec2_soft_av1dec_gav1",
601 "libcodec2_soft_avcdec",
602 "libcodec2_soft_avcenc",
603 "libcodec2_soft_common",
604 "libcodec2_soft_flacdec",
605 "libcodec2_soft_flacenc",
606 "libcodec2_soft_g711alawdec",
607 "libcodec2_soft_g711mlawdec",
608 "libcodec2_soft_gsmdec",
609 "libcodec2_soft_h263dec",
610 "libcodec2_soft_h263enc",
611 "libcodec2_soft_hevcdec",
612 "libcodec2_soft_hevcenc",
613 "libcodec2_soft_mp3dec",
614 "libcodec2_soft_mpeg2dec",
615 "libcodec2_soft_mpeg4dec",
616 "libcodec2_soft_mpeg4enc",
617 "libcodec2_soft_opusdec",
618 "libcodec2_soft_opusenc",
619 "libcodec2_soft_rawdec",
620 "libcodec2_soft_vorbisdec",
621 "libcodec2_soft_vp8dec",
622 "libcodec2_soft_vp8enc",
623 "libcodec2_soft_vp9dec",
624 "libcodec2_soft_vp9enc",
625 "libcodec2_vndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000626 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "libcutils_headers",
628 "libdexfile_support",
629 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000630 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900631 "libfmq",
632 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000633 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900634 "libgrallocusage",
635 "libgraphicsenv",
636 "libgsm",
637 "libgui_bufferqueue_static",
638 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000639 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "libhardware_headers",
641 "libhevcdec",
642 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000643 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900644 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000645 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900646 "libhidltransport-impl-internal",
647 "libhwbinder-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000648 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900649 "libjpeg",
650 "libjsoncpp",
651 "liblog_headers",
652 "liblzma",
653 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000654 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900655 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000656 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900657 "libminijail_gen_constants",
658 "libminijail_gen_constants_obj",
659 "libminijail_gen_syscall",
660 "libminijail_gen_syscall_obj",
661 "libminijail_generated",
662 "libmpeg2dec",
663 "libnativebase_headers",
664 "libnativebridge_lazy",
665 "libnativeloader_lazy",
666 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000667 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900668 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000669 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900670 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000671 "libscudo_wrapper",
672 "libsfplugin_ccodec_utils",
673 "libspeexresampler",
674 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900675 "libstagefright_amrnbdec",
676 "libstagefright_amrnbenc",
677 "libstagefright_amrwbdec",
678 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000679 "libstagefright_bufferpool@2.0.1",
680 "libstagefright_bufferqueue_helper",
681 "libstagefright_enc_common",
682 "libstagefright_flacdec",
683 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900684 "libstagefright_foundation_headers",
685 "libstagefright_headers",
686 "libstagefright_m4vh263dec",
687 "libstagefright_m4vh263enc",
688 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000689 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000691 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900692 "libui_headers",
693 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900694 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000695 "libvorbisidec",
696 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "libyuv",
698 "libyuv_static",
699 "media_ndk_headers",
700 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000701 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000702 }
703 //
704 // Module separator
705 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900706 m["com.android.mediaprovider"] = []string{
707 "MediaProvider",
708 "MediaProviderGoogle",
709 "fmtlib_ndk",
710 "guava",
711 "libbase_ndk",
712 "libfuse",
713 "libfuse_jni",
714 "libnativehelper_header_only",
715 }
716 //
717 // Module separator
718 //
719 m["com.android.permission"] = []string{
720 "androidx.annotation_annotation",
721 "androidx.annotation_annotation-nodeps",
722 "androidx.lifecycle_lifecycle-common",
723 "androidx.lifecycle_lifecycle-common-java8",
724 "androidx.lifecycle_lifecycle-common-java8-nodeps",
725 "androidx.lifecycle_lifecycle-common-nodeps",
726 "kotlin-annotations",
727 "kotlin-stdlib",
728 "kotlin-stdlib-jdk7",
729 "kotlin-stdlib-jdk8",
730 "kotlinx-coroutines-android",
731 "kotlinx-coroutines-android-nodeps",
732 "kotlinx-coroutines-core",
733 "kotlinx-coroutines-core-nodeps",
734 "libprotobuf-java-lite",
735 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900736 "GooglePermissionController",
737 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900738 }
Anton Hansson5053c292020-01-10 15:12:39 +0000739 //
740 // Module separator
741 //
Anton Hansson5053c292020-01-10 15:12:39 +0000742 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900743 "bionic_libc_platform_headers",
744 "fmtlib",
745 "libarm-optimized-routines-math",
746 "libasync_safe",
747 "libasync_safe_headers",
748 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000749 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900750 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000751 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900752 "libc_aeabi",
753 "libc_bionic",
754 "libc_bionic_ndk",
755 "libc_bootstrap",
756 "libc_common",
757 "libc_common_shared",
758 "libc_common_static",
759 "libc_dns",
760 "libc_dynamic_dispatch",
761 "libc_fortify",
762 "libc_freebsd",
763 "libc_freebsd_large_stack",
764 "libc_gdtoa",
765 "libc_headers",
766 "libc_init_dynamic",
767 "libc_init_static",
768 "libc_jemalloc_wrapper",
769 "libc_netbsd",
770 "libc_nomalloc",
771 "libc_nopthread",
772 "libc_openbsd",
773 "libc_openbsd_large_stack",
774 "libc_openbsd_ndk",
775 "libc_pthread",
776 "libc_static_dispatch",
777 "libc_syscalls",
778 "libc_tzcode",
779 "libc_unwind_static",
780 "libcutils",
781 "libcutils_headers",
782 "libdebuggerd",
783 "libdebuggerd_common_headers",
784 "libdebuggerd_handler_core",
785 "libdebuggerd_handler_fallback",
786 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000787 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900788 "libdexfile_support_static",
789 "libgtest_prod",
790 "libjemalloc5",
791 "liblinker_main",
792 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900793 "liblog_headers",
794 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000795 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900796 "libprocessgroup_headers",
797 "libprocinfo",
798 "libpropertyinfoparser",
799 "libscudo",
800 "libstdc++",
801 "libsystem_headers",
802 "libsystemproperties",
803 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000804 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 "libutils_headers",
806 "libz",
807 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000808 }
809 //
810 // Module separator
811 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900812 m["com.android.resolv"] = []string{
813 "bcm_object",
814 "dnsresolver_aidl_interface-unstable-ndk_platform",
815 "fmtlib",
816 "libbacktrace_headers",
817 "libbase",
818 "libbase_headers",
819 "libc++",
820 "libcrypto",
821 "libcutils",
822 "libcutils_headers",
823 "libgtest_prod",
824 "libjsoncpp",
Jiyong Parkfa899442020-01-31 02:49:53 +0900825 "liblog_headers",
826 "libnativehelper_header_only",
827 "libnetd_client_headers",
828 "libnetd_resolv",
829 "libnetdutils",
830 "libprocessgroup",
831 "libprocessgroup_headers",
832 "libprotobuf-cpp-lite",
833 "libssl",
834 "libstatslog_resolv",
835 "libstatspush_compat",
836 "libstatssocket",
837 "libstatssocket_headers",
838 "libsystem_headers",
839 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900840 "libutils_headers",
841 "netd_event_listener_interface-ndk_platform",
842 "server_configurable_flags",
843 "stats_proto",
844 }
Anton Hansson5053c292020-01-10 15:12:39 +0000845 //
846 // Module separator
847 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900848 m["com.android.tethering"] = []string{
849 "libbase",
850 "libc++",
851 "libnativehelper_compat_libc++",
852 "android.hardware.tetheroffload.config@1.0",
853 "fmtlib",
854 "libbacktrace_headers",
855 "libbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900856 "libcgrouprc",
857 "libcgrouprc_format",
858 "libcutils",
859 "libcutils_headers",
860 "libhidlbase",
861 "libhidlbase-impl-internal",
862 "libhidltransport-impl-internal",
863 "libhwbinder-impl-internal",
864 "libjsoncpp",
Jiyong Parkfa899442020-01-31 02:49:53 +0900865 "liblog_headers",
866 "libprocessgroup",
867 "libprocessgroup_headers",
868 "libsystem_headers",
869 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900870 "libutils_headers",
871 "libvndksupport",
872 "tethering-aidl-interfaces-java",
873 }
Anton Hansson5053c292020-01-10 15:12:39 +0000874 //
875 // Module separator
876 //
877 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900878 "PlatformProperties",
879 "android.hardware.wifi-V1.0-java",
880 "android.hardware.wifi-V1.1-java",
881 "android.hardware.wifi-V1.2-java",
882 "android.hardware.wifi-V1.3-java",
883 "android.hardware.wifi-V1.4-java",
884 "android.hardware.wifi.hostapd-V1.0-java",
885 "android.hardware.wifi.hostapd-V1.1-java",
886 "android.hardware.wifi.hostapd-V1.2-java",
887 "android.hardware.wifi.supplicant-V1.0-java",
888 "android.hardware.wifi.supplicant-V1.1-java",
889 "android.hardware.wifi.supplicant-V1.2-java",
890 "android.hardware.wifi.supplicant-V1.3-java",
891 "android.hidl.base-V1.0-java",
892 "android.hidl.manager-V1.0-java",
893 "android.hidl.manager-V1.1-java",
894 "android.hidl.manager-V1.2-java",
895 "androidx.annotation_annotation",
896 "androidx.annotation_annotation-nodeps",
897 "bouncycastle-unbundled",
898 "dnsresolver_aidl_interface-V2-java",
899 "error_prone_annotations",
900 "ipmemorystore-aidl-interfaces-V3-java",
901 "ipmemorystore-aidl-interfaces-java",
902 "ksoap2",
903 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000904 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900905 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000906 "libc++",
907 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900908 "libcutils_headers",
909 "liblog_headers",
910 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000911 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900912 "libprocessgroup_headers",
913 "libprotobuf-java-lite",
914 "libprotobuf-java-nano",
915 "libsystem_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900916 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000917 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900918 "net-utils-services-common",
919 "netd_aidl_interface-V2-java",
920 "netd_aidl_interface-unstable-java",
921 "netd_event_listener_interface-java",
922 "netlink-client",
923 "networkstack-aidl-interfaces-unstable-java",
924 "networkstack-client",
925 "services.net",
926 "wifi-lite-protos",
927 "wifi-nano-protos",
928 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000929 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900930 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000931 }
932 //
933 // Module separator
934 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900935 m["com.android.sdkext"] = []string{
936 "fmtlib_ndk",
937 "libbase_ndk",
938 "libprotobuf-cpp-lite-ndk",
939 }
940 //
941 // Module separator
942 //
943 m["com.android.os.statsd"] = []string{
944 "libbacktrace_headers",
945 "libbase_headers",
946 "libc++",
947 "libcutils",
948 "libcutils_headers",
949 "liblog_headers",
950 "libprocessgroup_headers",
951 "libstatssocket",
952 "libsystem_headers",
953 "libutils_headers",
954 }
955 //
956 // Module separator
957 //
958 m["//any"] = []string{
959 "crtbegin_dynamic",
960 "crtbegin_dynamic1",
961 "crtbegin_so",
962 "crtbegin_so1",
963 "crtbegin_static",
964 "crtbrand",
965 "crtend_android",
966 "crtend_so",
967 "libatomic",
968 "libc++_static",
969 "libc++abi",
970 "libc++demangle",
971 "libc_headers",
972 "libclang_rt",
973 "libgcc_stripped",
974 "libprofile-clang-extras",
975 "libprofile-clang-extras_ndk",
976 "libprofile-extras",
977 "libprofile-extras_ndk",
978 "libunwind_llvm",
979 "ndk_crtbegin_dynamic.27",
980 "ndk_crtbegin_so.16",
981 "ndk_crtbegin_so.19",
982 "ndk_crtbegin_so.21",
983 "ndk_crtbegin_so.24",
984 "ndk_crtbegin_so.27",
985 "ndk_crtend_android.27",
986 "ndk_crtend_so.16",
987 "ndk_crtend_so.19",
988 "ndk_crtend_so.21",
989 "ndk_crtend_so.24",
990 "ndk_crtend_so.27",
991 "ndk_libandroid_support",
992 "ndk_libc++_static",
993 "ndk_libc++abi",
994 "ndk_libunwind",
995 }
Anton Hansson5053c292020-01-10 15:12:39 +0000996 return m
997}
998
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900999func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001000 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001001 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001002 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001003 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001004 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001005 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001006
Jooyung Han31c470b2019-10-18 16:26:59 +09001007 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001008 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001009
1010 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1011 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1012 sort.Strings(*apexFileContextsInfos)
1013 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1014 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001015}
1016
Jooyung Han31c470b2019-10-18 16:26:59 +09001017func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1018 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1019 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1020}
1021
Jiyong Parkd1063c12019-07-17 20:08:41 +09001022func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001023 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001024 ctx.BottomUp("apex", apexMutator).Parallel()
1025 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1026 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001027}
1028
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001029// Mark the direct and transitive dependencies of apex bundles so that they
1030// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001031func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001032 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001033 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001034 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001035 apexBundles = []android.ApexInfo{{mctx.ModuleName(), proptools.Bool(a.properties.Legacy_android10_support)}}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001036 directDep = true
1037 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001038 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001039 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001040 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001041
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001042 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001043 return
1044 }
1045
1046 mctx.VisitDirectDeps(func(child android.Module) {
1047 depName := mctx.OtherModuleName(child)
1048 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1049 (directDep || am.DepIsInSameApex(mctx, child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001050 android.UpdateApexDependency(apexBundles, depName, directDep)
1051 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001052 }
1053 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054}
1055
1056// Create apex variations if a module is included in APEX(s).
1057func apexMutator(mctx android.BottomUpMutatorContext) {
1058 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001059 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001060 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001061 // apex bundle itself is mutated so that it and its modules have same
1062 // apex variant.
1063 apexBundleName := mctx.ModuleName()
1064 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001065 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1066 apexBundleName := o.GetOverriddenModuleName()
1067 if apexBundleName == "" {
1068 mctx.ModuleErrorf("base property is not set")
1069 return
1070 }
1071 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001072 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001073
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001074}
Sundong Ahne9b55722019-09-06 17:37:42 +09001075
Jooyung Han7a78a922019-10-08 21:59:58 +09001076var (
1077 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1078 apexFileContextsInfosMutex sync.Mutex
1079)
1080
1081func apexFileContextsInfos(config android.Config) *[]string {
1082 return config.Once(apexFileContextsInfosKey, func() interface{} {
1083 return &[]string{}
1084 }).(*[]string)
1085}
1086
Jooyung Han54aca7b2019-11-20 02:26:02 +09001087func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001088 apexFileContextsInfosMutex.Lock()
1089 defer apexFileContextsInfosMutex.Unlock()
1090 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001091 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001092}
1093
Sundong Ahne9b55722019-09-06 17:37:42 +09001094func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001095 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001096 var variants []string
1097 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1098 case "image":
1099 variants = append(variants, imageApexType, flattenedApexType)
1100 case "zip":
1101 variants = append(variants, zipApexType)
1102 case "both":
1103 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1104 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001105 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001106 return
1107 }
1108
1109 modules := mctx.CreateLocalVariations(variants...)
1110
1111 for i, v := range variants {
1112 switch v {
1113 case imageApexType:
1114 modules[i].(*apexBundle).properties.ApexType = imageApex
1115 case zipApexType:
1116 modules[i].(*apexBundle).properties.ApexType = zipApex
1117 case flattenedApexType:
1118 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001119 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001120 modules[i].(*apexBundle).MakeAsSystemExt()
1121 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001122 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001123 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001124 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1125 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001126 }
1127}
1128
Jooyung Han5c998b92019-06-27 11:30:33 +09001129func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1130 if ab, ok := mctx.Module().(*apexBundle); ok {
1131 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1132 }
1133}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001134
Jooyung Handc782442019-11-01 03:14:38 +09001135var (
1136 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1137)
1138
1139// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1140// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1141// which may cause compatibility issues. (e.g. libbinder)
1142// Even though libbinder restricts its availability via 'apex_available' property and relies on
1143// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1144// to avoid similar problems.
1145func useVendorWhitelist(config android.Config) []string {
1146 return config.Once(useVendorWhitelistKey, func() interface{} {
1147 return []string{
1148 // swcodec uses "vendor" variants for smaller size
1149 "com.android.media.swcodec",
1150 "test_com.android.media.swcodec",
1151 }
1152 }).([]string)
1153}
1154
1155// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1156// called before the first call to useVendorWhitelist()
1157func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1158 config.Once(useVendorWhitelistKey, func() interface{} {
1159 return whitelist
1160 })
1161}
1162
Alex Light9670d332019-01-29 18:07:33 -08001163type apexNativeDependencies struct {
1164 // List of native libraries
1165 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001166
Alex Light9670d332019-01-29 18:07:33 -08001167 // List of native executables
1168 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001169
Roland Levillain630846d2019-06-26 12:48:34 +01001170 // List of native tests
1171 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001172}
Jooyung Han344d5432019-08-23 11:17:39 +09001173
Alex Light9670d332019-01-29 18:07:33 -08001174type apexMultilibProperties struct {
1175 // Native dependencies whose compile_multilib is "first"
1176 First apexNativeDependencies
1177
1178 // Native dependencies whose compile_multilib is "both"
1179 Both apexNativeDependencies
1180
1181 // Native dependencies whose compile_multilib is "prefer32"
1182 Prefer32 apexNativeDependencies
1183
1184 // Native dependencies whose compile_multilib is "32"
1185 Lib32 apexNativeDependencies
1186
1187 // Native dependencies whose compile_multilib is "64"
1188 Lib64 apexNativeDependencies
1189}
1190
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001191type apexBundleProperties struct {
1192 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001193 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001194 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001195
Jiyong Park40e26a22019-02-08 02:53:06 +09001196 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1197 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001198 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001199
Roland Levillain411c5842019-09-19 16:37:20 +01001200 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1201 // device (/apex/<apex_name>).
1202 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001203 Apex_name *string
1204
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001205 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001206 // For platform APEXes, this should points to a file under /system/sepolicy
1207 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1208 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001209
1210 // List of native shared libs that are embedded inside this APEX bundle
1211 Native_shared_libs []string
1212
Roland Levillain630846d2019-06-26 12:48:34 +01001213 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001214 Binaries []string
1215
1216 // List of java libraries that are embedded inside this APEX bundle
1217 Java_libs []string
1218
1219 // List of prebuilt files that are embedded inside this APEX bundle
1220 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001221
Roland Levillain630846d2019-06-26 12:48:34 +01001222 // List of tests that are embedded inside this APEX bundle
1223 Tests []string
1224
Jiyong Parkff1458f2018-10-12 21:49:38 +09001225 // Name of the apex_key module that provides the private key to sign APEX
1226 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001227
Alex Light5098a612018-11-29 17:12:15 -08001228 // The type of APEX to build. Controls what the APEX payload is. Either
1229 // 'image', 'zip' or 'both'. Default: 'image'.
1230 Payload_type *string
1231
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001232 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1233 // or an android_app_certificate module name in the form ":module".
1234 Certificate *string
1235
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001236 // Whether this APEX is installable to one of the partitions. Default: true.
1237 Installable *bool
1238
Jiyong Parkda6eb592018-12-19 17:12:36 +09001239 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1240 // Default is false.
1241 Use_vendor *bool
1242
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001243 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1244 Ignore_system_library_special_case *bool
1245
Alex Light9670d332019-01-29 18:07:33 -08001246 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001247
Jiyong Parkf97782b2019-02-13 20:28:58 +09001248 // List of sanitizer names that this APEX is enabled for
1249 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001250
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001251 PreventInstall bool `blueprint:"mutated"`
1252
1253 HideFromMake bool `blueprint:"mutated"`
1254
Jooyung Han5c998b92019-06-27 11:30:33 +09001255 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1256 Provide_cpp_shared_libs *bool
1257
1258 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1259 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001260
1261 // A txt file containing list of files that are whitelisted to be included in this APEX.
1262 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001263
Sundong Ahnabb64432019-10-22 13:58:29 +09001264 // package format of this apex variant; could be non-flattened, flattened, or zip.
1265 // imageApex, zipApex or flattened
1266 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001267
Jiyong Parkd1063c12019-07-17 20:08:41 +09001268 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1269 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1270 // is implied. This value affects all modules included in this APEX. In other words, they are
1271 // also built with the SDKs specified here.
1272 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001273
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001274 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1275 // Should be only used in tests#.
1276 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001277
1278 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1279 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1280 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001281
1282 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001283
1284 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1285 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1286 // like symlinking to the system libs. Default is false.
1287 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001288
1289 // The minimum SDK version that this apex must be compatible with.
1290 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001291}
1292
1293type apexTargetBundleProperties struct {
1294 Target struct {
1295 // Multilib properties only for android.
1296 Android struct {
1297 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001298 }
Jooyung Han344d5432019-08-23 11:17:39 +09001299
Alex Light9670d332019-01-29 18:07:33 -08001300 // Multilib properties only for host.
1301 Host struct {
1302 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001303 }
Jooyung Han344d5432019-08-23 11:17:39 +09001304
Alex Light9670d332019-01-29 18:07:33 -08001305 // Multilib properties only for host linux_bionic.
1306 Linux_bionic struct {
1307 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001308 }
Jooyung Han344d5432019-08-23 11:17:39 +09001309
Alex Light9670d332019-01-29 18:07:33 -08001310 // Multilib properties only for host linux_glibc.
1311 Linux_glibc struct {
1312 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001313 }
1314 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001315}
1316
Jiyong Park5d790c32019-11-15 18:40:32 +09001317type overridableProperties struct {
1318 // List of APKs to package inside APEX
1319 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001320
1321 // Names of modules to be overridden. Listed modules can only be other binaries
1322 // (in Make or Soong).
1323 // This does not completely prevent installation of the overridden binaries, but if both
1324 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1325 // from PRODUCT_PACKAGES.
1326 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001327
1328 // Logging Parent value
1329 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001330}
1331
Alex Light5098a612018-11-29 17:12:15 -08001332type apexPackaging int
1333
1334const (
1335 imageApex apexPackaging = iota
1336 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001337 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001338)
1339
Sundong Ahnabb64432019-10-22 13:58:29 +09001340// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001341func (a apexPackaging) suffix() string {
1342 switch a {
1343 case imageApex:
1344 return imageApexSuffix
1345 case zipApex:
1346 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001347 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001348 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001349 }
1350}
1351
1352func (a apexPackaging) name() string {
1353 switch a {
1354 case imageApex:
1355 return imageApexType
1356 case zipApex:
1357 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001358 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001359 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001360 }
1361}
1362
Jiyong Parkf653b052019-11-18 15:39:01 +09001363type apexFileClass int
1364
1365const (
1366 etc apexFileClass = iota
1367 nativeSharedLib
1368 nativeExecutable
1369 shBinary
1370 pyBinary
1371 goBinary
1372 javaSharedLib
1373 nativeTest
1374 app
1375)
1376
Jiyong Park8fd61922018-11-08 02:50:25 +09001377func (class apexFileClass) NameInMake() string {
1378 switch class {
1379 case etc:
1380 return "ETC"
1381 case nativeSharedLib:
1382 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001383 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001384 return "EXECUTABLES"
1385 case javaSharedLib:
1386 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001387 case nativeTest:
1388 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001389 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001390 // b/142537672 Why isn't this APP? We want to have full control over
1391 // the paths and file names of the apk file under the flattend APEX.
1392 // If this is set to APP, then the paths and file names are modified
1393 // by the Make build system. For example, it is installed to
1394 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1395 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1396 // appends module name (which is <apexname>.<Appname> to the path.
1397 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001398 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001399 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001400 }
1401}
1402
Jiyong Parkf653b052019-11-18 15:39:01 +09001403// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001404type apexFile struct {
1405 builtFile android.Path
1406 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001407 installDir string
1408 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001409 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001410 // list of symlinks that will be created in installDir that point to this apexFile
1411 symlinks []string
1412 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001413 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001414
1415 requiredModuleNames []string
1416 targetRequiredModuleNames []string
1417 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001418
Colin Cross503c1d02020-01-28 14:00:53 -08001419 jacocoReportClassesFile android.Path // only for javalibs and apps
1420 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001421 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001422}
1423
Jiyong Park1833cef2019-12-13 13:28:36 +09001424func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1425 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001426 builtFile: builtFile,
1427 moduleName: moduleName,
1428 installDir: installDir,
1429 class: class,
1430 module: module,
1431 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001432 if module != nil {
1433 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001434 ret.requiredModuleNames = module.RequiredModuleNames()
1435 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1436 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001437 }
1438 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001439}
1440
1441func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001442 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001443}
1444
Jiyong Park7cd10e32020-01-14 09:22:18 +09001445// Path() returns path of this apex file relative to the APEX root
1446func (af *apexFile) Path() string {
1447 return filepath.Join(af.installDir, af.builtFile.Base())
1448}
1449
1450// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1451func (af *apexFile) SymlinkPaths() []string {
1452 var ret []string
1453 for _, symlink := range af.symlinks {
1454 ret = append(ret, filepath.Join(af.installDir, symlink))
1455 }
1456 return ret
1457}
1458
1459func (af *apexFile) AvailableToPlatform() bool {
1460 if af.module == nil {
1461 return false
1462 }
1463 if am, ok := af.module.(android.ApexModule); ok {
1464 return am.AvailableFor(android.AvailableToPlatform)
1465 }
1466 return false
1467}
1468
Jiyong Park678c8812020-02-07 17:25:49 +09001469type depInfo struct {
1470 to string
1471 from []string
1472 isExternal bool
1473}
1474
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001475type apexBundle struct {
1476 android.ModuleBase
1477 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001478 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001479 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001480
Jiyong Park5d790c32019-11-15 18:40:32 +09001481 properties apexBundleProperties
1482 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001483 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001484
Jooyung Hanf21c7972019-12-16 22:32:06 +09001485 // specific to apex_vndk modules
1486 vndkProperties apexVndkProperties
1487
Colin Crossa4925902018-11-16 11:36:28 -08001488 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001489 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001490 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001491
Jiyong Park03b68dd2019-07-26 23:20:40 +09001492 prebuiltFileToDelete string
1493
Jiyong Park42cca6c2019-04-01 11:15:50 +09001494 public_key_file android.Path
1495 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001496
1497 container_certificate_file android.Path
1498 container_private_key_file android.Path
1499
Jooyung Han54aca7b2019-11-20 02:26:02 +09001500 fileContexts android.Path
1501
Jiyong Park8fd61922018-11-08 02:50:25 +09001502 // list of files to be included in this apex
1503 filesInfo []apexFile
1504
Jiyong Park956305c2020-01-09 12:32:06 +09001505 // list of module names that should be installed along with this APEX
1506 requiredDeps []string
1507
Jiyong Park956305c2020-01-09 12:32:06 +09001508 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001509 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001510
Sundong Ahnabb64432019-10-22 13:58:29 +09001511 testApex bool
1512 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001513 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001514 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001515
Jooyung Han214bf372019-11-12 13:03:50 +09001516 manifestJsonOut android.WritablePath
1517 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001518
Jooyung Han002ab682020-01-08 01:57:58 +09001519 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001520 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001521 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001522 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1523 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001524
1525 // Suffix of module name in Android.mk
1526 // ".flattened", ".apex", ".zipapex", or ""
1527 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001528
1529 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001530
1531 // Whether to create symlink to the system file instead of having a file
1532 // inside the apex or not
1533 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001534
1535 // Struct holding the merged notice file paths in different formats
1536 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001537}
1538
Jiyong Park397e55e2018-10-24 21:09:55 +09001539func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001540 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001541 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001542 // Use *FarVariation* to be able to depend on modules having
1543 // conflicting variations with this module. This is required since
1544 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1545 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001546 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001547 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001548 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001549 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001550 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001551
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001552 ctx.AddFarVariationDependencies(append(target.Variations(),
1553 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1554 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001555
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001556 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001557 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001558 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001559 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001560}
1561
Alex Light9670d332019-01-29 18:07:33 -08001562func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1563 if ctx.Os().Class == android.Device {
1564 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1565 } else {
1566 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1567 if ctx.Os().Bionic() {
1568 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1569 } else {
1570 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1571 }
1572 }
1573}
1574
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001575func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001576 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1577 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1578 }
1579
Jiyong Park397e55e2018-10-24 21:09:55 +09001580 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001581 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001582
1583 a.combineProperties(ctx)
1584
Jiyong Park397e55e2018-10-24 21:09:55 +09001585 has32BitTarget := false
1586 for _, target := range targets {
1587 if target.Arch.ArchType.Multilib == "lib32" {
1588 has32BitTarget = true
1589 }
1590 }
1591 for i, target := range targets {
1592 // When multilib.* is omitted for native_shared_libs, it implies
1593 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001594 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001595 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001596 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001597 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001598
Roland Levillain630846d2019-06-26 12:48:34 +01001599 // When multilib.* is omitted for tests, it implies
1600 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001601 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001602 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001603 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001604 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001605
Jiyong Park397e55e2018-10-24 21:09:55 +09001606 // Add native modules targetting both ABIs
1607 addDependenciesForNativeModules(ctx,
1608 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001609 a.properties.Multilib.Both.Binaries,
1610 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001611 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001612 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001613
Alex Light3d673592019-01-18 14:37:31 -08001614 isPrimaryAbi := i == 0
1615 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001616 // When multilib.* is omitted for binaries, it implies
1617 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001618 ctx.AddFarVariationDependencies(append(target.Variations(),
1619 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1620 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001621
1622 // Add native modules targetting the first ABI
1623 addDependenciesForNativeModules(ctx,
1624 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001625 a.properties.Multilib.First.Binaries,
1626 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001627 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001628 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001629 }
1630
1631 switch target.Arch.ArchType.Multilib {
1632 case "lib32":
1633 // Add native modules targetting 32-bit ABI
1634 addDependenciesForNativeModules(ctx,
1635 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001636 a.properties.Multilib.Lib32.Binaries,
1637 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001638 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001639 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001640
1641 addDependenciesForNativeModules(ctx,
1642 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001643 a.properties.Multilib.Prefer32.Binaries,
1644 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001645 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001646 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001647 case "lib64":
1648 // Add native modules targetting 64-bit ABI
1649 addDependenciesForNativeModules(ctx,
1650 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001651 a.properties.Multilib.Lib64.Binaries,
1652 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001653 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001654 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001655
1656 if !has32BitTarget {
1657 addDependenciesForNativeModules(ctx,
1658 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001659 a.properties.Multilib.Prefer32.Binaries,
1660 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001661 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001663 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001664
1665 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1666 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1667 if sanitizer == "hwaddress" {
1668 addDependenciesForNativeModules(ctx,
1669 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001670 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001671 break
1672 }
1673 }
1674 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001675 }
1676
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001677 }
1678
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001679 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1680 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1681 // b/144532908
1682 archForPrebuiltEtc := config.Arches()[0]
1683 for _, arch := range config.Arches() {
1684 // Prefer 64-bit arch if there is any
1685 if arch.ArchType.Multilib == "lib64" {
1686 archForPrebuiltEtc = arch
1687 break
1688 }
1689 }
1690 ctx.AddFarVariationDependencies([]blueprint.Variation{
1691 {Mutator: "os", Variation: ctx.Os().String()},
1692 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1693 }, prebuiltTag, a.properties.Prebuilts...)
1694
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001695 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1696 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001697
Ulya Trafimovich44561882020-01-03 13:25:54 +00001698 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1699 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1700 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1701 javaLibTag, "jacocoagent")
1702 }
1703
Jiyong Park23c52b02019-02-02 13:13:47 +09001704 if String(a.properties.Key) == "" {
1705 ctx.ModuleErrorf("key is missing")
1706 return
1707 }
1708 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001709
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001710 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001711 if cert != "" {
1712 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001713 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001714
1715 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1716 if len(a.properties.Uses_sdks) > 0 {
1717 sdkRefs := []android.SdkRef{}
1718 for _, str := range a.properties.Uses_sdks {
1719 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1720 sdkRefs = append(sdkRefs, parsed)
1721 }
1722 a.BuildWithSdks(sdkRefs)
1723 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001724}
1725
Jiyong Park5d790c32019-11-15 18:40:32 +09001726func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1727 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1728 androidAppTag, a.overridableProperties.Apps...)
1729}
1730
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001731func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1732 // direct deps of an APEX bundle are all part of the APEX bundle
1733 return true
1734}
1735
Colin Cross0ea8ba82019-06-06 14:33:29 -07001736func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001737 moduleName := ctx.ModuleName()
1738 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1739 // we check with the pseudo module name to see if its certificate is overridden.
1740 if a.vndkApex {
1741 moduleName = vndkApexName
1742 }
1743 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001744 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001745 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001746 }
1747 return String(a.properties.Certificate)
1748}
1749
Colin Cross41955e82019-05-29 14:40:35 -07001750func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1751 switch tag {
1752 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001753 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001754 default:
1755 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001756 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001757}
1758
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001759func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001760 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001761}
1762
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001763func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1764 return proptools.Bool(a.properties.Test_only_no_hashtree)
1765}
1766
Jiyong Park7c1dc612019-01-05 11:15:24 +09001767func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001768 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001769 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001770 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001771 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001772 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001773 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001774 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001775 }
1776}
1777
Jiyong Parkf97782b2019-02-13 20:28:58 +09001778func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1779 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1780 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1781 }
1782}
1783
Jiyong Park388ef3f2019-01-28 19:47:32 +09001784func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001785 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1786 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001787 }
1788
1789 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001790 globalSanitizerNames := []string{}
1791 if a.Host() {
1792 globalSanitizerNames = ctx.Config().SanitizeHost()
1793 } else {
1794 arches := ctx.Config().SanitizeDeviceArch()
1795 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1796 globalSanitizerNames = ctx.Config().SanitizeDevice()
1797 }
1798 }
1799 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001800}
1801
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001802func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001803 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001804}
1805
1806func (a *apexBundle) PreventInstall() {
1807 a.properties.PreventInstall = true
1808}
1809
1810func (a *apexBundle) HideFromMake() {
1811 a.properties.HideFromMake = true
1812}
1813
Jiyong Park956305c2020-01-09 12:32:06 +09001814func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1815 a.properties.IsCoverageVariant = coverage
1816}
1817
Jiyong Parkf653b052019-11-18 15:39:01 +09001818// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001819func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001820 // Decide the APEX-local directory by the multilib of the library
1821 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001822 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001823 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001824 case "lib32":
1825 dirInApex = "lib"
1826 case "lib64":
1827 dirInApex = "lib64"
1828 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001829 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001830 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001831 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001832 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001833 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001834 // Special case for Bionic libs and other libs installed with them. This is
1835 // to prevent those libs from being included in the search path
1836 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1837 // those libs in the Runtime APEX are available via the legacy paths in
1838 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1839 // to the legacy paths and thus will be loaded into the default linker
1840 // namespace (aka "platform" namespace). If the libs are directly in
1841 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1842 // into the runtime linker namespace, which will result in double loading of
1843 // them, which isn't supported.
1844 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001845 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001846
Jiyong Parkf653b052019-11-18 15:39:01 +09001847 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001848 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849}
1850
Jiyong Park1833cef2019-12-13 13:28:36 +09001851func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001852 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001853 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001854 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001855 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001856 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001857 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001858 af.symlinks = cc.Symlinks()
1859 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001860}
1861
Jiyong Park1833cef2019-12-13 13:28:36 +09001862func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001863 dirInApex := "bin"
1864 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001865 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001866}
Jiyong Park1833cef2019-12-13 13:28:36 +09001867func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001868 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001869 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1870 if err != nil {
1871 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001873 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001874 fileToCopy := android.PathForOutput(ctx, s)
1875 // NB: Since go binaries are static we don't need the module for anything here, which is
1876 // good since the go tool is a blueprint.Module not an android.Module like we would
1877 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001878 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001879}
1880
Jiyong Park1833cef2019-12-13 13:28:36 +09001881func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001882 dirInApex := filepath.Join("bin", sh.SubDir())
1883 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001884 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 af.symlinks = sh.Symlinks()
1886 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001887}
1888
Jooyung Han58f26ab2019-12-18 15:34:32 +09001889// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1890type javaLibrary interface {
1891 android.Module
1892 java.Dependency
1893}
1894
1895func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001896 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001897 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001898 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1899 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1900 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001901}
1902
Jiyong Park1833cef2019-12-13 13:28:36 +09001903func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1905 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001906 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001907}
1908
atrost6e126252020-01-27 17:01:16 +00001909func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1910 dirInApex := filepath.Join("etc", config.SubDir())
1911 fileToCopy := config.CompatConfig()
1912 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1913}
1914
Jiyong Park1833cef2019-12-13 13:28:36 +09001915func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 android.Module
1917 Privileged() bool
1918 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001919 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001920 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001921}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001922 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001923 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001924 appDir = "priv-app"
1925 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001926 dirInApex := filepath.Join(appDir, pkgName)
1927 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001928 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1929 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001930 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001931
1932 if app, ok := aapp.(interface {
1933 OverriddenManifestPackageName() string
1934 }); ok {
1935 af.overriddenPackageName = app.OverriddenManifestPackageName()
1936 }
Jiyong Park618922e2020-01-08 13:35:43 +09001937 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001938}
1939
Roland Levillain935639d2019-08-13 14:55:28 +01001940// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1941type flattenedApexContext struct {
1942 android.ModuleContext
1943}
1944
1945func (c *flattenedApexContext) InstallBypassMake() bool {
1946 return true
1947}
1948
Jiyong Park201cedd2020-02-07 17:25:49 +09001949// Visit dependencies that contributes to the payload of this APEX
1950func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1951 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Parkfa899442020-01-31 02:49:53 +09001952 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1953 am, ok := child.(android.ApexModule)
1954 if !ok || !am.CanHaveApexVariants() {
1955 return false
1956 }
1957
1958 // Check for the direct dependencies that contribute to the payload
1959 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1960 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001961 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001962 return true
1963 }
1964 return false
1965 }
1966
1967 // Check for the indirect dependencies if it is considered as part of the APEX
1968 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001969 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001970 return true
1971 }
1972
Jiyong Park201cedd2020-02-07 17:25:49 +09001973 do(ctx, parent, am, true /* externalDep */)
1974
Jiyong Parkfa899442020-01-31 02:49:53 +09001975 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1976 return false
1977 })
1978}
1979
Jiyong Park201cedd2020-02-07 17:25:49 +09001980// Ensures that the dependencies are marked as available for this APEX
1981func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1982 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1983 if ctx.Host() || a.testApex || a.vndkApex {
1984 return
1985 }
1986
1987 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1988 apexName := ctx.ModuleName()
1989 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
1990 return
1991 }
1992 ctx.ModuleErrorf("requires %q that is not available for the APEX.", to.Name())
1993 })
1994}
1995
Jiyong Park678c8812020-02-07 17:25:49 +09001996// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1997func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1998 a.depInfos = make(map[string]depInfo)
1999 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2000 if from.Name() == to.Name() {
2001 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2002 return
2003 }
2004
2005 if info, exists := a.depInfos[to.Name()]; exists {
2006 if !android.InList(from.Name(), info.from) {
2007 info.from = append(info.from, from.Name())
2008 }
2009 info.isExternal = info.isExternal && externalDep
2010 a.depInfos[to.Name()] = info
2011 } else {
2012 a.depInfos[to.Name()] = depInfo{
2013 to: to.Name(),
2014 from: []string{from.Name()},
2015 isExternal: externalDep,
2016 }
2017 }
2018 })
2019}
2020
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002021func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002022 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2023 switch a.properties.ApexType {
2024 case imageApex:
2025 if buildFlattenedAsDefault {
2026 a.suffix = imageApexSuffix
2027 } else {
2028 a.suffix = ""
2029 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002030
2031 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002032 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002033 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002034 }
2035 case zipApex:
2036 if proptools.String(a.properties.Payload_type) == "zip" {
2037 a.suffix = ""
2038 a.primaryApexType = true
2039 } else {
2040 a.suffix = zipApexSuffix
2041 }
2042 case flattenedApex:
2043 if buildFlattenedAsDefault {
2044 a.suffix = ""
2045 a.primaryApexType = true
2046 } else {
2047 a.suffix = flattenedSuffix
2048 }
Alex Light5098a612018-11-29 17:12:15 -08002049 }
2050
Roland Levillain630846d2019-06-26 12:48:34 +01002051 if len(a.properties.Tests) > 0 && !a.testApex {
2052 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2053 return
2054 }
2055
Jiyong Parkfa899442020-01-31 02:49:53 +09002056 a.checkApexAvailability(ctx)
2057
Jiyong Park678c8812020-02-07 17:25:49 +09002058 a.collectDepsInfo(ctx)
2059
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002060 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2061
Jooyung Hane1633032019-08-01 17:41:43 +09002062 // native lib dependencies
2063 var provideNativeLibs []string
2064 var requireNativeLibs []string
2065
Jooyung Han5c998b92019-06-27 11:30:33 +09002066 // Check if "uses" requirements are met with dependent apexBundles
2067 var providedNativeSharedLibs []string
2068 useVendor := proptools.Bool(a.properties.Use_vendor)
2069 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2070 if ctx.OtherModuleDependencyTag(m) != usesTag {
2071 return
2072 }
2073 otherName := ctx.OtherModuleName(m)
2074 other, ok := m.(*apexBundle)
2075 if !ok {
2076 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2077 return
2078 }
2079 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2080 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2081 return
2082 }
2083 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2084 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2085 return
2086 }
2087 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2088 })
2089
Jiyong Parkf653b052019-11-18 15:39:01 +09002090 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002091 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002092 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002093 depTag := ctx.OtherModuleDependencyTag(child)
2094 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002095 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002096 switch depTag {
2097 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002098 if c, ok := child.(*cc.Module); ok {
2099 // bootstrap bionic libs are treated as provided by system
2100 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2101 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002102 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002103 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002104 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002105 } else {
2106 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002107 }
2108 case executableTag:
2109 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002110 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002111 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002112 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002113 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002114 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002115 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002116 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002118 } else {
Alex Light778127a2019-02-27 14:19:50 -08002119 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 +09002120 }
2121 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002122 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002123 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002124 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002125 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2126 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002127 filesInfo = append(filesInfo, af)
2128 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002129 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002130 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2131 af := apexFileForJavaLibrary(ctx, sdkLib)
2132 if !af.Ok() {
2133 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2134 return false
2135 }
2136 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002137 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002138 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002139 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002140 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002141 case androidAppTag:
2142 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2143 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002144 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002145 return true // track transitive dependencies
2146 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002147 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002148 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2149 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002150 } else {
2151 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2152 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002153 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002154 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002155 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002156 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2157 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002158 } else {
atrost6e126252020-01-27 17:01:16 +00002159 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002160 }
Roland Levillain630846d2019-06-26 12:48:34 +01002161 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002162 if ccTest, ok := child.(*cc.Module); ok {
2163 if ccTest.IsTestPerSrcAllTestsVariation() {
2164 // Multiple-output test module (where `test_per_src: true`).
2165 //
2166 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2167 // We do not add this variation to `filesInfo`, as it has no output;
2168 // however, we do add the other variations of this module as indirect
2169 // dependencies (see below).
2170 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002171 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002172 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002173 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002174 af.class = nativeTest
2175 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002176 }
Roland Levillain630846d2019-06-26 12:48:34 +01002177 } else {
2178 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2179 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002180 case keyTag:
2181 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002182 a.private_key_file = key.private_key_file
2183 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002184 } else {
2185 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002186 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002187 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002188 case certificateTag:
2189 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002190 a.container_certificate_file = dep.Certificate.Pem
2191 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002192 } else {
2193 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2194 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002195 case android.PrebuiltDepTag:
2196 // If the prebuilt is force disabled, remember to delete the prebuilt file
2197 // that might have been installed in the previous builds
2198 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2199 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2200 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002201 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002202 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002203 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002204 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002205 // We cannot use a switch statement on `depTag` here as the checked
2206 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002207 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002208 if cc, ok := child.(*cc.Module); ok {
2209 if android.InList(cc.Name(), providedNativeSharedLibs) {
2210 // If we're using a shared library which is provided from other APEX,
2211 // don't include it in this APEX
2212 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002213 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002214 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002215 // If the dependency is a stubs lib, don't include it in this APEX,
2216 // but make sure that the lib is installed on the device.
2217 // In case no APEX is having the lib, the lib is installed to the system
2218 // partition.
2219 //
2220 // Always include if we are a host-apex however since those won't have any
2221 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002222 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2223 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002224 }
Jooyung Hane1633032019-08-01 17:41:43 +09002225 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002226 // Don't track further
2227 return false
2228 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002229 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002230 af.transitiveDep = true
2231 filesInfo = append(filesInfo, af)
2232 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002233 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002234 } else if cc.IsTestPerSrcDepTag(depTag) {
2235 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002236 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002237 // Handle modules created as `test_per_src` variations of a single test module:
2238 // use the name of the generated test binary (`fileToCopy`) instead of the name
2239 // of the original test module (`depName`, shared by all `test_per_src`
2240 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002241 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002242 // these are not considered transitive dep
2243 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002244 filesInfo = append(filesInfo, af)
2245 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002246 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002247 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002248 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2249 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002250 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2251 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2252 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2253 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002254 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002255 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002256 }
2257 }
2258 }
2259 return false
2260 })
2261
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002262 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2263 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2264 // via the global boot image config.
2265 if a.artApex {
2266 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2267 dirInApex := filepath.Join("javalib", arch.String())
2268 for _, f := range files {
2269 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002270 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002271 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002272 }
2273 }
2274 }
2275
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002276 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002277 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2278 return
2279 }
2280
Jiyong Park8fd61922018-11-08 02:50:25 +09002281 // remove duplicates in filesInfo
2282 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002283 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002284 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002285 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002286 if e, ok := encountered[dest]; !ok {
2287 encountered[dest] = f
2288 } else {
2289 // If a module is directly included and also transitively depended on
2290 // consider it as directly included.
2291 e.transitiveDep = e.transitiveDep && f.transitiveDep
2292 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002293 }
2294 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002295 var result []apexFile
2296 for _, v := range encountered {
2297 result = append(result, v)
2298 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002299 return result
2300 }
2301 filesInfo = removeDup(filesInfo)
2302
2303 // to have consistent build rules
2304 sort.Slice(filesInfo, func(i, j int) bool {
2305 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2306 })
2307
Jiyong Park8fd61922018-11-08 02:50:25 +09002308 a.installDir = android.PathForModuleInstall(ctx, "apex")
2309 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002310
Jooyung Han54aca7b2019-11-20 02:26:02 +09002311 if a.properties.ApexType != zipApex {
2312 if a.properties.File_contexts == nil {
2313 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2314 } else {
2315 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2316 if a.Platform() {
2317 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2318 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2319 }
2320 }
2321 }
2322 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2323 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2324 return
2325 }
2326 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002327 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2328 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2329 // the same library in the system partition, thus effectively sharing the same libraries
2330 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2331 // in the APEX.
2332 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2333 a.installable() &&
2334 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002335
Jiyong Park9d677202020-02-19 16:29:35 +09002336 // We don't need the optimization for updatable APEXes, as it might give false signal
2337 // to the system health when the APEXes are still bundled (b/149805758)
2338 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2339 a.linkToSystemLib = false
2340 }
2341
Jiyong Park9b964182020-02-26 18:27:19 +09002342 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2343 if ctx.Host() {
2344 a.linkToSystemLib = false
2345 }
2346
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002347 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002348 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2349
2350 a.setCertificateAndPrivateKey(ctx)
2351 if a.properties.ApexType == flattenedApex {
2352 a.buildFlattenedApex(ctx)
2353 } else {
2354 a.buildUnflattenedApex(ctx)
2355 }
2356
Jooyung Han002ab682020-01-08 01:57:58 +09002357 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002358
2359 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002360}
2361
Jiyong Parkfa899442020-01-31 02:49:53 +09002362func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002363 key := apex
2364 key = strings.Replace(key, "test_", "", 1)
2365 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2366 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2367
2368 moduleName := module.Name()
Jiyong Parkfa899442020-01-31 02:49:53 +09002369 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2370 // system. Trim the prefix for the check since they are confusing
2371 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2372 if strings.HasPrefix(moduleName, "libclang_rt.") {
2373 // This module has many arch variants that depend on the product being built.
2374 // We don't want to list them all
2375 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002376 }
2377
2378 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2379 return true
2380 }
2381
Jiyong Parkfa899442020-01-31 02:49:53 +09002382 key = "//any"
2383 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2384 return true
2385 }
2386
Anton Hansson5053c292020-01-10 15:12:39 +00002387 return false
2388}
2389
Jooyung Han344d5432019-08-23 11:17:39 +09002390func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002391 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002392 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002393 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002394 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002395 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002396 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2397 })
Alex Light5098a612018-11-29 17:12:15 -08002398 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002399 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002400 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002401 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002402 return module
2403}
Jiyong Park30ca9372019-02-07 16:27:23 +09002404
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002405func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002406 bundle := newApexBundle()
2407 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002408 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002409 return bundle
2410}
2411
Jiyong Parkfce0b422020-02-11 03:56:06 +09002412// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2413// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002414func testApexBundleFactory() android.Module {
2415 bundle := newApexBundle()
2416 bundle.testApex = true
2417 return bundle
2418}
2419
Jiyong Parkfce0b422020-02-11 03:56:06 +09002420// apex packages other modules into an APEX file which is a packaging format for system-level
2421// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002422func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002423 return newApexBundle()
2424}
2425
Jiyong Park30ca9372019-02-07 16:27:23 +09002426//
2427// Defaults
2428//
2429type Defaults struct {
2430 android.ModuleBase
2431 android.DefaultsModuleBase
2432}
2433
Jiyong Park30ca9372019-02-07 16:27:23 +09002434func defaultsFactory() android.Module {
2435 return DefaultsFactory()
2436}
2437
2438func DefaultsFactory(props ...interface{}) android.Module {
2439 module := &Defaults{}
2440
2441 module.AddProperties(props...)
2442 module.AddProperties(
2443 &apexBundleProperties{},
2444 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002445 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002446 )
2447
2448 android.InitDefaultsModule(module)
2449 return module
2450}
Jiyong Park5d790c32019-11-15 18:40:32 +09002451
2452//
2453// OverrideApex
2454//
2455type OverrideApex struct {
2456 android.ModuleBase
2457 android.OverrideModuleBase
2458}
2459
2460func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2461 // All the overrides happen in the base module.
2462}
2463
2464// override_apex is used to create an apex module based on another apex module
2465// by overriding some of its properties.
2466func overrideApexFactory() android.Module {
2467 m := &OverrideApex{}
2468 m.AddProperties(&overridableProperties{})
2469
2470 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2471 android.InitOverrideModule(m)
2472 return m
2473}