blob: c50dd1de8470fdf65c4afd516a24794faf71100d [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",
97 "liblog",
98 "liblog_headers",
99 "libmdnssd",
100 "libminijail",
101 "libminijail_gen_constants",
102 "libminijail_gen_constants_obj",
103 "libminijail_gen_syscall",
104 "libminijail_gen_syscall_obj",
105 "libminijail_generated",
106 "libpackagelistparser",
107 "libpcre2",
108 "libprocessgroup_headers",
109 "libqemu_pipe",
110 "libselinux",
111 "libsystem_headers",
112 "libutils_headers",
113 }
114 //
115 // Module separator
116 //
117 m["com.android.appsearch"] = []string{
118 "icing-java-proto-lite",
119 "libprotobuf-java-lite",
120 }
Anton Hansson5053c292020-01-10 15:12:39 +0000121 //
122 // Module separator
123 //
124 m["com.android.art"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900125 "art_cmdlineparser_headers",
126 "art_disassembler_headers",
127 "art_libartbase_headers",
128 "bcm_object",
129 "bionic_libc_platform_headers",
130 "core-repackaged-icu4j",
131 "cpp-define-generator-asm-support",
132 "cpp-define-generator-definitions",
133 "crtbegin_dynamic",
134 "crtbegin_dynamic1",
135 "crtbegin_so1",
136 "crtbrand",
137 "conscrypt.module.intra.core.api.stubs",
138 "dex2oat_headers",
139 "dt_fd_forward_export",
140 "fmtlib",
141 "icu4c_extra_headers",
Anton Hanssonf17f2482020-01-16 09:11:57 +0000142 "jacocoagent",
Jiyong Parkfa899442020-01-31 02:49:53 +0900143 "javavm_headers",
144 "jni_platform_headers",
145 "libPlatformProperties",
146 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000147 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900148 "libandroidicuinit",
149 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000150 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900151 "libasync_safe",
Anton Hansson5053c292020-01-10 15:12:39 +0000152 "libbacktrace",
153 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900154 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000155 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900156 "libc++_static",
157 "libc++abi",
158 "libc++demangle",
159 "libc_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "libcrypto",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libdexfile_all_headers",
162 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000163 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900164 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000165 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900166 "libfdlibm",
167 "libgtest_prod",
168 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000169 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900170 "libicuuc_headers",
171 "libicuuc_stubdata",
172 "libjdwp_headers",
173 "liblog",
174 "liblog_headers",
175 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000176 "liblzma",
177 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900178 "libnativebridge-headers",
179 "libnativehelper_header_only",
180 "libnativeloader-headers",
181 "libnpt_headers",
182 "libopenjdkjvmti_headers",
183 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000184 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900185 "libprotobuf-cpp-lite",
186 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000187 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 "libv8",
189 "libv8base",
190 "libv8gen",
191 "libv8platform",
192 "libv8sampler",
193 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000194 "libvixl",
195 "libvixld",
196 "libz",
197 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900198 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000199 }
200 //
201 // Module separator
202 //
203 m["com.android.bluetooth.updatable"] = []string{
204 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000205 "android.hardware.bluetooth.a2dp@1.0",
206 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900207 "android.hardware.bluetooth@1.0",
208 "android.hardware.bluetooth@1.1",
209 "android.hardware.graphics.bufferqueue@1.0",
210 "android.hardware.graphics.bufferqueue@2.0",
211 "android.hardware.graphics.common@1.0",
212 "android.hardware.graphics.common@1.1",
213 "android.hardware.graphics.common@1.2",
214 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000215 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900216 "android.hidl.token@1.0",
217 "android.hidl.token@1.0-utils",
218 "avrcp-target-service",
219 "avrcp_headers",
220 "bcm_object",
221 "bluetooth-protos-lite",
222 "bluetooth.mapsapi",
223 "com.android.vcard",
224 "fmtlib",
225 "guava",
226 "internal_include_headers",
227 "lib-bt-packets",
228 "lib-bt-packets-avrcp",
229 "lib-bt-packets-base",
230 "libFraunhoferAAC",
231 "libaudio-a2dp-hw-utils",
232 "libaudio-hearing-aid-hw-utils",
233 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000234 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900235 "libbase_headers",
236 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000237 "libbinderthreadstate",
238 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900239 "libbluetooth-types",
240 "libbluetooth-types-header",
241 "libbluetooth_gd",
242 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000243 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900244 "libbt-audio-hal-interface",
245 "libbt-bta",
246 "libbt-common",
247 "libbt-hci",
248 "libbt-platform-protos-lite",
249 "libbt-protos-lite",
250 "libbt-sbc-decoder",
251 "libbt-sbc-encoder",
252 "libbt-stack",
253 "libbt-utils",
254 "libbtcore",
255 "libbtdevice",
256 "libbte",
257 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000258 "libc++",
259 "libchrome",
260 "libcrypto",
261 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900262 "libcutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000263 "libevent",
264 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "libg722codec",
266 "libgtest_prod",
267 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000268 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900269 "libhidlbase-impl-internal",
270 "libhidltransport-impl-internal",
271 "libhwbinder-impl-internal",
272 "libjsoncpp",
273 "liblog_headers",
274 "libmedia_headers",
275 "libmodpb64",
276 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000277 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900278 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000279 "libprotobuf-cpp-lite",
Jiyong Parkfa899442020-01-31 02:49:53 +0900280 "libprotobuf-java-lite",
281 "libprotobuf-java-micro",
282 "libstagefright_foundation_headers",
283 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000284 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900285 "libstatssocket",
286 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000287 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000289 "libutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900290 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000291 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "media_plugin_headers",
293 "sap-api-java-static",
294 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000295 }
296 //
297 // Module separator
298 //
299 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
300 //
301 // Module separator
302 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900303 m["com.android.conscrypt"] = []string{
304 "bcm_object",
305 "boringssl_self_test",
306 "libc++",
307 "libcrypto",
308 "libnativehelper_header_only",
309 "libssl",
310 }
Anton Hansson5053c292020-01-10 15:12:39 +0000311 //
312 // Module separator
313 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900314 m["com.android.extservices"] = []string{
315 "flatbuffer_headers",
316 "liblua",
317 "libtextclassifier",
318 "libtextclassifier_hash_static",
319 "libtflite_static",
320 "libutf",
321 "libz_current",
322 "tensorflow_headers",
323 }
324 //
325 // Module separator
326 //
327 m["com.android.cronet"] = []string{
328 "cronet_impl_common_java",
329 "cronet_impl_native_java",
330 "cronet_impl_platform_java",
331 "libcronet.80.0.3986.0",
332 "org.chromium.net.cronet",
333 "prebuilt_libcronet.80.0.3986.0",
334 }
335 //
336 // Module separator
337 //
338 m["com.android.neuralnetworks"] = []string{
339 "android.hardware.neuralnetworks@1.0",
340 "android.hardware.neuralnetworks@1.1",
341 "android.hardware.neuralnetworks@1.2",
342 "android.hardware.neuralnetworks@1.3",
343 "android.hidl.allocator@1.0",
344 "android.hidl.memory.token@1.0",
345 "android.hidl.memory@1.0",
346 "android.hidl.safe_union@1.0",
347 "bcm_object",
348 "fmtlib",
349 "gemmlowp_headers",
350 "libarect",
351 "libbacktrace_headers",
352 "libbase",
353 "libbase_headers",
354 "libbinderthreadstate",
355 "libbuildversion",
356 "libc++",
357 "libcrypto",
358 "libcrypto_static",
359 "libcutils",
360 "libcutils_headers",
361 "libeigen",
362 "libfmq",
363 "libhidlbase",
364 "libhidlbase-impl-internal",
365 "libhidlmemory",
366 "libhidltransport-impl-internal",
367 "libhwbinder-impl-internal",
368 "libjsoncpp",
369 "liblog_headers",
370 "libmath",
371 "libneuralnetworks_common",
372 "libneuralnetworks_headers",
373 "libprocessgroup",
374 "libprocessgroup_headers",
375 "libprocpartition",
376 "libsync",
377 "libsystem_headers",
378 "libtextclassifier_hash",
379 "libtextclassifier_hash_headers",
380 "libtextclassifier_hash_static",
381 "libtflite_kernel_utils",
382 "libutils",
383 "libutils_headers",
384 "philox_random",
385 "philox_random_headers",
386 "tensorflow_headers",
387 }
Anton Hansson5053c292020-01-10 15:12:39 +0000388 //
389 // Module separator
390 //
Anton Hansson5053c292020-01-10 15:12:39 +0000391 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900392 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900394 "android.hardware.cas@1.0",
395 "android.hardware.configstore-utils",
396 "android.hardware.configstore@1.0",
397 "android.hardware.configstore@1.1",
398 "android.hardware.graphics.allocator@2.0",
399 "android.hardware.graphics.allocator@3.0",
400 "android.hardware.graphics.bufferqueue@1.0",
401 "android.hardware.graphics.bufferqueue@2.0",
402 "android.hardware.graphics.common@1.0",
403 "android.hardware.graphics.common@1.1",
404 "android.hardware.graphics.common@1.2",
405 "android.hardware.graphics.mapper@2.0",
406 "android.hardware.graphics.mapper@2.1",
407 "android.hardware.graphics.mapper@3.0",
408 "android.hardware.media.omx@1.0",
409 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000410 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000411 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900412 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000413 "android.hidl.token@1.0",
414 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "bcm_object",
416 "bionic_libc_platform_headers",
417 "fmtlib",
418 "gl_headers",
419 "libEGL",
420 "libEGL_blobCache",
421 "libEGL_getProcAddress",
422 "libFLAC",
423 "libFLAC-config",
424 "libFLAC-headers",
425 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000426 "libaacextractor",
427 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900428 "libarect",
429 "libasync_safe",
430 "libaudio_system_headers",
431 "libaudioclient",
432 "libaudioclient_headers",
433 "libaudiofoundation",
434 "libaudiofoundation_headers",
435 "libaudiomanager",
436 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000437 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libaudioutils_fixedfft",
439 "libbacktrace",
440 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000441 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900442 "libbase_headers",
443 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000444 "libbinderthreadstate",
Jiyong Parkfa899442020-01-31 02:49:53 +0900445 "libbluetooth-types-header",
446 "libbufferhub",
447 "libbufferhub_headers",
448 "libbufferhubqueue",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "libc_headers",
451 "libc_malloc_debug_backtrace",
452 "libcamera_client",
453 "libcamera_metadata",
Anton Hansson5053c292020-01-10 15:12:39 +0000454 "libcrypto",
455 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "libcutils_headers",
457 "libdexfile_external_headers",
458 "libdexfile_support",
459 "libdvr_headers",
460 "libexpat",
461 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000462 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900463 "libgrallocusage",
464 "libgraphicsenv",
465 "libgui",
466 "libgui_headers",
467 "libhardware_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000468 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900469 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900471 "libhidltransport-impl-internal",
472 "libhwbinder-impl-internal",
473 "libinput",
474 "libjsoncpp",
475 "liblog_headers",
476 "liblzma",
477 "libmath",
478 "libmedia",
479 "libmedia_codeclist",
480 "libmedia_headers",
481 "libmedia_helper",
482 "libmedia_helper_headers",
483 "libmedia_midiiowrapper",
484 "libmedia_omx",
485 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000486 "libmidiextractor",
487 "libmkvextractor",
488 "libmp3extractor",
489 "libmp4extractor",
490 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "libnativebase_headers",
492 "libnativebridge-headers",
493 "libnativebridge_lazy",
494 "libnativeloader-headers",
495 "libnativeloader_lazy",
496 "libnativewindow_headers",
497 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libpackagelistparser",
500 "libpcre2",
501 "libpdx",
502 "libpdx_default_transport",
503 "libpdx_headers",
504 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000505 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900506 "libprocessgroup_headers",
507 "libprocinfo",
508 "libselinux",
509 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000510 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900511 "libspeexresampler",
512 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000513 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900514 "libstagefright_flacdec",
515 "libstagefright_foundation",
516 "libstagefright_foundation_headers",
517 "libstagefright_foundation_without_imemory",
518 "libstagefright_headers",
519 "libstagefright_id3",
520 "libstagefright_metadatautils",
521 "libstagefright_mpeg2extractor",
522 "libstagefright_mpeg2support",
523 "libsync",
524 "libsystem_headers",
525 "libui",
526 "libui_headers",
527 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000528 "libutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900529 "libutils_headers",
530 "libvibrator",
531 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000532 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libwebm",
534 "media_ndk_headers",
535 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000536 "updatable-media",
537 }
538 //
539 // Module separator
540 //
541 m["com.android.media.swcodec"] = []string{
542 "android.frameworks.bufferhub@1.0",
543 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900544 "android.hardware.configstore-utils",
545 "android.hardware.configstore@1.0",
546 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000547 "android.hardware.graphics.allocator@2.0",
548 "android.hardware.graphics.allocator@3.0",
549 "android.hardware.graphics.allocator@4.0",
550 "android.hardware.graphics.bufferqueue@1.0",
551 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900552 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000553 "android.hardware.graphics.common@1.0",
554 "android.hardware.graphics.common@1.1",
555 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000556 "android.hardware.graphics.mapper@2.0",
557 "android.hardware.graphics.mapper@2.1",
558 "android.hardware.graphics.mapper@3.0",
559 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000560 "android.hardware.media.bufferpool@2.0",
561 "android.hardware.media.c2@1.0",
562 "android.hardware.media.c2@1.1",
563 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900564 "android.hardware.media@1.0",
565 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000566 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900567 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000568 "android.hidl.safe_union@1.0",
569 "android.hidl.token@1.0",
570 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900571 "fmtlib",
572 "libEGL",
573 "libFLAC",
574 "libFLAC-config",
575 "libFLAC-headers",
576 "libFraunhoferAAC",
577 "libarect",
578 "libasync_safe",
579 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000580 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900581 "libaudioutils",
582 "libaudioutils_fixedfft",
583 "libavcdec",
584 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000585 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900586 "libavservices_minijail",
587 "libbacktrace",
588 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000589 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900590 "libbase_headers",
591 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000592 "libbinderthreadstate",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libbluetooth-types-header",
594 "libbufferhub_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000595 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900596 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 "libcap",
598 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900599 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000600 "libcodec2_hidl@1.0",
601 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000603 "libcodec2_soft_aacdec",
604 "libcodec2_soft_aacenc",
605 "libcodec2_soft_amrnbdec",
606 "libcodec2_soft_amrnbenc",
607 "libcodec2_soft_amrwbdec",
608 "libcodec2_soft_amrwbenc",
609 "libcodec2_soft_av1dec_gav1",
610 "libcodec2_soft_avcdec",
611 "libcodec2_soft_avcenc",
612 "libcodec2_soft_common",
613 "libcodec2_soft_flacdec",
614 "libcodec2_soft_flacenc",
615 "libcodec2_soft_g711alawdec",
616 "libcodec2_soft_g711mlawdec",
617 "libcodec2_soft_gsmdec",
618 "libcodec2_soft_h263dec",
619 "libcodec2_soft_h263enc",
620 "libcodec2_soft_hevcdec",
621 "libcodec2_soft_hevcenc",
622 "libcodec2_soft_mp3dec",
623 "libcodec2_soft_mpeg2dec",
624 "libcodec2_soft_mpeg4dec",
625 "libcodec2_soft_mpeg4enc",
626 "libcodec2_soft_opusdec",
627 "libcodec2_soft_opusenc",
628 "libcodec2_soft_rawdec",
629 "libcodec2_soft_vorbisdec",
630 "libcodec2_soft_vp8dec",
631 "libcodec2_soft_vp8enc",
632 "libcodec2_soft_vp9dec",
633 "libcodec2_soft_vp9enc",
634 "libcodec2_vndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000635 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900636 "libcutils_headers",
637 "libdexfile_support",
638 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000639 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "libfmq",
641 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000642 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900643 "libgrallocusage",
644 "libgraphicsenv",
645 "libgsm",
646 "libgui_bufferqueue_static",
647 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000648 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900649 "libhardware_headers",
650 "libhevcdec",
651 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000652 "libhidlbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900653 "libhidlbase-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000654 "libhidlmemory",
Jiyong Parkfa899442020-01-31 02:49:53 +0900655 "libhidltransport-impl-internal",
656 "libhwbinder-impl-internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000657 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900658 "libjpeg",
659 "libjsoncpp",
660 "liblog_headers",
661 "liblzma",
662 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000663 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900664 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000665 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900666 "libminijail_gen_constants",
667 "libminijail_gen_constants_obj",
668 "libminijail_gen_syscall",
669 "libminijail_gen_syscall_obj",
670 "libminijail_generated",
671 "libmpeg2dec",
672 "libnativebase_headers",
673 "libnativebridge_lazy",
674 "libnativeloader_lazy",
675 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000676 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000678 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000680 "libscudo_wrapper",
681 "libsfplugin_ccodec_utils",
682 "libspeexresampler",
683 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900684 "libstagefright_amrnbdec",
685 "libstagefright_amrnbenc",
686 "libstagefright_amrwbdec",
687 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000688 "libstagefright_bufferpool@2.0.1",
689 "libstagefright_bufferqueue_helper",
690 "libstagefright_enc_common",
691 "libstagefright_flacdec",
692 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900693 "libstagefright_foundation_headers",
694 "libstagefright_headers",
695 "libstagefright_m4vh263dec",
696 "libstagefright_m4vh263enc",
697 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000698 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000700 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900701 "libui_headers",
702 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000703 "libutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000705 "libvorbisidec",
706 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900707 "libyuv",
708 "libyuv_static",
709 "media_ndk_headers",
710 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000711 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000712 }
713 //
714 // Module separator
715 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900716 m["com.android.mediaprovider"] = []string{
717 "MediaProvider",
718 "MediaProviderGoogle",
719 "fmtlib_ndk",
720 "guava",
721 "libbase_ndk",
722 "libfuse",
723 "libfuse_jni",
724 "libnativehelper_header_only",
725 }
726 //
727 // Module separator
728 //
729 m["com.android.permission"] = []string{
730 "androidx.annotation_annotation",
731 "androidx.annotation_annotation-nodeps",
732 "androidx.lifecycle_lifecycle-common",
733 "androidx.lifecycle_lifecycle-common-java8",
734 "androidx.lifecycle_lifecycle-common-java8-nodeps",
735 "androidx.lifecycle_lifecycle-common-nodeps",
736 "kotlin-annotations",
737 "kotlin-stdlib",
738 "kotlin-stdlib-jdk7",
739 "kotlin-stdlib-jdk8",
740 "kotlinx-coroutines-android",
741 "kotlinx-coroutines-android-nodeps",
742 "kotlinx-coroutines-core",
743 "kotlinx-coroutines-core-nodeps",
744 "libprotobuf-java-lite",
745 "permissioncontroller-statsd",
746 }
Anton Hansson5053c292020-01-10 15:12:39 +0000747 //
748 // Module separator
749 //
Anton Hansson5053c292020-01-10 15:12:39 +0000750 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900751 "bionic_libc_platform_headers",
752 "fmtlib",
753 "libarm-optimized-routines-math",
754 "libasync_safe",
755 "libasync_safe_headers",
756 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000757 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900758 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000759 "libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900760 "libc_aeabi",
761 "libc_bionic",
762 "libc_bionic_ndk",
763 "libc_bootstrap",
764 "libc_common",
765 "libc_common_shared",
766 "libc_common_static",
767 "libc_dns",
768 "libc_dynamic_dispatch",
769 "libc_fortify",
770 "libc_freebsd",
771 "libc_freebsd_large_stack",
772 "libc_gdtoa",
773 "libc_headers",
774 "libc_init_dynamic",
775 "libc_init_static",
776 "libc_jemalloc_wrapper",
777 "libc_netbsd",
778 "libc_nomalloc",
779 "libc_nopthread",
780 "libc_openbsd",
781 "libc_openbsd_large_stack",
782 "libc_openbsd_ndk",
783 "libc_pthread",
784 "libc_static_dispatch",
785 "libc_syscalls",
786 "libc_tzcode",
787 "libc_unwind_static",
788 "libcutils",
789 "libcutils_headers",
790 "libdebuggerd",
791 "libdebuggerd_common_headers",
792 "libdebuggerd_handler_core",
793 "libdebuggerd_handler_fallback",
794 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000795 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900796 "libdexfile_support_static",
797 "libgtest_prod",
798 "libjemalloc5",
799 "liblinker_main",
800 "liblinker_malloc",
801 "liblog",
802 "liblog_headers",
803 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000804 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 "libprocessgroup_headers",
806 "libprocinfo",
807 "libpropertyinfoparser",
808 "libscudo",
809 "libstdc++",
810 "libsystem_headers",
811 "libsystemproperties",
812 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000813 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900814 "libutils_headers",
815 "libz",
816 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000817 }
818 //
819 // Module separator
820 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900821 m["com.android.resolv"] = []string{
822 "bcm_object",
823 "dnsresolver_aidl_interface-unstable-ndk_platform",
824 "fmtlib",
825 "libbacktrace_headers",
826 "libbase",
827 "libbase_headers",
828 "libc++",
829 "libcrypto",
830 "libcutils",
831 "libcutils_headers",
832 "libgtest_prod",
833 "libjsoncpp",
834 "liblog",
835 "liblog_headers",
836 "libnativehelper_header_only",
837 "libnetd_client_headers",
838 "libnetd_resolv",
839 "libnetdutils",
840 "libprocessgroup",
841 "libprocessgroup_headers",
842 "libprotobuf-cpp-lite",
843 "libssl",
844 "libstatslog_resolv",
845 "libstatspush_compat",
846 "libstatssocket",
847 "libstatssocket_headers",
848 "libsystem_headers",
849 "libsysutils",
850 "libutils",
851 "libutils_headers",
852 "netd_event_listener_interface-ndk_platform",
853 "server_configurable_flags",
854 "stats_proto",
855 }
Anton Hansson5053c292020-01-10 15:12:39 +0000856 //
857 // Module separator
858 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900859 m["com.android.tethering"] = []string{
860 "libbase",
861 "libc++",
862 "libnativehelper_compat_libc++",
863 "android.hardware.tetheroffload.config@1.0",
864 "fmtlib",
865 "libbacktrace_headers",
866 "libbase_headers",
867 "libbinderthreadstate",
868 "libcgrouprc",
869 "libcgrouprc_format",
870 "libcutils",
871 "libcutils_headers",
872 "libhidlbase",
873 "libhidlbase-impl-internal",
874 "libhidltransport-impl-internal",
875 "libhwbinder-impl-internal",
876 "libjsoncpp",
877 "liblog",
878 "liblog_headers",
879 "libprocessgroup",
880 "libprocessgroup_headers",
881 "libsystem_headers",
882 "libtetherutilsjni",
883 "libutils",
884 "libutils_headers",
885 "libvndksupport",
886 "tethering-aidl-interfaces-java",
887 }
Anton Hansson5053c292020-01-10 15:12:39 +0000888 //
889 // Module separator
890 //
891 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900892 "PlatformProperties",
893 "android.hardware.wifi-V1.0-java",
894 "android.hardware.wifi-V1.1-java",
895 "android.hardware.wifi-V1.2-java",
896 "android.hardware.wifi-V1.3-java",
897 "android.hardware.wifi-V1.4-java",
898 "android.hardware.wifi.hostapd-V1.0-java",
899 "android.hardware.wifi.hostapd-V1.1-java",
900 "android.hardware.wifi.hostapd-V1.2-java",
901 "android.hardware.wifi.supplicant-V1.0-java",
902 "android.hardware.wifi.supplicant-V1.1-java",
903 "android.hardware.wifi.supplicant-V1.2-java",
904 "android.hardware.wifi.supplicant-V1.3-java",
905 "android.hidl.base-V1.0-java",
906 "android.hidl.manager-V1.0-java",
907 "android.hidl.manager-V1.1-java",
908 "android.hidl.manager-V1.2-java",
909 "androidx.annotation_annotation",
910 "androidx.annotation_annotation-nodeps",
911 "bouncycastle-unbundled",
912 "dnsresolver_aidl_interface-V2-java",
913 "error_prone_annotations",
914 "ipmemorystore-aidl-interfaces-V3-java",
915 "ipmemorystore-aidl-interfaces-java",
916 "ksoap2",
917 "libbacktrace_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000918 "libbase",
Jiyong Parkfa899442020-01-31 02:49:53 +0900919 "libbase_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000920 "libc++",
921 "libcutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900922 "libcutils_headers",
923 "liblog_headers",
924 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000925 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900926 "libprocessgroup_headers",
927 "libprotobuf-java-lite",
928 "libprotobuf-java-nano",
929 "libsystem_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000930 "libutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900931 "libutils_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000932 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900933 "net-utils-services-common",
934 "netd_aidl_interface-V2-java",
935 "netd_aidl_interface-unstable-java",
936 "netd_event_listener_interface-java",
937 "netlink-client",
938 "networkstack-aidl-interfaces-unstable-java",
939 "networkstack-client",
940 "services.net",
941 "wifi-lite-protos",
942 "wifi-nano-protos",
943 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000944 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900945 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000946 }
947 //
948 // Module separator
949 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900950 m["com.android.sdkext"] = []string{
951 "fmtlib_ndk",
952 "libbase_ndk",
953 "libprotobuf-cpp-lite-ndk",
954 }
955 //
956 // Module separator
957 //
958 m["com.android.os.statsd"] = []string{
959 "libbacktrace_headers",
960 "libbase_headers",
961 "libc++",
962 "libcutils",
963 "libcutils_headers",
964 "liblog_headers",
965 "libprocessgroup_headers",
966 "libstatssocket",
967 "libsystem_headers",
968 "libutils_headers",
969 }
970 //
971 // Module separator
972 //
973 m["//any"] = []string{
974 "crtbegin_dynamic",
975 "crtbegin_dynamic1",
976 "crtbegin_so",
977 "crtbegin_so1",
978 "crtbegin_static",
979 "crtbrand",
980 "crtend_android",
981 "crtend_so",
982 "libatomic",
983 "libc++_static",
984 "libc++abi",
985 "libc++demangle",
986 "libc_headers",
987 "libclang_rt",
988 "libgcc_stripped",
989 "libprofile-clang-extras",
990 "libprofile-clang-extras_ndk",
991 "libprofile-extras",
992 "libprofile-extras_ndk",
993 "libunwind_llvm",
994 "ndk_crtbegin_dynamic.27",
995 "ndk_crtbegin_so.16",
996 "ndk_crtbegin_so.19",
997 "ndk_crtbegin_so.21",
998 "ndk_crtbegin_so.24",
999 "ndk_crtbegin_so.27",
1000 "ndk_crtend_android.27",
1001 "ndk_crtend_so.16",
1002 "ndk_crtend_so.19",
1003 "ndk_crtend_so.21",
1004 "ndk_crtend_so.24",
1005 "ndk_crtend_so.27",
1006 "ndk_libandroid_support",
1007 "ndk_libc++_static",
1008 "ndk_libc++abi",
1009 "ndk_libunwind",
1010 }
Anton Hansson5053c292020-01-10 15:12:39 +00001011 return m
1012}
1013
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001014func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001015 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001016 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001017 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001018 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001019 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001020 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001021
Jooyung Han31c470b2019-10-18 16:26:59 +09001022 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001023 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001024
1025 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1026 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1027 sort.Strings(*apexFileContextsInfos)
1028 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1029 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001030}
1031
Jooyung Han31c470b2019-10-18 16:26:59 +09001032func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1033 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1034 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1035}
1036
Jiyong Parkd1063c12019-07-17 20:08:41 +09001037func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parka308ea12019-11-15 10:38:39 +09001038 ctx.BottomUp("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001039 ctx.BottomUp("apex", apexMutator).Parallel()
1040 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1041 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001042}
1043
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001044// Mark the direct and transitive dependencies of apex bundles so that they
1045// can be built for the apex bundles.
Jiyong Parka308ea12019-11-15 10:38:39 +09001046func apexDepsMutator(mctx android.BottomUpMutatorContext) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00001047 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Colin Crossa4925902018-11-16 11:36:28 -08001048 apexBundleName := mctx.ModuleName()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049 mctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001050 depName := mctx.OtherModuleName(child)
1051 // If the parent is apexBundle, this child is directly depended.
1052 _, directDep := parent.(*apexBundle)
Alex Light0851b882019-02-07 13:20:53 -08001053 if a.installable() && !a.testApex {
Alex Lightf98087f2019-02-04 14:45:06 -08001054 // TODO(b/123892969): Workaround for not having any way to annotate test-apexs
1055 // non-installable apex's cannot be installed and so should not prevent libraries from being
1056 // installed to the system.
1057 android.UpdateApexDependency(apexBundleName, depName, directDep)
1058 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001059
Jiyong Park3ff16992019-12-27 14:11:47 +09001060 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
1061 (directDep || am.DepIsInSameApex(mctx, child)) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001062 am.BuildForApex(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001063 return true
1064 } else {
1065 return false
1066 }
1067 })
1068 }
1069}
1070
1071// Create apex variations if a module is included in APEX(s).
1072func apexMutator(mctx android.BottomUpMutatorContext) {
1073 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001074 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001075 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001076 // apex bundle itself is mutated so that it and its modules have same
1077 // apex variant.
1078 apexBundleName := mctx.ModuleName()
1079 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001080 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1081 apexBundleName := o.GetOverriddenModuleName()
1082 if apexBundleName == "" {
1083 mctx.ModuleErrorf("base property is not set")
1084 return
1085 }
1086 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001087 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001088
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001089}
Sundong Ahne9b55722019-09-06 17:37:42 +09001090
Jooyung Han7a78a922019-10-08 21:59:58 +09001091var (
1092 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1093 apexFileContextsInfosMutex sync.Mutex
1094)
1095
1096func apexFileContextsInfos(config android.Config) *[]string {
1097 return config.Once(apexFileContextsInfosKey, func() interface{} {
1098 return &[]string{}
1099 }).(*[]string)
1100}
1101
Jooyung Han54aca7b2019-11-20 02:26:02 +09001102func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001103 apexFileContextsInfosMutex.Lock()
1104 defer apexFileContextsInfosMutex.Unlock()
1105 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001106 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001107}
1108
Sundong Ahne9b55722019-09-06 17:37:42 +09001109func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001110 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001111 var variants []string
1112 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1113 case "image":
1114 variants = append(variants, imageApexType, flattenedApexType)
1115 case "zip":
1116 variants = append(variants, zipApexType)
1117 case "both":
1118 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1119 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001120 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001121 return
1122 }
1123
1124 modules := mctx.CreateLocalVariations(variants...)
1125
1126 for i, v := range variants {
1127 switch v {
1128 case imageApexType:
1129 modules[i].(*apexBundle).properties.ApexType = imageApex
1130 case zipApexType:
1131 modules[i].(*apexBundle).properties.ApexType = zipApex
1132 case flattenedApexType:
1133 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001134 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001135 modules[i].(*apexBundle).MakeAsSystemExt()
1136 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001137 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001138 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001139 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1140 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001141 }
1142}
1143
Jooyung Han5c998b92019-06-27 11:30:33 +09001144func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1145 if ab, ok := mctx.Module().(*apexBundle); ok {
1146 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1147 }
1148}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001149
Jooyung Handc782442019-11-01 03:14:38 +09001150var (
1151 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1152)
1153
1154// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1155// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1156// which may cause compatibility issues. (e.g. libbinder)
1157// Even though libbinder restricts its availability via 'apex_available' property and relies on
1158// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1159// to avoid similar problems.
1160func useVendorWhitelist(config android.Config) []string {
1161 return config.Once(useVendorWhitelistKey, func() interface{} {
1162 return []string{
1163 // swcodec uses "vendor" variants for smaller size
1164 "com.android.media.swcodec",
1165 "test_com.android.media.swcodec",
1166 }
1167 }).([]string)
1168}
1169
1170// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1171// called before the first call to useVendorWhitelist()
1172func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1173 config.Once(useVendorWhitelistKey, func() interface{} {
1174 return whitelist
1175 })
1176}
1177
Alex Light9670d332019-01-29 18:07:33 -08001178type apexNativeDependencies struct {
1179 // List of native libraries
1180 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001181
Alex Light9670d332019-01-29 18:07:33 -08001182 // List of native executables
1183 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001184
Roland Levillain630846d2019-06-26 12:48:34 +01001185 // List of native tests
1186 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001187}
Jooyung Han344d5432019-08-23 11:17:39 +09001188
Alex Light9670d332019-01-29 18:07:33 -08001189type apexMultilibProperties struct {
1190 // Native dependencies whose compile_multilib is "first"
1191 First apexNativeDependencies
1192
1193 // Native dependencies whose compile_multilib is "both"
1194 Both apexNativeDependencies
1195
1196 // Native dependencies whose compile_multilib is "prefer32"
1197 Prefer32 apexNativeDependencies
1198
1199 // Native dependencies whose compile_multilib is "32"
1200 Lib32 apexNativeDependencies
1201
1202 // Native dependencies whose compile_multilib is "64"
1203 Lib64 apexNativeDependencies
1204}
1205
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001206type apexBundleProperties struct {
1207 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001208 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001209 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001210
Jiyong Park40e26a22019-02-08 02:53:06 +09001211 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1212 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001213 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001214
Roland Levillain411c5842019-09-19 16:37:20 +01001215 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1216 // device (/apex/<apex_name>).
1217 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001218 Apex_name *string
1219
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001220 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001221 // For platform APEXes, this should points to a file under /system/sepolicy
1222 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1223 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001224
1225 // List of native shared libs that are embedded inside this APEX bundle
1226 Native_shared_libs []string
1227
Roland Levillain630846d2019-06-26 12:48:34 +01001228 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001229 Binaries []string
1230
1231 // List of java libraries that are embedded inside this APEX bundle
1232 Java_libs []string
1233
1234 // List of prebuilt files that are embedded inside this APEX bundle
1235 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001236
Roland Levillain630846d2019-06-26 12:48:34 +01001237 // List of tests that are embedded inside this APEX bundle
1238 Tests []string
1239
Jiyong Parkff1458f2018-10-12 21:49:38 +09001240 // Name of the apex_key module that provides the private key to sign APEX
1241 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001242
Alex Light5098a612018-11-29 17:12:15 -08001243 // The type of APEX to build. Controls what the APEX payload is. Either
1244 // 'image', 'zip' or 'both'. Default: 'image'.
1245 Payload_type *string
1246
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001247 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1248 // or an android_app_certificate module name in the form ":module".
1249 Certificate *string
1250
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001251 // Whether this APEX is installable to one of the partitions. Default: true.
1252 Installable *bool
1253
Jiyong Parkda6eb592018-12-19 17:12:36 +09001254 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1255 // Default is false.
1256 Use_vendor *bool
1257
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001258 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1259 Ignore_system_library_special_case *bool
1260
Alex Light9670d332019-01-29 18:07:33 -08001261 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001262
Jiyong Parkf97782b2019-02-13 20:28:58 +09001263 // List of sanitizer names that this APEX is enabled for
1264 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001265
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001266 PreventInstall bool `blueprint:"mutated"`
1267
1268 HideFromMake bool `blueprint:"mutated"`
1269
Jooyung Han5c998b92019-06-27 11:30:33 +09001270 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1271 Provide_cpp_shared_libs *bool
1272
1273 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1274 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001275
1276 // A txt file containing list of files that are whitelisted to be included in this APEX.
1277 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001278
Sundong Ahnabb64432019-10-22 13:58:29 +09001279 // package format of this apex variant; could be non-flattened, flattened, or zip.
1280 // imageApex, zipApex or flattened
1281 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001282
Jiyong Parkd1063c12019-07-17 20:08:41 +09001283 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1284 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1285 // is implied. This value affects all modules included in this APEX. In other words, they are
1286 // also built with the SDKs specified here.
1287 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001288
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001289 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1290 // Should be only used in tests#.
1291 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001292
1293 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1294 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1295 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001296
1297 IsCoverageVariant bool `blueprint:"mutated"`
Alex Light9670d332019-01-29 18:07:33 -08001298}
1299
1300type apexTargetBundleProperties struct {
1301 Target struct {
1302 // Multilib properties only for android.
1303 Android struct {
1304 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001305 }
Jooyung Han344d5432019-08-23 11:17:39 +09001306
Alex Light9670d332019-01-29 18:07:33 -08001307 // Multilib properties only for host.
1308 Host struct {
1309 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001310 }
Jooyung Han344d5432019-08-23 11:17:39 +09001311
Alex Light9670d332019-01-29 18:07:33 -08001312 // Multilib properties only for host linux_bionic.
1313 Linux_bionic struct {
1314 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001315 }
Jooyung Han344d5432019-08-23 11:17:39 +09001316
Alex Light9670d332019-01-29 18:07:33 -08001317 // Multilib properties only for host linux_glibc.
1318 Linux_glibc struct {
1319 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001320 }
1321 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001322}
1323
Jiyong Park5d790c32019-11-15 18:40:32 +09001324type overridableProperties struct {
1325 // List of APKs to package inside APEX
1326 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001327
1328 // Names of modules to be overridden. Listed modules can only be other binaries
1329 // (in Make or Soong).
1330 // This does not completely prevent installation of the overridden binaries, but if both
1331 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1332 // from PRODUCT_PACKAGES.
1333 Overrides []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001334}
1335
Alex Light5098a612018-11-29 17:12:15 -08001336type apexPackaging int
1337
1338const (
1339 imageApex apexPackaging = iota
1340 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001341 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001342)
1343
Sundong Ahnabb64432019-10-22 13:58:29 +09001344// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001345func (a apexPackaging) suffix() string {
1346 switch a {
1347 case imageApex:
1348 return imageApexSuffix
1349 case zipApex:
1350 return zipApexSuffix
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
1356func (a apexPackaging) name() string {
1357 switch a {
1358 case imageApex:
1359 return imageApexType
1360 case zipApex:
1361 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001362 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001363 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001364 }
1365}
1366
Jiyong Parkf653b052019-11-18 15:39:01 +09001367type apexFileClass int
1368
1369const (
1370 etc apexFileClass = iota
1371 nativeSharedLib
1372 nativeExecutable
1373 shBinary
1374 pyBinary
1375 goBinary
1376 javaSharedLib
1377 nativeTest
1378 app
1379)
1380
Jiyong Park8fd61922018-11-08 02:50:25 +09001381func (class apexFileClass) NameInMake() string {
1382 switch class {
1383 case etc:
1384 return "ETC"
1385 case nativeSharedLib:
1386 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001387 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001388 return "EXECUTABLES"
1389 case javaSharedLib:
1390 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001391 case nativeTest:
1392 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001393 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001394 // b/142537672 Why isn't this APP? We want to have full control over
1395 // the paths and file names of the apk file under the flattend APEX.
1396 // If this is set to APP, then the paths and file names are modified
1397 // by the Make build system. For example, it is installed to
1398 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1399 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1400 // appends module name (which is <apexname>.<Appname> to the path.
1401 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001402 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001403 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001404 }
1405}
1406
Jiyong Parkf653b052019-11-18 15:39:01 +09001407// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001408type apexFile struct {
1409 builtFile android.Path
1410 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001411 installDir string
1412 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001413 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001414 // list of symlinks that will be created in installDir that point to this apexFile
1415 symlinks []string
1416 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001417 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001418
1419 requiredModuleNames []string
1420 targetRequiredModuleNames []string
1421 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001422
Colin Cross503c1d02020-01-28 14:00:53 -08001423 jacocoReportClassesFile android.Path // only for javalibs and apps
1424 certificate java.Certificate // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001425}
1426
Jiyong Park1833cef2019-12-13 13:28:36 +09001427func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1428 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001429 builtFile: builtFile,
1430 moduleName: moduleName,
1431 installDir: installDir,
1432 class: class,
1433 module: module,
1434 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001435 if module != nil {
1436 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001437 ret.requiredModuleNames = module.RequiredModuleNames()
1438 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1439 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001440 }
1441 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001442}
1443
1444func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001445 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001446}
1447
Jiyong Park7cd10e32020-01-14 09:22:18 +09001448// Path() returns path of this apex file relative to the APEX root
1449func (af *apexFile) Path() string {
1450 return filepath.Join(af.installDir, af.builtFile.Base())
1451}
1452
1453// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1454func (af *apexFile) SymlinkPaths() []string {
1455 var ret []string
1456 for _, symlink := range af.symlinks {
1457 ret = append(ret, filepath.Join(af.installDir, symlink))
1458 }
1459 return ret
1460}
1461
1462func (af *apexFile) AvailableToPlatform() bool {
1463 if af.module == nil {
1464 return false
1465 }
1466 if am, ok := af.module.(android.ApexModule); ok {
1467 return am.AvailableFor(android.AvailableToPlatform)
1468 }
1469 return false
1470}
1471
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001472type apexBundle struct {
1473 android.ModuleBase
1474 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001475 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001476 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001477
Jiyong Park5d790c32019-11-15 18:40:32 +09001478 properties apexBundleProperties
1479 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001480 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001481
Jooyung Hanf21c7972019-12-16 22:32:06 +09001482 // specific to apex_vndk modules
1483 vndkProperties apexVndkProperties
1484
Colin Crossa4925902018-11-16 11:36:28 -08001485 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001486 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001487 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001488
Jiyong Park03b68dd2019-07-26 23:20:40 +09001489 prebuiltFileToDelete string
1490
Jiyong Park42cca6c2019-04-01 11:15:50 +09001491 public_key_file android.Path
1492 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001493
1494 container_certificate_file android.Path
1495 container_private_key_file android.Path
1496
Jooyung Han54aca7b2019-11-20 02:26:02 +09001497 fileContexts android.Path
1498
Jiyong Park8fd61922018-11-08 02:50:25 +09001499 // list of files to be included in this apex
1500 filesInfo []apexFile
1501
Jiyong Park956305c2020-01-09 12:32:06 +09001502 // list of module names that should be installed along with this APEX
1503 requiredDeps []string
1504
1505 // list of module names that this APEX is depending on (to be shown via *-deps-info target)
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001506 externalDeps []string
Jiyong Park956305c2020-01-09 12:32:06 +09001507 // list of module names that this APEX is including (to be shown via *-deps-info target)
1508 internalDeps []string
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001509
Sundong Ahnabb64432019-10-22 13:58:29 +09001510 testApex bool
1511 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001512 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001513 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001514
Jooyung Han214bf372019-11-12 13:03:50 +09001515 manifestJsonOut android.WritablePath
1516 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001517
Jooyung Han002ab682020-01-08 01:57:58 +09001518 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001519 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001520 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001521 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1522 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001523
1524 // Suffix of module name in Android.mk
1525 // ".flattened", ".apex", ".zipapex", or ""
1526 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001527
1528 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001529
1530 // Whether to create symlink to the system file instead of having a file
1531 // inside the apex or not
1532 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001533
1534 // Struct holding the merged notice file paths in different formats
1535 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001536}
1537
Jiyong Park397e55e2018-10-24 21:09:55 +09001538func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001539 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001540 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001541 // Use *FarVariation* to be able to depend on modules having
1542 // conflicting variations with this module. This is required since
1543 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1544 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001545 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001546 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001547 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001548 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001549 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001550
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001551 ctx.AddFarVariationDependencies(append(target.Variations(),
1552 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1553 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001554
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001555 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001556 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001557 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001558 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001559}
1560
Alex Light9670d332019-01-29 18:07:33 -08001561func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1562 if ctx.Os().Class == android.Device {
1563 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1564 } else {
1565 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1566 if ctx.Os().Bionic() {
1567 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1568 } else {
1569 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1570 }
1571 }
1572}
1573
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001574func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001575 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1576 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1577 }
1578
Jiyong Park397e55e2018-10-24 21:09:55 +09001579 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001580 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001581
1582 a.combineProperties(ctx)
1583
Jiyong Park397e55e2018-10-24 21:09:55 +09001584 has32BitTarget := false
1585 for _, target := range targets {
1586 if target.Arch.ArchType.Multilib == "lib32" {
1587 has32BitTarget = true
1588 }
1589 }
1590 for i, target := range targets {
1591 // When multilib.* is omitted for native_shared_libs, it implies
1592 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001593 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001594 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001595 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001596 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001597
Roland Levillain630846d2019-06-26 12:48:34 +01001598 // When multilib.* is omitted for tests, it implies
1599 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001600 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001601 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001602 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001603 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001604
Jiyong Park397e55e2018-10-24 21:09:55 +09001605 // Add native modules targetting both ABIs
1606 addDependenciesForNativeModules(ctx,
1607 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001608 a.properties.Multilib.Both.Binaries,
1609 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001610 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001611 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001612
Alex Light3d673592019-01-18 14:37:31 -08001613 isPrimaryAbi := i == 0
1614 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001615 // When multilib.* is omitted for binaries, it implies
1616 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001617 ctx.AddFarVariationDependencies(append(target.Variations(),
1618 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1619 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001620
1621 // Add native modules targetting the first ABI
1622 addDependenciesForNativeModules(ctx,
1623 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001624 a.properties.Multilib.First.Binaries,
1625 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001626 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001627 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001628 }
1629
1630 switch target.Arch.ArchType.Multilib {
1631 case "lib32":
1632 // Add native modules targetting 32-bit ABI
1633 addDependenciesForNativeModules(ctx,
1634 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001635 a.properties.Multilib.Lib32.Binaries,
1636 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001637 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001638 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001639
1640 addDependenciesForNativeModules(ctx,
1641 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001642 a.properties.Multilib.Prefer32.Binaries,
1643 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001644 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001645 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001646 case "lib64":
1647 // Add native modules targetting 64-bit ABI
1648 addDependenciesForNativeModules(ctx,
1649 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001650 a.properties.Multilib.Lib64.Binaries,
1651 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001652 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001653 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001654
1655 if !has32BitTarget {
1656 addDependenciesForNativeModules(ctx,
1657 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001658 a.properties.Multilib.Prefer32.Binaries,
1659 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001660 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001661 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001662 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001663
1664 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1665 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1666 if sanitizer == "hwaddress" {
1667 addDependenciesForNativeModules(ctx,
1668 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001669 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001670 break
1671 }
1672 }
1673 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001674 }
1675
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001676 }
1677
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001678 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1679 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1680 // b/144532908
1681 archForPrebuiltEtc := config.Arches()[0]
1682 for _, arch := range config.Arches() {
1683 // Prefer 64-bit arch if there is any
1684 if arch.ArchType.Multilib == "lib64" {
1685 archForPrebuiltEtc = arch
1686 break
1687 }
1688 }
1689 ctx.AddFarVariationDependencies([]blueprint.Variation{
1690 {Mutator: "os", Variation: ctx.Os().String()},
1691 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1692 }, prebuiltTag, a.properties.Prebuilts...)
1693
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001694 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1695 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001696
Ulya Trafimovich44561882020-01-03 13:25:54 +00001697 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1698 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1699 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1700 javaLibTag, "jacocoagent")
1701 }
1702
Jiyong Park23c52b02019-02-02 13:13:47 +09001703 if String(a.properties.Key) == "" {
1704 ctx.ModuleErrorf("key is missing")
1705 return
1706 }
1707 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001708
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001709 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001710 if cert != "" {
1711 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001712 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001713
1714 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1715 if len(a.properties.Uses_sdks) > 0 {
1716 sdkRefs := []android.SdkRef{}
1717 for _, str := range a.properties.Uses_sdks {
1718 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1719 sdkRefs = append(sdkRefs, parsed)
1720 }
1721 a.BuildWithSdks(sdkRefs)
1722 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001723}
1724
Jiyong Park5d790c32019-11-15 18:40:32 +09001725func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1726 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1727 androidAppTag, a.overridableProperties.Apps...)
1728}
1729
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001730func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1731 // direct deps of an APEX bundle are all part of the APEX bundle
1732 return true
1733}
1734
Colin Cross0ea8ba82019-06-06 14:33:29 -07001735func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001736 moduleName := ctx.ModuleName()
1737 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1738 // we check with the pseudo module name to see if its certificate is overridden.
1739 if a.vndkApex {
1740 moduleName = vndkApexName
1741 }
1742 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001743 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001744 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001745 }
1746 return String(a.properties.Certificate)
1747}
1748
Colin Cross41955e82019-05-29 14:40:35 -07001749func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1750 switch tag {
1751 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001752 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001753 default:
1754 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001755 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001756}
1757
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001758func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001759 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001760}
1761
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001762func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1763 return proptools.Bool(a.properties.Test_only_no_hashtree)
1764}
1765
Jiyong Park7c1dc612019-01-05 11:15:24 +09001766func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001767 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001768 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001769 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001770 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001771 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001772 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001773 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001774 }
1775}
1776
Jiyong Parkf97782b2019-02-13 20:28:58 +09001777func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1778 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1779 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1780 }
1781}
1782
Jiyong Park388ef3f2019-01-28 19:47:32 +09001783func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001784 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1785 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001786 }
1787
1788 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001789 globalSanitizerNames := []string{}
1790 if a.Host() {
1791 globalSanitizerNames = ctx.Config().SanitizeHost()
1792 } else {
1793 arches := ctx.Config().SanitizeDeviceArch()
1794 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1795 globalSanitizerNames = ctx.Config().SanitizeDevice()
1796 }
1797 }
1798 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001799}
1800
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001801func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001802 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001803}
1804
1805func (a *apexBundle) PreventInstall() {
1806 a.properties.PreventInstall = true
1807}
1808
1809func (a *apexBundle) HideFromMake() {
1810 a.properties.HideFromMake = true
1811}
1812
Jiyong Park956305c2020-01-09 12:32:06 +09001813func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1814 a.properties.IsCoverageVariant = coverage
1815}
1816
Jiyong Parkf653b052019-11-18 15:39:01 +09001817// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001818func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001819 // Decide the APEX-local directory by the multilib of the library
1820 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001821 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001822 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001823 case "lib32":
1824 dirInApex = "lib"
1825 case "lib64":
1826 dirInApex = "lib64"
1827 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001828 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001829 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001830 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001831 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001832 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001833 // Special case for Bionic libs and other libs installed with them. This is
1834 // to prevent those libs from being included in the search path
1835 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1836 // those libs in the Runtime APEX are available via the legacy paths in
1837 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1838 // to the legacy paths and thus will be loaded into the default linker
1839 // namespace (aka "platform" namespace). If the libs are directly in
1840 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1841 // into the runtime linker namespace, which will result in double loading of
1842 // them, which isn't supported.
1843 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001844 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001845
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001847 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001848}
1849
Jiyong Park1833cef2019-12-13 13:28:36 +09001850func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001851 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001852 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001853 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001854 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001855 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001856 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 af.symlinks = cc.Symlinks()
1858 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001859}
1860
Jiyong Park1833cef2019-12-13 13:28:36 +09001861func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 dirInApex := "bin"
1863 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001864 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001865}
Jiyong Park1833cef2019-12-13 13:28:36 +09001866func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001867 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001868 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1869 if err != nil {
1870 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001872 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 fileToCopy := android.PathForOutput(ctx, s)
1874 // NB: Since go binaries are static we don't need the module for anything here, which is
1875 // good since the go tool is a blueprint.Module not an android.Module like we would
1876 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001877 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001878}
1879
Jiyong Park1833cef2019-12-13 13:28:36 +09001880func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 dirInApex := filepath.Join("bin", sh.SubDir())
1882 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001883 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001884 af.symlinks = sh.Symlinks()
1885 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001886}
1887
Jooyung Han58f26ab2019-12-18 15:34:32 +09001888// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1889type javaLibrary interface {
1890 android.Module
1891 java.Dependency
1892}
1893
1894func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001896 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001897 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1898 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1899 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001900}
1901
Jiyong Park1833cef2019-12-13 13:28:36 +09001902func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1904 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001905 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001906}
1907
atrost6e126252020-01-27 17:01:16 +00001908func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1909 dirInApex := filepath.Join("etc", config.SubDir())
1910 fileToCopy := config.CompatConfig()
1911 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1912}
1913
Jiyong Park1833cef2019-12-13 13:28:36 +09001914func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001915 android.Module
1916 Privileged() bool
1917 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001918 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001919 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001920}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001921 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001922 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001923 appDir = "priv-app"
1924 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 dirInApex := filepath.Join(appDir, pkgName)
1926 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001927 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1928 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001929 af.certificate = aapp.Certificate()
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 Parkfa899442020-01-31 02:49:53 +09001942// Ensures that the dependencies are marked as available for this APEX
1943func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1944 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1945 if ctx.Host() || a.testApex || a.vndkApex {
1946 return
1947 }
1948
1949 checkDep := func(ctx android.ModuleContext, am android.ApexModule) {
1950 apexName := ctx.ModuleName()
1951 if am.AvailableFor(apexName) || whitelistedApexAvailable(apexName, am) {
1952 return
1953 }
1954 ctx.ModuleErrorf("requires %q that is not available for the APEX.", am.Name())
1955 }
1956
1957 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1958 am, ok := child.(android.ApexModule)
1959 if !ok || !am.CanHaveApexVariants() {
1960 return false
1961 }
1962
1963 // Check for the direct dependencies that contribute to the payload
1964 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1965 if dt.payload {
1966 checkDep(ctx, am)
1967 return true
1968 }
1969 return false
1970 }
1971
1972 // Check for the indirect dependencies if it is considered as part of the APEX
1973 if am.DepIsInSameApex(ctx, am) {
1974 checkDep(ctx, am)
1975 return true
1976 }
1977
1978 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1979 return false
1980 })
1981}
1982
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001983func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001984 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1985 switch a.properties.ApexType {
1986 case imageApex:
1987 if buildFlattenedAsDefault {
1988 a.suffix = imageApexSuffix
1989 } else {
1990 a.suffix = ""
1991 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001992
1993 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001994 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001995 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001996 }
1997 case zipApex:
1998 if proptools.String(a.properties.Payload_type) == "zip" {
1999 a.suffix = ""
2000 a.primaryApexType = true
2001 } else {
2002 a.suffix = zipApexSuffix
2003 }
2004 case flattenedApex:
2005 if buildFlattenedAsDefault {
2006 a.suffix = ""
2007 a.primaryApexType = true
2008 } else {
2009 a.suffix = flattenedSuffix
2010 }
Alex Light5098a612018-11-29 17:12:15 -08002011 }
2012
Roland Levillain630846d2019-06-26 12:48:34 +01002013 if len(a.properties.Tests) > 0 && !a.testApex {
2014 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2015 return
2016 }
2017
Jiyong Parkfa899442020-01-31 02:49:53 +09002018 a.checkApexAvailability(ctx)
2019
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002020 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2021
Jooyung Hane1633032019-08-01 17:41:43 +09002022 // native lib dependencies
2023 var provideNativeLibs []string
2024 var requireNativeLibs []string
2025
Jooyung Han5c998b92019-06-27 11:30:33 +09002026 // Check if "uses" requirements are met with dependent apexBundles
2027 var providedNativeSharedLibs []string
2028 useVendor := proptools.Bool(a.properties.Use_vendor)
2029 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2030 if ctx.OtherModuleDependencyTag(m) != usesTag {
2031 return
2032 }
2033 otherName := ctx.OtherModuleName(m)
2034 other, ok := m.(*apexBundle)
2035 if !ok {
2036 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2037 return
2038 }
2039 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2040 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2041 return
2042 }
2043 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2044 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2045 return
2046 }
2047 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2048 })
2049
Jiyong Parkf653b052019-11-18 15:39:01 +09002050 var filesInfo []apexFile
Alex Light778127a2019-02-27 14:19:50 -08002051 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002052 depTag := ctx.OtherModuleDependencyTag(child)
2053 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002054 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park956305c2020-01-09 12:32:06 +09002055 if depTag != keyTag && depTag != certificateTag {
2056 a.internalDeps = append(a.internalDeps, depName)
2057 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002058 switch depTag {
2059 case sharedLibTag:
2060 if cc, ok := child.(*cc.Module); ok {
Jooyung Hane1633032019-08-01 17:41:43 +09002061 if cc.HasStubsVariants() {
2062 provideNativeLibs = append(provideNativeLibs, cc.OutputFile().Path().Base())
2063 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002064 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, cc, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09002065 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002066 } else {
2067 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002068 }
2069 case executableTag:
2070 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002071 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002072 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002073 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002074 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002075 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002076 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002077 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002078 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002079 } else {
Alex Light778127a2019-02-27 14:19:50 -08002080 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 +09002081 }
2082 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002083 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002086 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2087 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002088 filesInfo = append(filesInfo, af)
2089 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002090 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002091 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2092 af := apexFileForJavaLibrary(ctx, sdkLib)
2093 if !af.Ok() {
2094 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2095 return false
2096 }
2097 filesInfo = append(filesInfo, af)
2098
Jooyung Han624058e2019-12-24 18:38:06 +09002099 pf, _ := sdkLib.OutputFiles(".xml")
2100 if len(pf) != 1 {
Jooyung Han58f26ab2019-12-18 15:34:32 +09002101 ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
2102 return false
2103 }
Jooyung Han624058e2019-12-24 18:38:06 +09002104 filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002105 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002106 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002107 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002108 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002109 case androidAppTag:
2110 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2111 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002112 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002113 return true // track transitive dependencies
2114 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002115 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002116 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2117 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002118 } else {
2119 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2120 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002121 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002122 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002123 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002124 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2125 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002126 } else {
atrost6e126252020-01-27 17:01:16 +00002127 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002128 }
Roland Levillain630846d2019-06-26 12:48:34 +01002129 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002130 if ccTest, ok := child.(*cc.Module); ok {
2131 if ccTest.IsTestPerSrcAllTestsVariation() {
2132 // Multiple-output test module (where `test_per_src: true`).
2133 //
2134 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2135 // We do not add this variation to `filesInfo`, as it has no output;
2136 // however, we do add the other variations of this module as indirect
2137 // dependencies (see below).
2138 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002139 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002140 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002141 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 af.class = nativeTest
2143 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002144 }
Roland Levillain630846d2019-06-26 12:48:34 +01002145 } else {
2146 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2147 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002148 case keyTag:
2149 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002150 a.private_key_file = key.private_key_file
2151 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002152 } else {
2153 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002154 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002155 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002156 case certificateTag:
2157 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002158 a.container_certificate_file = dep.Certificate.Pem
2159 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002160 } else {
2161 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2162 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002163 case android.PrebuiltDepTag:
2164 // If the prebuilt is force disabled, remember to delete the prebuilt file
2165 // that might have been installed in the previous builds
2166 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2167 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2168 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002169 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002170 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002171 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002172 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002173 // We cannot use a switch statement on `depTag` here as the checked
2174 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002175 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002176 if cc, ok := child.(*cc.Module); ok {
2177 if android.InList(cc.Name(), providedNativeSharedLibs) {
2178 // If we're using a shared library which is provided from other APEX,
2179 // don't include it in this APEX
2180 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002181 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002182 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002183 // If the dependency is a stubs lib, don't include it in this APEX,
2184 // but make sure that the lib is installed on the device.
2185 // In case no APEX is having the lib, the lib is installed to the system
2186 // partition.
2187 //
2188 // Always include if we are a host-apex however since those won't have any
2189 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002190 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2191 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002192 }
Jiyong Park956305c2020-01-09 12:32:06 +09002193 a.externalDeps = append(a.externalDeps, depName)
Jooyung Hane1633032019-08-01 17:41:43 +09002194 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002195 // Don't track further
2196 return false
2197 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002198 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002199 af.transitiveDep = true
2200 filesInfo = append(filesInfo, af)
Jiyong Park956305c2020-01-09 12:32:06 +09002201 a.internalDeps = append(a.internalDeps, depName)
2202 a.internalDeps = append(a.internalDeps, cc.AllStaticDeps()...)
Jiyong Parkf653b052019-11-18 15:39:01 +09002203 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002204 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002205 } else if cc.IsTestPerSrcDepTag(depTag) {
2206 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002207 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002208 // Handle modules created as `test_per_src` variations of a single test module:
2209 // use the name of the generated test binary (`fileToCopy`) instead of the name
2210 // of the original test module (`depName`, shared by all `test_per_src`
2211 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002212 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002213 // these are not considered transitive dep
2214 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002215 filesInfo = append(filesInfo, af)
2216 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002217 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002218 } else if java.IsJniDepTag(depTag) {
Jiyong Park956305c2020-01-09 12:32:06 +09002219 a.externalDeps = append(a.externalDeps, depName)
Jiyong Parkf653b052019-11-18 15:39:01 +09002220 return true
Jiyong Park956305c2020-01-09 12:32:06 +09002221 } else if java.IsStaticLibDepTag(depTag) {
2222 a.internalDeps = append(a.internalDeps, depName)
Jooyung Han9c80bae2019-08-20 17:30:57 +09002223 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002224 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002225 }
2226 }
2227 }
2228 return false
2229 })
2230
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002231 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2232 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2233 // via the global boot image config.
2234 if a.artApex {
2235 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2236 dirInApex := filepath.Join("javalib", arch.String())
2237 for _, f := range files {
2238 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002239 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002240 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002241 }
2242 }
2243 }
2244
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002245 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002246 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2247 return
2248 }
2249
Jiyong Park8fd61922018-11-08 02:50:25 +09002250 // remove duplicates in filesInfo
2251 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002252 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002253 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002254 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002255 if e, ok := encountered[dest]; !ok {
2256 encountered[dest] = f
2257 } else {
2258 // If a module is directly included and also transitively depended on
2259 // consider it as directly included.
2260 e.transitiveDep = e.transitiveDep && f.transitiveDep
2261 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002262 }
2263 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002264 var result []apexFile
2265 for _, v := range encountered {
2266 result = append(result, v)
2267 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002268 return result
2269 }
2270 filesInfo = removeDup(filesInfo)
2271
2272 // to have consistent build rules
2273 sort.Slice(filesInfo, func(i, j int) bool {
2274 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2275 })
2276
Jiyong Park8fd61922018-11-08 02:50:25 +09002277 a.installDir = android.PathForModuleInstall(ctx, "apex")
2278 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002279
Jooyung Han54aca7b2019-11-20 02:26:02 +09002280 if a.properties.ApexType != zipApex {
2281 if a.properties.File_contexts == nil {
2282 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2283 } else {
2284 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2285 if a.Platform() {
2286 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2287 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2288 }
2289 }
2290 }
2291 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2292 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2293 return
2294 }
2295 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002296 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2297 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2298 // the same library in the system partition, thus effectively sharing the same libraries
2299 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2300 // in the APEX.
2301 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2302 a.installable() &&
2303 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002304
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002305 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002306 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2307
2308 a.setCertificateAndPrivateKey(ctx)
2309 if a.properties.ApexType == flattenedApex {
2310 a.buildFlattenedApex(ctx)
2311 } else {
2312 a.buildUnflattenedApex(ctx)
2313 }
2314
Jooyung Han002ab682020-01-08 01:57:58 +09002315 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002316
2317 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002318}
2319
Jiyong Parkfa899442020-01-31 02:49:53 +09002320func whitelistedApexAvailable(apex string, module android.Module) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002321 key := apex
2322 key = strings.Replace(key, "test_", "", 1)
2323 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2324 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2325
2326 moduleName := module.Name()
Jiyong Parkfa899442020-01-31 02:49:53 +09002327 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2328 // system. Trim the prefix for the check since they are confusing
2329 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2330 if strings.HasPrefix(moduleName, "libclang_rt.") {
2331 // This module has many arch variants that depend on the product being built.
2332 // We don't want to list them all
2333 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002334 }
2335
2336 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2337 return true
2338 }
2339
Jiyong Parkfa899442020-01-31 02:49:53 +09002340 key = "//any"
2341 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2342 return true
2343 }
2344
Anton Hansson5053c292020-01-10 15:12:39 +00002345 return false
2346}
2347
Jooyung Han344d5432019-08-23 11:17:39 +09002348func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002349 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002350 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002351 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002352 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002353 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002354 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2355 })
Alex Light5098a612018-11-29 17:12:15 -08002356 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002357 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002358 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002359 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002360 return module
2361}
Jiyong Park30ca9372019-02-07 16:27:23 +09002362
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002363func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002364 bundle := newApexBundle()
2365 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002366 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002367 return bundle
2368}
2369
2370func testApexBundleFactory() android.Module {
2371 bundle := newApexBundle()
2372 bundle.testApex = true
2373 return bundle
2374}
2375
Jiyong Parkd1063c12019-07-17 20:08:41 +09002376func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002377 return newApexBundle()
2378}
2379
Jiyong Park30ca9372019-02-07 16:27:23 +09002380//
2381// Defaults
2382//
2383type Defaults struct {
2384 android.ModuleBase
2385 android.DefaultsModuleBase
2386}
2387
Jiyong Park30ca9372019-02-07 16:27:23 +09002388func defaultsFactory() android.Module {
2389 return DefaultsFactory()
2390}
2391
2392func DefaultsFactory(props ...interface{}) android.Module {
2393 module := &Defaults{}
2394
2395 module.AddProperties(props...)
2396 module.AddProperties(
2397 &apexBundleProperties{},
2398 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002399 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002400 )
2401
2402 android.InitDefaultsModule(module)
2403 return module
2404}
Jiyong Park5d790c32019-11-15 18:40:32 +09002405
2406//
2407// OverrideApex
2408//
2409type OverrideApex struct {
2410 android.ModuleBase
2411 android.OverrideModuleBase
2412}
2413
2414func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2415 // All the overrides happen in the base module.
2416}
2417
2418// override_apex is used to create an apex module based on another apex module
2419// by overriding some of its properties.
2420func overrideApexFactory() android.Module {
2421 m := &OverrideApex{}
2422 m.AddProperties(&overridableProperties{})
2423
2424 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2425 android.InitOverrideModule(m)
2426 return m
2427}