blob: bc992f063890bc13f683d072e75f95aff61b3547 [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",
Jiyong Park0f80c182020-01-31 02:49:53 +0900129 "libsystem_headers",
130 "libutils_headers",
131 }
132 //
133 // Module separator
134 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000135 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900136 "art_cmdlineparser_headers",
137 "art_disassembler_headers",
138 "art_libartbase_headers",
139 "bcm_object",
140 "bionic_libc_platform_headers",
141 "core-repackaged-icu4j",
142 "cpp-define-generator-asm-support",
143 "cpp-define-generator-definitions",
144 "crtbegin_dynamic",
145 "crtbegin_dynamic1",
146 "crtbegin_so1",
147 "crtbrand",
148 "conscrypt.module.intra.core.api.stubs",
149 "dex2oat_headers",
150 "dt_fd_forward_export",
151 "fmtlib",
152 "icu4c_extra_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000153 "jacocoagent",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "javavm_headers",
155 "jni_platform_headers",
156 "libPlatformProperties",
157 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000158 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900159 "libandroidicuinit",
160 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libasync_safe",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libbacktrace",
164 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libbase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000166 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900167 "libc++_static",
168 "libc++abi",
169 "libc++demangle",
170 "libc_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000171 "libcrypto",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "libdexfile_all_headers",
173 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000174 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900175 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000176 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900177 "libfdlibm",
178 "libgtest_prod",
179 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000180 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900181 "libicuuc_headers",
182 "libicuuc_stubdata",
183 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900184 "liblog_headers",
185 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000186 "liblzma",
187 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900188 "libnativebridge-headers",
189 "libnativehelper_header_only",
190 "libnativeloader-headers",
191 "libnpt_headers",
192 "libopenjdkjvmti_headers",
193 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000194 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900195 "libprotobuf-cpp-lite",
196 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000197 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "libv8",
199 "libv8base",
200 "libv8gen",
201 "libv8platform",
202 "libv8sampler",
203 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000204 "libvixl",
205 "libvixld",
206 "libz",
207 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900208 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000209 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000210 m["com.android.art.debug"] = artApexContents
211 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 //
213 // Module separator
214 //
215 m["com.android.bluetooth.updatable"] = []string{
216 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000217 "android.hardware.bluetooth.a2dp@1.0",
218 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 "android.hardware.bluetooth@1.0",
220 "android.hardware.bluetooth@1.1",
221 "android.hardware.graphics.bufferqueue@1.0",
222 "android.hardware.graphics.bufferqueue@2.0",
223 "android.hardware.graphics.common@1.0",
224 "android.hardware.graphics.common@1.1",
225 "android.hardware.graphics.common@1.2",
226 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000227 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900228 "android.hidl.token@1.0",
229 "android.hidl.token@1.0-utils",
230 "avrcp-target-service",
231 "avrcp_headers",
232 "bcm_object",
233 "bluetooth-protos-lite",
234 "bluetooth.mapsapi",
235 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900236 "dnsresolver_aidl_interface-V2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 "fmtlib",
238 "guava",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900239 "ipmemorystore-aidl-interfaces-V5-java",
240 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "internal_include_headers",
242 "lib-bt-packets",
243 "lib-bt-packets-avrcp",
244 "lib-bt-packets-base",
245 "libFraunhoferAAC",
246 "libaudio-a2dp-hw-utils",
247 "libaudio-hearing-aid-hw-utils",
248 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000249 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "libbase_headers",
251 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000252 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900253 "libbluetooth-types",
254 "libbluetooth-types-header",
255 "libbluetooth_gd",
256 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000257 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900258 "libbt-audio-hal-interface",
259 "libbt-bta",
260 "libbt-common",
261 "libbt-hci",
262 "libbt-platform-protos-lite",
263 "libbt-protos-lite",
264 "libbt-sbc-decoder",
265 "libbt-sbc-encoder",
266 "libbt-stack",
267 "libbt-utils",
268 "libbtcore",
269 "libbtdevice",
270 "libbte",
271 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000272 "libc++",
273 "libchrome",
274 "libcrypto",
275 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000277 "libevent",
278 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900279 "libg722codec",
280 "libgtest_prod",
281 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000282 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900283 "libhidlbase-impl-internal",
284 "libhidltransport-impl-internal",
285 "libhwbinder-impl-internal",
286 "libjsoncpp",
287 "liblog_headers",
288 "libmedia_headers",
289 "libmodpb64",
290 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000291 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900292 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000293 "libprotobuf-cpp-lite",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "libprotobuf-java-lite",
295 "libprotobuf-java-micro",
296 "libstagefright_foundation_headers",
297 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000298 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 "libstatssocket",
300 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000301 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900302 "libudrv-uipc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900303 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000304 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900305 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900306 "net-utils-services-common",
307 "netd_aidl_interface-unstable-java",
308 "netd_event_listener_interface-java",
309 "netlink-client",
310 "networkstack-aidl-interfaces-unstable-java",
311 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900312 "sap-api-java-static",
313 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000314 }
315 //
316 // Module separator
317 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900318 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000319 //
320 // Module separator
321 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900322 m["com.android.conscrypt"] = []string{
323 "bcm_object",
324 "boringssl_self_test",
325 "libc++",
326 "libcrypto",
327 "libnativehelper_header_only",
328 "libssl",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900329 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900330 }
331 //
332 // Module separator
333 //
334 m["com.android.extservices"] = []string{
335 "flatbuffer_headers",
336 "liblua",
337 "libtextclassifier",
338 "libtextclassifier_hash_static",
339 "libtflite_static",
340 "libutf",
341 "libz_current",
342 "tensorflow_headers",
343 }
344 //
345 // Module separator
346 //
347 m["com.android.cronet"] = []string{
348 "cronet_impl_common_java",
349 "cronet_impl_native_java",
350 "cronet_impl_platform_java",
351 "libcronet.80.0.3986.0",
352 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900353 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900354 "prebuilt_libcronet.80.0.3986.0",
355 }
356 //
357 // Module separator
358 //
359 m["com.android.neuralnetworks"] = []string{
360 "android.hardware.neuralnetworks@1.0",
361 "android.hardware.neuralnetworks@1.1",
362 "android.hardware.neuralnetworks@1.2",
363 "android.hardware.neuralnetworks@1.3",
364 "android.hidl.allocator@1.0",
365 "android.hidl.memory.token@1.0",
366 "android.hidl.memory@1.0",
367 "android.hidl.safe_union@1.0",
368 "bcm_object",
369 "fmtlib",
370 "gemmlowp_headers",
371 "libarect",
372 "libbacktrace_headers",
373 "libbase",
374 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900375 "libbuildversion",
376 "libc++",
377 "libcrypto",
378 "libcrypto_static",
379 "libcutils",
380 "libcutils_headers",
381 "libeigen",
382 "libfmq",
383 "libhidlbase",
384 "libhidlbase-impl-internal",
385 "libhidlmemory",
386 "libhidltransport-impl-internal",
387 "libhwbinder-impl-internal",
388 "libjsoncpp",
389 "liblog_headers",
390 "libmath",
391 "libneuralnetworks_common",
392 "libneuralnetworks_headers",
393 "libprocessgroup",
394 "libprocessgroup_headers",
395 "libprocpartition",
396 "libsync",
397 "libsystem_headers",
398 "libtextclassifier_hash",
399 "libtextclassifier_hash_headers",
400 "libtextclassifier_hash_static",
401 "libtflite_kernel_utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900402 "libutils_headers",
403 "philox_random",
404 "philox_random_headers",
405 "tensorflow_headers",
406 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000407 //
408 // Module separator
409 //
410 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000411 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900412 "android.hardware.cas.native@1.0",
413 "android.hardware.cas@1.0",
414 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000415 "android.hardware.configstore@1.0",
416 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000417 "android.hardware.graphics.allocator@2.0",
418 "android.hardware.graphics.allocator@3.0",
419 "android.hardware.graphics.bufferqueue@1.0",
420 "android.hardware.graphics.bufferqueue@2.0",
421 "android.hardware.graphics.common@1.0",
422 "android.hardware.graphics.common@1.1",
423 "android.hardware.graphics.common@1.2",
424 "android.hardware.graphics.mapper@2.0",
425 "android.hardware.graphics.mapper@2.1",
426 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900427 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000428 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900429 "android.hidl.allocator@1.0",
430 "android.hidl.memory.token@1.0",
431 "android.hidl.memory@1.0",
432 "android.hidl.token@1.0",
433 "android.hidl.token@1.0-utils",
434 "bcm_object",
435 "bionic_libc_platform_headers",
436 "fmtlib",
437 "gl_headers",
438 "libEGL",
439 "libEGL_blobCache",
440 "libEGL_getProcAddress",
441 "libFLAC",
442 "libFLAC-config",
443 "libFLAC-headers",
444 "libGLESv2",
445 "libaacextractor",
446 "libamrextractor",
447 "libarect",
448 "libasync_safe",
449 "libaudio_system_headers",
450 "libaudioclient",
451 "libaudioclient_headers",
452 "libaudiofoundation",
453 "libaudiofoundation_headers",
454 "libaudiomanager",
455 "libaudiopolicy",
456 "libaudioutils",
457 "libaudioutils_fixedfft",
458 "libbacktrace",
459 "libbacktrace_headers",
460 "libbase",
461 "libbase_headers",
462 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900463 "libbluetooth-types-header",
464 "libbufferhub",
465 "libbufferhub_headers",
466 "libbufferhubqueue",
467 "libc++",
468 "libc_headers",
469 "libc_malloc_debug_backtrace",
470 "libcamera_client",
471 "libcamera_metadata",
472 "libcrypto",
473 "libcutils",
474 "libcutils_headers",
475 "libdexfile_external_headers",
476 "libdexfile_support",
477 "libdvr_headers",
478 "libexpat",
479 "libfifo",
480 "libflacextractor",
481 "libgrallocusage",
482 "libgraphicsenv",
483 "libgui",
484 "libgui_headers",
485 "libhardware_headers",
486 "libhidlbase",
487 "libhidlbase-impl-internal",
488 "libhidlmemory",
489 "libhidltransport-impl-internal",
490 "libhwbinder-impl-internal",
491 "libinput",
492 "libjsoncpp",
493 "liblog_headers",
494 "liblzma",
495 "libmath",
496 "libmedia",
497 "libmedia_codeclist",
498 "libmedia_headers",
499 "libmedia_helper",
500 "libmedia_helper_headers",
501 "libmedia_midiiowrapper",
502 "libmedia_omx",
503 "libmediautils",
504 "libmidiextractor",
505 "libmkvextractor",
506 "libmp3extractor",
507 "libmp4extractor",
508 "libmpeg2extractor",
509 "libnativebase_headers",
510 "libnativebridge-headers",
511 "libnativebridge_lazy",
512 "libnativeloader-headers",
513 "libnativeloader_lazy",
514 "libnativewindow_headers",
515 "libnblog",
516 "liboggextractor",
517 "libpackagelistparser",
518 "libpcre2",
519 "libpdx",
520 "libpdx_default_transport",
521 "libpdx_headers",
522 "libpdx_uds",
523 "libprocessgroup",
524 "libprocessgroup_headers",
525 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900526 "libsonivox",
527 "libspeexresampler",
528 "libspeexresampler",
529 "libstagefright_esds",
530 "libstagefright_flacdec",
531 "libstagefright_flacdec",
532 "libstagefright_foundation",
533 "libstagefright_foundation_headers",
534 "libstagefright_foundation_without_imemory",
535 "libstagefright_headers",
536 "libstagefright_id3",
537 "libstagefright_metadatautils",
538 "libstagefright_mpeg2extractor",
539 "libstagefright_mpeg2support",
540 "libsync",
541 "libsystem_headers",
542 "libui",
543 "libui_headers",
544 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900545 "libutils_headers",
546 "libvibrator",
547 "libvorbisidec",
548 "libwavextractor",
549 "libwebm",
550 "media_ndk_headers",
551 "media_plugin_headers",
552 "updatable-media",
553 }
554 //
555 // Module separator
556 //
557 m["com.android.media.swcodec"] = []string{
558 "android.frameworks.bufferhub@1.0",
559 "android.hardware.common-ndk_platform",
560 "android.hardware.configstore-utils",
561 "android.hardware.configstore@1.0",
562 "android.hardware.configstore@1.1",
563 "android.hardware.graphics.allocator@2.0",
564 "android.hardware.graphics.allocator@3.0",
565 "android.hardware.graphics.bufferqueue@1.0",
566 "android.hardware.graphics.bufferqueue@2.0",
567 "android.hardware.graphics.common-ndk_platform",
568 "android.hardware.graphics.common@1.0",
569 "android.hardware.graphics.common@1.1",
570 "android.hardware.graphics.common@1.2",
571 "android.hardware.graphics.mapper@2.0",
572 "android.hardware.graphics.mapper@2.1",
573 "android.hardware.graphics.mapper@3.0",
574 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 "android.hardware.media.bufferpool@2.0",
576 "android.hardware.media.c2@1.0",
577 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "android.hardware.media@1.0",
579 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000580 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 "android.hidl.safe_union@1.0",
583 "android.hidl.token@1.0",
584 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900585 "fmtlib",
586 "libEGL",
587 "libFLAC",
588 "libFLAC-config",
589 "libFLAC-headers",
590 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900591 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900592 "libarect",
593 "libasync_safe",
594 "libaudio_system_headers",
595 "libaudioutils",
596 "libaudioutils",
597 "libaudioutils_fixedfft",
598 "libavcdec",
599 "libavcenc",
600 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 "libavservices_minijail",
602 "libbacktrace",
Jiyong Park0f80c182020-01-31 02:49:53 +0900603 "libbacktrace_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000604 "libbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "libbase_headers",
606 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900607 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 "libbluetooth-types-header",
609 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000610 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900611 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000612 "libcap",
613 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900614 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000615 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 "libcodec2_hidl@1.1",
617 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000618 "libcodec2_soft_aacdec",
619 "libcodec2_soft_aacenc",
620 "libcodec2_soft_amrnbdec",
621 "libcodec2_soft_amrnbenc",
622 "libcodec2_soft_amrwbdec",
623 "libcodec2_soft_amrwbenc",
624 "libcodec2_soft_av1dec_gav1",
625 "libcodec2_soft_avcdec",
626 "libcodec2_soft_avcenc",
627 "libcodec2_soft_common",
628 "libcodec2_soft_flacdec",
629 "libcodec2_soft_flacenc",
630 "libcodec2_soft_g711alawdec",
631 "libcodec2_soft_g711mlawdec",
632 "libcodec2_soft_gsmdec",
633 "libcodec2_soft_h263dec",
634 "libcodec2_soft_h263enc",
635 "libcodec2_soft_hevcdec",
636 "libcodec2_soft_hevcenc",
637 "libcodec2_soft_mp3dec",
638 "libcodec2_soft_mpeg2dec",
639 "libcodec2_soft_mpeg4dec",
640 "libcodec2_soft_mpeg4enc",
641 "libcodec2_soft_opusdec",
642 "libcodec2_soft_opusenc",
643 "libcodec2_soft_rawdec",
644 "libcodec2_soft_vorbisdec",
645 "libcodec2_soft_vp8dec",
646 "libcodec2_soft_vp8enc",
647 "libcodec2_soft_vp9dec",
648 "libcodec2_soft_vp9enc",
649 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000650 "libcutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900651 "libcutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900653 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000654 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900655 "libfmq",
656 "libgav1",
657 "libgralloctypes",
658 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000659 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900660 "libgsm",
661 "libgui_bufferqueue_static",
662 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000663 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libhardware_headers",
665 "libhevcdec",
666 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000667 "libhidlbase",
Jiyong Park0f80c182020-01-31 02:49:53 +0900668 "libhidlbase-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000669 "libhidlmemory",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 "libhidltransport-impl-internal",
671 "libhwbinder-impl-internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000672 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "libjpeg",
674 "libjsoncpp",
675 "liblog_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000676 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900677 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000678 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900679 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000680 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 "libminijail_gen_constants",
682 "libminijail_gen_constants_obj",
683 "libminijail_gen_syscall",
684 "libminijail_gen_syscall_obj",
685 "libminijail_generated",
686 "libmpeg2dec",
687 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000688 "libnativebridge_lazy",
689 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900690 "libnativewindow_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000691 "libopus",
Jiyong Park0f80c182020-01-31 02:49:53 +0900692 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000693 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000695 "libscudo_wrapper",
696 "libsfplugin_ccodec_utils",
697 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900698 "libstagefright_amrnbdec",
699 "libstagefright_amrnbenc",
700 "libstagefright_amrwbdec",
701 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000702 "libstagefright_bufferpool@2.0.1",
703 "libstagefright_bufferqueue_helper",
704 "libstagefright_enc_common",
705 "libstagefright_flacdec",
706 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900707 "libstagefright_foundation_headers",
708 "libstagefright_headers",
709 "libstagefright_m4vh263dec",
710 "libstagefright_m4vh263enc",
711 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000712 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900713 "libsystem_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000714 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900715 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000716 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900717 "libutils_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000718 "libvorbisidec",
719 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900720 "libyuv",
721 "libyuv_static",
722 "media_ndk_headers",
723 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000724 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900725 }
726 //
727 // Module separator
728 //
729 m["com.android.mediaprovider"] = []string{
730 "MediaProvider",
731 "MediaProviderGoogle",
732 "fmtlib_ndk",
733 "guava",
734 "libbase_ndk",
735 "libfuse",
736 "libfuse_jni",
737 "libnativehelper_header_only",
738 }
739 //
740 // Module separator
741 //
742 m["com.android.permission"] = []string{
743 "androidx.annotation_annotation",
744 "androidx.annotation_annotation-nodeps",
745 "androidx.lifecycle_lifecycle-common",
746 "androidx.lifecycle_lifecycle-common-java8",
747 "androidx.lifecycle_lifecycle-common-java8-nodeps",
748 "androidx.lifecycle_lifecycle-common-nodeps",
749 "kotlin-annotations",
750 "kotlin-stdlib",
751 "kotlin-stdlib-jdk7",
752 "kotlin-stdlib-jdk8",
753 "kotlinx-coroutines-android",
754 "kotlinx-coroutines-android-nodeps",
755 "kotlinx-coroutines-core",
756 "kotlinx-coroutines-core-nodeps",
757 "libprotobuf-java-lite",
758 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000759 }
760 //
761 // Module separator
762 //
763 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900764 "bionic_libc_platform_headers",
765 "fmtlib",
766 "libarm-optimized-routines-math",
767 "libasync_safe",
768 "libasync_safe_headers",
769 "libbacktrace_headers",
770 "libbase",
771 "libbase_headers",
772 "libc++",
773 "libc_aeabi",
774 "libc_bionic",
775 "libc_bionic_ndk",
776 "libc_bootstrap",
777 "libc_common",
778 "libc_common_shared",
779 "libc_common_static",
780 "libc_dns",
781 "libc_dynamic_dispatch",
782 "libc_fortify",
783 "libc_freebsd",
784 "libc_freebsd_large_stack",
785 "libc_gdtoa",
786 "libc_headers",
787 "libc_init_dynamic",
788 "libc_init_static",
789 "libc_jemalloc_wrapper",
790 "libc_netbsd",
791 "libc_nomalloc",
792 "libc_nopthread",
793 "libc_openbsd",
794 "libc_openbsd_large_stack",
795 "libc_openbsd_ndk",
796 "libc_pthread",
797 "libc_static_dispatch",
798 "libc_syscalls",
799 "libc_tzcode",
800 "libc_unwind_static",
801 "libcutils",
802 "libcutils_headers",
803 "libdebuggerd",
804 "libdebuggerd_common_headers",
805 "libdebuggerd_handler_core",
806 "libdebuggerd_handler_fallback",
807 "libdexfile_external_headers",
808 "libdexfile_support",
809 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900810 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900811 "libgtest_prod",
812 "libjemalloc5",
813 "liblinker_main",
814 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900815 "liblog_headers",
816 "liblz4",
817 "liblzma",
818 "libprocessgroup_headers",
819 "libprocinfo",
820 "libpropertyinfoparser",
821 "libscudo",
822 "libstdc++",
823 "libsystem_headers",
824 "libsystemproperties",
825 "libtombstoned_client_static",
826 "libunwindstack",
827 "libutils_headers",
828 "libz",
829 "libziparchive",
830 }
831 //
832 // Module separator
833 //
834 m["com.android.resolv"] = []string{
835 "bcm_object",
836 "dnsresolver_aidl_interface-unstable-ndk_platform",
837 "fmtlib",
838 "libbacktrace_headers",
839 "libbase",
840 "libbase_headers",
841 "libc++",
842 "libcrypto",
843 "libcutils",
844 "libcutils_headers",
845 "libgtest_prod",
846 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900847 "liblog_headers",
848 "libnativehelper_header_only",
849 "libnetd_client_headers",
850 "libnetd_resolv",
851 "libnetdutils",
852 "libprocessgroup",
853 "libprocessgroup_headers",
854 "libprotobuf-cpp-lite",
855 "libssl",
856 "libstatslog_resolv",
857 "libstatspush_compat",
858 "libstatssocket",
859 "libstatssocket_headers",
860 "libsystem_headers",
861 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900862 "libutils_headers",
863 "netd_event_listener_interface-ndk_platform",
864 "server_configurable_flags",
865 "stats_proto",
866 }
867 //
868 // Module separator
869 //
870 m["com.android.tethering"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000871 "libbase",
872 "libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900873 "libnativehelper_compat_libc++",
874 "android.hardware.tetheroffload.config@1.0",
875 "fmtlib",
876 "libbacktrace_headers",
877 "libbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900878 "libcgrouprc",
879 "libcgrouprc_format",
880 "libcutils",
881 "libcutils_headers",
882 "libhidlbase",
883 "libhidlbase-impl-internal",
884 "libhidltransport-impl-internal",
885 "libhwbinder-impl-internal",
886 "libjsoncpp",
Jiyong Park0f80c182020-01-31 02:49:53 +0900887 "liblog_headers",
888 "libprocessgroup",
889 "libprocessgroup_headers",
890 "libsystem_headers",
891 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900892 "libutils_headers",
893 "libvndksupport",
894 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000895 }
896 //
897 // Module separator
898 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900899 m["com.android.wifi"] = []string{
900 "PlatformProperties",
901 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900902 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900903 "android.hardware.wifi-V1.1-java",
904 "android.hardware.wifi-V1.2-java",
905 "android.hardware.wifi-V1.3-java",
906 "android.hardware.wifi-V1.4-java",
907 "android.hardware.wifi.hostapd-V1.0-java",
908 "android.hardware.wifi.hostapd-V1.1-java",
909 "android.hardware.wifi.hostapd-V1.2-java",
910 "android.hardware.wifi.supplicant-V1.0-java",
911 "android.hardware.wifi.supplicant-V1.1-java",
912 "android.hardware.wifi.supplicant-V1.2-java",
913 "android.hardware.wifi.supplicant-V1.3-java",
914 "android.hidl.base-V1.0-java",
915 "android.hidl.manager-V1.0-java",
916 "android.hidl.manager-V1.1-java",
917 "android.hidl.manager-V1.2-java",
918 "androidx.annotation_annotation",
919 "androidx.annotation_annotation-nodeps",
920 "bouncycastle-unbundled",
921 "dnsresolver_aidl_interface-V2-java",
922 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900923 "framework-wifi-pre-jarjar",
924 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900925 "ipmemorystore-aidl-interfaces-V3-java",
926 "ipmemorystore-aidl-interfaces-java",
927 "ksoap2",
928 "libbacktrace_headers",
929 "libbase",
930 "libbase_headers",
931 "libc++",
932 "libcutils",
933 "libcutils_headers",
934 "liblog_headers",
935 "libnanohttpd",
936 "libprocessgroup",
937 "libprocessgroup_headers",
938 "libprotobuf-java-lite",
939 "libprotobuf-java-nano",
940 "libsystem_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900941 "libutils_headers",
942 "libwifi-jni",
943 "net-utils-services-common",
944 "netd_aidl_interface-V2-java",
945 "netd_aidl_interface-unstable-java",
946 "netd_event_listener_interface-java",
947 "netlink-client",
948 "networkstack-aidl-interfaces-unstable-java",
949 "networkstack-client",
950 "services.net",
951 "wifi-lite-protos",
952 "wifi-nano-protos",
953 "wifi-service-pre-jarjar",
954 "wifi-service-resources",
955 "prebuilt_androidx.annotation_annotation-nodeps",
956 }
957 //
958 // Module separator
959 //
960 m["com.android.sdkext"] = []string{
961 "fmtlib_ndk",
962 "libbase_ndk",
963 "libprotobuf-cpp-lite-ndk",
964 }
965 //
966 // Module separator
967 //
968 m["com.android.os.statsd"] = []string{
969 "libbacktrace_headers",
970 "libbase_headers",
971 "libc++",
972 "libcutils",
973 "libcutils_headers",
974 "liblog_headers",
975 "libprocessgroup_headers",
976 "libstatssocket",
977 "libsystem_headers",
978 "libutils_headers",
979 }
980 //
981 // Module separator
982 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000983 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900984 "crtbegin_dynamic",
985 "crtbegin_dynamic1",
986 "crtbegin_so",
987 "crtbegin_so1",
988 "crtbegin_static",
989 "crtbrand",
990 "crtend_android",
991 "crtend_so",
992 "libatomic",
993 "libc++_static",
994 "libc++abi",
995 "libc++demangle",
996 "libc_headers",
997 "libclang_rt",
998 "libgcc_stripped",
999 "libprofile-clang-extras",
1000 "libprofile-clang-extras_ndk",
1001 "libprofile-extras",
1002 "libprofile-extras_ndk",
1003 "libunwind_llvm",
1004 "ndk_crtbegin_dynamic.27",
1005 "ndk_crtbegin_so.16",
1006 "ndk_crtbegin_so.19",
1007 "ndk_crtbegin_so.21",
1008 "ndk_crtbegin_so.24",
1009 "ndk_crtbegin_so.27",
1010 "ndk_crtend_android.27",
1011 "ndk_crtend_so.16",
1012 "ndk_crtend_so.19",
1013 "ndk_crtend_so.21",
1014 "ndk_crtend_so.24",
1015 "ndk_crtend_so.27",
1016 "ndk_libandroid_support",
1017 "ndk_libc++_static",
1018 "ndk_libc++abi",
1019 "ndk_libunwind",
1020 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001021 return m
1022}
1023
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001024func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +09001025 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -08001026 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +09001027 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +09001028 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001029 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +09001030 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031
Jooyung Han31c470b2019-10-18 16:26:59 +09001032 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001033 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +09001034
1035 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
1036 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
1037 sort.Strings(*apexFileContextsInfos)
1038 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
1039 })
Jiyong Parkd1063c12019-07-17 20:08:41 +09001040}
1041
Jooyung Han31c470b2019-10-18 16:26:59 +09001042func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
1043 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
1044 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
1045}
1046
Jiyong Parkd1063c12019-07-17 20:08:41 +09001047func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001048 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001049 ctx.BottomUp("apex", apexMutator).Parallel()
1050 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
1051 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001052}
1053
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054// Mark the direct and transitive dependencies of apex bundles so that they
1055// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +09001056func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001057 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +09001058 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +00001059 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han5e9013b2020-03-10 06:23:13 +09001060 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han5417f772020-03-12 18:37:20 +09001061 ApexName: mctx.ModuleName(),
1062 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Han5e9013b2020-03-10 06:23:13 +09001063 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +09001064 directDep = true
1065 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001066 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +09001067 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001068 }
Jiyong Parkf760cae2020-02-12 07:53:12 +09001069
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001070 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +09001071 return
1072 }
1073
Jooyung Han5e9013b2020-03-10 06:23:13 +09001074 cur := mctx.Module().(interface {
1075 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
1076 })
1077
Jiyong Parkf760cae2020-02-12 07:53:12 +09001078 mctx.VisitDirectDeps(func(child android.Module) {
1079 depName := mctx.OtherModuleName(child)
1080 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Han5e9013b2020-03-10 06:23:13 +09001081 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001082 android.UpdateApexDependency(apexBundles, depName, directDep)
1083 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +09001084 }
1085 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001086}
1087
1088// Create apex variations if a module is included in APEX(s).
1089func apexMutator(mctx android.BottomUpMutatorContext) {
1090 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001091 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001092 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001093 // apex bundle itself is mutated so that it and its modules have same
1094 // apex variant.
1095 apexBundleName := mctx.ModuleName()
1096 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +09001097 } else if o, ok := mctx.Module().(*OverrideApex); ok {
1098 apexBundleName := o.GetOverriddenModuleName()
1099 if apexBundleName == "" {
1100 mctx.ModuleErrorf("base property is not set")
1101 return
1102 }
1103 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001104 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001105
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001106}
Sundong Ahne9b55722019-09-06 17:37:42 +09001107
Jooyung Han7a78a922019-10-08 21:59:58 +09001108var (
1109 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
1110 apexFileContextsInfosMutex sync.Mutex
1111)
1112
1113func apexFileContextsInfos(config android.Config) *[]string {
1114 return config.Once(apexFileContextsInfosKey, func() interface{} {
1115 return &[]string{}
1116 }).(*[]string)
1117}
1118
Jooyung Han54aca7b2019-11-20 02:26:02 +09001119func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +09001120 apexFileContextsInfosMutex.Lock()
1121 defer apexFileContextsInfosMutex.Unlock()
1122 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +09001123 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +09001124}
1125
Sundong Ahne9b55722019-09-06 17:37:42 +09001126func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +09001127 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +09001128 var variants []string
1129 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
1130 case "image":
1131 variants = append(variants, imageApexType, flattenedApexType)
1132 case "zip":
1133 variants = append(variants, zipApexType)
1134 case "both":
1135 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
1136 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001137 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +09001138 return
1139 }
1140
1141 modules := mctx.CreateLocalVariations(variants...)
1142
1143 for i, v := range variants {
1144 switch v {
1145 case imageApexType:
1146 modules[i].(*apexBundle).properties.ApexType = imageApex
1147 case zipApexType:
1148 modules[i].(*apexBundle).properties.ApexType = zipApex
1149 case flattenedApexType:
1150 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001151 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001152 modules[i].(*apexBundle).MakeAsSystemExt()
1153 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001154 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001155 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001156 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1157 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001158 }
1159}
1160
Jooyung Han5c998b92019-06-27 11:30:33 +09001161func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1162 if ab, ok := mctx.Module().(*apexBundle); ok {
1163 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1164 }
1165}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001166
Jooyung Handc782442019-11-01 03:14:38 +09001167var (
1168 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1169)
1170
1171// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1172// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1173// which may cause compatibility issues. (e.g. libbinder)
1174// Even though libbinder restricts its availability via 'apex_available' property and relies on
1175// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1176// to avoid similar problems.
1177func useVendorWhitelist(config android.Config) []string {
1178 return config.Once(useVendorWhitelistKey, func() interface{} {
1179 return []string{
1180 // swcodec uses "vendor" variants for smaller size
1181 "com.android.media.swcodec",
1182 "test_com.android.media.swcodec",
1183 }
1184 }).([]string)
1185}
1186
1187// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1188// called before the first call to useVendorWhitelist()
1189func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1190 config.Once(useVendorWhitelistKey, func() interface{} {
1191 return whitelist
1192 })
1193}
1194
Jooyung Han01a868d2020-02-27 13:40:44 +09001195type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001196 // List of native libraries
1197 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001198
Jooyung Han643adc42020-02-27 13:50:06 +09001199 // List of JNI libraries
1200 Jni_libs []string
1201
Alex Light9670d332019-01-29 18:07:33 -08001202 // List of native executables
1203 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001204
Roland Levillain630846d2019-06-26 12:48:34 +01001205 // List of native tests
1206 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001207}
Jooyung Han344d5432019-08-23 11:17:39 +09001208
Alex Light9670d332019-01-29 18:07:33 -08001209type apexMultilibProperties struct {
1210 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001211 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001212
1213 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001214 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001215
1216 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001217 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001218
1219 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001220 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001221
1222 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001223 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001224}
1225
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001226type apexBundleProperties struct {
1227 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001228 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001229 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001230
Jiyong Park40e26a22019-02-08 02:53:06 +09001231 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1232 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001233 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001234
Roland Levillain411c5842019-09-19 16:37:20 +01001235 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1236 // device (/apex/<apex_name>).
1237 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001238 Apex_name *string
1239
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001240 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001241 // For platform APEXes, this should points to a file under /system/sepolicy
1242 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1243 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001244
Jooyung Han01a868d2020-02-27 13:40:44 +09001245 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001246
1247 // List of java libraries that are embedded inside this APEX bundle
1248 Java_libs []string
1249
1250 // List of prebuilt files that are embedded inside this APEX bundle
1251 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001252
1253 // Name of the apex_key module that provides the private key to sign APEX
1254 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001255
Alex Light5098a612018-11-29 17:12:15 -08001256 // The type of APEX to build. Controls what the APEX payload is. Either
1257 // 'image', 'zip' or 'both'. Default: 'image'.
1258 Payload_type *string
1259
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001260 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1261 // or an android_app_certificate module name in the form ":module".
1262 Certificate *string
1263
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001264 // Whether this APEX is installable to one of the partitions. Default: true.
1265 Installable *bool
1266
Jiyong Parkda6eb592018-12-19 17:12:36 +09001267 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1268 // Default is false.
1269 Use_vendor *bool
1270
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001271 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1272 Ignore_system_library_special_case *bool
1273
Alex Light9670d332019-01-29 18:07:33 -08001274 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001275
Jiyong Parkf97782b2019-02-13 20:28:58 +09001276 // List of sanitizer names that this APEX is enabled for
1277 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001278
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001279 PreventInstall bool `blueprint:"mutated"`
1280
1281 HideFromMake bool `blueprint:"mutated"`
1282
Jooyung Han5c998b92019-06-27 11:30:33 +09001283 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1284 Provide_cpp_shared_libs *bool
1285
1286 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1287 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001288
1289 // A txt file containing list of files that are whitelisted to be included in this APEX.
1290 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001291
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 // package format of this apex variant; could be non-flattened, flattened, or zip.
1293 // imageApex, zipApex or flattened
1294 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001295
Jiyong Parkd1063c12019-07-17 20:08:41 +09001296 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1297 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1298 // is implied. This value affects all modules included in this APEX. In other words, they are
1299 // also built with the SDKs specified here.
1300 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001301
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001302 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1303 // Should be only used in tests#.
1304 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001305
Jiyong Park956305c2020-01-09 12:32:06 +09001306 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001307
1308 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1309 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1310 // like symlinking to the system libs. Default is false.
1311 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001312
1313 // The minimum SDK version that this apex must be compatibile with.
1314 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001315}
1316
1317type apexTargetBundleProperties struct {
1318 Target struct {
1319 // Multilib properties only for android.
1320 Android struct {
1321 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001322 }
Jooyung Han344d5432019-08-23 11:17:39 +09001323
Alex Light9670d332019-01-29 18:07:33 -08001324 // Multilib properties only for host.
1325 Host struct {
1326 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001327 }
Jooyung Han344d5432019-08-23 11:17:39 +09001328
Alex Light9670d332019-01-29 18:07:33 -08001329 // Multilib properties only for host linux_bionic.
1330 Linux_bionic struct {
1331 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001332 }
Jooyung Han344d5432019-08-23 11:17:39 +09001333
Alex Light9670d332019-01-29 18:07:33 -08001334 // Multilib properties only for host linux_glibc.
1335 Linux_glibc struct {
1336 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001337 }
1338 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001339}
1340
Jiyong Park5d790c32019-11-15 18:40:32 +09001341type overridableProperties struct {
1342 // List of APKs to package inside APEX
1343 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001344
1345 // Names of modules to be overridden. Listed modules can only be other binaries
1346 // (in Make or Soong).
1347 // This does not completely prevent installation of the overridden binaries, but if both
1348 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1349 // from PRODUCT_PACKAGES.
1350 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001351
1352 // Logging Parent value
1353 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001354
1355 // Apex Container Package Name.
1356 // Override value for attribute package:name in AndroidManifest.xml
1357 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001358}
1359
Alex Light5098a612018-11-29 17:12:15 -08001360type apexPackaging int
1361
1362const (
1363 imageApex apexPackaging = iota
1364 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001365 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001366)
1367
Sundong Ahnabb64432019-10-22 13:58:29 +09001368// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001369func (a apexPackaging) suffix() string {
1370 switch a {
1371 case imageApex:
1372 return imageApexSuffix
1373 case zipApex:
1374 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001375 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001376 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001377 }
1378}
1379
1380func (a apexPackaging) name() string {
1381 switch a {
1382 case imageApex:
1383 return imageApexType
1384 case zipApex:
1385 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001386 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001387 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001388 }
1389}
1390
Jiyong Parkf653b052019-11-18 15:39:01 +09001391type apexFileClass int
1392
1393const (
1394 etc apexFileClass = iota
1395 nativeSharedLib
1396 nativeExecutable
1397 shBinary
1398 pyBinary
1399 goBinary
1400 javaSharedLib
1401 nativeTest
1402 app
1403)
1404
Jiyong Park8fd61922018-11-08 02:50:25 +09001405func (class apexFileClass) NameInMake() string {
1406 switch class {
1407 case etc:
1408 return "ETC"
1409 case nativeSharedLib:
1410 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001411 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001412 return "EXECUTABLES"
1413 case javaSharedLib:
1414 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001415 case nativeTest:
1416 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001417 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001418 // b/142537672 Why isn't this APP? We want to have full control over
1419 // the paths and file names of the apk file under the flattend APEX.
1420 // If this is set to APP, then the paths and file names are modified
1421 // by the Make build system. For example, it is installed to
1422 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1423 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1424 // appends module name (which is <apexname>.<Appname> to the path.
1425 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001426 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001427 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001428 }
1429}
1430
Jiyong Parkf653b052019-11-18 15:39:01 +09001431// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001432type apexFile struct {
1433 builtFile android.Path
1434 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001435 installDir string
1436 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001437 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001438 // list of symlinks that will be created in installDir that point to this apexFile
1439 symlinks []string
1440 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001441 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001442
1443 requiredModuleNames []string
1444 targetRequiredModuleNames []string
1445 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001446
Colin Cross503c1d02020-01-28 14:00:53 -08001447 jacocoReportClassesFile android.Path // only for javalibs and apps
1448 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001449 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001450
1451 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001452}
1453
Jiyong Park1833cef2019-12-13 13:28:36 +09001454func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1455 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001456 builtFile: builtFile,
1457 moduleName: moduleName,
1458 installDir: installDir,
1459 class: class,
1460 module: module,
1461 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001462 if module != nil {
1463 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001464 ret.requiredModuleNames = module.RequiredModuleNames()
1465 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1466 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001467 }
1468 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001469}
1470
1471func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001472 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001473}
1474
Jiyong Park7cd10e32020-01-14 09:22:18 +09001475// Path() returns path of this apex file relative to the APEX root
1476func (af *apexFile) Path() string {
1477 return filepath.Join(af.installDir, af.builtFile.Base())
1478}
1479
1480// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1481func (af *apexFile) SymlinkPaths() []string {
1482 var ret []string
1483 for _, symlink := range af.symlinks {
1484 ret = append(ret, filepath.Join(af.installDir, symlink))
1485 }
1486 return ret
1487}
1488
1489func (af *apexFile) AvailableToPlatform() bool {
1490 if af.module == nil {
1491 return false
1492 }
1493 if am, ok := af.module.(android.ApexModule); ok {
1494 return am.AvailableFor(android.AvailableToPlatform)
1495 }
1496 return false
1497}
1498
Jiyong Park678c8812020-02-07 17:25:49 +09001499type depInfo struct {
1500 to string
1501 from []string
1502 isExternal bool
1503}
1504
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001505type apexBundle struct {
1506 android.ModuleBase
1507 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001508 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001509 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001510
Jiyong Park5d790c32019-11-15 18:40:32 +09001511 properties apexBundleProperties
1512 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001513 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001514
Jooyung Hanf21c7972019-12-16 22:32:06 +09001515 // specific to apex_vndk modules
1516 vndkProperties apexVndkProperties
1517
Colin Crossa4925902018-11-16 11:36:28 -08001518 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001519 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001520 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001521
Jiyong Park03b68dd2019-07-26 23:20:40 +09001522 prebuiltFileToDelete string
1523
Jiyong Park42cca6c2019-04-01 11:15:50 +09001524 public_key_file android.Path
1525 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001526
1527 container_certificate_file android.Path
1528 container_private_key_file android.Path
1529
Jooyung Han54aca7b2019-11-20 02:26:02 +09001530 fileContexts android.Path
1531
Jiyong Park8fd61922018-11-08 02:50:25 +09001532 // list of files to be included in this apex
1533 filesInfo []apexFile
1534
Jiyong Park956305c2020-01-09 12:32:06 +09001535 // list of module names that should be installed along with this APEX
1536 requiredDeps []string
1537
Jiyong Park956305c2020-01-09 12:32:06 +09001538 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001539 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001540
Sundong Ahnabb64432019-10-22 13:58:29 +09001541 testApex bool
1542 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001543 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001544 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001545
Jooyung Han214bf372019-11-12 13:03:50 +09001546 manifestJsonOut android.WritablePath
1547 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001548
Jooyung Han002ab682020-01-08 01:57:58 +09001549 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001550 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001551 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001552 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1553 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001554
1555 // Suffix of module name in Android.mk
1556 // ".flattened", ".apex", ".zipapex", or ""
1557 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001558
1559 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001560
1561 // Whether to create symlink to the system file instead of having a file
1562 // inside the apex or not
1563 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001564
1565 // Struct holding the merged notice file paths in different formats
1566 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001567}
1568
Jiyong Park397e55e2018-10-24 21:09:55 +09001569func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001570 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001571 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001572 // Use *FarVariation* to be able to depend on modules having
1573 // conflicting variations with this module. This is required since
1574 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1575 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001576 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001577 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001578 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001579 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001580 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001581
Jooyung Han643adc42020-02-27 13:50:06 +09001582 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1583 {Mutator: "image", Variation: imageVariation},
1584 {Mutator: "link", Variation: "shared"},
1585 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1586 }...), jniLibTag, nativeModules.Jni_libs...)
1587
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001588 ctx.AddFarVariationDependencies(append(target.Variations(),
1589 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001590 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001591
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001592 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001593 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001594 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001595 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001596}
1597
Alex Light9670d332019-01-29 18:07:33 -08001598func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1599 if ctx.Os().Class == android.Device {
1600 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1601 } else {
1602 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1603 if ctx.Os().Bionic() {
1604 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1605 } else {
1606 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1607 }
1608 }
1609}
1610
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001611func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001612 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1613 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1614 }
1615
Jiyong Park397e55e2018-10-24 21:09:55 +09001616 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001617 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001618
1619 a.combineProperties(ctx)
1620
Jiyong Park397e55e2018-10-24 21:09:55 +09001621 has32BitTarget := false
1622 for _, target := range targets {
1623 if target.Arch.ArchType.Multilib == "lib32" {
1624 has32BitTarget = true
1625 }
1626 }
1627 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001628 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001629 // multilib.both
1630 addDependenciesForNativeModules(ctx,
1631 ApexNativeDependencies{
1632 Native_shared_libs: a.properties.Native_shared_libs,
1633 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001634 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001635 Binaries: nil,
1636 },
1637 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001638
Jiyong Park397e55e2018-10-24 21:09:55 +09001639 // Add native modules targetting both ABIs
1640 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001641 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001642 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001643 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001644
Alex Light3d673592019-01-18 14:37:31 -08001645 isPrimaryAbi := i == 0
1646 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001647 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001648 // multilib.first
1649 addDependenciesForNativeModules(ctx,
1650 ApexNativeDependencies{
1651 Native_shared_libs: nil,
1652 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001653 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001654 Binaries: a.properties.Binaries,
1655 },
1656 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001657
1658 // Add native modules targetting the first ABI
1659 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001660 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001661 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001662 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001663 }
1664
1665 switch target.Arch.ArchType.Multilib {
1666 case "lib32":
1667 // Add native modules targetting 32-bit ABI
1668 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001669 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001670 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001671 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001672
1673 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001674 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001675 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001676 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001677 case "lib64":
1678 // Add native modules targetting 64-bit ABI
1679 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001680 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001681 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001682 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001683
1684 if !has32BitTarget {
1685 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001686 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001687 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001688 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001689 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001690
1691 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1692 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1693 if sanitizer == "hwaddress" {
1694 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001695 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001696 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001697 break
1698 }
1699 }
1700 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001701 }
1702
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001703 }
1704
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001705 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1706 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1707 // b/144532908
1708 archForPrebuiltEtc := config.Arches()[0]
1709 for _, arch := range config.Arches() {
1710 // Prefer 64-bit arch if there is any
1711 if arch.ArchType.Multilib == "lib64" {
1712 archForPrebuiltEtc = arch
1713 break
1714 }
1715 }
1716 ctx.AddFarVariationDependencies([]blueprint.Variation{
1717 {Mutator: "os", Variation: ctx.Os().String()},
1718 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1719 }, prebuiltTag, a.properties.Prebuilts...)
1720
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001721 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1722 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001723
Ulya Trafimovich44561882020-01-03 13:25:54 +00001724 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1725 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1726 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1727 javaLibTag, "jacocoagent")
1728 }
1729
Jiyong Park23c52b02019-02-02 13:13:47 +09001730 if String(a.properties.Key) == "" {
1731 ctx.ModuleErrorf("key is missing")
1732 return
1733 }
1734 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001735
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001736 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001737 if cert != "" {
1738 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001739 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001740
1741 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1742 if len(a.properties.Uses_sdks) > 0 {
1743 sdkRefs := []android.SdkRef{}
1744 for _, str := range a.properties.Uses_sdks {
1745 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1746 sdkRefs = append(sdkRefs, parsed)
1747 }
1748 a.BuildWithSdks(sdkRefs)
1749 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001750}
1751
Jiyong Park5d790c32019-11-15 18:40:32 +09001752func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1753 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1754 androidAppTag, a.overridableProperties.Apps...)
1755}
1756
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001757func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1758 // direct deps of an APEX bundle are all part of the APEX bundle
1759 return true
1760}
1761
Colin Cross0ea8ba82019-06-06 14:33:29 -07001762func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001763 moduleName := ctx.ModuleName()
1764 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1765 // we check with the pseudo module name to see if its certificate is overridden.
1766 if a.vndkApex {
1767 moduleName = vndkApexName
1768 }
1769 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001770 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001771 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001772 }
1773 return String(a.properties.Certificate)
1774}
1775
Colin Cross41955e82019-05-29 14:40:35 -07001776func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1777 switch tag {
1778 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001779 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001780 default:
1781 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001782 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001783}
1784
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001785func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001786 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001787}
1788
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001789func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1790 return proptools.Bool(a.properties.Test_only_no_hashtree)
1791}
1792
Jiyong Park7c1dc612019-01-05 11:15:24 +09001793func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001794 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001795 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001796 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001797 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001798 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001799 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001800 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001801 }
1802}
1803
Jiyong Parkf97782b2019-02-13 20:28:58 +09001804func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1805 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1806 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1807 }
1808}
1809
Jiyong Park388ef3f2019-01-28 19:47:32 +09001810func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001811 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1812 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001813 }
1814
1815 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001816 globalSanitizerNames := []string{}
1817 if a.Host() {
1818 globalSanitizerNames = ctx.Config().SanitizeHost()
1819 } else {
1820 arches := ctx.Config().SanitizeDeviceArch()
1821 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1822 globalSanitizerNames = ctx.Config().SanitizeDevice()
1823 }
1824 }
1825 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001826}
1827
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001828func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001829 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001830}
1831
1832func (a *apexBundle) PreventInstall() {
1833 a.properties.PreventInstall = true
1834}
1835
1836func (a *apexBundle) HideFromMake() {
1837 a.properties.HideFromMake = true
1838}
1839
Jiyong Park956305c2020-01-09 12:32:06 +09001840func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1841 a.properties.IsCoverageVariant = coverage
1842}
1843
Jiyong Parkf653b052019-11-18 15:39:01 +09001844// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001845func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001846 // Decide the APEX-local directory by the multilib of the library
1847 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001848 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001849 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001850 case "lib32":
1851 dirInApex = "lib"
1852 case "lib64":
1853 dirInApex = "lib64"
1854 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001855 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001856 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001857 }
Jooyung Han35155c42020-02-06 17:33:20 +09001858 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001859 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001860 // Special case for Bionic libs and other libs installed with them. This is
1861 // to prevent those libs from being included in the search path
1862 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1863 // those libs in the Runtime APEX are available via the legacy paths in
1864 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1865 // to the legacy paths and thus will be loaded into the default linker
1866 // namespace (aka "platform" namespace). If the libs are directly in
1867 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1868 // into the runtime linker namespace, which will result in double loading of
1869 // them, which isn't supported.
1870 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001871 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001872
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001874 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001875}
1876
Jiyong Park1833cef2019-12-13 13:28:36 +09001877func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001878 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001879 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001880 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001881 }
Jooyung Han35155c42020-02-06 17:33:20 +09001882 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001883 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001884 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001885 af.symlinks = cc.Symlinks()
1886 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001887}
1888
Jiyong Park1833cef2019-12-13 13:28:36 +09001889func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001890 dirInApex := "bin"
1891 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001892 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001893}
Jiyong Park1833cef2019-12-13 13:28:36 +09001894func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001895 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001896 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1897 if err != nil {
1898 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001899 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001900 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001901 fileToCopy := android.PathForOutput(ctx, s)
1902 // NB: Since go binaries are static we don't need the module for anything here, which is
1903 // good since the go tool is a blueprint.Module not an android.Module like we would
1904 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001905 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001906}
1907
Jiyong Park1833cef2019-12-13 13:28:36 +09001908func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 dirInApex := filepath.Join("bin", sh.SubDir())
1910 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001911 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001912 af.symlinks = sh.Symlinks()
1913 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001914}
1915
Jooyung Han58f26ab2019-12-18 15:34:32 +09001916// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1917type javaLibrary interface {
1918 android.Module
1919 java.Dependency
1920}
1921
1922func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001923 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001924 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001925 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1926 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1927 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001928}
1929
Jiyong Park1833cef2019-12-13 13:28:36 +09001930func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001931 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1932 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001933 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001934}
1935
atrost6e126252020-01-27 17:01:16 +00001936func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1937 dirInApex := filepath.Join("etc", config.SubDir())
1938 fileToCopy := config.CompatConfig()
1939 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1940}
1941
Jiyong Park1833cef2019-12-13 13:28:36 +09001942func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001943 android.Module
1944 Privileged() bool
1945 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001946 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001947 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001948}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001949 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001950 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001951 appDir = "priv-app"
1952 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001953 dirInApex := filepath.Join(appDir, pkgName)
1954 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001955 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1956 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001957 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001958
1959 if app, ok := aapp.(interface {
1960 OverriddenManifestPackageName() string
1961 }); ok {
1962 af.overriddenPackageName = app.OverriddenManifestPackageName()
1963 }
Jiyong Park618922e2020-01-08 13:35:43 +09001964 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001965}
1966
Roland Levillain935639d2019-08-13 14:55:28 +01001967// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1968type flattenedApexContext struct {
1969 android.ModuleContext
1970}
1971
1972func (c *flattenedApexContext) InstallBypassMake() bool {
1973 return true
1974}
1975
Jiyong Park201cedd2020-02-07 17:25:49 +09001976// Visit dependencies that contributes to the payload of this APEX
1977func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1978 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001979 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001980 am, ok := child.(android.ApexModule)
1981 if !ok || !am.CanHaveApexVariants() {
1982 return false
1983 }
1984
1985 // Check for the direct dependencies that contribute to the payload
1986 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1987 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001988 do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001989 return true
1990 }
1991 return false
1992 }
1993
1994 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001995 if am.ApexName() != "" {
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
Jiyong Park201cedd2020-02-07 17:25:49 +09002000 do(ctx, parent, am, true /* externalDep */)
2001
Jiyong Park0f80c182020-01-31 02:49:53 +09002002 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2003 return false
2004 })
2005}
2006
Jooyung Han03b51852020-02-26 22:45:42 +09002007func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
2008 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
2009 if ver != "current" {
2010 minSdkVersion, err := strconv.Atoi(ver)
2011 if err != nil {
2012 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
2013 }
2014 return minSdkVersion
2015 }
2016 return android.FutureApiLevel
2017}
2018
Jiyong Park201cedd2020-02-07 17:25:49 +09002019// Ensures that the dependencies are marked as available for this APEX
2020func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2021 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2022 if ctx.Host() || a.testApex || a.vndkApex {
2023 return
2024 }
2025
Jiyong Park58d10902020-03-28 14:43:19 +09002026 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2027 // Requiring them and their transitive depencies with apex_available is not right
2028 // because they just add noise.
2029 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2030 return
2031 }
2032
Jiyong Park201cedd2020-02-07 17:25:49 +09002033 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2034 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002035 fromName := ctx.OtherModuleName(from)
2036 toName := ctx.OtherModuleName(to)
2037 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09002038 return
2039 }
Paul Duffindf915ff2020-03-30 17:58:21 +01002040 message := ""
2041 for _, m := range ctx.GetWalkPath()[1:] {
2042 message = fmt.Sprintf("%s\n -> %s", message, m.String())
2043 }
2044 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Jiyong Park201cedd2020-02-07 17:25:49 +09002045 })
2046}
2047
Jiyong Park678c8812020-02-07 17:25:49 +09002048// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
2049func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
2050 a.depInfos = make(map[string]depInfo)
2051 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
2052 if from.Name() == to.Name() {
2053 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
2054 return
2055 }
2056
2057 if info, exists := a.depInfos[to.Name()]; exists {
2058 if !android.InList(from.Name(), info.from) {
2059 info.from = append(info.from, from.Name())
2060 }
2061 info.isExternal = info.isExternal && externalDep
2062 a.depInfos[to.Name()] = info
2063 } else {
2064 a.depInfos[to.Name()] = depInfo{
2065 to: to.Name(),
2066 from: []string{from.Name()},
2067 isExternal: externalDep,
2068 }
2069 }
2070 })
2071}
2072
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002073func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09002074 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
2075 switch a.properties.ApexType {
2076 case imageApex:
2077 if buildFlattenedAsDefault {
2078 a.suffix = imageApexSuffix
2079 } else {
2080 a.suffix = ""
2081 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002082
2083 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002084 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002085 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002086 }
2087 case zipApex:
2088 if proptools.String(a.properties.Payload_type) == "zip" {
2089 a.suffix = ""
2090 a.primaryApexType = true
2091 } else {
2092 a.suffix = zipApexSuffix
2093 }
2094 case flattenedApex:
2095 if buildFlattenedAsDefault {
2096 a.suffix = ""
2097 a.primaryApexType = true
2098 } else {
2099 a.suffix = flattenedSuffix
2100 }
Alex Light5098a612018-11-29 17:12:15 -08002101 }
2102
Roland Levillain630846d2019-06-26 12:48:34 +01002103 if len(a.properties.Tests) > 0 && !a.testApex {
2104 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2105 return
2106 }
2107
Jiyong Park0f80c182020-01-31 02:49:53 +09002108 a.checkApexAvailability(ctx)
2109
Jiyong Park678c8812020-02-07 17:25:49 +09002110 a.collectDepsInfo(ctx)
2111
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002112 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2113
Jooyung Hane1633032019-08-01 17:41:43 +09002114 // native lib dependencies
2115 var provideNativeLibs []string
2116 var requireNativeLibs []string
2117
Jooyung Han5c998b92019-06-27 11:30:33 +09002118 // Check if "uses" requirements are met with dependent apexBundles
2119 var providedNativeSharedLibs []string
2120 useVendor := proptools.Bool(a.properties.Use_vendor)
2121 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2122 if ctx.OtherModuleDependencyTag(m) != usesTag {
2123 return
2124 }
2125 otherName := ctx.OtherModuleName(m)
2126 other, ok := m.(*apexBundle)
2127 if !ok {
2128 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2129 return
2130 }
2131 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2132 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2133 return
2134 }
2135 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2136 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2137 return
2138 }
2139 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2140 })
2141
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002143 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002144 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002145 depTag := ctx.OtherModuleDependencyTag(child)
2146 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002147 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002148 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002149 case sharedLibTag, jniLibTag:
2150 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002151 if c, ok := child.(*cc.Module); ok {
2152 // bootstrap bionic libs are treated as provided by system
2153 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2154 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002155 }
Jooyung Han643adc42020-02-27 13:50:06 +09002156 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2157 fi.isJniLib = isJniLib
2158 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002159 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002160 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002161 propertyName := "native_shared_libs"
2162 if isJniLib {
2163 propertyName = "jni_libs"
2164 }
2165 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002166 }
2167 case executableTag:
2168 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002169 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002170 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002171 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002172 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002173 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002174 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002175 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002176 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002177 } else {
Alex Light778127a2019-02-27 14:19:50 -08002178 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 +09002179 }
2180 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002181 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002182 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002183 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002184 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2185 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002186 filesInfo = append(filesInfo, af)
2187 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002188 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002189 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2190 af := apexFileForJavaLibrary(ctx, sdkLib)
2191 if !af.Ok() {
2192 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2193 return false
2194 }
2195 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002196 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002197 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002198 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002199 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002200 case androidAppTag:
2201 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
2202 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002203 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002204 return true // track transitive dependencies
2205 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002206 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002207 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2208 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002209 } else {
2210 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2211 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002212 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002213 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002214 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002215 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2216 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002217 } else {
atrost6e126252020-01-27 17:01:16 +00002218 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002219 }
Roland Levillain630846d2019-06-26 12:48:34 +01002220 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002221 if ccTest, ok := child.(*cc.Module); ok {
2222 if ccTest.IsTestPerSrcAllTestsVariation() {
2223 // Multiple-output test module (where `test_per_src: true`).
2224 //
2225 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2226 // We do not add this variation to `filesInfo`, as it has no output;
2227 // however, we do add the other variations of this module as indirect
2228 // dependencies (see below).
2229 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002230 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002231 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002232 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002233 af.class = nativeTest
2234 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002235 }
Roland Levillain630846d2019-06-26 12:48:34 +01002236 } else {
2237 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2238 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002239 case keyTag:
2240 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002241 a.private_key_file = key.private_key_file
2242 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002243 } else {
2244 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002245 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002246 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002247 case certificateTag:
2248 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002249 a.container_certificate_file = dep.Certificate.Pem
2250 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002251 } else {
2252 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2253 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002254 case android.PrebuiltDepTag:
2255 // If the prebuilt is force disabled, remember to delete the prebuilt file
2256 // that might have been installed in the previous builds
2257 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2258 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2259 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002260 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002261 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002262 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002263 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002264 // We cannot use a switch statement on `depTag` here as the checked
2265 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002266 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002267 if cc, ok := child.(*cc.Module); ok {
2268 if android.InList(cc.Name(), providedNativeSharedLibs) {
2269 // If we're using a shared library which is provided from other APEX,
2270 // don't include it in this APEX
2271 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002272 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002273 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002274 // If the dependency is a stubs lib, don't include it in this APEX,
2275 // but make sure that the lib is installed on the device.
2276 // In case no APEX is having the lib, the lib is installed to the system
2277 // partition.
2278 //
2279 // Always include if we are a host-apex however since those won't have any
2280 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002281 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2282 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002283 }
Jooyung Hane1633032019-08-01 17:41:43 +09002284 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002285 // Don't track further
2286 return false
2287 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002288 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002289 af.transitiveDep = true
2290 filesInfo = append(filesInfo, af)
2291 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002292 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002293 } else if cc.IsTestPerSrcDepTag(depTag) {
2294 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002295 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002296 // Handle modules created as `test_per_src` variations of a single test module:
2297 // use the name of the generated test binary (`fileToCopy`) instead of the name
2298 // of the original test module (`depName`, shared by all `test_per_src`
2299 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002300 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002301 // these are not considered transitive dep
2302 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002303 filesInfo = append(filesInfo, af)
2304 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002305 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002306 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002307 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2308 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002309 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2310 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2311 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2312 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002313 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002314 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002315 }
2316 }
2317 }
2318 return false
2319 })
2320
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002321 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2322 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2323 // via the global boot image config.
2324 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002325 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002326 dirInApex := filepath.Join("javalib", arch.String())
2327 for _, f := range files {
2328 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002329 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002330 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002331 }
2332 }
2333 }
2334
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002335 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002336 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2337 return
2338 }
2339
Jiyong Park8fd61922018-11-08 02:50:25 +09002340 // remove duplicates in filesInfo
2341 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002342 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002343 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002344 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002345 if e, ok := encountered[dest]; !ok {
2346 encountered[dest] = f
2347 } else {
2348 // If a module is directly included and also transitively depended on
2349 // consider it as directly included.
2350 e.transitiveDep = e.transitiveDep && f.transitiveDep
2351 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002352 }
2353 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002354 var result []apexFile
2355 for _, v := range encountered {
2356 result = append(result, v)
2357 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002358 return result
2359 }
2360 filesInfo = removeDup(filesInfo)
2361
2362 // to have consistent build rules
2363 sort.Slice(filesInfo, func(i, j int) bool {
2364 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2365 })
2366
Jiyong Park8fd61922018-11-08 02:50:25 +09002367 a.installDir = android.PathForModuleInstall(ctx, "apex")
2368 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002369
Jooyung Han54aca7b2019-11-20 02:26:02 +09002370 if a.properties.ApexType != zipApex {
2371 if a.properties.File_contexts == nil {
2372 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2373 } else {
2374 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2375 if a.Platform() {
2376 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2377 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2378 }
2379 }
2380 }
2381 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2382 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2383 return
2384 }
2385 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002386 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2387 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2388 // the same library in the system partition, thus effectively sharing the same libraries
2389 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2390 // in the APEX.
2391 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2392 a.installable() &&
2393 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002394
Jiyong Park9d677202020-02-19 16:29:35 +09002395 // We don't need the optimization for updatable APEXes, as it might give false signal
2396 // to the system health when the APEXes are still bundled (b/149805758)
2397 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2398 a.linkToSystemLib = false
2399 }
2400
Jiyong Park638d30e2020-02-26 18:27:19 +09002401 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2402 if ctx.Host() {
2403 a.linkToSystemLib = false
2404 }
2405
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002406 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002407 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2408
2409 a.setCertificateAndPrivateKey(ctx)
2410 if a.properties.ApexType == flattenedApex {
2411 a.buildFlattenedApex(ctx)
2412 } else {
2413 a.buildUnflattenedApex(ctx)
2414 }
2415
Jooyung Han002ab682020-01-08 01:57:58 +09002416 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002417
2418 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002419}
2420
Jooyung Han5e9013b2020-03-10 06:23:13 +09002421func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002422 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002423 moduleName = normalizeModuleName(moduleName)
2424
2425 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2426 return true
2427 }
2428
2429 key = android.AvailableToAnyApex
2430 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2431 return true
2432 }
2433
2434 return false
2435}
2436
2437func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002438 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2439 // system. Trim the prefix for the check since they are confusing
2440 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2441 if strings.HasPrefix(moduleName, "libclang_rt.") {
2442 // This module has many arch variants that depend on the product being built.
2443 // We don't want to list them all
2444 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002445 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002446 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002447}
2448
Jooyung Han344d5432019-08-23 11:17:39 +09002449func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002450 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002451 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002452 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002453 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002454 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002455 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2456 })
Alex Light5098a612018-11-29 17:12:15 -08002457 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002458 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002459 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002460 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002461 return module
2462}
Jiyong Park30ca9372019-02-07 16:27:23 +09002463
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002464func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002465 bundle := newApexBundle()
2466 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002467 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002468 return bundle
2469}
2470
Jiyong Parkfce0b422020-02-11 03:56:06 +09002471// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2472// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002473func testApexBundleFactory() android.Module {
2474 bundle := newApexBundle()
2475 bundle.testApex = true
2476 return bundle
2477}
2478
Jiyong Parkfce0b422020-02-11 03:56:06 +09002479// apex packages other modules into an APEX file which is a packaging format for system-level
2480// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002481func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002482 return newApexBundle()
2483}
2484
Jiyong Park30ca9372019-02-07 16:27:23 +09002485//
2486// Defaults
2487//
2488type Defaults struct {
2489 android.ModuleBase
2490 android.DefaultsModuleBase
2491}
2492
Jiyong Park30ca9372019-02-07 16:27:23 +09002493func defaultsFactory() android.Module {
2494 return DefaultsFactory()
2495}
2496
2497func DefaultsFactory(props ...interface{}) android.Module {
2498 module := &Defaults{}
2499
2500 module.AddProperties(props...)
2501 module.AddProperties(
2502 &apexBundleProperties{},
2503 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002504 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002505 )
2506
2507 android.InitDefaultsModule(module)
2508 return module
2509}
Jiyong Park5d790c32019-11-15 18:40:32 +09002510
2511//
2512// OverrideApex
2513//
2514type OverrideApex struct {
2515 android.ModuleBase
2516 android.OverrideModuleBase
2517}
2518
2519func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2520 // All the overrides happen in the base module.
2521}
2522
2523// override_apex is used to create an apex module based on another apex module
2524// by overriding some of its properties.
2525func overrideApexFactory() android.Module {
2526 m := &OverrideApex{}
2527 m.AddProperties(&overridableProperties{})
2528
2529 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2530 android.InitOverrideModule(m)
2531 return m
2532}