blob: 1855841b08743314d1708cb73313ac145b9d94b9 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090022 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Park0f80c182020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090056 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090057 executableTag = dependencyTag{name: "executable", payload: true}
58 javaLibTag = dependencyTag{name: "javaLib", payload: true}
59 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
60 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090061 keyTag = dependencyTag{name: "key"}
62 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090063 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090064 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Jiyong Park0f80c182020-01-31 02:49:53 +090096 m["com.android.adbd"] = []string{
97 "adbd",
98 "bcm_object",
99 "fmtlib",
100 "libadbconnection_server",
101 "libadbd",
102 "libadbd_auth",
103 "libadbd_core",
104 "libadbd_services",
105 "libasyncio",
106 "libbacktrace_headers",
107 "libbase",
108 "libbase_headers",
109 "libbuildversion",
110 "libc++",
111 "libcap",
112 "libcrypto",
113 "libcrypto_utils",
114 "libcutils",
115 "libcutils_headers",
116 "libdiagnose_usb",
Jiyong Park0f80c182020-01-31 02:49:53 +0900117 "liblog_headers",
118 "libmdnssd",
119 "libminijail",
120 "libminijail_gen_constants",
121 "libminijail_gen_constants_obj",
122 "libminijail_gen_syscall",
123 "libminijail_gen_syscall_obj",
124 "libminijail_generated",
125 "libpackagelistparser",
126 "libpcre2",
127 "libprocessgroup_headers",
128 "libqemu_pipe",
129 "libselinux",
130 "libsystem_headers",
131 "libutils_headers",
132 }
133 //
134 // Module separator
135 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000136 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900137 "art_cmdlineparser_headers",
138 "art_disassembler_headers",
139 "art_libartbase_headers",
140 "bcm_object",
141 "bionic_libc_platform_headers",
142 "core-repackaged-icu4j",
143 "cpp-define-generator-asm-support",
144 "cpp-define-generator-definitions",
145 "crtbegin_dynamic",
146 "crtbegin_dynamic1",
147 "crtbegin_so1",
148 "crtbrand",
149 "conscrypt.module.intra.core.api.stubs",
150 "dex2oat_headers",
151 "dt_fd_forward_export",
152 "fmtlib",
153 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "javavm_headers",
156 "jni_platform_headers",
157 "libPlatformProperties",
158 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libandroidicuinit",
161 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libbacktrace",
165 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900166 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000167 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900168 "libc++_static",
169 "libc++abi",
170 "libc++demangle",
171 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "libdexfile_all_headers",
174 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 "libfdlibm",
179 "libgtest_prod",
180 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000181 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "libicuuc_headers",
183 "libicuuc_stubdata",
184 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 "liblog_headers",
186 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000187 "liblzma",
188 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900189 "libnativebridge-headers",
190 "libnativehelper_header_only",
191 "libnativeloader-headers",
192 "libnpt_headers",
193 "libopenjdkjvmti_headers",
194 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000195 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libprotobuf-cpp-lite",
197 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000198 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900199 "libv8",
200 "libv8base",
201 "libv8gen",
202 "libv8platform",
203 "libv8sampler",
204 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "libvixl",
206 "libvixld",
207 "libz",
208 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900209 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000211 m["com.android.art.debug"] = artApexContents
212 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000213 //
214 // Module separator
215 //
216 m["com.android.bluetooth.updatable"] = []string{
217 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000218 "android.hardware.bluetooth.a2dp@1.0",
219 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900220 "android.hardware.bluetooth@1.0",
221 "android.hardware.bluetooth@1.1",
222 "android.hardware.graphics.bufferqueue@1.0",
223 "android.hardware.graphics.bufferqueue@2.0",
224 "android.hardware.graphics.common@1.0",
225 "android.hardware.graphics.common@1.1",
226 "android.hardware.graphics.common@1.2",
227 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000228 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900229 "android.hidl.token@1.0",
230 "android.hidl.token@1.0-utils",
231 "avrcp-target-service",
232 "avrcp_headers",
233 "bcm_object",
234 "bluetooth-protos-lite",
235 "bluetooth.mapsapi",
236 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900237 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900238 "fmtlib",
239 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900240 "ipmemorystore-aidl-interfaces-V5-java",
241 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "internal_include_headers",
243 "lib-bt-packets",
244 "lib-bt-packets-avrcp",
245 "lib-bt-packets-base",
246 "libFraunhoferAAC",
247 "libaudio-a2dp-hw-utils",
248 "libaudio-hearing-aid-hw-utils",
249 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000250 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900251 "libbase_headers",
252 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000253 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900254 "libbluetooth-types",
255 "libbluetooth-types-header",
256 "libbluetooth_gd",
257 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 "libbt-audio-hal-interface",
260 "libbt-bta",
261 "libbt-common",
262 "libbt-hci",
263 "libbt-platform-protos-lite",
264 "libbt-protos-lite",
265 "libbt-sbc-decoder",
266 "libbt-sbc-encoder",
267 "libbt-stack",
268 "libbt-utils",
269 "libbtcore",
270 "libbtdevice",
271 "libbte",
272 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000273 "libc++",
274 "libchrome",
275 "libcrypto",
276 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900277 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000278 "libevent",
279 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900280 "libg722codec",
281 "libgtest_prod",
282 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000283 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900284 "libhidlbase-impl-internal",
285 "libhidltransport-impl-internal",
286 "libhwbinder-impl-internal",
287 "libjsoncpp",
288 "liblog_headers",
289 "libmedia_headers",
290 "libmodpb64",
291 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000292 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900293 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000294 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "libprotobuf-java-lite",
296 "libprotobuf-java-micro",
297 "libstagefright_foundation_headers",
298 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000299 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 "libstatssocket",
301 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000302 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900304 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000305 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900306 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900307 "net-utils-services-common",
308 "netd_aidl_interface-unstable-java",
309 "netd_event_listener_interface-java",
310 "netlink-client",
311 "networkstack-aidl-interfaces-unstable-java",
312 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "sap-api-java-static",
314 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000315 }
316 //
317 // Module separator
318 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000320 //
321 // Module separator
322 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900323 m["com.android.conscrypt"] = []string{
324 "bcm_object",
325 "boringssl_self_test",
326 "libc++",
327 "libcrypto",
328 "libnativehelper_header_only",
329 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900330 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900331 }
332 //
333 // Module separator
334 //
335 m["com.android.extservices"] = []string{
336 "flatbuffer_headers",
337 "liblua",
338 "libtextclassifier",
339 "libtextclassifier_hash_static",
340 "libtflite_static",
341 "libutf",
342 "libz_current",
343 "tensorflow_headers",
344 }
345 //
346 // Module separator
347 //
348 m["com.android.cronet"] = []string{
349 "cronet_impl_common_java",
350 "cronet_impl_native_java",
351 "cronet_impl_platform_java",
352 "libcronet.80.0.3986.0",
353 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900354 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900355 "prebuilt_libcronet.80.0.3986.0",
356 }
357 //
358 // Module separator
359 //
360 m["com.android.neuralnetworks"] = []string{
361 "android.hardware.neuralnetworks@1.0",
362 "android.hardware.neuralnetworks@1.1",
363 "android.hardware.neuralnetworks@1.2",
364 "android.hardware.neuralnetworks@1.3",
365 "android.hidl.allocator@1.0",
366 "android.hidl.memory.token@1.0",
367 "android.hidl.memory@1.0",
368 "android.hidl.safe_union@1.0",
369 "bcm_object",
370 "fmtlib",
371 "gemmlowp_headers",
372 "libarect",
373 "libbacktrace_headers",
374 "libbase",
375 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900376 "libbuildversion",
377 "libc++",
378 "libcrypto",
379 "libcrypto_static",
380 "libcutils",
381 "libcutils_headers",
382 "libeigen",
383 "libfmq",
384 "libhidlbase",
385 "libhidlbase-impl-internal",
386 "libhidlmemory",
387 "libhidltransport-impl-internal",
388 "libhwbinder-impl-internal",
389 "libjsoncpp",
390 "liblog_headers",
391 "libmath",
392 "libneuralnetworks_common",
393 "libneuralnetworks_headers",
394 "libprocessgroup",
395 "libprocessgroup_headers",
396 "libprocpartition",
397 "libsync",
398 "libsystem_headers",
399 "libtextclassifier_hash",
400 "libtextclassifier_hash_headers",
401 "libtextclassifier_hash_static",
402 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900403 "libutils_headers",
404 "philox_random",
405 "philox_random_headers",
406 "tensorflow_headers",
407 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000408 //
409 // Module separator
410 //
411 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000412 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900413 "android.hardware.cas.native@1.0",
414 "android.hardware.cas@1.0",
415 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000416 "android.hardware.configstore@1.0",
417 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000418 "android.hardware.graphics.allocator@2.0",
419 "android.hardware.graphics.allocator@3.0",
420 "android.hardware.graphics.bufferqueue@1.0",
421 "android.hardware.graphics.bufferqueue@2.0",
422 "android.hardware.graphics.common@1.0",
423 "android.hardware.graphics.common@1.1",
424 "android.hardware.graphics.common@1.2",
425 "android.hardware.graphics.mapper@2.0",
426 "android.hardware.graphics.mapper@2.1",
427 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000429 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "android.hidl.allocator@1.0",
431 "android.hidl.memory.token@1.0",
432 "android.hidl.memory@1.0",
433 "android.hidl.token@1.0",
434 "android.hidl.token@1.0-utils",
435 "bcm_object",
436 "bionic_libc_platform_headers",
437 "fmtlib",
438 "gl_headers",
439 "libEGL",
440 "libEGL_blobCache",
441 "libEGL_getProcAddress",
442 "libFLAC",
443 "libFLAC-config",
444 "libFLAC-headers",
445 "libGLESv2",
446 "libaacextractor",
447 "libamrextractor",
448 "libarect",
449 "libasync_safe",
450 "libaudio_system_headers",
451 "libaudioclient",
452 "libaudioclient_headers",
453 "libaudiofoundation",
454 "libaudiofoundation_headers",
455 "libaudiomanager",
456 "libaudiopolicy",
457 "libaudioutils",
458 "libaudioutils_fixedfft",
459 "libbacktrace",
460 "libbacktrace_headers",
461 "libbase",
462 "libbase_headers",
463 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900464 "libbluetooth-types-header",
465 "libbufferhub",
466 "libbufferhub_headers",
467 "libbufferhubqueue",
468 "libc++",
469 "libc_headers",
470 "libc_malloc_debug_backtrace",
471 "libcamera_client",
472 "libcamera_metadata",
473 "libcrypto",
474 "libcutils",
475 "libcutils_headers",
476 "libdexfile_external_headers",
477 "libdexfile_support",
478 "libdvr_headers",
479 "libexpat",
480 "libfifo",
481 "libflacextractor",
482 "libgrallocusage",
483 "libgraphicsenv",
484 "libgui",
485 "libgui_headers",
486 "libhardware_headers",
487 "libhidlbase",
488 "libhidlbase-impl-internal",
489 "libhidlmemory",
490 "libhidltransport-impl-internal",
491 "libhwbinder-impl-internal",
492 "libinput",
493 "libjsoncpp",
494 "liblog_headers",
495 "liblzma",
496 "libmath",
497 "libmedia",
498 "libmedia_codeclist",
499 "libmedia_headers",
500 "libmedia_helper",
501 "libmedia_helper_headers",
502 "libmedia_midiiowrapper",
503 "libmedia_omx",
504 "libmediautils",
505 "libmidiextractor",
506 "libmkvextractor",
507 "libmp3extractor",
508 "libmp4extractor",
509 "libmpeg2extractor",
510 "libnativebase_headers",
511 "libnativebridge-headers",
512 "libnativebridge_lazy",
513 "libnativeloader-headers",
514 "libnativeloader_lazy",
515 "libnativewindow_headers",
516 "libnblog",
517 "liboggextractor",
518 "libpackagelistparser",
519 "libpcre2",
520 "libpdx",
521 "libpdx_default_transport",
522 "libpdx_headers",
523 "libpdx_uds",
524 "libprocessgroup",
525 "libprocessgroup_headers",
526 "libprocinfo",
527 "libselinux",
528 "libsonivox",
529 "libspeexresampler",
530 "libspeexresampler",
531 "libstagefright_esds",
532 "libstagefright_flacdec",
533 "libstagefright_flacdec",
534 "libstagefright_foundation",
535 "libstagefright_foundation_headers",
536 "libstagefright_foundation_without_imemory",
537 "libstagefright_headers",
538 "libstagefright_id3",
539 "libstagefright_metadatautils",
540 "libstagefright_mpeg2extractor",
541 "libstagefright_mpeg2support",
542 "libsync",
543 "libsystem_headers",
544 "libui",
545 "libui_headers",
546 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libutils_headers",
548 "libvibrator",
549 "libvorbisidec",
550 "libwavextractor",
551 "libwebm",
552 "media_ndk_headers",
553 "media_plugin_headers",
554 "updatable-media",
555 }
556 //
557 // Module separator
558 //
559 m["com.android.media.swcodec"] = []string{
560 "android.frameworks.bufferhub@1.0",
561 "android.hardware.common-ndk_platform",
562 "android.hardware.configstore-utils",
563 "android.hardware.configstore@1.0",
564 "android.hardware.configstore@1.1",
565 "android.hardware.graphics.allocator@2.0",
566 "android.hardware.graphics.allocator@3.0",
567 "android.hardware.graphics.bufferqueue@1.0",
568 "android.hardware.graphics.bufferqueue@2.0",
569 "android.hardware.graphics.common-ndk_platform",
570 "android.hardware.graphics.common@1.0",
571 "android.hardware.graphics.common@1.1",
572 "android.hardware.graphics.common@1.2",
573 "android.hardware.graphics.mapper@2.0",
574 "android.hardware.graphics.mapper@2.1",
575 "android.hardware.graphics.mapper@3.0",
576 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000577 "android.hardware.media.bufferpool@2.0",
578 "android.hardware.media.c2@1.0",
579 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "android.hardware.media@1.0",
581 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900583 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000584 "android.hidl.safe_union@1.0",
585 "android.hidl.token@1.0",
586 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "fmtlib",
588 "libEGL",
589 "libFLAC",
590 "libFLAC-config",
591 "libFLAC-headers",
592 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900593 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libarect",
595 "libasync_safe",
596 "libaudio_system_headers",
597 "libaudioutils",
598 "libaudioutils",
599 "libaudioutils_fixedfft",
600 "libavcdec",
601 "libavcenc",
602 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000603 "libavservices_minijail",
604 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000606 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900607 "libbase_headers",
608 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900609 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900610 "libbluetooth-types-header",
611 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000612 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900613 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000614 "libcap",
615 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000617 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "libcodec2_hidl@1.1",
619 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000620 "libcodec2_soft_aacdec",
621 "libcodec2_soft_aacenc",
622 "libcodec2_soft_amrnbdec",
623 "libcodec2_soft_amrnbenc",
624 "libcodec2_soft_amrwbdec",
625 "libcodec2_soft_amrwbenc",
626 "libcodec2_soft_av1dec_gav1",
627 "libcodec2_soft_avcdec",
628 "libcodec2_soft_avcenc",
629 "libcodec2_soft_common",
630 "libcodec2_soft_flacdec",
631 "libcodec2_soft_flacenc",
632 "libcodec2_soft_g711alawdec",
633 "libcodec2_soft_g711mlawdec",
634 "libcodec2_soft_gsmdec",
635 "libcodec2_soft_h263dec",
636 "libcodec2_soft_h263enc",
637 "libcodec2_soft_hevcdec",
638 "libcodec2_soft_hevcenc",
639 "libcodec2_soft_mp3dec",
640 "libcodec2_soft_mpeg2dec",
641 "libcodec2_soft_mpeg4dec",
642 "libcodec2_soft_mpeg4enc",
643 "libcodec2_soft_opusdec",
644 "libcodec2_soft_opusenc",
645 "libcodec2_soft_rawdec",
646 "libcodec2_soft_vorbisdec",
647 "libcodec2_soft_vp8dec",
648 "libcodec2_soft_vp8enc",
649 "libcodec2_soft_vp9dec",
650 "libcodec2_soft_vp9enc",
651 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000656 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900657 "libfmq",
658 "libgav1",
659 "libgralloctypes",
660 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libgsm",
663 "libgui_bufferqueue_static",
664 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000665 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900666 "libhardware_headers",
667 "libhevcdec",
668 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000671 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "libhidltransport-impl-internal",
673 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000674 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900675 "libjpeg",
676 "libjsoncpp",
677 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000678 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900679 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000680 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000682 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900683 "libminijail_gen_constants",
684 "libminijail_gen_constants_obj",
685 "libminijail_gen_syscall",
686 "libminijail_gen_syscall_obj",
687 "libminijail_generated",
688 "libmpeg2dec",
689 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000690 "libnativebridge_lazy",
691 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900692 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000693 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000695 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900696 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000697 "libscudo_wrapper",
698 "libsfplugin_ccodec_utils",
699 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900700 "libstagefright_amrnbdec",
701 "libstagefright_amrnbenc",
702 "libstagefright_amrwbdec",
703 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000704 "libstagefright_bufferpool@2.0.1",
705 "libstagefright_bufferqueue_helper",
706 "libstagefright_enc_common",
707 "libstagefright_flacdec",
708 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900709 "libstagefright_foundation_headers",
710 "libstagefright_headers",
711 "libstagefright_m4vh263dec",
712 "libstagefright_m4vh263enc",
713 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000714 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000716 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900717 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000718 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900719 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000720 "libvorbisidec",
721 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900722 "libyuv",
723 "libyuv_static",
724 "media_ndk_headers",
725 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000726 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900727 }
728 //
729 // Module separator
730 //
731 m["com.android.mediaprovider"] = []string{
732 "MediaProvider",
733 "MediaProviderGoogle",
734 "fmtlib_ndk",
735 "guava",
736 "libbase_ndk",
737 "libfuse",
738 "libfuse_jni",
739 "libnativehelper_header_only",
740 }
741 //
742 // Module separator
743 //
744 m["com.android.permission"] = []string{
745 "androidx.annotation_annotation",
746 "androidx.annotation_annotation-nodeps",
747 "androidx.lifecycle_lifecycle-common",
748 "androidx.lifecycle_lifecycle-common-java8",
749 "androidx.lifecycle_lifecycle-common-java8-nodeps",
750 "androidx.lifecycle_lifecycle-common-nodeps",
751 "kotlin-annotations",
752 "kotlin-stdlib",
753 "kotlin-stdlib-jdk7",
754 "kotlin-stdlib-jdk8",
755 "kotlinx-coroutines-android",
756 "kotlinx-coroutines-android-nodeps",
757 "kotlinx-coroutines-core",
758 "kotlinx-coroutines-core-nodeps",
759 "libprotobuf-java-lite",
760 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000761 }
762 //
763 // Module separator
764 //
765 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900766 "bionic_libc_platform_headers",
767 "fmtlib",
768 "libarm-optimized-routines-math",
769 "libasync_safe",
770 "libasync_safe_headers",
771 "libbacktrace_headers",
772 "libbase",
773 "libbase_headers",
774 "libc++",
775 "libc_aeabi",
776 "libc_bionic",
777 "libc_bionic_ndk",
778 "libc_bootstrap",
779 "libc_common",
780 "libc_common_shared",
781 "libc_common_static",
782 "libc_dns",
783 "libc_dynamic_dispatch",
784 "libc_fortify",
785 "libc_freebsd",
786 "libc_freebsd_large_stack",
787 "libc_gdtoa",
788 "libc_headers",
789 "libc_init_dynamic",
790 "libc_init_static",
791 "libc_jemalloc_wrapper",
792 "libc_netbsd",
793 "libc_nomalloc",
794 "libc_nopthread",
795 "libc_openbsd",
796 "libc_openbsd_large_stack",
797 "libc_openbsd_ndk",
798 "libc_pthread",
799 "libc_static_dispatch",
800 "libc_syscalls",
801 "libc_tzcode",
802 "libc_unwind_static",
803 "libcutils",
804 "libcutils_headers",
805 "libdebuggerd",
806 "libdebuggerd_common_headers",
807 "libdebuggerd_handler_core",
808 "libdebuggerd_handler_fallback",
809 "libdexfile_external_headers",
810 "libdexfile_support",
811 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900812 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900813 "libgtest_prod",
814 "libjemalloc5",
815 "liblinker_main",
816 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900817 "liblog_headers",
818 "liblz4",
819 "liblzma",
820 "libprocessgroup_headers",
821 "libprocinfo",
822 "libpropertyinfoparser",
823 "libscudo",
824 "libstdc++",
825 "libsystem_headers",
826 "libsystemproperties",
827 "libtombstoned_client_static",
828 "libunwindstack",
829 "libutils_headers",
830 "libz",
831 "libziparchive",
832 }
833 //
834 // Module separator
835 //
836 m["com.android.resolv"] = []string{
837 "bcm_object",
838 "dnsresolver_aidl_interface-unstable-ndk_platform",
839 "fmtlib",
840 "libbacktrace_headers",
841 "libbase",
842 "libbase_headers",
843 "libc++",
844 "libcrypto",
845 "libcutils",
846 "libcutils_headers",
847 "libgtest_prod",
848 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900849 "liblog_headers",
850 "libnativehelper_header_only",
851 "libnetd_client_headers",
852 "libnetd_resolv",
853 "libnetdutils",
854 "libprocessgroup",
855 "libprocessgroup_headers",
856 "libprotobuf-cpp-lite",
857 "libssl",
858 "libstatslog_resolv",
859 "libstatspush_compat",
860 "libstatssocket",
861 "libstatssocket_headers",
862 "libsystem_headers",
863 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900864 "libutils_headers",
865 "netd_event_listener_interface-ndk_platform",
866 "server_configurable_flags",
867 "stats_proto",
868 }
869 //
870 // Module separator
871 //
872 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000873 "libbase",
874 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900875 "libnativehelper_compat_libc++",
876 "android.hardware.tetheroffload.config@1.0",
877 "fmtlib",
878 "libbacktrace_headers",
879 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900880 "libcgrouprc",
881 "libcgrouprc_format",
882 "libcutils",
883 "libcutils_headers",
884 "libhidlbase",
885 "libhidlbase-impl-internal",
886 "libhidltransport-impl-internal",
887 "libhwbinder-impl-internal",
888 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900889 "liblog_headers",
890 "libprocessgroup",
891 "libprocessgroup_headers",
892 "libsystem_headers",
893 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900894 "libutils_headers",
895 "libvndksupport",
896 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000897 }
898 //
899 // Module separator
900 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900901 m["com.android.wifi"] = []string{
902 "PlatformProperties",
903 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900904 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900905 "android.hardware.wifi-V1.1-java",
906 "android.hardware.wifi-V1.2-java",
907 "android.hardware.wifi-V1.3-java",
908 "android.hardware.wifi-V1.4-java",
909 "android.hardware.wifi.hostapd-V1.0-java",
910 "android.hardware.wifi.hostapd-V1.1-java",
911 "android.hardware.wifi.hostapd-V1.2-java",
912 "android.hardware.wifi.supplicant-V1.0-java",
913 "android.hardware.wifi.supplicant-V1.1-java",
914 "android.hardware.wifi.supplicant-V1.2-java",
915 "android.hardware.wifi.supplicant-V1.3-java",
916 "android.hidl.base-V1.0-java",
917 "android.hidl.manager-V1.0-java",
918 "android.hidl.manager-V1.1-java",
919 "android.hidl.manager-V1.2-java",
920 "androidx.annotation_annotation",
921 "androidx.annotation_annotation-nodeps",
922 "bouncycastle-unbundled",
923 "dnsresolver_aidl_interface-V2-java",
924 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900925 "framework-wifi-pre-jarjar",
926 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900927 "ipmemorystore-aidl-interfaces-V3-java",
928 "ipmemorystore-aidl-interfaces-java",
929 "ksoap2",
930 "libbacktrace_headers",
931 "libbase",
932 "libbase_headers",
933 "libc++",
934 "libcutils",
935 "libcutils_headers",
936 "liblog_headers",
937 "libnanohttpd",
938 "libprocessgroup",
939 "libprocessgroup_headers",
940 "libprotobuf-java-lite",
941 "libprotobuf-java-nano",
942 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900943 "libutils_headers",
944 "libwifi-jni",
945 "net-utils-services-common",
946 "netd_aidl_interface-V2-java",
947 "netd_aidl_interface-unstable-java",
948 "netd_event_listener_interface-java",
949 "netlink-client",
950 "networkstack-aidl-interfaces-unstable-java",
951 "networkstack-client",
952 "services.net",
953 "wifi-lite-protos",
954 "wifi-nano-protos",
955 "wifi-service-pre-jarjar",
956 "wifi-service-resources",
957 "prebuilt_androidx.annotation_annotation-nodeps",
958 }
959 //
960 // Module separator
961 //
962 m["com.android.sdkext"] = []string{
963 "fmtlib_ndk",
964 "libbase_ndk",
965 "libprotobuf-cpp-lite-ndk",
966 }
967 //
968 // Module separator
969 //
970 m["com.android.os.statsd"] = []string{
971 "libbacktrace_headers",
972 "libbase_headers",
973 "libc++",
974 "libcutils",
975 "libcutils_headers",
976 "liblog_headers",
977 "libprocessgroup_headers",
978 "libstatssocket",
979 "libsystem_headers",
980 "libutils_headers",
981 }
982 //
983 // Module separator
984 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000985 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900986 "crtbegin_dynamic",
987 "crtbegin_dynamic1",
988 "crtbegin_so",
989 "crtbegin_so1",
990 "crtbegin_static",
991 "crtbrand",
992 "crtend_android",
993 "crtend_so",
994 "libatomic",
995 "libc++_static",
996 "libc++abi",
997 "libc++demangle",
998 "libc_headers",
999 "libclang_rt",
1000 "libgcc_stripped",
1001 "libprofile-clang-extras",
1002 "libprofile-clang-extras_ndk",
1003 "libprofile-extras",
1004 "libprofile-extras_ndk",
1005 "libunwind_llvm",
1006 "ndk_crtbegin_dynamic.27",
1007 "ndk_crtbegin_so.16",
1008 "ndk_crtbegin_so.19",
1009 "ndk_crtbegin_so.21",
1010 "ndk_crtbegin_so.24",
1011 "ndk_crtbegin_so.27",
1012 "ndk_crtend_android.27",
1013 "ndk_crtend_so.16",
1014 "ndk_crtend_so.19",
1015 "ndk_crtend_so.21",
1016 "ndk_crtend_so.24",
1017 "ndk_crtend_so.27",
1018 "ndk_libandroid_support",
1019 "ndk_libc++_static",
1020 "ndk_libc++abi",
1021 "ndk_libunwind",
1022 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001023 return m
1024}
1025
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001027 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001028 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001029 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001030 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001031 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001032 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033
Jooyung Han31c470b2019-10-18 16:26:59 +09001034 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001035 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001036
1037 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1038 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1039 sort.Strings(*apexFileContextsInfos)
1040 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1041 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001042}
1043
Jooyung Han31c470b2019-10-18 16:26:59 +09001044func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1045 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1046 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1047}
1048
Jiyong Parkd1063c12019-07-17 20:08:41 +09001049func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001050 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001051 ctx.BottomUp("apex", apexMutator).Parallel()
1052 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1053 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054}
1055
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056// Mark the direct and transitive dependencies of apex bundles so that they
1057// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001058func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001059 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001060 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001061 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han03b51852020-02-26 22:45:42 +09001062 minSdkVersion := a.minSdkVersion(mctx)
Jooyung Han5e9013b2020-03-10 06:23:13 +09001063 apexBundles = []android.ApexInfo{android.ApexInfo{
1064 ApexName: mctx.ModuleName(),
1065 LegacyAndroid10Support: proptools.Bool(a.properties.Legacy_android10_support),
1066 MinSdkVersion: minSdkVersion,
1067 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001068 directDep = true
1069 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001070 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001071 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001072 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001073
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001074 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001075 return
1076 }
1077
Jooyung Han5e9013b2020-03-10 06:23:13 +09001078 cur := mctx.Module().(interface {
1079 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1080 })
1081
Jiyong Parkf760cae2020-02-12 07:53:12 +09001082 mctx.VisitDirectDeps(func(child android.Module) {
1083 depName := mctx.OtherModuleName(child)
1084 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001085 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001086 android.UpdateApexDependency(apexBundles, depName, directDep)
1087 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001088 }
1089 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001090}
1091
1092// Create apex variations if a module is included in APEX(s).
1093func apexMutator(mctx android.BottomUpMutatorContext) {
1094 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001095 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001096 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001097 // apex bundle itself is mutated so that it and its modules have same
1098 // apex variant.
1099 apexBundleName := mctx.ModuleName()
1100 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001101 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1102 apexBundleName := o.GetOverriddenModuleName()
1103 if apexBundleName == "" {
1104 mctx.ModuleErrorf("base property is not set")
1105 return
1106 }
1107 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001108 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001109
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001110}
Sundong Ahne9b55722019-09-06 17:37:42 +09001111
Jooyung Han7a78a922019-10-08 21:59:58 +09001112var (
1113 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1114 apexFileContextsInfosMutex sync.Mutex
1115)
1116
1117func apexFileContextsInfos(config android.Config) *[]string {
1118 return config.Once(apexFileContextsInfosKey, func() interface{} {
1119 return &[]string{}
1120 }).(*[]string)
1121}
1122
Jooyung Han54aca7b2019-11-20 02:26:02 +09001123func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001124 apexFileContextsInfosMutex.Lock()
1125 defer apexFileContextsInfosMutex.Unlock()
1126 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001127 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001128}
1129
Sundong Ahne9b55722019-09-06 17:37:42 +09001130func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001131 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001132 var variants []string
1133 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1134 case "image":
1135 variants = append(variants, imageApexType, flattenedApexType)
1136 case "zip":
1137 variants = append(variants, zipApexType)
1138 case "both":
1139 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1140 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001141 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001142 return
1143 }
1144
1145 modules := mctx.CreateLocalVariations(variants...)
1146
1147 for i, v := range variants {
1148 switch v {
1149 case imageApexType:
1150 modules[i].(*apexBundle).properties.ApexType = imageApex
1151 case zipApexType:
1152 modules[i].(*apexBundle).properties.ApexType = zipApex
1153 case flattenedApexType:
1154 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001155 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001156 modules[i].(*apexBundle).MakeAsSystemExt()
1157 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001158 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001159 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001160 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1161 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001162 }
1163}
1164
Jooyung Han5c998b92019-06-27 11:30:33 +09001165func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1166 if ab, ok := mctx.Module().(*apexBundle); ok {
1167 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1168 }
1169}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001170
Jooyung Handc782442019-11-01 03:14:38 +09001171var (
1172 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1173)
1174
1175// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1176// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1177// which may cause compatibility issues. (e.g. libbinder)
1178// Even though libbinder restricts its availability via 'apex_available' property and relies on
1179// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1180// to avoid similar problems.
1181func useVendorWhitelist(config android.Config) []string {
1182 return config.Once(useVendorWhitelistKey, func() interface{} {
1183 return []string{
1184 // swcodec uses "vendor" variants for smaller size
1185 "com.android.media.swcodec",
1186 "test_com.android.media.swcodec",
1187 }
1188 }).([]string)
1189}
1190
1191// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1192// called before the first call to useVendorWhitelist()
1193func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1194 config.Once(useVendorWhitelistKey, func() interface{} {
1195 return whitelist
1196 })
1197}
1198
Jooyung Han01a868d2020-02-27 13:40:44 +09001199type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001200 // List of native libraries
1201 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001202
Jooyung Han643adc42020-02-27 13:50:06 +09001203 // List of JNI libraries
1204 Jni_libs []string
1205
Alex Light9670d332019-01-29 18:07:33 -08001206 // List of native executables
1207 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001208
Roland Levillain630846d2019-06-26 12:48:34 +01001209 // List of native tests
1210 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001211}
Jooyung Han344d5432019-08-23 11:17:39 +09001212
Alex Light9670d332019-01-29 18:07:33 -08001213type apexMultilibProperties struct {
1214 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001215 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001216
1217 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001218 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001219
1220 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001221 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001222
1223 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001224 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001225
1226 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001227 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001228}
1229
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001230type apexBundleProperties struct {
1231 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001232 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001233 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001234
Jiyong Park40e26a22019-02-08 02:53:06 +09001235 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1236 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001237 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001238
Roland Levillain411c5842019-09-19 16:37:20 +01001239 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1240 // device (/apex/<apex_name>).
1241 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001242 Apex_name *string
1243
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001244 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001245 // For platform APEXes, this should points to a file under /system/sepolicy
1246 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1247 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001248
Jooyung Han01a868d2020-02-27 13:40:44 +09001249 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001250
1251 // List of java libraries that are embedded inside this APEX bundle
1252 Java_libs []string
1253
1254 // List of prebuilt files that are embedded inside this APEX bundle
1255 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001256
1257 // Name of the apex_key module that provides the private key to sign APEX
1258 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001259
Alex Light5098a612018-11-29 17:12:15 -08001260 // The type of APEX to build. Controls what the APEX payload is. Either
1261 // 'image', 'zip' or 'both'. Default: 'image'.
1262 Payload_type *string
1263
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001264 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1265 // or an android_app_certificate module name in the form ":module".
1266 Certificate *string
1267
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001268 // Whether this APEX is installable to one of the partitions. Default: true.
1269 Installable *bool
1270
Jiyong Parkda6eb592018-12-19 17:12:36 +09001271 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1272 // Default is false.
1273 Use_vendor *bool
1274
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001275 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1276 Ignore_system_library_special_case *bool
1277
Alex Light9670d332019-01-29 18:07:33 -08001278 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001279
Jiyong Parkf97782b2019-02-13 20:28:58 +09001280 // List of sanitizer names that this APEX is enabled for
1281 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001282
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001283 PreventInstall bool `blueprint:"mutated"`
1284
1285 HideFromMake bool `blueprint:"mutated"`
1286
Jooyung Han5c998b92019-06-27 11:30:33 +09001287 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1288 Provide_cpp_shared_libs *bool
1289
1290 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1291 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001292
1293 // A txt file containing list of files that are whitelisted to be included in this APEX.
1294 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001295
Sundong Ahnabb64432019-10-22 13:58:29 +09001296 // package format of this apex variant; could be non-flattened, flattened, or zip.
1297 // imageApex, zipApex or flattened
1298 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001299
Jiyong Parkd1063c12019-07-17 20:08:41 +09001300 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1301 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1302 // is implied. This value affects all modules included in this APEX. In other words, they are
1303 // also built with the SDKs specified here.
1304 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001305
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001306 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1307 // Should be only used in tests#.
1308 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001309
1310 // Whether this APEX should support Android10. Default is false. If this is set true, then apex_manifest.json is bundled as well
1311 // because Android10 requires legacy apex_manifest.json instead of apex_manifest.pb
1312 Legacy_android10_support *bool
Jiyong Park956305c2020-01-09 12:32:06 +09001313
1314 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001315
1316 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1317 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1318 // like symlinking to the system libs. Default is false.
1319 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001320
1321 // The minimum SDK version that this apex must be compatibile with.
1322 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001323}
1324
1325type apexTargetBundleProperties struct {
1326 Target struct {
1327 // Multilib properties only for android.
1328 Android struct {
1329 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001330 }
Jooyung Han344d5432019-08-23 11:17:39 +09001331
Alex Light9670d332019-01-29 18:07:33 -08001332 // Multilib properties only for host.
1333 Host struct {
1334 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001335 }
Jooyung Han344d5432019-08-23 11:17:39 +09001336
Alex Light9670d332019-01-29 18:07:33 -08001337 // Multilib properties only for host linux_bionic.
1338 Linux_bionic struct {
1339 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001340 }
Jooyung Han344d5432019-08-23 11:17:39 +09001341
Alex Light9670d332019-01-29 18:07:33 -08001342 // Multilib properties only for host linux_glibc.
1343 Linux_glibc struct {
1344 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001345 }
1346 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001347}
1348
Jiyong Park5d790c32019-11-15 18:40:32 +09001349type overridableProperties struct {
1350 // List of APKs to package inside APEX
1351 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001352
1353 // Names of modules to be overridden. Listed modules can only be other binaries
1354 // (in Make or Soong).
1355 // This does not completely prevent installation of the overridden binaries, but if both
1356 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1357 // from PRODUCT_PACKAGES.
1358 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001359
1360 // Logging Parent value
1361 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001362
1363 // Apex Container Package Name.
1364 // Override value for attribute package:name in AndroidManifest.xml
1365 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001366}
1367
Alex Light5098a612018-11-29 17:12:15 -08001368type apexPackaging int
1369
1370const (
1371 imageApex apexPackaging = iota
1372 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001373 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001374)
1375
Sundong Ahnabb64432019-10-22 13:58:29 +09001376// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001377func (a apexPackaging) suffix() string {
1378 switch a {
1379 case imageApex:
1380 return imageApexSuffix
1381 case zipApex:
1382 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001383 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001384 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001385 }
1386}
1387
1388func (a apexPackaging) name() string {
1389 switch a {
1390 case imageApex:
1391 return imageApexType
1392 case zipApex:
1393 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001394 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001395 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001396 }
1397}
1398
Jiyong Parkf653b052019-11-18 15:39:01 +09001399type apexFileClass int
1400
1401const (
1402 etc apexFileClass = iota
1403 nativeSharedLib
1404 nativeExecutable
1405 shBinary
1406 pyBinary
1407 goBinary
1408 javaSharedLib
1409 nativeTest
1410 app
1411)
1412
Jiyong Park8fd61922018-11-08 02:50:25 +09001413func (class apexFileClass) NameInMake() string {
1414 switch class {
1415 case etc:
1416 return "ETC"
1417 case nativeSharedLib:
1418 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001419 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001420 return "EXECUTABLES"
1421 case javaSharedLib:
1422 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001423 case nativeTest:
1424 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001425 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001426 // b/142537672 Why isn't this APP? We want to have full control over
1427 // the paths and file names of the apk file under the flattend APEX.
1428 // If this is set to APP, then the paths and file names are modified
1429 // by the Make build system. For example, it is installed to
1430 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1431 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1432 // appends module name (which is <apexname>.<Appname> to the path.
1433 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001434 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001435 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001436 }
1437}
1438
Jiyong Parkf653b052019-11-18 15:39:01 +09001439// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001440type apexFile struct {
1441 builtFile android.Path
1442 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001443 installDir string
1444 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001445 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001446 // list of symlinks that will be created in installDir that point to this apexFile
1447 symlinks []string
1448 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001449 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001450
1451 requiredModuleNames []string
1452 targetRequiredModuleNames []string
1453 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001454
Colin Cross503c1d02020-01-28 14:00:53 -08001455 jacocoReportClassesFile android.Path // only for javalibs and apps
1456 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001457 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001458
1459 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001460}
1461
Jiyong Park1833cef2019-12-13 13:28:36 +09001462func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1463 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001464 builtFile: builtFile,
1465 moduleName: moduleName,
1466 installDir: installDir,
1467 class: class,
1468 module: module,
1469 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001470 if module != nil {
1471 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001472 ret.requiredModuleNames = module.RequiredModuleNames()
1473 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1474 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001475 }
1476 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001477}
1478
1479func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001480 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001481}
1482
Jiyong Park7cd10e32020-01-14 09:22:18 +09001483// Path() returns path of this apex file relative to the APEX root
1484func (af *apexFile) Path() string {
1485 return filepath.Join(af.installDir, af.builtFile.Base())
1486}
1487
1488// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1489func (af *apexFile) SymlinkPaths() []string {
1490 var ret []string
1491 for _, symlink := range af.symlinks {
1492 ret = append(ret, filepath.Join(af.installDir, symlink))
1493 }
1494 return ret
1495}
1496
1497func (af *apexFile) AvailableToPlatform() bool {
1498 if af.module == nil {
1499 return false
1500 }
1501 if am, ok := af.module.(android.ApexModule); ok {
1502 return am.AvailableFor(android.AvailableToPlatform)
1503 }
1504 return false
1505}
1506
Jiyong Park678c8812020-02-07 17:25:49 +09001507type depInfo struct {
1508 to string
1509 from []string
1510 isExternal bool
1511}
1512
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001513type apexBundle struct {
1514 android.ModuleBase
1515 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001516 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001517 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001518
Jiyong Park5d790c32019-11-15 18:40:32 +09001519 properties apexBundleProperties
1520 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001521 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001522
Jooyung Hanf21c7972019-12-16 22:32:06 +09001523 // specific to apex_vndk modules
1524 vndkProperties apexVndkProperties
1525
Colin Crossa4925902018-11-16 11:36:28 -08001526 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001527 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001528 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001529
Jiyong Park03b68dd2019-07-26 23:20:40 +09001530 prebuiltFileToDelete string
1531
Jiyong Park42cca6c2019-04-01 11:15:50 +09001532 public_key_file android.Path
1533 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001534
1535 container_certificate_file android.Path
1536 container_private_key_file android.Path
1537
Jooyung Han54aca7b2019-11-20 02:26:02 +09001538 fileContexts android.Path
1539
Jiyong Park8fd61922018-11-08 02:50:25 +09001540 // list of files to be included in this apex
1541 filesInfo []apexFile
1542
Jiyong Park956305c2020-01-09 12:32:06 +09001543 // list of module names that should be installed along with this APEX
1544 requiredDeps []string
1545
Jiyong Park956305c2020-01-09 12:32:06 +09001546 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001547 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001548
Sundong Ahnabb64432019-10-22 13:58:29 +09001549 testApex bool
1550 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001551 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001552 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001553
Jooyung Han214bf372019-11-12 13:03:50 +09001554 manifestJsonOut android.WritablePath
1555 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001556
Jooyung Han002ab682020-01-08 01:57:58 +09001557 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001558 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001559 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001560 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1561 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001562
1563 // Suffix of module name in Android.mk
1564 // ".flattened", ".apex", ".zipapex", or ""
1565 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001566
1567 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001568
1569 // Whether to create symlink to the system file instead of having a file
1570 // inside the apex or not
1571 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001572
1573 // Struct holding the merged notice file paths in different formats
1574 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001575}
1576
Jiyong Park397e55e2018-10-24 21:09:55 +09001577func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001578 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001579 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001580 // Use *FarVariation* to be able to depend on modules having
1581 // conflicting variations with this module. This is required since
1582 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1583 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001584 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001585 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001586 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001587 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001588 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001589
Jooyung Han643adc42020-02-27 13:50:06 +09001590 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1591 {Mutator: "image", Variation: imageVariation},
1592 {Mutator: "link", Variation: "shared"},
1593 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1594 }...), jniLibTag, nativeModules.Jni_libs...)
1595
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001596 ctx.AddFarVariationDependencies(append(target.Variations(),
1597 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001598 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001599
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: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001602 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001603 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001604}
1605
Alex Light9670d332019-01-29 18:07:33 -08001606func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1607 if ctx.Os().Class == android.Device {
1608 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1609 } else {
1610 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1611 if ctx.Os().Bionic() {
1612 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1613 } else {
1614 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1615 }
1616 }
1617}
1618
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001619func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001620 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1621 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1622 }
1623
Jiyong Park397e55e2018-10-24 21:09:55 +09001624 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001625 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001626
1627 a.combineProperties(ctx)
1628
Jiyong Park397e55e2018-10-24 21:09:55 +09001629 has32BitTarget := false
1630 for _, target := range targets {
1631 if target.Arch.ArchType.Multilib == "lib32" {
1632 has32BitTarget = true
1633 }
1634 }
1635 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001636 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001637 // multilib.both
1638 addDependenciesForNativeModules(ctx,
1639 ApexNativeDependencies{
1640 Native_shared_libs: a.properties.Native_shared_libs,
1641 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001642 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001643 Binaries: nil,
1644 },
1645 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001646
Jiyong Park397e55e2018-10-24 21:09:55 +09001647 // Add native modules targetting both ABIs
1648 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001649 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001650 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001651 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001652
Alex Light3d673592019-01-18 14:37:31 -08001653 isPrimaryAbi := i == 0
1654 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001655 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001656 // multilib.first
1657 addDependenciesForNativeModules(ctx,
1658 ApexNativeDependencies{
1659 Native_shared_libs: nil,
1660 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001661 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001662 Binaries: a.properties.Binaries,
1663 },
1664 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001665
1666 // Add native modules targetting the first ABI
1667 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001668 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001669 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001670 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001671 }
1672
1673 switch target.Arch.ArchType.Multilib {
1674 case "lib32":
1675 // Add native modules targetting 32-bit ABI
1676 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001677 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001678 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001679 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001680
1681 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001682 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001683 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001684 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001685 case "lib64":
1686 // Add native modules targetting 64-bit ABI
1687 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001688 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001689 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001690 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001691
1692 if !has32BitTarget {
1693 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001694 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001695 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001696 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001697 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001698
1699 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1700 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1701 if sanitizer == "hwaddress" {
1702 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001703 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001704 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001705 break
1706 }
1707 }
1708 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001709 }
1710
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001711 }
1712
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001713 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1714 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1715 // b/144532908
1716 archForPrebuiltEtc := config.Arches()[0]
1717 for _, arch := range config.Arches() {
1718 // Prefer 64-bit arch if there is any
1719 if arch.ArchType.Multilib == "lib64" {
1720 archForPrebuiltEtc = arch
1721 break
1722 }
1723 }
1724 ctx.AddFarVariationDependencies([]blueprint.Variation{
1725 {Mutator: "os", Variation: ctx.Os().String()},
1726 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1727 }, prebuiltTag, a.properties.Prebuilts...)
1728
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001729 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1730 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001731
Ulya Trafimovich44561882020-01-03 13:25:54 +00001732 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1733 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1734 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1735 javaLibTag, "jacocoagent")
1736 }
1737
Jiyong Park23c52b02019-02-02 13:13:47 +09001738 if String(a.properties.Key) == "" {
1739 ctx.ModuleErrorf("key is missing")
1740 return
1741 }
1742 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001743
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001744 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001745 if cert != "" {
1746 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001747 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001748
1749 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1750 if len(a.properties.Uses_sdks) > 0 {
1751 sdkRefs := []android.SdkRef{}
1752 for _, str := range a.properties.Uses_sdks {
1753 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1754 sdkRefs = append(sdkRefs, parsed)
1755 }
1756 a.BuildWithSdks(sdkRefs)
1757 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001758}
1759
Jiyong Park5d790c32019-11-15 18:40:32 +09001760func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1761 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1762 androidAppTag, a.overridableProperties.Apps...)
1763}
1764
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001765func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1766 // direct deps of an APEX bundle are all part of the APEX bundle
1767 return true
1768}
1769
Colin Cross0ea8ba82019-06-06 14:33:29 -07001770func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001771 moduleName := ctx.ModuleName()
1772 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1773 // we check with the pseudo module name to see if its certificate is overridden.
1774 if a.vndkApex {
1775 moduleName = vndkApexName
1776 }
1777 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001778 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001779 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001780 }
1781 return String(a.properties.Certificate)
1782}
1783
Colin Cross41955e82019-05-29 14:40:35 -07001784func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1785 switch tag {
1786 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001787 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001788 default:
1789 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001790 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001791}
1792
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001793func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001794 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001795}
1796
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001797func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1798 return proptools.Bool(a.properties.Test_only_no_hashtree)
1799}
1800
Jiyong Park7c1dc612019-01-05 11:15:24 +09001801func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001802 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001803 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001804 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001805 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001806 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001807 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001808 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001809 }
1810}
1811
Jiyong Parkf97782b2019-02-13 20:28:58 +09001812func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1813 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1814 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1815 }
1816}
1817
Jiyong Park388ef3f2019-01-28 19:47:32 +09001818func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001819 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1820 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001821 }
1822
1823 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001824 globalSanitizerNames := []string{}
1825 if a.Host() {
1826 globalSanitizerNames = ctx.Config().SanitizeHost()
1827 } else {
1828 arches := ctx.Config().SanitizeDeviceArch()
1829 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1830 globalSanitizerNames = ctx.Config().SanitizeDevice()
1831 }
1832 }
1833 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001834}
1835
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001836func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001837 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001838}
1839
1840func (a *apexBundle) PreventInstall() {
1841 a.properties.PreventInstall = true
1842}
1843
1844func (a *apexBundle) HideFromMake() {
1845 a.properties.HideFromMake = true
1846}
1847
Jiyong Park956305c2020-01-09 12:32:06 +09001848func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1849 a.properties.IsCoverageVariant = coverage
1850}
1851
Jiyong Parkf653b052019-11-18 15:39:01 +09001852// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001853func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001854 // Decide the APEX-local directory by the multilib of the library
1855 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001856 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001857 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001858 case "lib32":
1859 dirInApex = "lib"
1860 case "lib64":
1861 dirInApex = "lib64"
1862 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001863 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001864 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001865 }
Jooyung Han35155c42020-02-06 17:33:20 +09001866 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001867 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001868 // Special case for Bionic libs and other libs installed with them. This is
1869 // to prevent those libs from being included in the search path
1870 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1871 // those libs in the Runtime APEX are available via the legacy paths in
1872 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1873 // to the legacy paths and thus will be loaded into the default linker
1874 // namespace (aka "platform" namespace). If the libs are directly in
1875 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1876 // into the runtime linker namespace, which will result in double loading of
1877 // them, which isn't supported.
1878 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001879 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001880
Jiyong Parkf653b052019-11-18 15:39:01 +09001881 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001882 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001883}
1884
Jiyong Park1833cef2019-12-13 13:28:36 +09001885func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001886 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001887 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001888 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001889 }
Jooyung Han35155c42020-02-06 17:33:20 +09001890 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001891 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001892 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001893 af.symlinks = cc.Symlinks()
1894 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001895}
1896
Jiyong Park1833cef2019-12-13 13:28:36 +09001897func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001898 dirInApex := "bin"
1899 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001900 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001901}
Jiyong Park1833cef2019-12-13 13:28:36 +09001902func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001904 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1905 if err != nil {
1906 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001907 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001908 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 fileToCopy := android.PathForOutput(ctx, s)
1910 // NB: Since go binaries are static we don't need the module for anything here, which is
1911 // good since the go tool is a blueprint.Module not an android.Module like we would
1912 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001913 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001914}
1915
Jiyong Park1833cef2019-12-13 13:28:36 +09001916func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001917 dirInApex := filepath.Join("bin", sh.SubDir())
1918 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001919 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001920 af.symlinks = sh.Symlinks()
1921 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001922}
1923
Jooyung Han58f26ab2019-12-18 15:34:32 +09001924// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1925type javaLibrary interface {
1926 android.Module
1927 java.Dependency
1928}
1929
1930func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001931 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001932 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001933 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1934 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1935 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001936}
1937
Jiyong Park1833cef2019-12-13 13:28:36 +09001938func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1940 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001941 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001942}
1943
atrost6e126252020-01-27 17:01:16 +00001944func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1945 dirInApex := filepath.Join("etc", config.SubDir())
1946 fileToCopy := config.CompatConfig()
1947 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1948}
1949
Jiyong Park1833cef2019-12-13 13:28:36 +09001950func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001951 android.Module
1952 Privileged() bool
1953 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001954 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001955 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001956}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001957 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001958 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001959 appDir = "priv-app"
1960 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001961 dirInApex := filepath.Join(appDir, pkgName)
1962 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001963 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1964 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001965 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001966
1967 if app, ok := aapp.(interface {
1968 OverriddenManifestPackageName() string
1969 }); ok {
1970 af.overriddenPackageName = app.OverriddenManifestPackageName()
1971 }
Jiyong Park618922e2020-01-08 13:35:43 +09001972 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001973}
1974
Roland Levillain935639d2019-08-13 14:55:28 +01001975// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1976type flattenedApexContext struct {
1977 android.ModuleContext
1978}
1979
1980func (c *flattenedApexContext) InstallBypassMake() bool {
1981 return true
1982}
1983
Jiyong Park201cedd2020-02-07 17:25:49 +09001984// Visit dependencies that contributes to the payload of this APEX
1985func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1986 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Park0f80c182020-01-31 02:49:53 +09001987 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1988 am, ok := child.(android.ApexModule)
1989 if !ok || !am.CanHaveApexVariants() {
1990 return false
1991 }
1992
1993 // Check for the direct dependencies that contribute to the payload
1994 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1995 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001996 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001997 return true
1998 }
1999 return false
2000 }
2001
2002 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09002003 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09002004 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002005 return true
2006 }
2007
Jiyong Park201cedd2020-02-07 17:25:49 +09002008 do(ctx, parent, am, true /* externalDep */)
2009
Jiyong Park0f80c182020-01-31 02:49:53 +09002010 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2011 return false
2012 })
2013}
2014
Jooyung Han03b51852020-02-26 22:45:42 +09002015func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
2016 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
2017 if ver != "current" {
2018 minSdkVersion, err := strconv.Atoi(ver)
2019 if err != nil {
2020 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
2021 }
2022 return minSdkVersion
2023 }
2024 return android.FutureApiLevel
2025}
2026
Jiyong Park201cedd2020-02-07 17:25:49 +09002027// Ensures that the dependencies are marked as available for this APEX
2028func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2029 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2030 if ctx.Host() || a.testApex || a.vndkApex {
2031 return
2032 }
2033
2034 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2035 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002036 fromName := ctx.OtherModuleName(from)
2037 toName := ctx.OtherModuleName(to)
2038 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002039 return
2040 }
Jooyung Han5e9013b2020-03-10 06:23:13 +09002041 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09002042 })
2043}
2044
Jiyong Park678c8812020-02-07 17:25:49 +09002045// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2046func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2047 a.depInfos = make(map[string]depInfo)
2048 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2049 if from.Name() == to.Name() {
2050 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2051 return
2052 }
2053
2054 if info, exists := a.depInfos[to.Name()]; exists {
2055 if !android.InList(from.Name(), info.from) {
2056 info.from = append(info.from, from.Name())
2057 }
2058 info.isExternal = info.isExternal && externalDep
2059 a.depInfos[to.Name()] = info
2060 } else {
2061 a.depInfos[to.Name()] = depInfo{
2062 to: to.Name(),
2063 from: []string{from.Name()},
2064 isExternal: externalDep,
2065 }
2066 }
2067 })
2068}
2069
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002070func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002071 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2072 switch a.properties.ApexType {
2073 case imageApex:
2074 if buildFlattenedAsDefault {
2075 a.suffix = imageApexSuffix
2076 } else {
2077 a.suffix = ""
2078 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002079
2080 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002081 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002082 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002083 }
2084 case zipApex:
2085 if proptools.String(a.properties.Payload_type) == "zip" {
2086 a.suffix = ""
2087 a.primaryApexType = true
2088 } else {
2089 a.suffix = zipApexSuffix
2090 }
2091 case flattenedApex:
2092 if buildFlattenedAsDefault {
2093 a.suffix = ""
2094 a.primaryApexType = true
2095 } else {
2096 a.suffix = flattenedSuffix
2097 }
Alex Light5098a612018-11-29 17:12:15 -08002098 }
2099
Roland Levillain630846d2019-06-26 12:48:34 +01002100 if len(a.properties.Tests) > 0 && !a.testApex {
2101 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2102 return
2103 }
2104
Jiyong Park0f80c182020-01-31 02:49:53 +09002105 a.checkApexAvailability(ctx)
2106
Jiyong Park678c8812020-02-07 17:25:49 +09002107 a.collectDepsInfo(ctx)
2108
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002109 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2110
Jooyung Hane1633032019-08-01 17:41:43 +09002111 // native lib dependencies
2112 var provideNativeLibs []string
2113 var requireNativeLibs []string
2114
Jooyung Han5c998b92019-06-27 11:30:33 +09002115 // Check if "uses" requirements are met with dependent apexBundles
2116 var providedNativeSharedLibs []string
2117 useVendor := proptools.Bool(a.properties.Use_vendor)
2118 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2119 if ctx.OtherModuleDependencyTag(m) != usesTag {
2120 return
2121 }
2122 otherName := ctx.OtherModuleName(m)
2123 other, ok := m.(*apexBundle)
2124 if !ok {
2125 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2126 return
2127 }
2128 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2129 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2130 return
2131 }
2132 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2133 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2134 return
2135 }
2136 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2137 })
2138
Jiyong Parkf653b052019-11-18 15:39:01 +09002139 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002140 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002141 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002142 depTag := ctx.OtherModuleDependencyTag(child)
2143 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002144 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002145 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002146 case sharedLibTag, jniLibTag:
2147 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002148 if c, ok := child.(*cc.Module); ok {
2149 // bootstrap bionic libs are treated as provided by system
2150 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2151 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002152 }
Jooyung Han643adc42020-02-27 13:50:06 +09002153 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2154 fi.isJniLib = isJniLib
2155 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002156 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002157 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002158 propertyName := "native_shared_libs"
2159 if isJniLib {
2160 propertyName = "jni_libs"
2161 }
2162 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002163 }
2164 case executableTag:
2165 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002166 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002167 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002168 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002169 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002170 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002171 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002172 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002173 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002174 } else {
Alex Light778127a2019-02-27 14:19:50 -08002175 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 +09002176 }
2177 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002178 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002179 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002180 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002181 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2182 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002183 filesInfo = append(filesInfo, af)
2184 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002185 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002186 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2187 af := apexFileForJavaLibrary(ctx, sdkLib)
2188 if !af.Ok() {
2189 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2190 return false
2191 }
2192 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002193 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002194 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002195 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002196 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002197 case androidAppTag:
2198 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2199 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002200 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002201 return true // track transitive dependencies
2202 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002203 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002204 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2205 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002206 } else {
2207 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2208 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002209 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002210 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002211 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002212 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2213 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002214 } else {
atrost6e126252020-01-27 17:01:16 +00002215 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002216 }
Roland Levillain630846d2019-06-26 12:48:34 +01002217 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002218 if ccTest, ok := child.(*cc.Module); ok {
2219 if ccTest.IsTestPerSrcAllTestsVariation() {
2220 // Multiple-output test module (where `test_per_src: true`).
2221 //
2222 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2223 // We do not add this variation to `filesInfo`, as it has no output;
2224 // however, we do add the other variations of this module as indirect
2225 // dependencies (see below).
2226 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002227 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002228 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002229 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002230 af.class = nativeTest
2231 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002232 }
Roland Levillain630846d2019-06-26 12:48:34 +01002233 } else {
2234 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2235 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002236 case keyTag:
2237 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002238 a.private_key_file = key.private_key_file
2239 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002240 } else {
2241 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002242 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002243 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002244 case certificateTag:
2245 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002246 a.container_certificate_file = dep.Certificate.Pem
2247 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002248 } else {
2249 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2250 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002251 case android.PrebuiltDepTag:
2252 // If the prebuilt is force disabled, remember to delete the prebuilt file
2253 // that might have been installed in the previous builds
2254 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2255 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2256 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002257 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002258 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002259 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002260 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002261 // We cannot use a switch statement on `depTag` here as the checked
2262 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002263 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002264 if cc, ok := child.(*cc.Module); ok {
2265 if android.InList(cc.Name(), providedNativeSharedLibs) {
2266 // If we're using a shared library which is provided from other APEX,
2267 // don't include it in this APEX
2268 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002269 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002270 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002271 // If the dependency is a stubs lib, don't include it in this APEX,
2272 // but make sure that the lib is installed on the device.
2273 // In case no APEX is having the lib, the lib is installed to the system
2274 // partition.
2275 //
2276 // Always include if we are a host-apex however since those won't have any
2277 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002278 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2279 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002280 }
Jooyung Hane1633032019-08-01 17:41:43 +09002281 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002282 // Don't track further
2283 return false
2284 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002285 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002286 af.transitiveDep = true
2287 filesInfo = append(filesInfo, af)
2288 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002289 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002290 } else if cc.IsTestPerSrcDepTag(depTag) {
2291 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002292 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002293 // Handle modules created as `test_per_src` variations of a single test module:
2294 // use the name of the generated test binary (`fileToCopy`) instead of the name
2295 // of the original test module (`depName`, shared by all `test_per_src`
2296 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002297 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002298 // these are not considered transitive dep
2299 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002300 filesInfo = append(filesInfo, af)
2301 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002302 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002303 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002304 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2305 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002306 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2307 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2308 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2309 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002310 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002311 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002312 }
2313 }
2314 }
2315 return false
2316 })
2317
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002318 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2319 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2320 // via the global boot image config.
2321 if a.artApex {
2322 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2323 dirInApex := filepath.Join("javalib", arch.String())
2324 for _, f := range files {
2325 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002326 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002327 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002328 }
2329 }
2330 }
2331
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002332 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002333 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2334 return
2335 }
2336
Jiyong Park8fd61922018-11-08 02:50:25 +09002337 // remove duplicates in filesInfo
2338 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002339 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002340 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002341 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002342 if e, ok := encountered[dest]; !ok {
2343 encountered[dest] = f
2344 } else {
2345 // If a module is directly included and also transitively depended on
2346 // consider it as directly included.
2347 e.transitiveDep = e.transitiveDep && f.transitiveDep
2348 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002349 }
2350 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002351 var result []apexFile
2352 for _, v := range encountered {
2353 result = append(result, v)
2354 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002355 return result
2356 }
2357 filesInfo = removeDup(filesInfo)
2358
2359 // to have consistent build rules
2360 sort.Slice(filesInfo, func(i, j int) bool {
2361 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2362 })
2363
Jiyong Park8fd61922018-11-08 02:50:25 +09002364 a.installDir = android.PathForModuleInstall(ctx, "apex")
2365 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002366
Jooyung Han54aca7b2019-11-20 02:26:02 +09002367 if a.properties.ApexType != zipApex {
2368 if a.properties.File_contexts == nil {
2369 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2370 } else {
2371 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2372 if a.Platform() {
2373 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2374 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2375 }
2376 }
2377 }
2378 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2379 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2380 return
2381 }
2382 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002383 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2384 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2385 // the same library in the system partition, thus effectively sharing the same libraries
2386 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2387 // in the APEX.
2388 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2389 a.installable() &&
2390 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002391
Jiyong Park9d677202020-02-19 16:29:35 +09002392 // We don't need the optimization for updatable APEXes, as it might give false signal
2393 // to the system health when the APEXes are still bundled (b/149805758)
2394 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2395 a.linkToSystemLib = false
2396 }
2397
Jiyong Park638d30e2020-02-26 18:27:19 +09002398 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2399 if ctx.Host() {
2400 a.linkToSystemLib = false
2401 }
2402
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002403 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002404 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2405
2406 a.setCertificateAndPrivateKey(ctx)
2407 if a.properties.ApexType == flattenedApex {
2408 a.buildFlattenedApex(ctx)
2409 } else {
2410 a.buildUnflattenedApex(ctx)
2411 }
2412
Jooyung Han002ab682020-01-08 01:57:58 +09002413 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002414
2415 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002416}
2417
Jooyung Han5e9013b2020-03-10 06:23:13 +09002418func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002419 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002420 moduleName = normalizeModuleName(moduleName)
2421
2422 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2423 return true
2424 }
2425
2426 key = android.AvailableToAnyApex
2427 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2428 return true
2429 }
2430
2431 return false
2432}
2433
2434func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002435 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2436 // system. Trim the prefix for the check since they are confusing
2437 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2438 if strings.HasPrefix(moduleName, "libclang_rt.") {
2439 // This module has many arch variants that depend on the product being built.
2440 // We don't want to list them all
2441 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002442 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002443 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002444}
2445
Jooyung Han344d5432019-08-23 11:17:39 +09002446func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002447 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002448 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002449 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002450 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002451 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002452 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2453 })
Alex Light5098a612018-11-29 17:12:15 -08002454 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002455 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002456 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002457 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002458 return module
2459}
Jiyong Park30ca9372019-02-07 16:27:23 +09002460
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002461func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002462 bundle := newApexBundle()
2463 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002464 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002465 return bundle
2466}
2467
Jiyong Parkfce0b422020-02-11 03:56:06 +09002468// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2469// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002470func testApexBundleFactory() android.Module {
2471 bundle := newApexBundle()
2472 bundle.testApex = true
2473 return bundle
2474}
2475
Jiyong Parkfce0b422020-02-11 03:56:06 +09002476// apex packages other modules into an APEX file which is a packaging format for system-level
2477// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002478func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002479 return newApexBundle()
2480}
2481
Jiyong Park30ca9372019-02-07 16:27:23 +09002482//
2483// Defaults
2484//
2485type Defaults struct {
2486 android.ModuleBase
2487 android.DefaultsModuleBase
2488}
2489
Jiyong Park30ca9372019-02-07 16:27:23 +09002490func defaultsFactory() android.Module {
2491 return DefaultsFactory()
2492}
2493
2494func DefaultsFactory(props ...interface{}) android.Module {
2495 module := &Defaults{}
2496
2497 module.AddProperties(props...)
2498 module.AddProperties(
2499 &apexBundleProperties{},
2500 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002501 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002502 )
2503
2504 android.InitDefaultsModule(module)
2505 return module
2506}
Jiyong Park5d790c32019-11-15 18:40:32 +09002507
2508//
2509// OverrideApex
2510//
2511type OverrideApex struct {
2512 android.ModuleBase
2513 android.OverrideModuleBase
2514}
2515
2516func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2517 // All the overrides happen in the base module.
2518}
2519
2520// override_apex is used to create an apex module based on another apex module
2521// by overriding some of its properties.
2522func overrideApexFactory() android.Module {
2523 m := &OverrideApex{}
2524 m.AddProperties(&overridableProperties{})
2525
2526 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2527 android.InitOverrideModule(m)
2528 return m
2529}