blob: 8bcd7ef345653e243316361389b1eb2f5ef779e8 [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"
Paul Duffinc5192442020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jooyung Han03b51852020-02-26 22:45:42 +090023 "strconv"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090025 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026
27 "android/soong/android"
28 "android/soong/cc"
29 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080030 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090031
32 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080033 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034 "github.com/google/blueprint/proptools"
35)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090045)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046
47type dependencyTag struct {
48 blueprint.BaseDependencyTag
49 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090050
51 // determines if the dependent will be part of the APEX payload
52 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090053}
54
55var (
Jiyong Park0f80c182020-01-31 02:49:53 +090056 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090057 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090058 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hanssoneec79eb2020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Jiyong Park0f80c182020-01-31 02:49:53 +090097 m["com.android.adbd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +090098 "libadbd_auth",
Jiyong Park0f80c182020-01-31 02:49:53 +090099 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "libcap",
Jiyong Park0f80c182020-01-31 02:49:53 +0900101 "libmdnssd",
102 "libminijail",
103 "libminijail_gen_constants",
104 "libminijail_gen_constants_obj",
105 "libminijail_gen_syscall",
106 "libminijail_gen_syscall_obj",
107 "libminijail_generated",
108 "libpackagelistparser",
109 "libpcre2",
110 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 }
112 //
113 // Module separator
114 //
Paul Duffin50cbefd2020-03-10 13:44:19 +0000115 artApexContents := []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "art_cmdlineparser_headers",
117 "art_disassembler_headers",
118 "art_libartbase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "bionic_libc_platform_headers",
120 "core-repackaged-icu4j",
121 "cpp-define-generator-asm-support",
122 "cpp-define-generator-definitions",
123 "crtbegin_dynamic",
124 "crtbegin_dynamic1",
125 "crtbegin_so1",
126 "crtbrand",
Jiyong Park0f80c182020-01-31 02:49:53 +0900127 "dex2oat_headers",
128 "dt_fd_forward_export",
Jiyong Park0f80c182020-01-31 02:49:53 +0900129 "icu4c_extra_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "javavm_headers",
131 "jni_platform_headers",
132 "libPlatformProperties",
133 "libadbconnection_client",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 "libadbconnection_server",
Jiyong Park0f80c182020-01-31 02:49:53 +0900135 "libandroidicuinit",
136 "libart_runtime_headers_ndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000137 "libartd-disassembler",
Jiyong Park0f80c182020-01-31 02:49:53 +0900138 "libasync_safe",
Jiyong Park0f80c182020-01-31 02:49:53 +0900139 "libdexfile_all_headers",
140 "libdexfile_external_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libdmabufinfo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000143 "libexpat",
Jiyong Park0f80c182020-01-31 02:49:53 +0900144 "libfdlibm",
145 "libgtest_prod",
146 "libicui18n_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000147 "libicuuc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900148 "libicuuc_headers",
149 "libicuuc_stubdata",
150 "libjdwp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900151 "liblz4",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000152 "liblzma",
153 "libmeminfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libnativebridge-headers",
155 "libnativehelper_header_only",
156 "libnativeloader-headers",
157 "libnpt_headers",
158 "libopenjdkjvmti_headers",
159 "libperfetto_client_experimental",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000160 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900161 "libunwind_llvm",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900163 "libv8",
164 "libv8base",
165 "libv8gen",
166 "libv8platform",
167 "libv8sampler",
168 "libv8src",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000169 "libvixl",
170 "libvixld",
171 "libz",
172 "libziparchive",
Jiyong Park0f80c182020-01-31 02:49:53 +0900173 "perfetto_trace_protos",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000174 }
Paul Duffin50cbefd2020-03-10 13:44:19 +0000175 m["com.android.art.debug"] = artApexContents
176 m["com.android.art.release"] = artApexContents
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 //
178 // Module separator
179 //
180 m["com.android.bluetooth.updatable"] = []string{
181 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000182 "android.hardware.bluetooth.a2dp@1.0",
183 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900184 "android.hardware.bluetooth@1.0",
185 "android.hardware.bluetooth@1.1",
186 "android.hardware.graphics.bufferqueue@1.0",
187 "android.hardware.graphics.bufferqueue@2.0",
188 "android.hardware.graphics.common@1.0",
189 "android.hardware.graphics.common@1.1",
190 "android.hardware.graphics.common@1.2",
191 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000192 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900193 "android.hidl.token@1.0",
194 "android.hidl.token@1.0-utils",
195 "avrcp-target-service",
196 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "bluetooth-protos-lite",
198 "bluetooth.mapsapi",
199 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900200 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900201 "ipmemorystore-aidl-interfaces-V5-java",
202 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900203 "internal_include_headers",
204 "lib-bt-packets",
205 "lib-bt-packets-avrcp",
206 "lib-bt-packets-base",
207 "libFraunhoferAAC",
208 "libaudio-a2dp-hw-utils",
209 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900210 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900212 "libbluetooth-types",
213 "libbluetooth-types-header",
214 "libbluetooth_gd",
215 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000216 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900217 "libbt-audio-hal-interface",
218 "libbt-bta",
219 "libbt-common",
220 "libbt-hci",
221 "libbt-platform-protos-lite",
222 "libbt-protos-lite",
223 "libbt-sbc-decoder",
224 "libbt-sbc-encoder",
225 "libbt-stack",
226 "libbt-utils",
227 "libbtcore",
228 "libbtdevice",
229 "libbte",
230 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000231 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000232 "libevent",
233 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900234 "libg722codec",
235 "libgtest_prod",
236 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900237 "libmedia_headers",
238 "libmodpb64",
239 "libosi",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000240 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libstagefright_foundation_headers",
243 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000244 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900245 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000246 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900247 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000248 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900249 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900250 "net-utils-services-common",
251 "netd_aidl_interface-unstable-java",
252 "netd_event_listener_interface-java",
253 "netlink-client",
254 "networkstack-aidl-interfaces-unstable-java",
255 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900256 "sap-api-java-static",
257 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000258 }
259 //
260 // Module separator
261 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000263 //
264 // Module separator
265 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900266 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900267 "boringssl_self_test",
Jiyong Park0f80c182020-01-31 02:49:53 +0900268 "libnativehelper_header_only",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900269 "unsupportedappusage",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 }
271 //
272 // Module separator
273 //
274 m["com.android.extservices"] = []string{
275 "flatbuffer_headers",
276 "liblua",
277 "libtextclassifier",
278 "libtextclassifier_hash_static",
279 "libtflite_static",
280 "libutf",
281 "libz_current",
282 "tensorflow_headers",
283 }
284 //
285 // Module separator
286 //
287 m["com.android.cronet"] = []string{
288 "cronet_impl_common_java",
289 "cronet_impl_native_java",
290 "cronet_impl_platform_java",
291 "libcronet.80.0.3986.0",
292 "org.chromium.net.cronet",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900293 "org.chromium.net.cronet.xml",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "prebuilt_libcronet.80.0.3986.0",
295 }
296 //
297 // Module separator
298 //
299 m["com.android.neuralnetworks"] = []string{
300 "android.hardware.neuralnetworks@1.0",
301 "android.hardware.neuralnetworks@1.1",
302 "android.hardware.neuralnetworks@1.2",
303 "android.hardware.neuralnetworks@1.3",
304 "android.hidl.allocator@1.0",
305 "android.hidl.memory.token@1.0",
306 "android.hidl.memory@1.0",
307 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900308 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900309 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900310 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900311 "libprocessgroup",
312 "libprocessgroup_headers",
313 "libprocpartition",
314 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000316 //
317 // Module separator
318 //
319 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000320 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900321 "android.hardware.cas.native@1.0",
322 "android.hardware.cas@1.0",
323 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000324 "android.hardware.configstore@1.0",
325 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000326 "android.hardware.graphics.allocator@2.0",
327 "android.hardware.graphics.allocator@3.0",
328 "android.hardware.graphics.bufferqueue@1.0",
329 "android.hardware.graphics.bufferqueue@2.0",
330 "android.hardware.graphics.common@1.0",
331 "android.hardware.graphics.common@1.1",
332 "android.hardware.graphics.common@1.2",
333 "android.hardware.graphics.mapper@2.0",
334 "android.hardware.graphics.mapper@2.1",
335 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900336 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000337 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900338 "android.hidl.allocator@1.0",
339 "android.hidl.memory.token@1.0",
340 "android.hidl.memory@1.0",
341 "android.hidl.token@1.0",
342 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900343 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900344 "gl_headers",
345 "libEGL",
346 "libEGL_blobCache",
347 "libEGL_getProcAddress",
348 "libFLAC",
349 "libFLAC-config",
350 "libFLAC-headers",
351 "libGLESv2",
352 "libaacextractor",
353 "libamrextractor",
354 "libarect",
355 "libasync_safe",
356 "libaudio_system_headers",
357 "libaudioclient",
358 "libaudioclient_headers",
359 "libaudiofoundation",
360 "libaudiofoundation_headers",
361 "libaudiomanager",
362 "libaudiopolicy",
363 "libaudioutils",
364 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900365 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900366 "libbluetooth-types-header",
367 "libbufferhub",
368 "libbufferhub_headers",
369 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900370 "libc_malloc_debug_backtrace",
371 "libcamera_client",
372 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libdexfile_external_headers",
374 "libdexfile_support",
375 "libdvr_headers",
376 "libexpat",
377 "libfifo",
378 "libflacextractor",
379 "libgrallocusage",
380 "libgraphicsenv",
381 "libgui",
382 "libgui_headers",
383 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900384 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900385 "liblzma",
386 "libmath",
387 "libmedia",
388 "libmedia_codeclist",
389 "libmedia_headers",
390 "libmedia_helper",
391 "libmedia_helper_headers",
392 "libmedia_midiiowrapper",
393 "libmedia_omx",
394 "libmediautils",
395 "libmidiextractor",
396 "libmkvextractor",
397 "libmp3extractor",
398 "libmp4extractor",
399 "libmpeg2extractor",
400 "libnativebase_headers",
401 "libnativebridge-headers",
402 "libnativebridge_lazy",
403 "libnativeloader-headers",
404 "libnativeloader_lazy",
405 "libnativewindow_headers",
406 "libnblog",
407 "liboggextractor",
408 "libpackagelistparser",
409 "libpcre2",
410 "libpdx",
411 "libpdx_default_transport",
412 "libpdx_headers",
413 "libpdx_uds",
414 "libprocessgroup",
415 "libprocessgroup_headers",
416 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900417 "libsonivox",
418 "libspeexresampler",
419 "libspeexresampler",
420 "libstagefright_esds",
421 "libstagefright_flacdec",
422 "libstagefright_flacdec",
423 "libstagefright_foundation",
424 "libstagefright_foundation_headers",
425 "libstagefright_foundation_without_imemory",
426 "libstagefright_headers",
427 "libstagefright_id3",
428 "libstagefright_metadatautils",
429 "libstagefright_mpeg2extractor",
430 "libstagefright_mpeg2support",
431 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900432 "libui",
433 "libui_headers",
434 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libvibrator",
436 "libvorbisidec",
437 "libwavextractor",
438 "libwebm",
439 "media_ndk_headers",
440 "media_plugin_headers",
441 "updatable-media",
442 }
443 //
444 // Module separator
445 //
446 m["com.android.media.swcodec"] = []string{
447 "android.frameworks.bufferhub@1.0",
448 "android.hardware.common-ndk_platform",
449 "android.hardware.configstore-utils",
450 "android.hardware.configstore@1.0",
451 "android.hardware.configstore@1.1",
452 "android.hardware.graphics.allocator@2.0",
453 "android.hardware.graphics.allocator@3.0",
454 "android.hardware.graphics.bufferqueue@1.0",
455 "android.hardware.graphics.bufferqueue@2.0",
456 "android.hardware.graphics.common-ndk_platform",
457 "android.hardware.graphics.common@1.0",
458 "android.hardware.graphics.common@1.1",
459 "android.hardware.graphics.common@1.2",
460 "android.hardware.graphics.mapper@2.0",
461 "android.hardware.graphics.mapper@2.1",
462 "android.hardware.graphics.mapper@3.0",
463 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000464 "android.hardware.media.bufferpool@2.0",
465 "android.hardware.media.c2@1.0",
466 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900467 "android.hardware.media@1.0",
468 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000469 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900470 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000471 "android.hidl.safe_union@1.0",
472 "android.hidl.token@1.0",
473 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900474 "libEGL",
475 "libFLAC",
476 "libFLAC-config",
477 "libFLAC-headers",
478 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900479 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900480 "libarect",
481 "libasync_safe",
482 "libaudio_system_headers",
483 "libaudioutils",
484 "libaudioutils",
485 "libaudioutils_fixedfft",
486 "libavcdec",
487 "libavcenc",
488 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000489 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900490 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900491 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900492 "libbluetooth-types-header",
493 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900494 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000495 "libcap",
496 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900497 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000498 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "libcodec2_hidl@1.1",
500 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000501 "libcodec2_soft_aacdec",
502 "libcodec2_soft_aacenc",
503 "libcodec2_soft_amrnbdec",
504 "libcodec2_soft_amrnbenc",
505 "libcodec2_soft_amrwbdec",
506 "libcodec2_soft_amrwbenc",
507 "libcodec2_soft_av1dec_gav1",
508 "libcodec2_soft_avcdec",
509 "libcodec2_soft_avcenc",
510 "libcodec2_soft_common",
511 "libcodec2_soft_flacdec",
512 "libcodec2_soft_flacenc",
513 "libcodec2_soft_g711alawdec",
514 "libcodec2_soft_g711mlawdec",
515 "libcodec2_soft_gsmdec",
516 "libcodec2_soft_h263dec",
517 "libcodec2_soft_h263enc",
518 "libcodec2_soft_hevcdec",
519 "libcodec2_soft_hevcenc",
520 "libcodec2_soft_mp3dec",
521 "libcodec2_soft_mpeg2dec",
522 "libcodec2_soft_mpeg4dec",
523 "libcodec2_soft_mpeg4enc",
524 "libcodec2_soft_opusdec",
525 "libcodec2_soft_opusenc",
526 "libcodec2_soft_rawdec",
527 "libcodec2_soft_vorbisdec",
528 "libcodec2_soft_vp8dec",
529 "libcodec2_soft_vp8enc",
530 "libcodec2_soft_vp9dec",
531 "libcodec2_soft_vp9enc",
532 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000533 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900534 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000535 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900536 "libfmq",
537 "libgav1",
538 "libgralloctypes",
539 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000540 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900541 "libgsm",
542 "libgui_bufferqueue_static",
543 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000544 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900545 "libhardware_headers",
546 "libhevcdec",
547 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000548 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900549 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000550 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900551 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000552 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900553 "libmedia_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000554 "libminijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900555 "libminijail_gen_constants",
556 "libminijail_gen_constants_obj",
557 "libminijail_gen_syscall",
558 "libminijail_gen_syscall_obj",
559 "libminijail_generated",
560 "libmpeg2dec",
561 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000562 "libnativebridge_lazy",
563 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900564 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000566 "libprocessgroup",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "libprocessgroup_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000568 "libscudo_wrapper",
569 "libsfplugin_ccodec_utils",
570 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900571 "libstagefright_amrnbdec",
572 "libstagefright_amrnbenc",
573 "libstagefright_amrwbdec",
574 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000575 "libstagefright_bufferpool@2.0.1",
576 "libstagefright_bufferqueue_helper",
577 "libstagefright_enc_common",
578 "libstagefright_flacdec",
579 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libstagefright_foundation_headers",
581 "libstagefright_headers",
582 "libstagefright_m4vh263dec",
583 "libstagefright_m4vh263enc",
584 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000585 "libsync",
586 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000588 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000589 "libvorbisidec",
590 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900591 "libyuv",
592 "libyuv_static",
593 "media_ndk_headers",
594 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000595 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900596 }
597 //
598 // Module separator
599 //
600 m["com.android.mediaprovider"] = []string{
601 "MediaProvider",
602 "MediaProviderGoogle",
603 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900604 "libbase_ndk",
605 "libfuse",
606 "libfuse_jni",
607 "libnativehelper_header_only",
608 }
609 //
610 // Module separator
611 //
612 m["com.android.permission"] = []string{
613 "androidx.annotation_annotation",
614 "androidx.annotation_annotation-nodeps",
615 "androidx.lifecycle_lifecycle-common",
616 "androidx.lifecycle_lifecycle-common-java8",
617 "androidx.lifecycle_lifecycle-common-java8-nodeps",
618 "androidx.lifecycle_lifecycle-common-nodeps",
619 "kotlin-annotations",
620 "kotlin-stdlib",
621 "kotlin-stdlib-jdk7",
622 "kotlin-stdlib-jdk8",
623 "kotlinx-coroutines-android",
624 "kotlinx-coroutines-android-nodeps",
625 "kotlinx-coroutines-core",
626 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900627 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000628 }
629 //
630 // Module separator
631 //
632 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900633 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 "libarm-optimized-routines-math",
635 "libasync_safe",
636 "libasync_safe_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900637 "libc_aeabi",
638 "libc_bionic",
639 "libc_bionic_ndk",
640 "libc_bootstrap",
641 "libc_common",
642 "libc_common_shared",
643 "libc_common_static",
644 "libc_dns",
645 "libc_dynamic_dispatch",
646 "libc_fortify",
647 "libc_freebsd",
648 "libc_freebsd_large_stack",
649 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900650 "libc_init_dynamic",
651 "libc_init_static",
652 "libc_jemalloc_wrapper",
653 "libc_netbsd",
654 "libc_nomalloc",
655 "libc_nopthread",
656 "libc_openbsd",
657 "libc_openbsd_large_stack",
658 "libc_openbsd_ndk",
659 "libc_pthread",
660 "libc_static_dispatch",
661 "libc_syscalls",
662 "libc_tzcode",
663 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900664 "libdebuggerd",
665 "libdebuggerd_common_headers",
666 "libdebuggerd_handler_core",
667 "libdebuggerd_handler_fallback",
668 "libdexfile_external_headers",
669 "libdexfile_support",
670 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900671 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900672 "libgtest_prod",
673 "libjemalloc5",
674 "liblinker_main",
675 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900676 "liblz4",
677 "liblzma",
678 "libprocessgroup_headers",
679 "libprocinfo",
680 "libpropertyinfoparser",
681 "libscudo",
682 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900683 "libsystemproperties",
684 "libtombstoned_client_static",
685 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900686 "libz",
687 "libziparchive",
688 }
689 //
690 // Module separator
691 //
692 m["com.android.resolv"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900693 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Park0f80c182020-01-31 02:49:53 +0900694 "libgtest_prod",
Jiyong Park0f80c182020-01-31 02:49:53 +0900695 "libnativehelper_header_only",
696 "libnetd_client_headers",
697 "libnetd_resolv",
698 "libnetdutils",
699 "libprocessgroup",
700 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900701 "libstatslog_resolv",
702 "libstatspush_compat",
703 "libstatssocket",
704 "libstatssocket_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900705 "libsysutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900706 "netd_event_listener_interface-ndk_platform",
707 "server_configurable_flags",
708 "stats_proto",
709 }
710 //
711 // Module separator
712 //
713 m["com.android.tethering"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900714 "libnativehelper_compat_libc++",
715 "android.hardware.tetheroffload.config@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900716 "libcgrouprc",
717 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900718 "libprocessgroup",
719 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900720 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900721 "libvndksupport",
722 "tethering-aidl-interfaces-java",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000723 }
724 //
725 // Module separator
726 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900727 m["com.android.wifi"] = []string{
728 "PlatformProperties",
729 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900730 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900731 "android.hardware.wifi-V1.1-java",
732 "android.hardware.wifi-V1.2-java",
733 "android.hardware.wifi-V1.3-java",
734 "android.hardware.wifi-V1.4-java",
735 "android.hardware.wifi.hostapd-V1.0-java",
736 "android.hardware.wifi.hostapd-V1.1-java",
737 "android.hardware.wifi.hostapd-V1.2-java",
738 "android.hardware.wifi.supplicant-V1.0-java",
739 "android.hardware.wifi.supplicant-V1.1-java",
740 "android.hardware.wifi.supplicant-V1.2-java",
741 "android.hardware.wifi.supplicant-V1.3-java",
742 "android.hidl.base-V1.0-java",
743 "android.hidl.manager-V1.0-java",
744 "android.hidl.manager-V1.1-java",
745 "android.hidl.manager-V1.2-java",
746 "androidx.annotation_annotation",
747 "androidx.annotation_annotation-nodeps",
748 "bouncycastle-unbundled",
749 "dnsresolver_aidl_interface-V2-java",
750 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900751 "framework-wifi-pre-jarjar",
752 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900753 "ipmemorystore-aidl-interfaces-V3-java",
754 "ipmemorystore-aidl-interfaces-java",
755 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900756 "libnanohttpd",
757 "libprocessgroup",
758 "libprocessgroup_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900759 "libwifi-jni",
760 "net-utils-services-common",
761 "netd_aidl_interface-V2-java",
762 "netd_aidl_interface-unstable-java",
763 "netd_event_listener_interface-java",
764 "netlink-client",
765 "networkstack-aidl-interfaces-unstable-java",
766 "networkstack-client",
767 "services.net",
768 "wifi-lite-protos",
769 "wifi-nano-protos",
770 "wifi-service-pre-jarjar",
771 "wifi-service-resources",
772 "prebuilt_androidx.annotation_annotation-nodeps",
773 }
774 //
775 // Module separator
776 //
777 m["com.android.sdkext"] = []string{
778 "fmtlib_ndk",
779 "libbase_ndk",
780 "libprotobuf-cpp-lite-ndk",
781 }
782 //
783 // Module separator
784 //
785 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900786 "libprocessgroup_headers",
787 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900788 }
789 //
790 // Module separator
791 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000792 m[android.AvailableToAnyApex] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900793 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900794 "libclang_rt",
795 "libgcc_stripped",
796 "libprofile-clang-extras",
797 "libprofile-clang-extras_ndk",
798 "libprofile-extras",
799 "libprofile-extras_ndk",
800 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900801 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000802 return m
803}
804
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900805func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900806 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800807 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900808 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900809 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700810 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900811 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900812
Jooyung Han31c470b2019-10-18 16:26:59 +0900813 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900814 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900815
816 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
817 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
818 sort.Strings(*apexFileContextsInfos)
819 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
820 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900821}
822
Jooyung Han31c470b2019-10-18 16:26:59 +0900823func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
824 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
825 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
826}
827
Jiyong Parkd1063c12019-07-17 20:08:41 +0900828func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900829 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900830 ctx.BottomUp("apex", apexMutator).Parallel()
831 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
832 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900833 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900834}
835
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900836// Mark the direct and transitive dependencies of apex bundles so that they
837// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900838func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900839 if !mctx.Module().Enabled() {
840 return
841 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800842 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900843 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000844 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900845 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900846 ApexName: mctx.ModuleName(),
847 MinSdkVersion: a.minSdkVersion(mctx),
Ulya Trafimovich7c140d82020-04-22 18:05:58 +0100848 Updatable: proptools.Bool(a.properties.Updatable),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900849 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900850 directDep = true
851 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800852 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900853 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900854 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900855
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800856 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900857 return
858 }
859
Paul Duffin923e8a52020-03-30 15:33:32 +0100860 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900861
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862 mctx.VisitDirectDeps(func(child android.Module) {
863 depName := mctx.OtherModuleName(child)
864 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100865 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800866 android.UpdateApexDependency(apexBundles, depName, directDep)
867 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900868 }
869 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900870}
871
Jiyong Park89e850a2020-04-07 16:37:39 +0900872// mark if a module cannot be available to platform. A module cannot be available
873// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
874// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
875func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
876 // Host and recovery are not considered as platform
877 if mctx.Host() || mctx.Module().InstallInRecovery() {
878 return
879 }
880
881 if am, ok := mctx.Module().(android.ApexModule); ok {
882 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
883
884 // In a rare case when a lib is marked as available only to an apex
885 // but the apex doesn't exist. This can happen in a partial manifest branch
886 // like master-art. Currently, libstatssocket in the stats APEX is causing
887 // this problem.
888 // Include the lib in platform because the module SDK that ought to provide
889 // it doesn't exist, so it would otherwise be left out completely.
890 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
891 // this check for libraries provided by SDKs.
892 if !availableToPlatform && !android.InAnyApex(am.Name()) {
893 availableToPlatform = true
894 }
895
896 // If any of the dep is not available to platform, this module is also considered
897 // as being not available to platform even if it has "//apex_available:platform"
898 mctx.VisitDirectDeps(func(child android.Module) {
899 if !am.DepIsInSameApex(mctx, child) {
900 // if the dependency crosses apex boundary, don't consider it
901 return
902 }
903 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
904 availableToPlatform = false
905 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
906 }
907 })
908
909 // Exception 1: stub libraries and native bridge libraries are always available to platform
910 if cc, ok := mctx.Module().(*cc.Module); ok &&
911 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
912 availableToPlatform = true
913 }
914
915 // Exception 2: bootstrap bionic libraries are also always available to platform
916 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
917 availableToPlatform = true
918 }
919
920 if !availableToPlatform {
921 am.SetNotAvailableForPlatform()
922 }
923 }
924}
925
Paul Duffin65347702020-03-31 15:23:40 +0100926// If a module in an APEX depends on a module from an SDK then it needs an APEX
927// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
928func inAnySdk(module android.Module) bool {
929 if sa, ok := module.(android.SdkAware); ok {
930 return sa.IsInAnySdk()
931 }
932
933 return false
934}
935
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900936// Create apex variations if a module is included in APEX(s).
937func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900938 if !mctx.Module().Enabled() {
939 return
940 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900941 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900942 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000943 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900944 // apex bundle itself is mutated so that it and its modules have same
945 // apex variant.
946 apexBundleName := mctx.ModuleName()
947 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900948 } else if o, ok := mctx.Module().(*OverrideApex); ok {
949 apexBundleName := o.GetOverriddenModuleName()
950 if apexBundleName == "" {
951 mctx.ModuleErrorf("base property is not set")
952 return
953 }
954 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900955 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900956
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900957}
Sundong Ahne9b55722019-09-06 17:37:42 +0900958
Jooyung Han7a78a922019-10-08 21:59:58 +0900959var (
960 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
961 apexFileContextsInfosMutex sync.Mutex
962)
963
964func apexFileContextsInfos(config android.Config) *[]string {
965 return config.Once(apexFileContextsInfosKey, func() interface{} {
966 return &[]string{}
967 }).(*[]string)
968}
969
Jooyung Han54aca7b2019-11-20 02:26:02 +0900970func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900971 apexFileContextsInfosMutex.Lock()
972 defer apexFileContextsInfosMutex.Unlock()
973 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900974 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900975}
976
Sundong Ahne9b55722019-09-06 17:37:42 +0900977func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900978 if !mctx.Module().Enabled() {
979 return
980 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900981 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900982 var variants []string
983 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
984 case "image":
985 variants = append(variants, imageApexType, flattenedApexType)
986 case "zip":
987 variants = append(variants, zipApexType)
988 case "both":
989 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
990 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900991 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900992 return
993 }
994
995 modules := mctx.CreateLocalVariations(variants...)
996
997 for i, v := range variants {
998 switch v {
999 case imageApexType:
1000 modules[i].(*apexBundle).properties.ApexType = imageApex
1001 case zipApexType:
1002 modules[i].(*apexBundle).properties.ApexType = zipApex
1003 case flattenedApexType:
1004 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001005 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001006 modules[i].(*apexBundle).MakeAsSystemExt()
1007 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001008 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001009 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001010 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1011 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001012 }
1013}
1014
Jooyung Han5c998b92019-06-27 11:30:33 +09001015func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1016 if ab, ok := mctx.Module().(*apexBundle); ok {
1017 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1018 }
1019}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001020
Jooyung Handc782442019-11-01 03:14:38 +09001021var (
1022 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
1023)
1024
1025// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
1026// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1027// which may cause compatibility issues. (e.g. libbinder)
1028// Even though libbinder restricts its availability via 'apex_available' property and relies on
1029// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1030// to avoid similar problems.
1031func useVendorWhitelist(config android.Config) []string {
1032 return config.Once(useVendorWhitelistKey, func() interface{} {
1033 return []string{
1034 // swcodec uses "vendor" variants for smaller size
1035 "com.android.media.swcodec",
1036 "test_com.android.media.swcodec",
1037 }
1038 }).([]string)
1039}
1040
1041// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
1042// called before the first call to useVendorWhitelist()
1043func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
1044 config.Once(useVendorWhitelistKey, func() interface{} {
1045 return whitelist
1046 })
1047}
1048
Jooyung Han01a868d2020-02-27 13:40:44 +09001049type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001050 // List of native libraries
1051 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001052
Jooyung Han643adc42020-02-27 13:50:06 +09001053 // List of JNI libraries
1054 Jni_libs []string
1055
Alex Light9670d332019-01-29 18:07:33 -08001056 // List of native executables
1057 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001058
Roland Levillain630846d2019-06-26 12:48:34 +01001059 // List of native tests
1060 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001061}
Jooyung Han344d5432019-08-23 11:17:39 +09001062
Alex Light9670d332019-01-29 18:07:33 -08001063type apexMultilibProperties struct {
1064 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001065 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001066
1067 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001068 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001069
1070 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001071 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001072
1073 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001074 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001075
1076 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001077 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001078}
1079
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001080type apexBundleProperties struct {
1081 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001082 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001083 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001084
Jiyong Park40e26a22019-02-08 02:53:06 +09001085 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1086 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001087 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001088
Roland Levillain411c5842019-09-19 16:37:20 +01001089 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1090 // device (/apex/<apex_name>).
1091 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001092 Apex_name *string
1093
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001094 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001095 // For platform APEXes, this should points to a file under /system/sepolicy
1096 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1097 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001098
Jooyung Han01a868d2020-02-27 13:40:44 +09001099 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001100
1101 // List of java libraries that are embedded inside this APEX bundle
1102 Java_libs []string
1103
1104 // List of prebuilt files that are embedded inside this APEX bundle
1105 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001106
1107 // Name of the apex_key module that provides the private key to sign APEX
1108 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001109
Alex Light5098a612018-11-29 17:12:15 -08001110 // The type of APEX to build. Controls what the APEX payload is. Either
1111 // 'image', 'zip' or 'both'. Default: 'image'.
1112 Payload_type *string
1113
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001114 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1115 // or an android_app_certificate module name in the form ":module".
1116 Certificate *string
1117
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001118 // Whether this APEX is installable to one of the partitions. Default: true.
1119 Installable *bool
1120
Jiyong Parkda6eb592018-12-19 17:12:36 +09001121 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1122 // Default is false.
1123 Use_vendor *bool
1124
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001125 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1126 Ignore_system_library_special_case *bool
1127
Alex Light9670d332019-01-29 18:07:33 -08001128 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001129
Jiyong Parkf97782b2019-02-13 20:28:58 +09001130 // List of sanitizer names that this APEX is enabled for
1131 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001132
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001133 PreventInstall bool `blueprint:"mutated"`
1134
1135 HideFromMake bool `blueprint:"mutated"`
1136
Jooyung Han5c998b92019-06-27 11:30:33 +09001137 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1138 Provide_cpp_shared_libs *bool
1139
1140 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1141 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001142
1143 // A txt file containing list of files that are whitelisted to be included in this APEX.
1144 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001145
Sundong Ahnabb64432019-10-22 13:58:29 +09001146 // package format of this apex variant; could be non-flattened, flattened, or zip.
1147 // imageApex, zipApex or flattened
1148 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001149
Jiyong Parkd1063c12019-07-17 20:08:41 +09001150 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1151 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1152 // is implied. This value affects all modules included in this APEX. In other words, they are
1153 // also built with the SDKs specified here.
1154 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001155
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001156 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1157 // Should be only used in tests#.
1158 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001159
Jiyong Park956305c2020-01-09 12:32:06 +09001160 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001161
1162 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1163 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1164 // like symlinking to the system libs. Default is false.
1165 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001166
1167 // The minimum SDK version that this apex must be compatibile with.
1168 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001169}
1170
1171type apexTargetBundleProperties struct {
1172 Target struct {
1173 // Multilib properties only for android.
1174 Android struct {
1175 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001176 }
Jooyung Han344d5432019-08-23 11:17:39 +09001177
Alex Light9670d332019-01-29 18:07:33 -08001178 // Multilib properties only for host.
1179 Host struct {
1180 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001181 }
Jooyung Han344d5432019-08-23 11:17:39 +09001182
Alex Light9670d332019-01-29 18:07:33 -08001183 // Multilib properties only for host linux_bionic.
1184 Linux_bionic struct {
1185 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001186 }
Jooyung Han344d5432019-08-23 11:17:39 +09001187
Alex Light9670d332019-01-29 18:07:33 -08001188 // Multilib properties only for host linux_glibc.
1189 Linux_glibc struct {
1190 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001191 }
1192 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001193}
1194
Jiyong Park5d790c32019-11-15 18:40:32 +09001195type overridableProperties struct {
1196 // List of APKs to package inside APEX
1197 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001198
1199 // Names of modules to be overridden. Listed modules can only be other binaries
1200 // (in Make or Soong).
1201 // This does not completely prevent installation of the overridden binaries, but if both
1202 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1203 // from PRODUCT_PACKAGES.
1204 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001205
1206 // Logging Parent value
1207 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001208
1209 // Apex Container Package Name.
1210 // Override value for attribute package:name in AndroidManifest.xml
1211 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001212}
1213
Alex Light5098a612018-11-29 17:12:15 -08001214type apexPackaging int
1215
1216const (
1217 imageApex apexPackaging = iota
1218 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001219 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001220)
1221
Sundong Ahnabb64432019-10-22 13:58:29 +09001222// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001223func (a apexPackaging) suffix() string {
1224 switch a {
1225 case imageApex:
1226 return imageApexSuffix
1227 case zipApex:
1228 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001229 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001230 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001231 }
1232}
1233
1234func (a apexPackaging) name() string {
1235 switch a {
1236 case imageApex:
1237 return imageApexType
1238 case zipApex:
1239 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001240 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001241 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001242 }
1243}
1244
Jiyong Parkf653b052019-11-18 15:39:01 +09001245type apexFileClass int
1246
1247const (
1248 etc apexFileClass = iota
1249 nativeSharedLib
1250 nativeExecutable
1251 shBinary
1252 pyBinary
1253 goBinary
1254 javaSharedLib
1255 nativeTest
1256 app
1257)
1258
Jiyong Park8fd61922018-11-08 02:50:25 +09001259func (class apexFileClass) NameInMake() string {
1260 switch class {
1261 case etc:
1262 return "ETC"
1263 case nativeSharedLib:
1264 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001265 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001266 return "EXECUTABLES"
1267 case javaSharedLib:
1268 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001269 case nativeTest:
1270 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001271 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001272 // b/142537672 Why isn't this APP? We want to have full control over
1273 // the paths and file names of the apk file under the flattend APEX.
1274 // If this is set to APP, then the paths and file names are modified
1275 // by the Make build system. For example, it is installed to
1276 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1277 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1278 // appends module name (which is <apexname>.<Appname> to the path.
1279 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001280 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001281 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001282 }
1283}
1284
Jiyong Parkf653b052019-11-18 15:39:01 +09001285// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001286type apexFile struct {
1287 builtFile android.Path
1288 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001289 installDir string
1290 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001291 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001292 // list of symlinks that will be created in installDir that point to this apexFile
1293 symlinks []string
1294 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001295 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001296
1297 requiredModuleNames []string
1298 targetRequiredModuleNames []string
1299 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001300
Colin Cross503c1d02020-01-28 14:00:53 -08001301 jacocoReportClassesFile android.Path // only for javalibs and apps
1302 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001303 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001304
1305 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001306}
1307
Jiyong Park1833cef2019-12-13 13:28:36 +09001308func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1309 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001310 builtFile: builtFile,
1311 moduleName: moduleName,
1312 installDir: installDir,
1313 class: class,
1314 module: module,
1315 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001316 if module != nil {
1317 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001318 ret.requiredModuleNames = module.RequiredModuleNames()
1319 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1320 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001321 }
1322 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001323}
1324
1325func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001326 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001327}
1328
Jiyong Park7cd10e32020-01-14 09:22:18 +09001329// Path() returns path of this apex file relative to the APEX root
1330func (af *apexFile) Path() string {
1331 return filepath.Join(af.installDir, af.builtFile.Base())
1332}
1333
1334// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1335func (af *apexFile) SymlinkPaths() []string {
1336 var ret []string
1337 for _, symlink := range af.symlinks {
1338 ret = append(ret, filepath.Join(af.installDir, symlink))
1339 }
1340 return ret
1341}
1342
1343func (af *apexFile) AvailableToPlatform() bool {
1344 if af.module == nil {
1345 return false
1346 }
1347 if am, ok := af.module.(android.ApexModule); ok {
1348 return am.AvailableFor(android.AvailableToPlatform)
1349 }
1350 return false
1351}
1352
Jiyong Park678c8812020-02-07 17:25:49 +09001353type depInfo struct {
1354 to string
1355 from []string
1356 isExternal bool
1357}
1358
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001359type apexBundle struct {
1360 android.ModuleBase
1361 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001362 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001363 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001364
Jiyong Park5d790c32019-11-15 18:40:32 +09001365 properties apexBundleProperties
1366 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001367 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001368
Jooyung Hanf21c7972019-12-16 22:32:06 +09001369 // specific to apex_vndk modules
1370 vndkProperties apexVndkProperties
1371
Colin Crossa4925902018-11-16 11:36:28 -08001372 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001373 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001374 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001375
Jiyong Park03b68dd2019-07-26 23:20:40 +09001376 prebuiltFileToDelete string
1377
Jiyong Park42cca6c2019-04-01 11:15:50 +09001378 public_key_file android.Path
1379 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001380
1381 container_certificate_file android.Path
1382 container_private_key_file android.Path
1383
Jooyung Han54aca7b2019-11-20 02:26:02 +09001384 fileContexts android.Path
1385
Jiyong Park8fd61922018-11-08 02:50:25 +09001386 // list of files to be included in this apex
1387 filesInfo []apexFile
1388
Jiyong Park956305c2020-01-09 12:32:06 +09001389 // list of module names that should be installed along with this APEX
1390 requiredDeps []string
1391
Jiyong Park956305c2020-01-09 12:32:06 +09001392 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001393 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001394
Sundong Ahnabb64432019-10-22 13:58:29 +09001395 testApex bool
1396 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001397 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001398 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001399
Jooyung Han214bf372019-11-12 13:03:50 +09001400 manifestJsonOut android.WritablePath
1401 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001402
Jooyung Han002ab682020-01-08 01:57:58 +09001403 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001404 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001405 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001406 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1407 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001408
1409 // Suffix of module name in Android.mk
1410 // ".flattened", ".apex", ".zipapex", or ""
1411 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001412
1413 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001414
1415 // Whether to create symlink to the system file instead of having a file
1416 // inside the apex or not
1417 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001418
1419 // Struct holding the merged notice file paths in different formats
1420 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001421}
1422
Jiyong Park397e55e2018-10-24 21:09:55 +09001423func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001424 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001425 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001426 // Use *FarVariation* to be able to depend on modules having
1427 // conflicting variations with this module. This is required since
1428 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1429 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001430 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001431 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001432 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001433 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001434 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001435
Jooyung Han643adc42020-02-27 13:50:06 +09001436 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1437 {Mutator: "image", Variation: imageVariation},
1438 {Mutator: "link", Variation: "shared"},
1439 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1440 }...), jniLibTag, nativeModules.Jni_libs...)
1441
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001442 ctx.AddFarVariationDependencies(append(target.Variations(),
1443 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001444 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001445
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001446 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001447 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001448 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001449 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001450}
1451
Alex Light9670d332019-01-29 18:07:33 -08001452func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1453 if ctx.Os().Class == android.Device {
1454 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1455 } else {
1456 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1457 if ctx.Os().Bionic() {
1458 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1459 } else {
1460 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1461 }
1462 }
1463}
1464
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001465func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001466 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1467 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1468 }
1469
Jiyong Park397e55e2018-10-24 21:09:55 +09001470 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001471 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001472
1473 a.combineProperties(ctx)
1474
Jiyong Park397e55e2018-10-24 21:09:55 +09001475 has32BitTarget := false
1476 for _, target := range targets {
1477 if target.Arch.ArchType.Multilib == "lib32" {
1478 has32BitTarget = true
1479 }
1480 }
1481 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001482 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001483 // multilib.both
1484 addDependenciesForNativeModules(ctx,
1485 ApexNativeDependencies{
1486 Native_shared_libs: a.properties.Native_shared_libs,
1487 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001488 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001489 Binaries: nil,
1490 },
1491 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001492
Jiyong Park397e55e2018-10-24 21:09:55 +09001493 // Add native modules targetting both ABIs
1494 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001495 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001496 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001497 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001498
Alex Light3d673592019-01-18 14:37:31 -08001499 isPrimaryAbi := i == 0
1500 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001501 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001502 // multilib.first
1503 addDependenciesForNativeModules(ctx,
1504 ApexNativeDependencies{
1505 Native_shared_libs: nil,
1506 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001507 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001508 Binaries: a.properties.Binaries,
1509 },
1510 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001511
1512 // Add native modules targetting the first ABI
1513 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001514 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001515 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001516 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001517 }
1518
1519 switch target.Arch.ArchType.Multilib {
1520 case "lib32":
1521 // Add native modules targetting 32-bit ABI
1522 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001523 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001524 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001525 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001526
1527 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001528 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001529 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001530 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001531 case "lib64":
1532 // Add native modules targetting 64-bit ABI
1533 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001534 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001535 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001536 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001537
1538 if !has32BitTarget {
1539 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001540 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001541 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001542 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001543 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001544
1545 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1546 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1547 if sanitizer == "hwaddress" {
1548 addDependenciesForNativeModules(ctx,
Jooyung Han643adc42020-02-27 13:50:06 +09001549 ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
Jooyung Han01a868d2020-02-27 13:40:44 +09001550 target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001551 break
1552 }
1553 }
1554 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001555 }
1556
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001557 }
1558
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001559 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1560 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1561 // b/144532908
1562 archForPrebuiltEtc := config.Arches()[0]
1563 for _, arch := range config.Arches() {
1564 // Prefer 64-bit arch if there is any
1565 if arch.ArchType.Multilib == "lib64" {
1566 archForPrebuiltEtc = arch
1567 break
1568 }
1569 }
1570 ctx.AddFarVariationDependencies([]blueprint.Variation{
1571 {Mutator: "os", Variation: ctx.Os().String()},
1572 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1573 }, prebuiltTag, a.properties.Prebuilts...)
1574
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001575 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1576 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001577
Ulya Trafimovich44561882020-01-03 13:25:54 +00001578 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1579 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1580 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1581 javaLibTag, "jacocoagent")
1582 }
1583
Jiyong Park23c52b02019-02-02 13:13:47 +09001584 if String(a.properties.Key) == "" {
1585 ctx.ModuleErrorf("key is missing")
1586 return
1587 }
1588 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001589
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001590 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001591 if cert != "" {
1592 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001593 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001594
1595 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1596 if len(a.properties.Uses_sdks) > 0 {
1597 sdkRefs := []android.SdkRef{}
1598 for _, str := range a.properties.Uses_sdks {
1599 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1600 sdkRefs = append(sdkRefs, parsed)
1601 }
1602 a.BuildWithSdks(sdkRefs)
1603 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001604}
1605
Jiyong Park5d790c32019-11-15 18:40:32 +09001606func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1607 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1608 androidAppTag, a.overridableProperties.Apps...)
1609}
1610
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001611func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1612 // direct deps of an APEX bundle are all part of the APEX bundle
1613 return true
1614}
1615
Colin Cross0ea8ba82019-06-06 14:33:29 -07001616func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001617 moduleName := ctx.ModuleName()
1618 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1619 // we check with the pseudo module name to see if its certificate is overridden.
1620 if a.vndkApex {
1621 moduleName = vndkApexName
1622 }
1623 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001624 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001625 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001626 }
1627 return String(a.properties.Certificate)
1628}
1629
Colin Cross41955e82019-05-29 14:40:35 -07001630func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1631 switch tag {
1632 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001633 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001634 default:
1635 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001636 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001637}
1638
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001639func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001640 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001641}
1642
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001643func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1644 return proptools.Bool(a.properties.Test_only_no_hashtree)
1645}
1646
Jiyong Park7c1dc612019-01-05 11:15:24 +09001647func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001648 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001649 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001650 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001651 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001652 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001653 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001654 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001655 }
1656}
1657
Jiyong Parkf97782b2019-02-13 20:28:58 +09001658func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1659 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1660 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1661 }
1662}
1663
Jiyong Park388ef3f2019-01-28 19:47:32 +09001664func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001665 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1666 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001667 }
1668
1669 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001670 globalSanitizerNames := []string{}
1671 if a.Host() {
1672 globalSanitizerNames = ctx.Config().SanitizeHost()
1673 } else {
1674 arches := ctx.Config().SanitizeDeviceArch()
1675 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1676 globalSanitizerNames = ctx.Config().SanitizeDevice()
1677 }
1678 }
1679 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001680}
1681
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001682func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001683 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001684}
1685
1686func (a *apexBundle) PreventInstall() {
1687 a.properties.PreventInstall = true
1688}
1689
1690func (a *apexBundle) HideFromMake() {
1691 a.properties.HideFromMake = true
1692}
1693
Jiyong Park956305c2020-01-09 12:32:06 +09001694func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1695 a.properties.IsCoverageVariant = coverage
1696}
1697
Jiyong Parkf653b052019-11-18 15:39:01 +09001698// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001699func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001700 // Decide the APEX-local directory by the multilib of the library
1701 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001703 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001704 case "lib32":
1705 dirInApex = "lib"
1706 case "lib64":
1707 dirInApex = "lib64"
1708 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001709 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001710 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001711 }
Jooyung Han35155c42020-02-06 17:33:20 +09001712 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001713 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001714 // Special case for Bionic libs and other libs installed with them. This is
1715 // to prevent those libs from being included in the search path
1716 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1717 // those libs in the Runtime APEX are available via the legacy paths in
1718 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1719 // to the legacy paths and thus will be loaded into the default linker
1720 // namespace (aka "platform" namespace). If the libs are directly in
1721 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1722 // into the runtime linker namespace, which will result in double loading of
1723 // them, which isn't supported.
1724 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001725 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001726
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001728 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001729}
1730
Jiyong Park1833cef2019-12-13 13:28:36 +09001731func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001732 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001733 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001734 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001735 }
Jooyung Han35155c42020-02-06 17:33:20 +09001736 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001737 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001738 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001739 af.symlinks = cc.Symlinks()
1740 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001741}
1742
Jiyong Park1833cef2019-12-13 13:28:36 +09001743func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 dirInApex := "bin"
1745 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001746 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001747}
Jiyong Park1833cef2019-12-13 13:28:36 +09001748func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001750 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1751 if err != nil {
1752 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001753 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001754 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001755 fileToCopy := android.PathForOutput(ctx, s)
1756 // NB: Since go binaries are static we don't need the module for anything here, which is
1757 // good since the go tool is a blueprint.Module not an android.Module like we would
1758 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001759 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001760}
1761
Jiyong Park1833cef2019-12-13 13:28:36 +09001762func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001763 dirInApex := filepath.Join("bin", sh.SubDir())
1764 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001765 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001766 af.symlinks = sh.Symlinks()
1767 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001768}
1769
Jooyung Han58f26ab2019-12-18 15:34:32 +09001770// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1771type javaLibrary interface {
1772 android.Module
1773 java.Dependency
1774}
1775
1776func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001777 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001778 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001779 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1780 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1781 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001782}
1783
Jiyong Park1833cef2019-12-13 13:28:36 +09001784func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001785 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1786 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001787 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001788}
1789
atrost6e126252020-01-27 17:01:16 +00001790func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1791 dirInApex := filepath.Join("etc", config.SubDir())
1792 fileToCopy := config.CompatConfig()
1793 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1794}
1795
Jiyong Park1833cef2019-12-13 13:28:36 +09001796func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001797 android.Module
1798 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001799 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001800 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001801 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001802 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001803}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001804 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001805 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001806 appDir = "priv-app"
1807 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001808 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001809 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001810 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1811 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001812 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001813
1814 if app, ok := aapp.(interface {
1815 OverriddenManifestPackageName() string
1816 }); ok {
1817 af.overriddenPackageName = app.OverriddenManifestPackageName()
1818 }
Jiyong Park618922e2020-01-08 13:35:43 +09001819 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001820}
1821
Roland Levillain935639d2019-08-13 14:55:28 +01001822// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1823type flattenedApexContext struct {
1824 android.ModuleContext
1825}
1826
1827func (c *flattenedApexContext) InstallBypassMake() bool {
1828 return true
1829}
1830
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001831// Function called while walking an APEX's payload dependencies.
1832//
1833// Return true if the `to` module should be visited, false otherwise.
1834type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1835
Jiyong Park201cedd2020-02-07 17:25:49 +09001836// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001837func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001838 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001839 am, ok := child.(android.ApexModule)
1840 if !ok || !am.CanHaveApexVariants() {
1841 return false
1842 }
1843
1844 // Check for the direct dependencies that contribute to the payload
1845 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1846 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001847 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001848 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001849 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001850 return false
1851 }
1852
1853 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001854 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001855 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001856 }
1857
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001858 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001859 })
1860}
1861
Jooyung Han03b51852020-02-26 22:45:42 +09001862func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1863 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
1864 if ver != "current" {
1865 minSdkVersion, err := strconv.Atoi(ver)
1866 if err != nil {
1867 ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
1868 }
1869 return minSdkVersion
1870 }
1871 return android.FutureApiLevel
1872}
1873
Paul Duffinc5192442020-03-31 11:31:36 +01001874// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1875// a dependency tag.
1876var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1877
1878func PrettyPrintTag(tag blueprint.DependencyTag) string {
1879 // Use tag's custom String() method if available.
1880 if stringer, ok := tag.(fmt.Stringer); ok {
1881 return stringer.String()
1882 }
1883
1884 // Otherwise, get a default string representation of the tag's struct.
1885 tagString := fmt.Sprintf("%#v", tag)
1886
1887 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1888 tagString = tagCleaner.ReplaceAllString(tagString, "")
1889 return tagString
1890}
1891
Jiyong Park201cedd2020-02-07 17:25:49 +09001892// Ensures that the dependencies are marked as available for this APEX
1893func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1894 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1895 if ctx.Host() || a.testApex || a.vndkApex {
1896 return
1897 }
1898
Jiyong Park58d10902020-03-28 14:43:19 +09001899 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1900 // Requiring them and their transitive depencies with apex_available is not right
1901 // because they just add noise.
1902 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1903 return
1904 }
1905
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001906 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1907 if externalDep {
1908 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1909 return false
1910 }
1911
Jiyong Park201cedd2020-02-07 17:25:49 +09001912 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001913 fromName := ctx.OtherModuleName(from)
1914 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001915
1916 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1917 // do any of its dependencies.
1918 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1919 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1920 return false
1921 }
1922
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001923 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1924 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001925 }
Paul Duffindf915ff2020-03-30 17:58:21 +01001926 message := ""
Paul Duffinc5192442020-03-31 11:31:36 +01001927 tagPath := ctx.GetTagPath()
1928 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1929 walkPath := ctx.GetWalkPath()[1:]
1930 for i, m := range walkPath {
1931 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffindf915ff2020-03-30 17:58:21 +01001932 }
1933 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001934 // Visit this module's dependencies to check and report any issues with their availability.
1935 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001936 })
1937}
1938
Jiyong Park678c8812020-02-07 17:25:49 +09001939// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1940func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1941 a.depInfos = make(map[string]depInfo)
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001942 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001943 if from.Name() == to.Name() {
1944 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001945 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1946 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001947 }
1948
1949 if info, exists := a.depInfos[to.Name()]; exists {
1950 if !android.InList(from.Name(), info.from) {
1951 info.from = append(info.from, from.Name())
1952 }
1953 info.isExternal = info.isExternal && externalDep
1954 a.depInfos[to.Name()] = info
1955 } else {
1956 a.depInfos[to.Name()] = depInfo{
1957 to: to.Name(),
1958 from: []string{from.Name()},
1959 isExternal: externalDep,
1960 }
1961 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001962
1963 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1964 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001965 })
1966}
1967
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001968func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001969 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1970 switch a.properties.ApexType {
1971 case imageApex:
1972 if buildFlattenedAsDefault {
1973 a.suffix = imageApexSuffix
1974 } else {
1975 a.suffix = ""
1976 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001977
1978 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001979 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001980 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001981 }
1982 case zipApex:
1983 if proptools.String(a.properties.Payload_type) == "zip" {
1984 a.suffix = ""
1985 a.primaryApexType = true
1986 } else {
1987 a.suffix = zipApexSuffix
1988 }
1989 case flattenedApex:
1990 if buildFlattenedAsDefault {
1991 a.suffix = ""
1992 a.primaryApexType = true
1993 } else {
1994 a.suffix = flattenedSuffix
1995 }
Alex Light5098a612018-11-29 17:12:15 -08001996 }
1997
Roland Levillain630846d2019-06-26 12:48:34 +01001998 if len(a.properties.Tests) > 0 && !a.testApex {
1999 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2000 return
2001 }
2002
Jiyong Park0f80c182020-01-31 02:49:53 +09002003 a.checkApexAvailability(ctx)
2004
Jiyong Park678c8812020-02-07 17:25:49 +09002005 a.collectDepsInfo(ctx)
2006
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002007 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2008
Jooyung Hane1633032019-08-01 17:41:43 +09002009 // native lib dependencies
2010 var provideNativeLibs []string
2011 var requireNativeLibs []string
2012
Jooyung Han5c998b92019-06-27 11:30:33 +09002013 // Check if "uses" requirements are met with dependent apexBundles
2014 var providedNativeSharedLibs []string
2015 useVendor := proptools.Bool(a.properties.Use_vendor)
2016 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2017 if ctx.OtherModuleDependencyTag(m) != usesTag {
2018 return
2019 }
2020 otherName := ctx.OtherModuleName(m)
2021 other, ok := m.(*apexBundle)
2022 if !ok {
2023 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2024 return
2025 }
2026 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2027 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2028 return
2029 }
2030 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2031 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2032 return
2033 }
2034 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2035 })
2036
Jiyong Parkf653b052019-11-18 15:39:01 +09002037 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002038 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002039 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002040 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002041 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2042 return false
2043 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002044 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002045 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002046 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002047 case sharedLibTag, jniLibTag:
2048 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002049 if c, ok := child.(*cc.Module); ok {
2050 // bootstrap bionic libs are treated as provided by system
2051 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
2052 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09002053 }
Jooyung Han643adc42020-02-27 13:50:06 +09002054 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2055 fi.isJniLib = isJniLib
2056 filesInfo = append(filesInfo, fi)
Jiyong Parkf653b052019-11-18 15:39:01 +09002057 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002058 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002059 propertyName := "native_shared_libs"
2060 if isJniLib {
2061 propertyName = "jni_libs"
2062 }
2063 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002064 }
2065 case executableTag:
2066 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002067 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002068 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09002069 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002071 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002072 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002073 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002074 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002075 } else {
Alex Light778127a2019-02-27 14:19:50 -08002076 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 +09002077 }
2078 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002079 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002080 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09002081 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09002082 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2083 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09002084 filesInfo = append(filesInfo, af)
2085 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09002086 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09002087 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
2088 af := apexFileForJavaLibrary(ctx, sdkLib)
2089 if !af.Ok() {
2090 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2091 return false
2092 }
2093 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002094 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002095 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09002096 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002097 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002098 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002099 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002100 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002101 return true // track transitive dependencies
2102 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002103 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002104 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002105 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002106 } else {
2107 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2108 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002109 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002110 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002111 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002112 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2113 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002114 } else {
atrost6e126252020-01-27 17:01:16 +00002115 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002116 }
Roland Levillain630846d2019-06-26 12:48:34 +01002117 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002118 if ccTest, ok := child.(*cc.Module); ok {
2119 if ccTest.IsTestPerSrcAllTestsVariation() {
2120 // Multiple-output test module (where `test_per_src: true`).
2121 //
2122 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2123 // We do not add this variation to `filesInfo`, as it has no output;
2124 // however, we do add the other variations of this module as indirect
2125 // dependencies (see below).
2126 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002127 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002128 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002129 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002130 af.class = nativeTest
2131 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002132 }
Roland Levillain630846d2019-06-26 12:48:34 +01002133 } else {
2134 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2135 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002136 case keyTag:
2137 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002138 a.private_key_file = key.private_key_file
2139 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002140 } else {
2141 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002142 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002143 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002144 case certificateTag:
2145 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002146 a.container_certificate_file = dep.Certificate.Pem
2147 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002148 } else {
2149 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2150 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002151 case android.PrebuiltDepTag:
2152 // If the prebuilt is force disabled, remember to delete the prebuilt file
2153 // that might have been installed in the previous builds
2154 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2155 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2156 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002157 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002158 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002159 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002160 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002161 // We cannot use a switch statement on `depTag` here as the checked
2162 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002163 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002164 if cc, ok := child.(*cc.Module); ok {
2165 if android.InList(cc.Name(), providedNativeSharedLibs) {
2166 // If we're using a shared library which is provided from other APEX,
2167 // don't include it in this APEX
2168 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002169 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002170 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002171 // If the dependency is a stubs lib, don't include it in this APEX,
2172 // but make sure that the lib is installed on the device.
2173 // In case no APEX is having the lib, the lib is installed to the system
2174 // partition.
2175 //
2176 // Always include if we are a host-apex however since those won't have any
2177 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002178 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2179 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002180 }
Jooyung Hane1633032019-08-01 17:41:43 +09002181 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002182 // Don't track further
2183 return false
2184 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002185 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002186 af.transitiveDep = true
2187 filesInfo = append(filesInfo, af)
2188 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002189 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002190 } else if cc.IsTestPerSrcDepTag(depTag) {
2191 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002192 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002193 // Handle modules created as `test_per_src` variations of a single test module:
2194 // use the name of the generated test binary (`fileToCopy`) instead of the name
2195 // of the original test module (`depName`, shared by all `test_per_src`
2196 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002197 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002198 // these are not considered transitive dep
2199 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002200 filesInfo = append(filesInfo, af)
2201 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002202 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002203 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002204 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2205 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002206 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2207 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2208 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2209 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002210 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffindddd5462020-04-07 15:25:44 +01002211 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002212 }
2213 }
2214 }
2215 return false
2216 })
2217
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002218 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2219 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2220 // via the global boot image config.
2221 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002222 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002223 dirInApex := filepath.Join("javalib", arch.String())
2224 for _, f := range files {
2225 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002226 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002227 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002228 }
2229 }
2230 }
2231
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002232 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002233 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2234 return
2235 }
2236
Jiyong Park8fd61922018-11-08 02:50:25 +09002237 // remove duplicates in filesInfo
2238 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002239 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002240 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002241 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002242 if e, ok := encountered[dest]; !ok {
2243 encountered[dest] = f
2244 } else {
2245 // If a module is directly included and also transitively depended on
2246 // consider it as directly included.
2247 e.transitiveDep = e.transitiveDep && f.transitiveDep
2248 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002249 }
2250 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002251 var result []apexFile
2252 for _, v := range encountered {
2253 result = append(result, v)
2254 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002255 return result
2256 }
2257 filesInfo = removeDup(filesInfo)
2258
2259 // to have consistent build rules
2260 sort.Slice(filesInfo, func(i, j int) bool {
2261 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2262 })
2263
Jiyong Park8fd61922018-11-08 02:50:25 +09002264 a.installDir = android.PathForModuleInstall(ctx, "apex")
2265 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002266
Jooyung Han54aca7b2019-11-20 02:26:02 +09002267 if a.properties.ApexType != zipApex {
2268 if a.properties.File_contexts == nil {
2269 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2270 } else {
2271 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2272 if a.Platform() {
2273 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2274 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2275 }
2276 }
2277 }
2278 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2279 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2280 return
2281 }
2282 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002283 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2284 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2285 // the same library in the system partition, thus effectively sharing the same libraries
2286 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2287 // in the APEX.
2288 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2289 a.installable() &&
2290 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002291
Jiyong Park9d677202020-02-19 16:29:35 +09002292 // We don't need the optimization for updatable APEXes, as it might give false signal
2293 // to the system health when the APEXes are still bundled (b/149805758)
2294 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2295 a.linkToSystemLib = false
2296 }
2297
Jiyong Park638d30e2020-02-26 18:27:19 +09002298 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2299 if ctx.Host() {
2300 a.linkToSystemLib = false
2301 }
2302
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002303 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002304 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2305
2306 a.setCertificateAndPrivateKey(ctx)
2307 if a.properties.ApexType == flattenedApex {
2308 a.buildFlattenedApex(ctx)
2309 } else {
2310 a.buildUnflattenedApex(ctx)
2311 }
2312
Jooyung Han002ab682020-01-08 01:57:58 +09002313 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002314
2315 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002316}
2317
Jooyung Han5e9013b2020-03-10 06:23:13 +09002318func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002319 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002320 moduleName = normalizeModuleName(moduleName)
2321
2322 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2323 return true
2324 }
2325
2326 key = android.AvailableToAnyApex
2327 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2328 return true
2329 }
2330
2331 return false
2332}
2333
2334func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002335 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2336 // system. Trim the prefix for the check since they are confusing
2337 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2338 if strings.HasPrefix(moduleName, "libclang_rt.") {
2339 // This module has many arch variants that depend on the product being built.
2340 // We don't want to list them all
2341 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002342 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002343 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002344}
2345
Jooyung Han344d5432019-08-23 11:17:39 +09002346func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002347 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002348 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002349 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002350 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002351 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002352 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2353 })
Alex Light5098a612018-11-29 17:12:15 -08002354 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002355 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002356 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002357 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002358 return module
2359}
Jiyong Park30ca9372019-02-07 16:27:23 +09002360
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002361func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002362 bundle := newApexBundle()
2363 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002364 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002365 return bundle
2366}
2367
Jiyong Parkfce0b422020-02-11 03:56:06 +09002368// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2369// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002370func testApexBundleFactory() android.Module {
2371 bundle := newApexBundle()
2372 bundle.testApex = true
2373 return bundle
2374}
2375
Jiyong Parkfce0b422020-02-11 03:56:06 +09002376// apex packages other modules into an APEX file which is a packaging format for system-level
2377// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002378func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002379 return newApexBundle()
2380}
2381
Jiyong Park30ca9372019-02-07 16:27:23 +09002382//
2383// Defaults
2384//
2385type Defaults struct {
2386 android.ModuleBase
2387 android.DefaultsModuleBase
2388}
2389
Jiyong Park30ca9372019-02-07 16:27:23 +09002390func defaultsFactory() android.Module {
2391 return DefaultsFactory()
2392}
2393
2394func DefaultsFactory(props ...interface{}) android.Module {
2395 module := &Defaults{}
2396
2397 module.AddProperties(props...)
2398 module.AddProperties(
2399 &apexBundleProperties{},
2400 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002401 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002402 )
2403
2404 android.InitDefaultsModule(module)
2405 return module
2406}
Jiyong Park5d790c32019-11-15 18:40:32 +09002407
2408//
2409// OverrideApex
2410//
2411type OverrideApex struct {
2412 android.ModuleBase
2413 android.OverrideModuleBase
2414}
2415
2416func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2417 // All the overrides happen in the base module.
2418}
2419
2420// override_apex is used to create an apex module based on another apex module
2421// by overriding some of its properties.
2422func overrideApexFactory() android.Module {
2423 m := &OverrideApex{}
2424 m.AddProperties(&overridableProperties{})
2425
2426 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2427 android.InitOverrideModule(m)
2428 return m
2429}