blob: ee6f93ae3867a73c29941398de919f3f50da5836 [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 //
Anton Hansson5053c292020-01-10 15:12:39 +0000116 m["com.android.art"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900117 "art_cmdlineparser_headers",
118 "art_disassembler_headers",
119 "art_libartbase_headers",
120 "bcm_object",
121 "bionic_libc_platform_headers",
122 "core-repackaged-icu4j",
123 "cpp-define-generator-asm-support",
124 "cpp-define-generator-definitions",
125 "crtbegin_dynamic",
126 "crtbegin_dynamic1",
127 "crtbegin_so1",
128 "crtbrand",
129 "conscrypt.module.intra.core.api.stubs",
130 "dex2oat_headers",
131 "dt_fd_forward_export",
132 "fmtlib",
133 "icu4c_extra_headers",
Anton Hanssonf17f2482020-01-16 09:11:57 +0000134 "jacocoagent",
Jiyong Parkfa899442020-01-31 02:49:53 +0900135 "javavm_headers",
136 "jni_platform_headers",
137 "libPlatformProperties",
138 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000139 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libandroidicuinit",
141 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000142 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900143 "libasync_safe",
Anton Hansson5053c292020-01-10 15:12:39 +0000144 "libbacktrace",
145 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900146 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000147 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900148 "libc++_static",
149 "libc++abi",
150 "libc++demangle",
151 "libc_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000152 "libcrypto",
Jiyong Parkfa899442020-01-31 02:49:53 +0900153 "libdexfile_all_headers",
154 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000155 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900156 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000157 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900158 "libfdlibm",
159 "libgtest_prod",
160 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000161 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "libicuuc_headers",
163 "libicuuc_stubdata",
164 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900165 "liblog_headers",
166 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "liblzma",
168 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900169 "libnativebridge-headers",
170 "libnativehelper_header_only",
171 "libnativeloader-headers",
172 "libnpt_headers",
173 "libopenjdkjvmti_headers",
174 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000175 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900176 "libprotobuf-cpp-lite",
177 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000178 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900179 "libv8",
180 "libv8base",
181 "libv8gen",
182 "libv8platform",
183 "libv8sampler",
184 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000185 "libvixl",
186 "libvixld",
187 "libz",
188 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900189 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 }
191 //
192 // Module separator
193 //
194 m["com.android.bluetooth.updatable"] = []string{
195 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000196 "android.hardware.bluetooth.a2dp@1.0",
197 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900198 "android.hardware.bluetooth@1.0",
199 "android.hardware.bluetooth@1.1",
200 "android.hardware.graphics.bufferqueue@1.0",
201 "android.hardware.graphics.bufferqueue@2.0",
202 "android.hardware.graphics.common@1.0",
203 "android.hardware.graphics.common@1.1",
204 "android.hardware.graphics.common@1.2",
205 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000206 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900207 "android.hidl.token@1.0",
208 "android.hidl.token@1.0-utils",
209 "avrcp-target-service",
210 "avrcp_headers",
211 "bcm_object",
212 "bluetooth-protos-lite",
213 "bluetooth.mapsapi",
214 "com.android.vcard",
215 "fmtlib",
216 "guava",
217 "internal_include_headers",
218 "lib-bt-packets",
219 "lib-bt-packets-avrcp",
220 "lib-bt-packets-base",
221 "libFraunhoferAAC",
222 "libaudio-a2dp-hw-utils",
223 "libaudio-hearing-aid-hw-utils",
224 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000225 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900226 "libbase_headers",
227 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000228 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900229 "libbluetooth-types",
230 "libbluetooth-types-header",
231 "libbluetooth_gd",
232 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000233 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900234 "libbt-audio-hal-interface",
235 "libbt-bta",
236 "libbt-common",
237 "libbt-hci",
238 "libbt-platform-protos-lite",
239 "libbt-protos-lite",
240 "libbt-sbc-decoder",
241 "libbt-sbc-encoder",
242 "libbt-stack",
243 "libbt-utils",
244 "libbtcore",
245 "libbtdevice",
246 "libbte",
247 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000248 "libc++",
249 "libchrome",
250 "libcrypto",
251 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900252 "libcutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000253 "libevent",
254 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900255 "libg722codec",
256 "libgtest_prod",
257 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000258 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900259 "libhidlbase-impl-internal",
260 "libhidltransport-impl-internal",
261 "libhwbinder-impl-internal",
262 "libjsoncpp",
263 "liblog_headers",
264 "libmedia_headers",
265 "libmodpb64",
266 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000267 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000269 "libprotobuf-cpp-lite",
Jiyong Parkfa899442020-01-31 02:49:53 +0900270 "libprotobuf-java-lite",
271 "libprotobuf-java-micro",
272 "libstagefright_foundation_headers",
273 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000274 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900275 "libstatssocket",
276 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000277 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900278 "libudrv-uipc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900279 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000280 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900281 "media_plugin_headers",
282 "sap-api-java-static",
283 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000284 }
285 //
286 // Module separator
287 //
288 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
289 //
290 // Module separator
291 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 m["com.android.conscrypt"] = []string{
293 "bcm_object",
294 "boringssl_self_test",
295 "libc++",
296 "libcrypto",
297 "libnativehelper_header_only",
298 "libssl",
299 }
Anton Hansson5053c292020-01-10 15:12:39 +0000300 //
301 // Module separator
302 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900303 m["com.android.extservices"] = []string{
304 "flatbuffer_headers",
305 "liblua",
306 "libtextclassifier",
307 "libtextclassifier_hash_static",
308 "libtflite_static",
309 "libutf",
310 "libz_current",
311 "tensorflow_headers",
312 }
313 //
314 // Module separator
315 //
316 m["com.android.cronet"] = []string{
317 "cronet_impl_common_java",
318 "cronet_impl_native_java",
319 "cronet_impl_platform_java",
320 "libcronet.80.0.3986.0",
321 "org.chromium.net.cronet",
322 "prebuilt_libcronet.80.0.3986.0",
323 }
324 //
325 // Module separator
326 //
327 m["com.android.neuralnetworks"] = []string{
328 "android.hardware.neuralnetworks@1.0",
329 "android.hardware.neuralnetworks@1.1",
330 "android.hardware.neuralnetworks@1.2",
331 "android.hardware.neuralnetworks@1.3",
332 "android.hidl.allocator@1.0",
333 "android.hidl.memory.token@1.0",
334 "android.hidl.memory@1.0",
335 "android.hidl.safe_union@1.0",
336 "bcm_object",
337 "fmtlib",
338 "gemmlowp_headers",
339 "libarect",
340 "libbacktrace_headers",
341 "libbase",
342 "libbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900343 "libbuildversion",
344 "libc++",
345 "libcrypto",
346 "libcrypto_static",
347 "libcutils",
348 "libcutils_headers",
349 "libeigen",
350 "libfmq",
351 "libhidlbase",
352 "libhidlbase-impl-internal",
353 "libhidlmemory",
354 "libhidltransport-impl-internal",
355 "libhwbinder-impl-internal",
356 "libjsoncpp",
357 "liblog_headers",
358 "libmath",
359 "libneuralnetworks_common",
360 "libneuralnetworks_headers",
361 "libprocessgroup",
362 "libprocessgroup_headers",
363 "libprocpartition",
364 "libsync",
365 "libsystem_headers",
366 "libtextclassifier_hash",
367 "libtextclassifier_hash_headers",
368 "libtextclassifier_hash_static",
369 "libtflite_kernel_utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900370 "libutils_headers",
371 "philox_random",
372 "philox_random_headers",
373 "tensorflow_headers",
374 }
Anton Hansson5053c292020-01-10 15:12:39 +0000375 //
376 // Module separator
377 //
Anton Hansson5053c292020-01-10 15:12:39 +0000378 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900379 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000380 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900381 "android.hardware.cas@1.0",
382 "android.hardware.configstore-utils",
383 "android.hardware.configstore@1.0",
384 "android.hardware.configstore@1.1",
385 "android.hardware.graphics.allocator@2.0",
386 "android.hardware.graphics.allocator@3.0",
387 "android.hardware.graphics.bufferqueue@1.0",
388 "android.hardware.graphics.bufferqueue@2.0",
389 "android.hardware.graphics.common@1.0",
390 "android.hardware.graphics.common@1.1",
391 "android.hardware.graphics.common@1.2",
392 "android.hardware.graphics.mapper@2.0",
393 "android.hardware.graphics.mapper@2.1",
394 "android.hardware.graphics.mapper@3.0",
395 "android.hardware.media.omx@1.0",
396 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000397 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900399 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000400 "android.hidl.token@1.0",
401 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900402 "bcm_object",
403 "bionic_libc_platform_headers",
404 "fmtlib",
405 "gl_headers",
406 "libEGL",
407 "libEGL_blobCache",
408 "libEGL_getProcAddress",
409 "libFLAC",
410 "libFLAC-config",
411 "libFLAC-headers",
412 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000413 "libaacextractor",
414 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "libarect",
416 "libasync_safe",
417 "libaudio_system_headers",
418 "libaudioclient",
419 "libaudioclient_headers",
420 "libaudiofoundation",
421 "libaudiofoundation_headers",
422 "libaudiomanager",
423 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000424 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900425 "libaudioutils_fixedfft",
426 "libbacktrace",
427 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000428 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "libbase_headers",
430 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900431 "libbluetooth-types-header",
432 "libbufferhub",
433 "libbufferhub_headers",
434 "libbufferhubqueue",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libc_headers",
437 "libc_malloc_debug_backtrace",
438 "libcamera_client",
439 "libcamera_metadata",
Anton Hansson5053c292020-01-10 15:12:39 +0000440 "libcrypto",
441 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900442 "libcutils_headers",
443 "libdexfile_external_headers",
444 "libdexfile_support",
445 "libdvr_headers",
446 "libexpat",
447 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000448 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900449 "libgrallocusage",
450 "libgraphicsenv",
451 "libgui",
452 "libgui_headers",
453 "libhardware_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000454 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000456 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900457 "libhidltransport-impl-internal",
458 "libhwbinder-impl-internal",
459 "libinput",
460 "libjsoncpp",
461 "liblog_headers",
462 "liblzma",
463 "libmath",
464 "libmedia",
465 "libmedia_codeclist",
466 "libmedia_headers",
467 "libmedia_helper",
468 "libmedia_helper_headers",
469 "libmedia_midiiowrapper",
470 "libmedia_omx",
471 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000472 "libmidiextractor",
473 "libmkvextractor",
474 "libmp3extractor",
475 "libmp4extractor",
476 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900477 "libnativebase_headers",
478 "libnativebridge-headers",
479 "libnativebridge_lazy",
480 "libnativeloader-headers",
481 "libnativeloader_lazy",
482 "libnativewindow_headers",
483 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000484 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900485 "libpackagelistparser",
486 "libpcre2",
487 "libpdx",
488 "libpdx_default_transport",
489 "libpdx_headers",
490 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000491 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libprocessgroup_headers",
493 "libprocinfo",
494 "libselinux",
495 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000496 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900497 "libspeexresampler",
498 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000499 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libstagefright_flacdec",
501 "libstagefright_foundation",
502 "libstagefright_foundation_headers",
503 "libstagefright_foundation_without_imemory",
504 "libstagefright_headers",
505 "libstagefright_id3",
506 "libstagefright_metadatautils",
507 "libstagefright_mpeg2extractor",
508 "libstagefright_mpeg2support",
509 "libsync",
510 "libsystem_headers",
511 "libui",
512 "libui_headers",
513 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900514 "libutils_headers",
515 "libvibrator",
516 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000517 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900518 "libwebm",
519 "media_ndk_headers",
520 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000521 "updatable-media",
522 }
523 //
524 // Module separator
525 //
526 m["com.android.media.swcodec"] = []string{
527 "android.frameworks.bufferhub@1.0",
528 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900529 "android.hardware.configstore-utils",
530 "android.hardware.configstore@1.0",
531 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000532 "android.hardware.graphics.allocator@2.0",
533 "android.hardware.graphics.allocator@3.0",
534 "android.hardware.graphics.allocator@4.0",
535 "android.hardware.graphics.bufferqueue@1.0",
536 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000538 "android.hardware.graphics.common@1.0",
539 "android.hardware.graphics.common@1.1",
540 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000541 "android.hardware.graphics.mapper@2.0",
542 "android.hardware.graphics.mapper@2.1",
543 "android.hardware.graphics.mapper@3.0",
544 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000545 "android.hardware.media.bufferpool@2.0",
546 "android.hardware.media.c2@1.0",
547 "android.hardware.media.c2@1.1",
548 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "android.hardware.media@1.0",
550 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000551 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900552 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000553 "android.hidl.safe_union@1.0",
554 "android.hidl.token@1.0",
555 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900556 "fmtlib",
557 "libEGL",
558 "libFLAC",
559 "libFLAC-config",
560 "libFLAC-headers",
561 "libFraunhoferAAC",
562 "libarect",
563 "libasync_safe",
564 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000565 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900566 "libaudioutils",
567 "libaudioutils_fixedfft",
568 "libavcdec",
569 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000570 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900571 "libavservices_minijail",
572 "libbacktrace",
573 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000574 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "libbase_headers",
576 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900577 "libbluetooth-types-header",
578 "libbufferhub_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000579 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900580 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000581 "libcap",
582 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900583 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000584 "libcodec2_hidl@1.0",
585 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900586 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000587 "libcodec2_soft_aacdec",
588 "libcodec2_soft_aacenc",
589 "libcodec2_soft_amrnbdec",
590 "libcodec2_soft_amrnbenc",
591 "libcodec2_soft_amrwbdec",
592 "libcodec2_soft_amrwbenc",
593 "libcodec2_soft_av1dec_gav1",
594 "libcodec2_soft_avcdec",
595 "libcodec2_soft_avcenc",
596 "libcodec2_soft_common",
597 "libcodec2_soft_flacdec",
598 "libcodec2_soft_flacenc",
599 "libcodec2_soft_g711alawdec",
600 "libcodec2_soft_g711mlawdec",
601 "libcodec2_soft_gsmdec",
602 "libcodec2_soft_h263dec",
603 "libcodec2_soft_h263enc",
604 "libcodec2_soft_hevcdec",
605 "libcodec2_soft_hevcenc",
606 "libcodec2_soft_mp3dec",
607 "libcodec2_soft_mpeg2dec",
608 "libcodec2_soft_mpeg4dec",
609 "libcodec2_soft_mpeg4enc",
610 "libcodec2_soft_opusdec",
611 "libcodec2_soft_opusenc",
612 "libcodec2_soft_rawdec",
613 "libcodec2_soft_vorbisdec",
614 "libcodec2_soft_vp8dec",
615 "libcodec2_soft_vp8enc",
616 "libcodec2_soft_vp9dec",
617 "libcodec2_soft_vp9enc",
618 "libcodec2_vndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000619 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900620 "libcutils_headers",
621 "libdexfile_support",
622 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000623 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900624 "libfmq",
625 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000626 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900627 "libgrallocusage",
628 "libgraphicsenv",
629 "libgsm",
630 "libgui_bufferqueue_static",
631 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000632 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900633 "libhardware_headers",
634 "libhevcdec",
635 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000636 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000638 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900639 "libhidltransport-impl-internal",
640 "libhwbinder-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000641 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "libjpeg",
643 "libjsoncpp",
644 "liblog_headers",
645 "liblzma",
646 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000647 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900648 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000649 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900650 "libminijail_gen_constants",
651 "libminijail_gen_constants_obj",
652 "libminijail_gen_syscall",
653 "libminijail_gen_syscall_obj",
654 "libminijail_generated",
655 "libmpeg2dec",
656 "libnativebase_headers",
657 "libnativebridge_lazy",
658 "libnativeloader_lazy",
659 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000660 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900661 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000662 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900663 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000664 "libscudo_wrapper",
665 "libsfplugin_ccodec_utils",
666 "libspeexresampler",
667 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900668 "libstagefright_amrnbdec",
669 "libstagefright_amrnbenc",
670 "libstagefright_amrwbdec",
671 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000672 "libstagefright_bufferpool@2.0.1",
673 "libstagefright_bufferqueue_helper",
674 "libstagefright_enc_common",
675 "libstagefright_flacdec",
676 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "libstagefright_foundation_headers",
678 "libstagefright_headers",
679 "libstagefright_m4vh263dec",
680 "libstagefright_m4vh263enc",
681 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000682 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900683 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000684 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900685 "libui_headers",
686 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000688 "libvorbisidec",
689 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "libyuv",
691 "libyuv_static",
692 "media_ndk_headers",
693 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000694 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000695 }
696 //
697 // Module separator
698 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 m["com.android.mediaprovider"] = []string{
700 "MediaProvider",
701 "MediaProviderGoogle",
702 "fmtlib_ndk",
703 "guava",
704 "libbase_ndk",
705 "libfuse",
706 "libfuse_jni",
707 "libnativehelper_header_only",
708 }
709 //
710 // Module separator
711 //
712 m["com.android.permission"] = []string{
713 "androidx.annotation_annotation",
714 "androidx.annotation_annotation-nodeps",
715 "androidx.lifecycle_lifecycle-common",
716 "androidx.lifecycle_lifecycle-common-java8",
717 "androidx.lifecycle_lifecycle-common-java8-nodeps",
718 "androidx.lifecycle_lifecycle-common-nodeps",
719 "kotlin-annotations",
720 "kotlin-stdlib",
721 "kotlin-stdlib-jdk7",
722 "kotlin-stdlib-jdk8",
723 "kotlinx-coroutines-android",
724 "kotlinx-coroutines-android-nodeps",
725 "kotlinx-coroutines-core",
726 "kotlinx-coroutines-core-nodeps",
727 "libprotobuf-java-lite",
728 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900729 "GooglePermissionController",
730 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900731 }
Anton Hansson5053c292020-01-10 15:12:39 +0000732 //
733 // Module separator
734 //
Anton Hansson5053c292020-01-10 15:12:39 +0000735 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900736 "bionic_libc_platform_headers",
737 "fmtlib",
738 "libarm-optimized-routines-math",
739 "libasync_safe",
740 "libasync_safe_headers",
741 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000742 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900743 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000744 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900745 "libc_aeabi",
746 "libc_bionic",
747 "libc_bionic_ndk",
748 "libc_bootstrap",
749 "libc_common",
750 "libc_common_shared",
751 "libc_common_static",
752 "libc_dns",
753 "libc_dynamic_dispatch",
754 "libc_fortify",
755 "libc_freebsd",
756 "libc_freebsd_large_stack",
757 "libc_gdtoa",
758 "libc_headers",
759 "libc_init_dynamic",
760 "libc_init_static",
761 "libc_jemalloc_wrapper",
762 "libc_netbsd",
763 "libc_nomalloc",
764 "libc_nopthread",
765 "libc_openbsd",
766 "libc_openbsd_large_stack",
767 "libc_openbsd_ndk",
768 "libc_pthread",
769 "libc_static_dispatch",
770 "libc_syscalls",
771 "libc_tzcode",
772 "libc_unwind_static",
773 "libcutils",
774 "libcutils_headers",
775 "libdebuggerd",
776 "libdebuggerd_common_headers",
777 "libdebuggerd_handler_core",
778 "libdebuggerd_handler_fallback",
779 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000780 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900781 "libdexfile_support_static",
782 "libgtest_prod",
783 "libjemalloc5",
784 "liblinker_main",
785 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900786 "liblog_headers",
787 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000788 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900789 "libprocessgroup_headers",
790 "libprocinfo",
791 "libpropertyinfoparser",
792 "libscudo",
793 "libstdc++",
794 "libsystem_headers",
795 "libsystemproperties",
796 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000797 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900798 "libutils_headers",
799 "libz",
800 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000801 }
802 //
803 // Module separator
804 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 m["com.android.resolv"] = []string{
806 "bcm_object",
807 "dnsresolver_aidl_interface-unstable-ndk_platform",
808 "fmtlib",
809 "libbacktrace_headers",
810 "libbase",
811 "libbase_headers",
812 "libc++",
813 "libcrypto",
814 "libcutils",
815 "libcutils_headers",
816 "libgtest_prod",
817 "libjsoncpp",
Jiyong Parkfa899442020-01-31 02:49:53 +0900818 "liblog_headers",
819 "libnativehelper_header_only",
820 "libnetd_client_headers",
821 "libnetd_resolv",
822 "libnetdutils",
823 "libprocessgroup",
824 "libprocessgroup_headers",
825 "libprotobuf-cpp-lite",
826 "libssl",
827 "libstatslog_resolv",
828 "libstatspush_compat",
829 "libstatssocket",
830 "libstatssocket_headers",
831 "libsystem_headers",
832 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900833 "libutils_headers",
834 "netd_event_listener_interface-ndk_platform",
835 "server_configurable_flags",
836 "stats_proto",
837 }
Anton Hansson5053c292020-01-10 15:12:39 +0000838 //
839 // Module separator
840 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900841 m["com.android.tethering"] = []string{
842 "libbase",
843 "libc++",
844 "libnativehelper_compat_libc++",
845 "android.hardware.tetheroffload.config@1.0",
846 "fmtlib",
847 "libbacktrace_headers",
848 "libbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900849 "libcgrouprc",
850 "libcgrouprc_format",
851 "libcutils",
852 "libcutils_headers",
853 "libhidlbase",
854 "libhidlbase-impl-internal",
855 "libhidltransport-impl-internal",
856 "libhwbinder-impl-internal",
857 "libjsoncpp",
Jiyong Parkfa899442020-01-31 02:49:53 +0900858 "liblog_headers",
859 "libprocessgroup",
860 "libprocessgroup_headers",
861 "libsystem_headers",
862 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900863 "libutils_headers",
864 "libvndksupport",
865 "tethering-aidl-interfaces-java",
866 }
Anton Hansson5053c292020-01-10 15:12:39 +0000867 //
868 // Module separator
869 //
870 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900871 "PlatformProperties",
872 "android.hardware.wifi-V1.0-java",
873 "android.hardware.wifi-V1.1-java",
874 "android.hardware.wifi-V1.2-java",
875 "android.hardware.wifi-V1.3-java",
876 "android.hardware.wifi-V1.4-java",
877 "android.hardware.wifi.hostapd-V1.0-java",
878 "android.hardware.wifi.hostapd-V1.1-java",
879 "android.hardware.wifi.hostapd-V1.2-java",
880 "android.hardware.wifi.supplicant-V1.0-java",
881 "android.hardware.wifi.supplicant-V1.1-java",
882 "android.hardware.wifi.supplicant-V1.2-java",
883 "android.hardware.wifi.supplicant-V1.3-java",
884 "android.hidl.base-V1.0-java",
885 "android.hidl.manager-V1.0-java",
886 "android.hidl.manager-V1.1-java",
887 "android.hidl.manager-V1.2-java",
888 "androidx.annotation_annotation",
889 "androidx.annotation_annotation-nodeps",
890 "bouncycastle-unbundled",
891 "dnsresolver_aidl_interface-V2-java",
892 "error_prone_annotations",
893 "ipmemorystore-aidl-interfaces-V3-java",
894 "ipmemorystore-aidl-interfaces-java",
895 "ksoap2",
896 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000897 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900898 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000899 "libc++",
900 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900901 "libcutils_headers",
902 "liblog_headers",
903 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000904 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900905 "libprocessgroup_headers",
906 "libprotobuf-java-lite",
907 "libprotobuf-java-nano",
908 "libsystem_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900909 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000910 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900911 "net-utils-services-common",
912 "netd_aidl_interface-V2-java",
913 "netd_aidl_interface-unstable-java",
914 "netd_event_listener_interface-java",
915 "netlink-client",
916 "networkstack-aidl-interfaces-unstable-java",
917 "networkstack-client",
918 "services.net",
919 "wifi-lite-protos",
920 "wifi-nano-protos",
921 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000922 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900923 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000924 }
925 //
926 // Module separator
927 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900928 m["com.android.sdkext"] = []string{
929 "fmtlib_ndk",
930 "libbase_ndk",
931 "libprotobuf-cpp-lite-ndk",
932 }
933 //
934 // Module separator
935 //
936 m["com.android.os.statsd"] = []string{
937 "libbacktrace_headers",
938 "libbase_headers",
939 "libc++",
940 "libcutils",
941 "libcutils_headers",
942 "liblog_headers",
943 "libprocessgroup_headers",
944 "libstatssocket",
945 "libsystem_headers",
946 "libutils_headers",
947 }
948 //
949 // Module separator
950 //
951 m["//any"] = []string{
952 "crtbegin_dynamic",
953 "crtbegin_dynamic1",
954 "crtbegin_so",
955 "crtbegin_so1",
956 "crtbegin_static",
957 "crtbrand",
958 "crtend_android",
959 "crtend_so",
960 "libatomic",
961 "libc++_static",
962 "libc++abi",
963 "libc++demangle",
964 "libc_headers",
965 "libclang_rt",
966 "libgcc_stripped",
967 "libprofile-clang-extras",
968 "libprofile-clang-extras_ndk",
969 "libprofile-extras",
970 "libprofile-extras_ndk",
971 "libunwind_llvm",
972 "ndk_crtbegin_dynamic.27",
973 "ndk_crtbegin_so.16",
974 "ndk_crtbegin_so.19",
975 "ndk_crtbegin_so.21",
976 "ndk_crtbegin_so.24",
977 "ndk_crtbegin_so.27",
978 "ndk_crtend_android.27",
979 "ndk_crtend_so.16",
980 "ndk_crtend_so.19",
981 "ndk_crtend_so.21",
982 "ndk_crtend_so.24",
983 "ndk_crtend_so.27",
984 "ndk_libandroid_support",
985 "ndk_libc++_static",
986 "ndk_libc++abi",
987 "ndk_libunwind",
988 }
Anton Hansson5053c292020-01-10 15:12:39 +0000989 return m
990}
991
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900992func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900993 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800994 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900995 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900996 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700997 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900998 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900999
Jooyung Han31c470b2019-10-18 16:26:59 +09001000 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001001 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001002
1003 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1004 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1005 sort.Strings(*apexFileContextsInfos)
1006 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1007 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001008}
1009
Jooyung Han31c470b2019-10-18 16:26:59 +09001010func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1011 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1012 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1013}
1014
Jiyong Parkd1063c12019-07-17 20:08:41 +09001015func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001016 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001017 ctx.BottomUp("apex", apexMutator).Parallel()
1018 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1019 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001020}
1021
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001022// Mark the direct and transitive dependencies of apex bundles so that they
1023// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001024func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001025 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001026 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001027 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001028 apexBundles = []android.ApexInfo{{mctx.ModuleName(), proptools.Bool(a.properties.Legacy_android10_support)}}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001029 directDep = true
1030 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001031 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001032 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001034
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001035 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001036 return
1037 }
1038
1039 mctx.VisitDirectDeps(func(child android.Module) {
1040 depName := mctx.OtherModuleName(child)
1041 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1042 (directDep || am.DepIsInSameApex(mctx, child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001043 android.UpdateApexDependency(apexBundles, depName, directDep)
1044 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001045 }
1046 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001047}
1048
1049// Create apex variations if a module is included in APEX(s).
1050func apexMutator(mctx android.BottomUpMutatorContext) {
1051 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001052 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001053 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054 // apex bundle itself is mutated so that it and its modules have same
1055 // apex variant.
1056 apexBundleName := mctx.ModuleName()
1057 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001058 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1059 apexBundleName := o.GetOverriddenModuleName()
1060 if apexBundleName == "" {
1061 mctx.ModuleErrorf("base property is not set")
1062 return
1063 }
1064 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001065 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001066
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001067}
Sundong Ahne9b55722019-09-06 17:37:42 +09001068
Jooyung Han7a78a922019-10-08 21:59:58 +09001069var (
1070 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1071 apexFileContextsInfosMutex sync.Mutex
1072)
1073
1074func apexFileContextsInfos(config android.Config) *[]string {
1075 return config.Once(apexFileContextsInfosKey, func() interface{} {
1076 return &[]string{}
1077 }).(*[]string)
1078}
1079
Jooyung Han54aca7b2019-11-20 02:26:02 +09001080func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001081 apexFileContextsInfosMutex.Lock()
1082 defer apexFileContextsInfosMutex.Unlock()
1083 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001084 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001085}
1086
Sundong Ahne9b55722019-09-06 17:37:42 +09001087func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001088 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001089 var variants []string
1090 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1091 case "image":
1092 variants = append(variants, imageApexType, flattenedApexType)
1093 case "zip":
1094 variants = append(variants, zipApexType)
1095 case "both":
1096 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1097 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001098 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001099 return
1100 }
1101
1102 modules := mctx.CreateLocalVariations(variants...)
1103
1104 for i, v := range variants {
1105 switch v {
1106 case imageApexType:
1107 modules[i].(*apexBundle).properties.ApexType = imageApex
1108 case zipApexType:
1109 modules[i].(*apexBundle).properties.ApexType = zipApex
1110 case flattenedApexType:
1111 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001112 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001113 modules[i].(*apexBundle).MakeAsSystemExt()
1114 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001115 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001116 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001117 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1118 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001119 }
1120}
1121
Jooyung Han5c998b92019-06-27 11:30:33 +09001122func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1123 if ab, ok := mctx.Module().(*apexBundle); ok {
1124 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1125 }
1126}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001127
Jooyung Handc782442019-11-01 03:14:38 +09001128var (
1129 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1130)
1131
1132// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1133// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1134// which may cause compatibility issues. (e.g. libbinder)
1135// Even though libbinder restricts its availability via 'apex_available' property and relies on
1136// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1137// to avoid similar problems.
1138func useVendorWhitelist(config android.Config) []string {
1139 return config.Once(useVendorWhitelistKey, func() interface{} {
1140 return []string{
1141 // swcodec uses "vendor" variants for smaller size
1142 "com.android.media.swcodec",
1143 "test_com.android.media.swcodec",
1144 }
1145 }).([]string)
1146}
1147
1148// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1149// called before the first call to useVendorWhitelist()
1150func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1151 config.Once(useVendorWhitelistKey, func() interface{} {
1152 return whitelist
1153 })
1154}
1155
Alex Light9670d332019-01-29 18:07:33 -08001156type apexNativeDependencies struct {
1157 // List of native libraries
1158 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001159
Alex Light9670d332019-01-29 18:07:33 -08001160 // List of native executables
1161 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001162
Roland Levillain630846d2019-06-26 12:48:34 +01001163 // List of native tests
1164 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001165}
Jooyung Han344d5432019-08-23 11:17:39 +09001166
Alex Light9670d332019-01-29 18:07:33 -08001167type apexMultilibProperties struct {
1168 // Native dependencies whose compile_multilib is "first"
1169 First apexNativeDependencies
1170
1171 // Native dependencies whose compile_multilib is "both"
1172 Both apexNativeDependencies
1173
1174 // Native dependencies whose compile_multilib is "prefer32"
1175 Prefer32 apexNativeDependencies
1176
1177 // Native dependencies whose compile_multilib is "32"
1178 Lib32 apexNativeDependencies
1179
1180 // Native dependencies whose compile_multilib is "64"
1181 Lib64 apexNativeDependencies
1182}
1183
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001184type apexBundleProperties struct {
1185 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001186 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001187 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001188
Jiyong Park40e26a22019-02-08 02:53:06 +09001189 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1190 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001191 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001192
Roland Levillain411c5842019-09-19 16:37:20 +01001193 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1194 // device (/apex/<apex_name>).
1195 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001196 Apex_name *string
1197
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001198 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001199 // For platform APEXes, this should points to a file under /system/sepolicy
1200 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1201 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001202
1203 // List of native shared libs that are embedded inside this APEX bundle
1204 Native_shared_libs []string
1205
Roland Levillain630846d2019-06-26 12:48:34 +01001206 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001207 Binaries []string
1208
1209 // List of java libraries that are embedded inside this APEX bundle
1210 Java_libs []string
1211
1212 // List of prebuilt files that are embedded inside this APEX bundle
1213 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001214
Roland Levillain630846d2019-06-26 12:48:34 +01001215 // List of tests that are embedded inside this APEX bundle
1216 Tests []string
1217
Jiyong Parkff1458f2018-10-12 21:49:38 +09001218 // Name of the apex_key module that provides the private key to sign APEX
1219 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001220
Alex Light5098a612018-11-29 17:12:15 -08001221 // The type of APEX to build. Controls what the APEX payload is. Either
1222 // 'image', 'zip' or 'both'. Default: 'image'.
1223 Payload_type *string
1224
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001225 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1226 // or an android_app_certificate module name in the form ":module".
1227 Certificate *string
1228
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001229 // Whether this APEX is installable to one of the partitions. Default: true.
1230 Installable *bool
1231
Jiyong Parkda6eb592018-12-19 17:12:36 +09001232 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1233 // Default is false.
1234 Use_vendor *bool
1235
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001236 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1237 Ignore_system_library_special_case *bool
1238
Alex Light9670d332019-01-29 18:07:33 -08001239 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001240
Jiyong Parkf97782b2019-02-13 20:28:58 +09001241 // List of sanitizer names that this APEX is enabled for
1242 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001243
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001244 PreventInstall bool `blueprint:"mutated"`
1245
1246 HideFromMake bool `blueprint:"mutated"`
1247
Jooyung Han5c998b92019-06-27 11:30:33 +09001248 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1249 Provide_cpp_shared_libs *bool
1250
1251 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1252 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001253
1254 // A txt file containing list of files that are whitelisted to be included in this APEX.
1255 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001256
Sundong Ahnabb64432019-10-22 13:58:29 +09001257 // package format of this apex variant; could be non-flattened, flattened, or zip.
1258 // imageApex, zipApex or flattened
1259 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001260
Jiyong Parkd1063c12019-07-17 20:08:41 +09001261 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1262 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1263 // is implied. This value affects all modules included in this APEX. In other words, they are
1264 // also built with the SDKs specified here.
1265 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001266
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001267 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1268 // Should be only used in tests#.
1269 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001270
1271 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1272 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1273 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001274
1275 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001276
1277 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1278 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1279 // like symlinking to the system libs. Default is false.
1280 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001281
1282 // The minimum SDK version that this apex must be compatible with.
1283 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001284}
1285
1286type apexTargetBundleProperties struct {
1287 Target struct {
1288 // Multilib properties only for android.
1289 Android struct {
1290 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001291 }
Jooyung Han344d5432019-08-23 11:17:39 +09001292
Alex Light9670d332019-01-29 18:07:33 -08001293 // Multilib properties only for host.
1294 Host struct {
1295 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001296 }
Jooyung Han344d5432019-08-23 11:17:39 +09001297
Alex Light9670d332019-01-29 18:07:33 -08001298 // Multilib properties only for host linux_bionic.
1299 Linux_bionic struct {
1300 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001301 }
Jooyung Han344d5432019-08-23 11:17:39 +09001302
Alex Light9670d332019-01-29 18:07:33 -08001303 // Multilib properties only for host linux_glibc.
1304 Linux_glibc struct {
1305 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001306 }
1307 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001308}
1309
Jiyong Park5d790c32019-11-15 18:40:32 +09001310type overridableProperties struct {
1311 // List of APKs to package inside APEX
1312 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001313
1314 // Names of modules to be overridden. Listed modules can only be other binaries
1315 // (in Make or Soong).
1316 // This does not completely prevent installation of the overridden binaries, but if both
1317 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1318 // from PRODUCT_PACKAGES.
1319 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001320
1321 // Logging Parent value
1322 Logging_parent string
Jiyong Park5d790c32019-11-15 18:40:32 +09001323}
1324
Alex Light5098a612018-11-29 17:12:15 -08001325type apexPackaging int
1326
1327const (
1328 imageApex apexPackaging = iota
1329 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001330 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001331)
1332
Sundong Ahnabb64432019-10-22 13:58:29 +09001333// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001334func (a apexPackaging) suffix() string {
1335 switch a {
1336 case imageApex:
1337 return imageApexSuffix
1338 case zipApex:
1339 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001340 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001341 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001342 }
1343}
1344
1345func (a apexPackaging) name() string {
1346 switch a {
1347 case imageApex:
1348 return imageApexType
1349 case zipApex:
1350 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001351 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001352 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001353 }
1354}
1355
Jiyong Parkf653b052019-11-18 15:39:01 +09001356type apexFileClass int
1357
1358const (
1359 etc apexFileClass = iota
1360 nativeSharedLib
1361 nativeExecutable
1362 shBinary
1363 pyBinary
1364 goBinary
1365 javaSharedLib
1366 nativeTest
1367 app
1368)
1369
Jiyong Park8fd61922018-11-08 02:50:25 +09001370func (class apexFileClass) NameInMake() string {
1371 switch class {
1372 case etc:
1373 return "ETC"
1374 case nativeSharedLib:
1375 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001376 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001377 return "EXECUTABLES"
1378 case javaSharedLib:
1379 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001380 case nativeTest:
1381 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001382 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001383 // b/142537672 Why isn't this APP? We want to have full control over
1384 // the paths and file names of the apk file under the flattend APEX.
1385 // If this is set to APP, then the paths and file names are modified
1386 // by the Make build system. For example, it is installed to
1387 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1388 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1389 // appends module name (which is <apexname>.<Appname> to the path.
1390 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001391 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001392 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001393 }
1394}
1395
Jiyong Parkf653b052019-11-18 15:39:01 +09001396// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001397type apexFile struct {
1398 builtFile android.Path
1399 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001400 installDir string
1401 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001402 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001403 // list of symlinks that will be created in installDir that point to this apexFile
1404 symlinks []string
1405 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001406 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001407
1408 requiredModuleNames []string
1409 targetRequiredModuleNames []string
1410 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001411
Colin Cross503c1d02020-01-28 14:00:53 -08001412 jacocoReportClassesFile android.Path // only for javalibs and apps
1413 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001414 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001415}
1416
Jiyong Park1833cef2019-12-13 13:28:36 +09001417func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1418 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001419 builtFile: builtFile,
1420 moduleName: moduleName,
1421 installDir: installDir,
1422 class: class,
1423 module: module,
1424 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001425 if module != nil {
1426 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001427 ret.requiredModuleNames = module.RequiredModuleNames()
1428 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1429 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001430 }
1431 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001432}
1433
1434func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001435 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001436}
1437
Jiyong Park7cd10e32020-01-14 09:22:18 +09001438// Path() returns path of this apex file relative to the APEX root
1439func (af *apexFile) Path() string {
1440 return filepath.Join(af.installDir, af.builtFile.Base())
1441}
1442
1443// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1444func (af *apexFile) SymlinkPaths() []string {
1445 var ret []string
1446 for _, symlink := range af.symlinks {
1447 ret = append(ret, filepath.Join(af.installDir, symlink))
1448 }
1449 return ret
1450}
1451
1452func (af *apexFile) AvailableToPlatform() bool {
1453 if af.module == nil {
1454 return false
1455 }
1456 if am, ok := af.module.(android.ApexModule); ok {
1457 return am.AvailableFor(android.AvailableToPlatform)
1458 }
1459 return false
1460}
1461
Jiyong Park678c8812020-02-07 17:25:49 +09001462type depInfo struct {
1463 to string
1464 from []string
1465 isExternal bool
1466}
1467
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001468type apexBundle struct {
1469 android.ModuleBase
1470 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001471 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001472 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001473
Jiyong Park5d790c32019-11-15 18:40:32 +09001474 properties apexBundleProperties
1475 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001476 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001477
Jooyung Hanf21c7972019-12-16 22:32:06 +09001478 // specific to apex_vndk modules
1479 vndkProperties apexVndkProperties
1480
Colin Crossa4925902018-11-16 11:36:28 -08001481 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001482 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001483 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001484
Jiyong Park03b68dd2019-07-26 23:20:40 +09001485 prebuiltFileToDelete string
1486
Jiyong Park42cca6c2019-04-01 11:15:50 +09001487 public_key_file android.Path
1488 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001489
1490 container_certificate_file android.Path
1491 container_private_key_file android.Path
1492
Jooyung Han54aca7b2019-11-20 02:26:02 +09001493 fileContexts android.Path
1494
Jiyong Park8fd61922018-11-08 02:50:25 +09001495 // list of files to be included in this apex
1496 filesInfo []apexFile
1497
Jiyong Park956305c2020-01-09 12:32:06 +09001498 // list of module names that should be installed along with this APEX
1499 requiredDeps []string
1500
Jiyong Park956305c2020-01-09 12:32:06 +09001501 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001502 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001503
Sundong Ahnabb64432019-10-22 13:58:29 +09001504 testApex bool
1505 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001506 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001507 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001508
Jooyung Han214bf372019-11-12 13:03:50 +09001509 manifestJsonOut android.WritablePath
1510 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001511
Jooyung Han002ab682020-01-08 01:57:58 +09001512 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001513 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001514 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001515 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1516 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001517
1518 // Suffix of module name in Android.mk
1519 // ".flattened", ".apex", ".zipapex", or ""
1520 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001521
1522 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001523
1524 // Whether to create symlink to the system file instead of having a file
1525 // inside the apex or not
1526 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001527
1528 // Struct holding the merged notice file paths in different formats
1529 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001530}
1531
Jiyong Park397e55e2018-10-24 21:09:55 +09001532func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001533 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001534 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001535 // Use *FarVariation* to be able to depend on modules having
1536 // conflicting variations with this module. This is required since
1537 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1538 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001539 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001540 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001541 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001542 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001543 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001544
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001545 ctx.AddFarVariationDependencies(append(target.Variations(),
1546 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1547 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001548
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001549 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001550 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001551 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001552 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001553}
1554
Alex Light9670d332019-01-29 18:07:33 -08001555func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1556 if ctx.Os().Class == android.Device {
1557 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1558 } else {
1559 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1560 if ctx.Os().Bionic() {
1561 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1562 } else {
1563 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1564 }
1565 }
1566}
1567
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001568func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001569 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1570 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1571 }
1572
Jiyong Park397e55e2018-10-24 21:09:55 +09001573 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001574 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001575
1576 a.combineProperties(ctx)
1577
Jiyong Park397e55e2018-10-24 21:09:55 +09001578 has32BitTarget := false
1579 for _, target := range targets {
1580 if target.Arch.ArchType.Multilib == "lib32" {
1581 has32BitTarget = true
1582 }
1583 }
1584 for i, target := range targets {
1585 // When multilib.* is omitted for native_shared_libs, it implies
1586 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001587 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001588 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001589 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001590 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001591
Roland Levillain630846d2019-06-26 12:48:34 +01001592 // When multilib.* is omitted for tests, it implies
1593 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001594 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001595 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001596 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001597 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001598
Jiyong Park397e55e2018-10-24 21:09:55 +09001599 // Add native modules targetting both ABIs
1600 addDependenciesForNativeModules(ctx,
1601 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001602 a.properties.Multilib.Both.Binaries,
1603 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001604 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001605 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001606
Alex Light3d673592019-01-18 14:37:31 -08001607 isPrimaryAbi := i == 0
1608 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001609 // When multilib.* is omitted for binaries, it implies
1610 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001611 ctx.AddFarVariationDependencies(append(target.Variations(),
1612 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1613 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001614
1615 // Add native modules targetting the first ABI
1616 addDependenciesForNativeModules(ctx,
1617 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001618 a.properties.Multilib.First.Binaries,
1619 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001620 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001621 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001622 }
1623
1624 switch target.Arch.ArchType.Multilib {
1625 case "lib32":
1626 // Add native modules targetting 32-bit ABI
1627 addDependenciesForNativeModules(ctx,
1628 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001629 a.properties.Multilib.Lib32.Binaries,
1630 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001631 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001632 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001633
1634 addDependenciesForNativeModules(ctx,
1635 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001636 a.properties.Multilib.Prefer32.Binaries,
1637 a.properties.Multilib.Prefer32.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 case "lib64":
1641 // Add native modules targetting 64-bit ABI
1642 addDependenciesForNativeModules(ctx,
1643 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001644 a.properties.Multilib.Lib64.Binaries,
1645 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001646 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001647 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001648
1649 if !has32BitTarget {
1650 addDependenciesForNativeModules(ctx,
1651 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001652 a.properties.Multilib.Prefer32.Binaries,
1653 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001654 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001655 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001656 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001657
1658 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1659 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1660 if sanitizer == "hwaddress" {
1661 addDependenciesForNativeModules(ctx,
1662 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001663 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001664 break
1665 }
1666 }
1667 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001668 }
1669
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001670 }
1671
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001672 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1673 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1674 // b/144532908
1675 archForPrebuiltEtc := config.Arches()[0]
1676 for _, arch := range config.Arches() {
1677 // Prefer 64-bit arch if there is any
1678 if arch.ArchType.Multilib == "lib64" {
1679 archForPrebuiltEtc = arch
1680 break
1681 }
1682 }
1683 ctx.AddFarVariationDependencies([]blueprint.Variation{
1684 {Mutator: "os", Variation: ctx.Os().String()},
1685 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1686 }, prebuiltTag, a.properties.Prebuilts...)
1687
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001688 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1689 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001690
Ulya Trafimovich44561882020-01-03 13:25:54 +00001691 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1692 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1693 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1694 javaLibTag, "jacocoagent")
1695 }
1696
Jiyong Park23c52b02019-02-02 13:13:47 +09001697 if String(a.properties.Key) == "" {
1698 ctx.ModuleErrorf("key is missing")
1699 return
1700 }
1701 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001702
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001703 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001704 if cert != "" {
1705 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001706 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001707
1708 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1709 if len(a.properties.Uses_sdks) > 0 {
1710 sdkRefs := []android.SdkRef{}
1711 for _, str := range a.properties.Uses_sdks {
1712 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1713 sdkRefs = append(sdkRefs, parsed)
1714 }
1715 a.BuildWithSdks(sdkRefs)
1716 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001717}
1718
Jiyong Park5d790c32019-11-15 18:40:32 +09001719func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1720 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1721 androidAppTag, a.overridableProperties.Apps...)
1722}
1723
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001724func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1725 // direct deps of an APEX bundle are all part of the APEX bundle
1726 return true
1727}
1728
Colin Cross0ea8ba82019-06-06 14:33:29 -07001729func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001730 moduleName := ctx.ModuleName()
1731 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1732 // we check with the pseudo module name to see if its certificate is overridden.
1733 if a.vndkApex {
1734 moduleName = vndkApexName
1735 }
1736 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001737 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001738 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001739 }
1740 return String(a.properties.Certificate)
1741}
1742
Colin Cross41955e82019-05-29 14:40:35 -07001743func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1744 switch tag {
1745 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001746 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001747 default:
1748 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001749 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001750}
1751
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001752func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001753 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001754}
1755
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001756func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1757 return proptools.Bool(a.properties.Test_only_no_hashtree)
1758}
1759
Jiyong Park7c1dc612019-01-05 11:15:24 +09001760func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001761 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001762 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001763 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001764 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001765 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001766 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001767 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001768 }
1769}
1770
Jiyong Parkf97782b2019-02-13 20:28:58 +09001771func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1772 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1773 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1774 }
1775}
1776
Jiyong Park388ef3f2019-01-28 19:47:32 +09001777func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001778 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1779 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001780 }
1781
1782 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001783 globalSanitizerNames := []string{}
1784 if a.Host() {
1785 globalSanitizerNames = ctx.Config().SanitizeHost()
1786 } else {
1787 arches := ctx.Config().SanitizeDeviceArch()
1788 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1789 globalSanitizerNames = ctx.Config().SanitizeDevice()
1790 }
1791 }
1792 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001793}
1794
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001795func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001796 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001797}
1798
1799func (a *apexBundle) PreventInstall() {
1800 a.properties.PreventInstall = true
1801}
1802
1803func (a *apexBundle) HideFromMake() {
1804 a.properties.HideFromMake = true
1805}
1806
Jiyong Park956305c2020-01-09 12:32:06 +09001807func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1808 a.properties.IsCoverageVariant = coverage
1809}
1810
Jiyong Parkf653b052019-11-18 15:39:01 +09001811// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001812func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001813 // Decide the APEX-local directory by the multilib of the library
1814 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001815 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001816 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001817 case "lib32":
1818 dirInApex = "lib"
1819 case "lib64":
1820 dirInApex = "lib64"
1821 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001822 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001823 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001824 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001825 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001826 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001827 // Special case for Bionic libs and other libs installed with them. This is
1828 // to prevent those libs from being included in the search path
1829 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1830 // those libs in the Runtime APEX are available via the legacy paths in
1831 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1832 // to the legacy paths and thus will be loaded into the default linker
1833 // namespace (aka "platform" namespace). If the libs are directly in
1834 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1835 // into the runtime linker namespace, which will result in double loading of
1836 // them, which isn't supported.
1837 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001838 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001839
Jiyong Parkf653b052019-11-18 15:39:01 +09001840 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001841 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001842}
1843
Jiyong Park1833cef2019-12-13 13:28:36 +09001844func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001845 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001846 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001847 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001848 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001849 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001850 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001851 af.symlinks = cc.Symlinks()
1852 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001853}
1854
Jiyong Park1833cef2019-12-13 13:28:36 +09001855func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001856 dirInApex := "bin"
1857 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001858 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001859}
Jiyong Park1833cef2019-12-13 13:28:36 +09001860func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001861 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001862 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1863 if err != nil {
1864 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001865 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001866 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001867 fileToCopy := android.PathForOutput(ctx, s)
1868 // NB: Since go binaries are static we don't need the module for anything here, which is
1869 // good since the go tool is a blueprint.Module not an android.Module like we would
1870 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001871 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001872}
1873
Jiyong Park1833cef2019-12-13 13:28:36 +09001874func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001875 dirInApex := filepath.Join("bin", sh.SubDir())
1876 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001877 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001878 af.symlinks = sh.Symlinks()
1879 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001880}
1881
Jooyung Han58f26ab2019-12-18 15:34:32 +09001882// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1883type javaLibrary interface {
1884 android.Module
1885 java.Dependency
1886}
1887
1888func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001889 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001890 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001891 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1892 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1893 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001894}
1895
Jiyong Park1833cef2019-12-13 13:28:36 +09001896func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001897 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1898 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001899 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001900}
1901
atrost6e126252020-01-27 17:01:16 +00001902func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1903 dirInApex := filepath.Join("etc", config.SubDir())
1904 fileToCopy := config.CompatConfig()
1905 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1906}
1907
Jiyong Park1833cef2019-12-13 13:28:36 +09001908func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 android.Module
1910 Privileged() bool
1911 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001912 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001913 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001914}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001915 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001917 appDir = "priv-app"
1918 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001919 dirInApex := filepath.Join(appDir, pkgName)
1920 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001921 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1922 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001923 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001924
1925 if app, ok := aapp.(interface {
1926 OverriddenManifestPackageName() string
1927 }); ok {
1928 af.overriddenPackageName = app.OverriddenManifestPackageName()
1929 }
Jiyong Park618922e2020-01-08 13:35:43 +09001930 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001931}
1932
Roland Levillain935639d2019-08-13 14:55:28 +01001933// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1934type flattenedApexContext struct {
1935 android.ModuleContext
1936}
1937
1938func (c *flattenedApexContext) InstallBypassMake() bool {
1939 return true
1940}
1941
Jiyong Park201cedd2020-02-07 17:25:49 +09001942// Visit dependencies that contributes to the payload of this APEX
1943func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1944 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Parkfa899442020-01-31 02:49:53 +09001945 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1946 am, ok := child.(android.ApexModule)
1947 if !ok || !am.CanHaveApexVariants() {
1948 return false
1949 }
1950
1951 // Check for the direct dependencies that contribute to the payload
1952 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1953 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001954 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001955 return true
1956 }
1957 return false
1958 }
1959
1960 // Check for the indirect dependencies if it is considered as part of the APEX
1961 if am.DepIsInSameApex(ctx, am) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001962 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001963 return true
1964 }
1965
Jiyong Park201cedd2020-02-07 17:25:49 +09001966 do(ctx, parent, am, true /* externalDep */)
1967
Jiyong Parkfa899442020-01-31 02:49:53 +09001968 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1969 return false
1970 })
1971}
1972
Jiyong Park201cedd2020-02-07 17:25:49 +09001973// Ensures that the dependencies are marked as available for this APEX
1974func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1975 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1976 if ctx.Host() || a.testApex || a.vndkApex {
1977 return
1978 }
1979
1980 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1981 apexName := ctx.ModuleName()
1982 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, to) {
1983 return
1984 }
Jiyong Park7bd94442020-03-09 14:29:18 +09001985 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", from.Name(), to.Name())
Jiyong Park201cedd2020-02-07 17:25:49 +09001986 })
1987}
1988
Jiyong Park678c8812020-02-07 17:25:49 +09001989// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1990func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1991 a.depInfos = make(map[string]depInfo)
1992 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1993 if from.Name() == to.Name() {
1994 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1995 return
1996 }
1997
1998 if info, exists := a.depInfos[to.Name()]; exists {
1999 if !android.InList(from.Name(), info.from) {
2000 info.from = append(info.from, from.Name())
2001 }
2002 info.isExternal = info.isExternal && externalDep
2003 a.depInfos[to.Name()] = info
2004 } else {
2005 a.depInfos[to.Name()] = depInfo{
2006 to: to.Name(),
2007 from: []string{from.Name()},
2008 isExternal: externalDep,
2009 }
2010 }
2011 })
2012}
2013
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002014func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002015 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2016 switch a.properties.ApexType {
2017 case imageApex:
2018 if buildFlattenedAsDefault {
2019 a.suffix = imageApexSuffix
2020 } else {
2021 a.suffix = ""
2022 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002023
2024 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002025 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002026 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002027 }
2028 case zipApex:
2029 if proptools.String(a.properties.Payload_type) == "zip" {
2030 a.suffix = ""
2031 a.primaryApexType = true
2032 } else {
2033 a.suffix = zipApexSuffix
2034 }
2035 case flattenedApex:
2036 if buildFlattenedAsDefault {
2037 a.suffix = ""
2038 a.primaryApexType = true
2039 } else {
2040 a.suffix = flattenedSuffix
2041 }
Alex Light5098a612018-11-29 17:12:15 -08002042 }
2043
Roland Levillain630846d2019-06-26 12:48:34 +01002044 if len(a.properties.Tests) > 0 && !a.testApex {
2045 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2046 return
2047 }
2048
Jiyong Parkfa899442020-01-31 02:49:53 +09002049 a.checkApexAvailability(ctx)
2050
Jiyong Park678c8812020-02-07 17:25:49 +09002051 a.collectDepsInfo(ctx)
2052
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002053 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2054
Jooyung Hane1633032019-08-01 17:41:43 +09002055 // native lib dependencies
2056 var provideNativeLibs []string
2057 var requireNativeLibs []string
2058
Jooyung Han5c998b92019-06-27 11:30:33 +09002059 // Check if "uses" requirements are met with dependent apexBundles
2060 var providedNativeSharedLibs []string
2061 useVendor := proptools.Bool(a.properties.Use_vendor)
2062 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2063 if ctx.OtherModuleDependencyTag(m) != usesTag {
2064 return
2065 }
2066 otherName := ctx.OtherModuleName(m)
2067 other, ok := m.(*apexBundle)
2068 if !ok {
2069 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2070 return
2071 }
2072 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2073 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2074 return
2075 }
2076 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2077 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2078 return
2079 }
2080 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2081 })
2082
Jiyong Parkf653b052019-11-18 15:39:01 +09002083 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002084 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002085 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002086 depTag := ctx.OtherModuleDependencyTag(child)
2087 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002088 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002089 switch depTag {
2090 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002091 if c, ok := child.(*cc.Module); ok {
2092 // bootstrap bionic libs are treated as provided by system
2093 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2094 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002095 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002096 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002097 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002098 } else {
2099 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002100 }
2101 case executableTag:
2102 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002103 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002104 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002105 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002106 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002107 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002108 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002109 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002110 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002111 } else {
Alex Light778127a2019-02-27 14:19:50 -08002112 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 +09002113 }
2114 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002115 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002116 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002118 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2119 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002120 filesInfo = append(filesInfo, af)
2121 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002122 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002123 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2124 af := apexFileForJavaLibrary(ctx, sdkLib)
2125 if !af.Ok() {
2126 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2127 return false
2128 }
2129 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002130 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002131 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002132 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002133 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002134 case androidAppTag:
2135 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2136 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002137 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002138 return true // track transitive dependencies
2139 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002140 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002141 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2142 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002143 } else {
2144 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2145 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002146 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002147 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002148 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002149 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2150 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002151 } else {
atrost6e126252020-01-27 17:01:16 +00002152 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002153 }
Roland Levillain630846d2019-06-26 12:48:34 +01002154 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002155 if ccTest, ok := child.(*cc.Module); ok {
2156 if ccTest.IsTestPerSrcAllTestsVariation() {
2157 // Multiple-output test module (where `test_per_src: true`).
2158 //
2159 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2160 // We do not add this variation to `filesInfo`, as it has no output;
2161 // however, we do add the other variations of this module as indirect
2162 // dependencies (see below).
2163 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002164 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002165 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002166 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002167 af.class = nativeTest
2168 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002169 }
Roland Levillain630846d2019-06-26 12:48:34 +01002170 } else {
2171 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2172 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002173 case keyTag:
2174 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002175 a.private_key_file = key.private_key_file
2176 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002177 } else {
2178 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002179 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002180 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002181 case certificateTag:
2182 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002183 a.container_certificate_file = dep.Certificate.Pem
2184 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002185 } else {
2186 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2187 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002188 case android.PrebuiltDepTag:
2189 // If the prebuilt is force disabled, remember to delete the prebuilt file
2190 // that might have been installed in the previous builds
2191 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2192 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2193 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002194 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002195 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002196 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002197 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002198 // We cannot use a switch statement on `depTag` here as the checked
2199 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002200 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002201 if cc, ok := child.(*cc.Module); ok {
2202 if android.InList(cc.Name(), providedNativeSharedLibs) {
2203 // If we're using a shared library which is provided from other APEX,
2204 // don't include it in this APEX
2205 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002206 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002207 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002208 // If the dependency is a stubs lib, don't include it in this APEX,
2209 // but make sure that the lib is installed on the device.
2210 // In case no APEX is having the lib, the lib is installed to the system
2211 // partition.
2212 //
2213 // Always include if we are a host-apex however since those won't have any
2214 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002215 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2216 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002217 }
Jooyung Hane1633032019-08-01 17:41:43 +09002218 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002219 // Don't track further
2220 return false
2221 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002222 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002223 af.transitiveDep = true
2224 filesInfo = append(filesInfo, af)
2225 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002226 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002227 } else if cc.IsTestPerSrcDepTag(depTag) {
2228 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002229 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002230 // Handle modules created as `test_per_src` variations of a single test module:
2231 // use the name of the generated test binary (`fileToCopy`) instead of the name
2232 // of the original test module (`depName`, shared by all `test_per_src`
2233 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002234 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002235 // these are not considered transitive dep
2236 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002237 filesInfo = append(filesInfo, af)
2238 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002239 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002240 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002241 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2242 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002243 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2244 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2245 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2246 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002247 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002248 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002249 }
2250 }
2251 }
2252 return false
2253 })
2254
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002255 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2256 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2257 // via the global boot image config.
2258 if a.artApex {
2259 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2260 dirInApex := filepath.Join("javalib", arch.String())
2261 for _, f := range files {
2262 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002263 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002264 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002265 }
2266 }
2267 }
2268
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002269 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002270 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2271 return
2272 }
2273
Jiyong Park8fd61922018-11-08 02:50:25 +09002274 // remove duplicates in filesInfo
2275 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002276 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002277 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002278 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002279 if e, ok := encountered[dest]; !ok {
2280 encountered[dest] = f
2281 } else {
2282 // If a module is directly included and also transitively depended on
2283 // consider it as directly included.
2284 e.transitiveDep = e.transitiveDep && f.transitiveDep
2285 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002286 }
2287 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002288 var result []apexFile
2289 for _, v := range encountered {
2290 result = append(result, v)
2291 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002292 return result
2293 }
2294 filesInfo = removeDup(filesInfo)
2295
2296 // to have consistent build rules
2297 sort.Slice(filesInfo, func(i, j int) bool {
2298 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2299 })
2300
Jiyong Park8fd61922018-11-08 02:50:25 +09002301 a.installDir = android.PathForModuleInstall(ctx, "apex")
2302 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002303
Jooyung Han54aca7b2019-11-20 02:26:02 +09002304 if a.properties.ApexType != zipApex {
2305 if a.properties.File_contexts == nil {
2306 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2307 } else {
2308 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2309 if a.Platform() {
2310 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2311 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2312 }
2313 }
2314 }
2315 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2316 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2317 return
2318 }
2319 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002320 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2321 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2322 // the same library in the system partition, thus effectively sharing the same libraries
2323 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2324 // in the APEX.
2325 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2326 a.installable() &&
2327 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002328
Jiyong Park9d677202020-02-19 16:29:35 +09002329 // We don't need the optimization for updatable APEXes, as it might give false signal
2330 // to the system health when the APEXes are still bundled (b/149805758)
2331 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2332 a.linkToSystemLib = false
2333 }
2334
Jiyong Park9b964182020-02-26 18:27:19 +09002335 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2336 if ctx.Host() {
2337 a.linkToSystemLib = false
2338 }
2339
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002340 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002341 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2342
2343 a.setCertificateAndPrivateKey(ctx)
2344 if a.properties.ApexType == flattenedApex {
2345 a.buildFlattenedApex(ctx)
2346 } else {
2347 a.buildUnflattenedApex(ctx)
2348 }
2349
Jooyung Han002ab682020-01-08 01:57:58 +09002350 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002351
2352 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002353}
2354
Jiyong Parkfa899442020-01-31 02:49:53 +09002355func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002356 key := apex
2357 key = strings.Replace(key, "test_", "", 1)
2358 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2359 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2360
2361 moduleName := module.Name()
Jiyong Parkfa899442020-01-31 02:49:53 +09002362 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2363 // system. Trim the prefix for the check since they are confusing
2364 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2365 if strings.HasPrefix(moduleName, "libclang_rt.") {
2366 // This module has many arch variants that depend on the product being built.
2367 // We don't want to list them all
2368 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002369 }
2370
2371 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2372 return true
2373 }
2374
Jiyong Parkfa899442020-01-31 02:49:53 +09002375 key = "//any"
2376 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2377 return true
2378 }
2379
Anton Hansson5053c292020-01-10 15:12:39 +00002380 return false
2381}
2382
Jooyung Han344d5432019-08-23 11:17:39 +09002383func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002384 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002385 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002386 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002387 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002388 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002389 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2390 })
Alex Light5098a612018-11-29 17:12:15 -08002391 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002392 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002393 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002394 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002395 return module
2396}
Jiyong Park30ca9372019-02-07 16:27:23 +09002397
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002398func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002399 bundle := newApexBundle()
2400 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002401 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002402 return bundle
2403}
2404
Jiyong Parkfce0b422020-02-11 03:56:06 +09002405// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2406// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002407func testApexBundleFactory() android.Module {
2408 bundle := newApexBundle()
2409 bundle.testApex = true
2410 return bundle
2411}
2412
Jiyong Parkfce0b422020-02-11 03:56:06 +09002413// apex packages other modules into an APEX file which is a packaging format for system-level
2414// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002415func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002416 return newApexBundle()
2417}
2418
Jiyong Park30ca9372019-02-07 16:27:23 +09002419//
2420// Defaults
2421//
2422type Defaults struct {
2423 android.ModuleBase
2424 android.DefaultsModuleBase
2425}
2426
Jiyong Park30ca9372019-02-07 16:27:23 +09002427func defaultsFactory() android.Module {
2428 return DefaultsFactory()
2429}
2430
2431func DefaultsFactory(props ...interface{}) android.Module {
2432 module := &Defaults{}
2433
2434 module.AddProperties(props...)
2435 module.AddProperties(
2436 &apexBundleProperties{},
2437 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002438 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002439 )
2440
2441 android.InitDefaultsModule(module)
2442 return module
2443}
Jiyong Park5d790c32019-11-15 18:40:32 +09002444
2445//
2446// OverrideApex
2447//
2448type OverrideApex struct {
2449 android.ModuleBase
2450 android.OverrideModuleBase
2451}
2452
2453func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2454 // All the overrides happen in the base module.
2455}
2456
2457// override_apex is used to create an apex module based on another apex module
2458// by overriding some of its properties.
2459func overrideApexFactory() android.Module {
2460 m := &OverrideApex{}
2461 m.AddProperties(&overridableProperties{})
2462
2463 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2464 android.InitOverrideModule(m)
2465 return m
2466}