blob: bb466129bf69b2df3f47a81e7d48538db89792f1 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Parkfa899442020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
55 executableTag = dependencyTag{name: "executable", payload: true}
56 javaLibTag = dependencyTag{name: "javaLib", payload: true}
57 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
58 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090059 keyTag = dependencyTag{name: "key"}
60 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090061 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090062 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000063 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000064
65 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090066)
67
Paul Duffin404db3f2020-03-06 12:30:13 +000068// Transform the map of apex -> modules to module -> apexes.
69func invertApexWhiteList(m map[string][]string) map[string][]string {
70 r := make(map[string][]string)
71 for apex, modules := range m {
72 for _, module := range modules {
73 r[module] = append(r[module], apex)
74 }
75 }
76 return r
77}
78
79// Retrieve the while list of apexes to which the supplied module belongs.
80func WhitelistedApexAvailable(moduleName string) []string {
81 return inverseApexAvailWl[normalizeModuleName(moduleName)]
82}
83
Anton Hansson5053c292020-01-10 15:12:39 +000084// This is a map from apex to modules, which overrides the
85// apex_available setting for that particular module to make
86// it available for the apex regardless of its setting.
87// TODO(b/147364041): remove this
88func makeApexAvailableWhitelist() map[string][]string {
89 // The "Module separator"s below are employed to minimize merge conflicts.
90 m := make(map[string][]string)
91 //
92 // Module separator
93 //
Jiyong Parkfa899442020-01-31 02:49:53 +090094 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090095 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090097 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "libmdnssd",
99 "libminijail",
100 "libminijail_gen_constants",
101 "libminijail_gen_constants_obj",
102 "libminijail_gen_syscall",
103 "libminijail_gen_syscall_obj",
104 "libminijail_generated",
105 "libpackagelistparser",
106 "libpcre2",
107 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900108 }
109 //
110 // Module separator
111 //
Paul Duffinc23d9f62020-03-10 13:44:19 +0000112 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900113 "art_cmdlineparser_headers",
114 "art_disassembler_headers",
115 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900116 "bionic_libc_platform_headers",
117 "core-repackaged-icu4j",
118 "cpp-define-generator-asm-support",
119 "cpp-define-generator-definitions",
120 "crtbegin_dynamic",
121 "crtbegin_dynamic1",
122 "crtbegin_so1",
123 "crtbrand",
124 "conscrypt.module.intra.core.api.stubs",
125 "dex2oat_headers",
126 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "javavm_headers",
129 "jni_platform_headers",
130 "libPlatformProperties",
131 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900133 "libandroidicuinit",
134 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000135 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900136 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libdexfile_all_headers",
138 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000139 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900140 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libfdlibm",
143 "libgtest_prod",
144 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000145 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900146 "libicuuc_headers",
147 "libicuuc_stubdata",
148 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900149 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000150 "liblzma",
151 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900152 "libnativebridge-headers",
153 "libnativehelper_header_only",
154 "libnativeloader-headers",
155 "libnpt_headers",
156 "libopenjdkjvmti_headers",
157 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000158 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libv8",
162 "libv8base",
163 "libv8gen",
164 "libv8platform",
165 "libv8sampler",
166 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libvixl",
168 "libvixld",
169 "libz",
170 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000173 m["com.android.art.debug"] = artApexContents
174 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000175 //
176 // Module separator
177 //
178 m["com.android.bluetooth.updatable"] = []string{
179 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000180 "android.hardware.bluetooth.a2dp@1.0",
181 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900182 "android.hardware.bluetooth@1.0",
183 "android.hardware.bluetooth@1.1",
184 "android.hardware.graphics.bufferqueue@1.0",
185 "android.hardware.graphics.bufferqueue@2.0",
186 "android.hardware.graphics.common@1.0",
187 "android.hardware.graphics.common@1.1",
188 "android.hardware.graphics.common@1.2",
189 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000190 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 "android.hidl.token@1.0",
192 "android.hidl.token@1.0-utils",
193 "avrcp-target-service",
194 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "bluetooth-protos-lite",
196 "bluetooth.mapsapi",
197 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900198 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900199 "ipmemorystore-aidl-interfaces-V5-java",
200 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900201 "internal_include_headers",
202 "lib-bt-packets",
203 "lib-bt-packets-avrcp",
204 "lib-bt-packets-base",
205 "libFraunhoferAAC",
206 "libaudio-a2dp-hw-utils",
207 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900208 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900210 "libbluetooth-types",
211 "libbluetooth-types-header",
212 "libbluetooth_gd",
213 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000214 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libbt-audio-hal-interface",
216 "libbt-bta",
217 "libbt-common",
218 "libbt-hci",
219 "libbt-platform-protos-lite",
220 "libbt-protos-lite",
221 "libbt-sbc-decoder",
222 "libbt-sbc-encoder",
223 "libbt-stack",
224 "libbt-utils",
225 "libbtcore",
226 "libbtdevice",
227 "libbte",
228 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000229 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000230 "libevent",
231 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900232 "libg722codec",
233 "libgtest_prod",
234 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900235 "libmedia_headers",
236 "libmodpb64",
237 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000238 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900239 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 "libstagefright_foundation_headers",
241 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000242 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900243 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000244 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900248 "net-utils-services-common",
249 "netd_aidl_interface-unstable-java",
250 "netd_event_listener_interface-java",
251 "netlink-client",
252 "networkstack-aidl-interfaces-unstable-java",
253 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900254 "sap-api-java-static",
255 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000256 }
257 //
258 // Module separator
259 //
260 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
261 //
262 // Module separator
263 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900267 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900268 }
Anton Hansson5053c292020-01-10 15:12:39 +0000269 //
270 // Module separator
271 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 m["com.android.extservices"] = []string{
273 "flatbuffer_headers",
274 "liblua",
275 "libtextclassifier",
276 "libtextclassifier_hash_static",
277 "libtflite_static",
278 "libutf",
279 "libz_current",
280 "tensorflow_headers",
281 }
282 //
283 // Module separator
284 //
285 m["com.android.cronet"] = []string{
286 "cronet_impl_common_java",
287 "cronet_impl_native_java",
288 "cronet_impl_platform_java",
289 "libcronet.80.0.3986.0",
290 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900291 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "prebuilt_libcronet.80.0.3986.0",
293 }
294 //
295 // Module separator
296 //
297 m["com.android.neuralnetworks"] = []string{
298 "android.hardware.neuralnetworks@1.0",
299 "android.hardware.neuralnetworks@1.1",
300 "android.hardware.neuralnetworks@1.2",
301 "android.hardware.neuralnetworks@1.3",
302 "android.hidl.allocator@1.0",
303 "android.hidl.memory.token@1.0",
304 "android.hidl.memory@1.0",
305 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900308 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libprocessgroup",
310 "libprocessgroup_headers",
311 "libprocpartition",
312 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900313 }
Anton Hansson5053c292020-01-10 15:12:39 +0000314 //
315 // Module separator
316 //
Anton Hansson5053c292020-01-10 15:12:39 +0000317 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "android.hardware.cas@1.0",
321 "android.hardware.configstore-utils",
322 "android.hardware.configstore@1.0",
323 "android.hardware.configstore@1.1",
324 "android.hardware.graphics.allocator@2.0",
325 "android.hardware.graphics.allocator@3.0",
326 "android.hardware.graphics.bufferqueue@1.0",
327 "android.hardware.graphics.bufferqueue@2.0",
328 "android.hardware.graphics.common@1.0",
329 "android.hardware.graphics.common@1.1",
330 "android.hardware.graphics.common@1.2",
331 "android.hardware.graphics.mapper@2.0",
332 "android.hardware.graphics.mapper@2.1",
333 "android.hardware.graphics.mapper@3.0",
334 "android.hardware.media.omx@1.0",
335 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000336 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000337 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "android.hidl.token@1.0",
340 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "gl_headers",
343 "libEGL",
344 "libEGL_blobCache",
345 "libEGL_getProcAddress",
346 "libFLAC",
347 "libFLAC-config",
348 "libFLAC-headers",
349 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000350 "libaacextractor",
351 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900352 "libarect",
353 "libasync_safe",
354 "libaudio_system_headers",
355 "libaudioclient",
356 "libaudioclient_headers",
357 "libaudiofoundation",
358 "libaudiofoundation_headers",
359 "libaudiomanager",
360 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900364 "libbluetooth-types-header",
365 "libbufferhub",
366 "libbufferhub_headers",
367 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900368 "libc_malloc_debug_backtrace",
369 "libcamera_client",
370 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900371 "libdexfile_external_headers",
372 "libdexfile_support",
373 "libdvr_headers",
374 "libexpat",
375 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "libgrallocusage",
378 "libgraphicsenv",
379 "libgui",
380 "libgui_headers",
381 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900382 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900383 "liblzma",
384 "libmath",
385 "libmedia",
386 "libmedia_codeclist",
387 "libmedia_headers",
388 "libmedia_helper",
389 "libmedia_helper_headers",
390 "libmedia_midiiowrapper",
391 "libmedia_omx",
392 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000393 "libmidiextractor",
394 "libmkvextractor",
395 "libmp3extractor",
396 "libmp4extractor",
397 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libnativebase_headers",
399 "libnativebridge-headers",
400 "libnativebridge_lazy",
401 "libnativeloader-headers",
402 "libnativeloader_lazy",
403 "libnativewindow_headers",
404 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000405 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900406 "libpackagelistparser",
407 "libpcre2",
408 "libpdx",
409 "libpdx_default_transport",
410 "libpdx_headers",
411 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000412 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "libprocessgroup_headers",
414 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000416 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900417 "libspeexresampler",
418 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000419 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900420 "libstagefright_flacdec",
421 "libstagefright_foundation",
422 "libstagefright_foundation_headers",
423 "libstagefright_foundation_without_imemory",
424 "libstagefright_headers",
425 "libstagefright_id3",
426 "libstagefright_metadatautils",
427 "libstagefright_mpeg2extractor",
428 "libstagefright_mpeg2support",
429 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900430 "libui",
431 "libui_headers",
432 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900433 "libvibrator",
434 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libwebm",
437 "media_ndk_headers",
438 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000439 "updatable-media",
440 }
441 //
442 // Module separator
443 //
444 m["com.android.media.swcodec"] = []string{
445 "android.frameworks.bufferhub@1.0",
446 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "android.hardware.configstore-utils",
448 "android.hardware.configstore@1.0",
449 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000450 "android.hardware.graphics.allocator@2.0",
451 "android.hardware.graphics.allocator@3.0",
452 "android.hardware.graphics.allocator@4.0",
453 "android.hardware.graphics.bufferqueue@1.0",
454 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000456 "android.hardware.graphics.common@1.0",
457 "android.hardware.graphics.common@1.1",
458 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000459 "android.hardware.graphics.mapper@2.0",
460 "android.hardware.graphics.mapper@2.1",
461 "android.hardware.graphics.mapper@3.0",
462 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "android.hardware.media.bufferpool@2.0",
464 "android.hardware.media.c2@1.0",
465 "android.hardware.media.c2@1.1",
466 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900467 "android.hardware.media@1.0",
468 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000469 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900470 "android.hidl.memory@1.0",
Anton Hansson5053c292020-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 Parkfa899442020-01-31 02:49:53 +0900474 "libEGL",
475 "libFLAC",
476 "libFLAC-config",
477 "libFLAC-headers",
478 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900479 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libarect",
481 "libasync_safe",
482 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000483 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900484 "libaudioutils",
485 "libaudioutils_fixedfft",
486 "libavcdec",
487 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000488 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900490 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900491 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900492 "libbluetooth-types-header",
493 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900494 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000495 "libcap",
496 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900497 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "libcodec2_hidl@1.0",
499 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libcodec2_internal",
Anton Hansson5053c292020-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",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libdexfile_support",
534 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "libfmq",
537 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000538 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900539 "libgrallocusage",
540 "libgraphicsenv",
541 "libgsm",
542 "libgui_bufferqueue_static",
543 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000544 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900545 "libhardware_headers",
546 "libhevcdec",
547 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000548 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900549 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "liblzma",
551 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000552 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900553 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000554 "libminijail",
Jiyong Parkfa899442020-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",
562 "libnativebridge_lazy",
563 "libnativeloader_lazy",
564 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000565 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900566 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000567 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900568 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000569 "libscudo_wrapper",
570 "libsfplugin_ccodec_utils",
571 "libspeexresampler",
572 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libstagefright_amrnbdec",
574 "libstagefright_amrnbenc",
575 "libstagefright_amrwbdec",
576 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "libstagefright_bufferpool@2.0.1",
578 "libstagefright_bufferqueue_helper",
579 "libstagefright_enc_common",
580 "libstagefright_flacdec",
581 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libstagefright_foundation_headers",
583 "libstagefright_headers",
584 "libstagefright_m4vh263dec",
585 "libstagefright_m4vh263enc",
586 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000587 "libsync",
588 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900589 "libui_headers",
590 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000591 "libvorbisidec",
592 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 "libyuv",
594 "libyuv_static",
595 "media_ndk_headers",
596 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000597 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000598 }
599 //
600 // Module separator
601 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 m["com.android.mediaprovider"] = []string{
603 "MediaProvider",
604 "MediaProviderGoogle",
605 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900606 "libbase_ndk",
607 "libfuse",
608 "libfuse_jni",
609 "libnativehelper_header_only",
610 }
611 //
612 // Module separator
613 //
614 m["com.android.permission"] = []string{
615 "androidx.annotation_annotation",
616 "androidx.annotation_annotation-nodeps",
617 "androidx.lifecycle_lifecycle-common",
618 "androidx.lifecycle_lifecycle-common-java8",
619 "androidx.lifecycle_lifecycle-common-java8-nodeps",
620 "androidx.lifecycle_lifecycle-common-nodeps",
621 "kotlin-annotations",
622 "kotlin-stdlib",
623 "kotlin-stdlib-jdk7",
624 "kotlin-stdlib-jdk8",
625 "kotlinx-coroutines-android",
626 "kotlinx-coroutines-android-nodeps",
627 "kotlinx-coroutines-core",
628 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900630 "GooglePermissionController",
631 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 }
Anton Hansson5053c292020-01-10 15:12:39 +0000633 //
634 // Module separator
635 //
Anton Hansson5053c292020-01-10 15:12:39 +0000636 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900638 "libarm-optimized-routines-math",
639 "libasync_safe",
640 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900641 "libc_aeabi",
642 "libc_bionic",
643 "libc_bionic_ndk",
644 "libc_bootstrap",
645 "libc_common",
646 "libc_common_shared",
647 "libc_common_static",
648 "libc_dns",
649 "libc_dynamic_dispatch",
650 "libc_fortify",
651 "libc_freebsd",
652 "libc_freebsd_large_stack",
653 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 "libc_init_dynamic",
655 "libc_init_static",
656 "libc_jemalloc_wrapper",
657 "libc_netbsd",
658 "libc_nomalloc",
659 "libc_nopthread",
660 "libc_openbsd",
661 "libc_openbsd_large_stack",
662 "libc_openbsd_ndk",
663 "libc_pthread",
664 "libc_static_dispatch",
665 "libc_syscalls",
666 "libc_tzcode",
667 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900668 "libdebuggerd",
669 "libdebuggerd_common_headers",
670 "libdebuggerd_handler_core",
671 "libdebuggerd_handler_fallback",
672 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000673 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900674 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900675 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900676 "libgtest_prod",
677 "libjemalloc5",
678 "liblinker_main",
679 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900680 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000681 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900682 "libprocessgroup_headers",
683 "libprocinfo",
684 "libpropertyinfoparser",
685 "libscudo",
686 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 "libsystemproperties",
688 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000689 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "libz",
691 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000692 }
693 //
694 // Module separator
695 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900696 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900699 "libnativehelper_header_only",
700 "libnetd_client_headers",
701 "libnetd_resolv",
702 "libnetdutils",
703 "libprocessgroup",
704 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900705 "libstatslog_resolv",
706 "libstatspush_compat",
707 "libstatssocket",
708 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900709 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900710 "netd_event_listener_interface-ndk_platform",
711 "server_configurable_flags",
712 "stats_proto",
713 }
Anton Hansson5053c292020-01-10 15:12:39 +0000714 //
715 // Module separator
716 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900717 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900718 "libnativehelper_compat_libc++",
719 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900720 "libcgrouprc",
721 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900722 "libprocessgroup",
723 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900724 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900725 "libvndksupport",
726 "tethering-aidl-interfaces-java",
727 }
Anton Hansson5053c292020-01-10 15:12:39 +0000728 //
729 // Module separator
730 //
731 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900732 "PlatformProperties",
733 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900734 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900735 "android.hardware.wifi-V1.1-java",
736 "android.hardware.wifi-V1.2-java",
737 "android.hardware.wifi-V1.3-java",
738 "android.hardware.wifi-V1.4-java",
739 "android.hardware.wifi.hostapd-V1.0-java",
740 "android.hardware.wifi.hostapd-V1.1-java",
741 "android.hardware.wifi.hostapd-V1.2-java",
742 "android.hardware.wifi.supplicant-V1.0-java",
743 "android.hardware.wifi.supplicant-V1.1-java",
744 "android.hardware.wifi.supplicant-V1.2-java",
745 "android.hardware.wifi.supplicant-V1.3-java",
746 "android.hidl.base-V1.0-java",
747 "android.hidl.manager-V1.0-java",
748 "android.hidl.manager-V1.1-java",
749 "android.hidl.manager-V1.2-java",
750 "androidx.annotation_annotation",
751 "androidx.annotation_annotation-nodeps",
752 "bouncycastle-unbundled",
753 "dnsresolver_aidl_interface-V2-java",
754 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900755 "framework-wifi-pre-jarjar",
756 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900757 "ipmemorystore-aidl-interfaces-V3-java",
758 "ipmemorystore-aidl-interfaces-java",
759 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900760 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000761 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900762 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000763 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900764 "net-utils-services-common",
765 "netd_aidl_interface-V2-java",
766 "netd_aidl_interface-unstable-java",
767 "netd_event_listener_interface-java",
768 "netlink-client",
769 "networkstack-aidl-interfaces-unstable-java",
770 "networkstack-client",
771 "services.net",
772 "wifi-lite-protos",
773 "wifi-nano-protos",
774 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000775 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900776 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000777 }
778 //
779 // Module separator
780 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900781 m["com.android.sdkext"] = []string{
782 "fmtlib_ndk",
783 "libbase_ndk",
784 "libprotobuf-cpp-lite-ndk",
785 }
786 //
787 // Module separator
788 //
789 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900790 "libprocessgroup_headers",
791 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900792 }
793 //
794 // Module separator
795 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000796 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900797 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900798 "libclang_rt",
799 "libgcc_stripped",
800 "libprofile-clang-extras",
801 "libprofile-clang-extras_ndk",
802 "libprofile-extras",
803 "libprofile-extras_ndk",
804 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900805 }
Anton Hansson5053c292020-01-10 15:12:39 +0000806 return m
807}
808
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900809func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900810 android.AddNeverAllowRules(android.NeverAllow().
811 ModuleType("apex").
812 With("updatable", "true").
813 With("min_sdk_version", "").
814 Because("All updatable apexes should set min_sdk_version."))
815
Jiyong Parkd1063c12019-07-17 20:08:41 +0900816 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800817 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900818 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900819 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700820 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900821 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822
Jooyung Han31c470b2019-10-18 16:26:59 +0900823 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900824 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900825
826 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
827 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
828 sort.Strings(*apexFileContextsInfos)
829 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
830 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900831}
832
Jooyung Han31c470b2019-10-18 16:26:59 +0900833func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
834 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
835 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
836}
837
Jiyong Parkd1063c12019-07-17 20:08:41 +0900838func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900839 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900840 ctx.BottomUp("apex", apexMutator).Parallel()
841 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
842 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900843}
844
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900845// Mark the direct and transitive dependencies of apex bundles so that they
846// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900847func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800848 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900849 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000850 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900851 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900852 ApexName: mctx.ModuleName(),
853 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900854 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900855 directDep = true
856 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800857 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900858 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900859 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900860
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800861 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900862 return
863 }
864
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900865 cur := mctx.Module().(interface {
866 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
867 })
868
Jiyong Parkf760cae2020-02-12 07:53:12 +0900869 mctx.VisitDirectDeps(func(child android.Module) {
870 depName := mctx.OtherModuleName(child)
871 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900872 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800873 android.UpdateApexDependency(apexBundles, depName, directDep)
874 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900875 }
876 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877}
878
879// Create apex variations if a module is included in APEX(s).
880func apexMutator(mctx android.BottomUpMutatorContext) {
881 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900882 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000883 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900884 // apex bundle itself is mutated so that it and its modules have same
885 // apex variant.
886 apexBundleName := mctx.ModuleName()
887 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900888 } else if o, ok := mctx.Module().(*OverrideApex); ok {
889 apexBundleName := o.GetOverriddenModuleName()
890 if apexBundleName == "" {
891 mctx.ModuleErrorf("base property is not set")
892 return
893 }
894 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900895 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900896
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897}
Sundong Ahne9b55722019-09-06 17:37:42 +0900898
Jooyung Han7a78a922019-10-08 21:59:58 +0900899var (
900 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
901 apexFileContextsInfosMutex sync.Mutex
902)
903
904func apexFileContextsInfos(config android.Config) *[]string {
905 return config.Once(apexFileContextsInfosKey, func() interface{} {
906 return &[]string{}
907 }).(*[]string)
908}
909
Jooyung Han54aca7b2019-11-20 02:26:02 +0900910func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900911 apexFileContextsInfosMutex.Lock()
912 defer apexFileContextsInfosMutex.Unlock()
913 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900914 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900915}
916
Sundong Ahne9b55722019-09-06 17:37:42 +0900917func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900918 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900919 var variants []string
920 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
921 case "image":
922 variants = append(variants, imageApexType, flattenedApexType)
923 case "zip":
924 variants = append(variants, zipApexType)
925 case "both":
926 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
927 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900928 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900929 return
930 }
931
932 modules := mctx.CreateLocalVariations(variants...)
933
934 for i, v := range variants {
935 switch v {
936 case imageApexType:
937 modules[i].(*apexBundle).properties.ApexType = imageApex
938 case zipApexType:
939 modules[i].(*apexBundle).properties.ApexType = zipApex
940 case flattenedApexType:
941 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900942 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900943 modules[i].(*apexBundle).MakeAsSystemExt()
944 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900945 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900946 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900947 } else if _, ok := mctx.Module().(*OverrideApex); ok {
948 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900949 }
950}
951
Jooyung Han5c998b92019-06-27 11:30:33 +0900952func apexUsesMutator(mctx android.BottomUpMutatorContext) {
953 if ab, ok := mctx.Module().(*apexBundle); ok {
954 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
955 }
956}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900957
Jooyung Handc782442019-11-01 03:14:38 +0900958var (
959 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
960)
961
962// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
963// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
964// which may cause compatibility issues. (e.g. libbinder)
965// Even though libbinder restricts its availability via 'apex_available' property and relies on
966// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
967// to avoid similar problems.
968func useVendorWhitelist(config android.Config) []string {
969 return config.Once(useVendorWhitelistKey, func() interface{} {
970 return []string{
971 // swcodec uses "vendor" variants for smaller size
972 "com.android.media.swcodec",
973 "test_com.android.media.swcodec",
974 }
975 }).([]string)
976}
977
978// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
979// called before the first call to useVendorWhitelist()
980func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
981 config.Once(useVendorWhitelistKey, func() interface{} {
982 return whitelist
983 })
984}
985
Alex Light9670d332019-01-29 18:07:33 -0800986type apexNativeDependencies struct {
987 // List of native libraries
988 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900989
Alex Light9670d332019-01-29 18:07:33 -0800990 // List of native executables
991 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900992
Roland Levillain630846d2019-06-26 12:48:34 +0100993 // List of native tests
994 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800995}
Jooyung Han344d5432019-08-23 11:17:39 +0900996
Alex Light9670d332019-01-29 18:07:33 -0800997type apexMultilibProperties struct {
998 // Native dependencies whose compile_multilib is "first"
999 First apexNativeDependencies
1000
1001 // Native dependencies whose compile_multilib is "both"
1002 Both apexNativeDependencies
1003
1004 // Native dependencies whose compile_multilib is "prefer32"
1005 Prefer32 apexNativeDependencies
1006
1007 // Native dependencies whose compile_multilib is "32"
1008 Lib32 apexNativeDependencies
1009
1010 // Native dependencies whose compile_multilib is "64"
1011 Lib64 apexNativeDependencies
1012}
1013
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001014type apexBundleProperties struct {
1015 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001016 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001017 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001018
Jiyong Park40e26a22019-02-08 02:53:06 +09001019 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1020 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001021 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001022
Roland Levillain411c5842019-09-19 16:37:20 +01001023 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1024 // device (/apex/<apex_name>).
1025 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001026 Apex_name *string
1027
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001028 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001029 // For platform APEXes, this should points to a file under /system/sepolicy
1030 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1031 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001032
1033 // List of native shared libs that are embedded inside this APEX bundle
1034 Native_shared_libs []string
1035
Roland Levillain630846d2019-06-26 12:48:34 +01001036 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001037 Binaries []string
1038
1039 // List of java libraries that are embedded inside this APEX bundle
1040 Java_libs []string
1041
1042 // List of prebuilt files that are embedded inside this APEX bundle
1043 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001044
Roland Levillain630846d2019-06-26 12:48:34 +01001045 // List of tests that are embedded inside this APEX bundle
1046 Tests []string
1047
Jiyong Parkff1458f2018-10-12 21:49:38 +09001048 // Name of the apex_key module that provides the private key to sign APEX
1049 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001050
Alex Light5098a612018-11-29 17:12:15 -08001051 // The type of APEX to build. Controls what the APEX payload is. Either
1052 // 'image', 'zip' or 'both'. Default: 'image'.
1053 Payload_type *string
1054
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001055 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1056 // or an android_app_certificate module name in the form ":module".
1057 Certificate *string
1058
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001059 // Whether this APEX is installable to one of the partitions. Default: true.
1060 Installable *bool
1061
Jiyong Parkda6eb592018-12-19 17:12:36 +09001062 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1063 // Default is false.
1064 Use_vendor *bool
1065
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001066 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1067 Ignore_system_library_special_case *bool
1068
Alex Light9670d332019-01-29 18:07:33 -08001069 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001070
Jiyong Parkf97782b2019-02-13 20:28:58 +09001071 // List of sanitizer names that this APEX is enabled for
1072 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001073
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001074 PreventInstall bool `blueprint:"mutated"`
1075
1076 HideFromMake bool `blueprint:"mutated"`
1077
Jooyung Han5c998b92019-06-27 11:30:33 +09001078 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1079 Provide_cpp_shared_libs *bool
1080
1081 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1082 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001083
1084 // A txt file containing list of files that are whitelisted to be included in this APEX.
1085 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001086
Sundong Ahnabb64432019-10-22 13:58:29 +09001087 // package format of this apex variant; could be non-flattened, flattened, or zip.
1088 // imageApex, zipApex or flattened
1089 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001090
Jiyong Parkd1063c12019-07-17 20:08:41 +09001091 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1092 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1093 // is implied. This value affects all modules included in this APEX. In other words, they are
1094 // also built with the SDKs specified here.
1095 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001096
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001097 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1098 // Should be only used in tests#.
1099 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001100
Jiyong Park956305c2020-01-09 12:32:06 +09001101 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001102
1103 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1104 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1105 // like symlinking to the system libs. Default is false.
1106 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001107
1108 // The minimum SDK version that this apex must be compatible with.
1109 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001110}
1111
1112type apexTargetBundleProperties struct {
1113 Target struct {
1114 // Multilib properties only for android.
1115 Android struct {
1116 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001117 }
Jooyung Han344d5432019-08-23 11:17:39 +09001118
Alex Light9670d332019-01-29 18:07:33 -08001119 // Multilib properties only for host.
1120 Host struct {
1121 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001122 }
Jooyung Han344d5432019-08-23 11:17:39 +09001123
Alex Light9670d332019-01-29 18:07:33 -08001124 // Multilib properties only for host linux_bionic.
1125 Linux_bionic struct {
1126 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001127 }
Jooyung Han344d5432019-08-23 11:17:39 +09001128
Alex Light9670d332019-01-29 18:07:33 -08001129 // Multilib properties only for host linux_glibc.
1130 Linux_glibc struct {
1131 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001132 }
1133 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001134}
1135
Jiyong Park5d790c32019-11-15 18:40:32 +09001136type overridableProperties struct {
1137 // List of APKs to package inside APEX
1138 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001139
1140 // Names of modules to be overridden. Listed modules can only be other binaries
1141 // (in Make or Soong).
1142 // This does not completely prevent installation of the overridden binaries, but if both
1143 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1144 // from PRODUCT_PACKAGES.
1145 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001146
1147 // Logging Parent value
1148 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001149
1150 // Apex Container Package Name.
1151 // Override value for attribute package:name in AndroidManifest.xml
1152 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001153}
1154
Alex Light5098a612018-11-29 17:12:15 -08001155type apexPackaging int
1156
1157const (
1158 imageApex apexPackaging = iota
1159 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001160 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001161)
1162
Sundong Ahnabb64432019-10-22 13:58:29 +09001163// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001164func (a apexPackaging) suffix() string {
1165 switch a {
1166 case imageApex:
1167 return imageApexSuffix
1168 case zipApex:
1169 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001170 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001171 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001172 }
1173}
1174
1175func (a apexPackaging) name() string {
1176 switch a {
1177 case imageApex:
1178 return imageApexType
1179 case zipApex:
1180 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001181 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001182 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001183 }
1184}
1185
Jiyong Parkf653b052019-11-18 15:39:01 +09001186type apexFileClass int
1187
1188const (
1189 etc apexFileClass = iota
1190 nativeSharedLib
1191 nativeExecutable
1192 shBinary
1193 pyBinary
1194 goBinary
1195 javaSharedLib
1196 nativeTest
1197 app
1198)
1199
Jiyong Park8fd61922018-11-08 02:50:25 +09001200func (class apexFileClass) NameInMake() string {
1201 switch class {
1202 case etc:
1203 return "ETC"
1204 case nativeSharedLib:
1205 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001206 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001207 return "EXECUTABLES"
1208 case javaSharedLib:
1209 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001210 case nativeTest:
1211 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001212 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001213 // b/142537672 Why isn't this APP? We want to have full control over
1214 // the paths and file names of the apk file under the flattend APEX.
1215 // If this is set to APP, then the paths and file names are modified
1216 // by the Make build system. For example, it is installed to
1217 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1218 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1219 // appends module name (which is <apexname>.<Appname> to the path.
1220 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001221 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001222 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001223 }
1224}
1225
Jiyong Parkf653b052019-11-18 15:39:01 +09001226// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001227type apexFile struct {
1228 builtFile android.Path
1229 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001230 installDir string
1231 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001232 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001233 // list of symlinks that will be created in installDir that point to this apexFile
1234 symlinks []string
1235 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001236 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001237
1238 requiredModuleNames []string
1239 targetRequiredModuleNames []string
1240 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001241
Colin Cross503c1d02020-01-28 14:00:53 -08001242 jacocoReportClassesFile android.Path // only for javalibs and apps
1243 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001244 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001245}
1246
Jiyong Park1833cef2019-12-13 13:28:36 +09001247func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1248 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001249 builtFile: builtFile,
1250 moduleName: moduleName,
1251 installDir: installDir,
1252 class: class,
1253 module: module,
1254 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001255 if module != nil {
1256 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001257 ret.requiredModuleNames = module.RequiredModuleNames()
1258 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1259 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001260 }
1261 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001262}
1263
1264func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001265 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001266}
1267
Jiyong Park7cd10e32020-01-14 09:22:18 +09001268// Path() returns path of this apex file relative to the APEX root
1269func (af *apexFile) Path() string {
1270 return filepath.Join(af.installDir, af.builtFile.Base())
1271}
1272
1273// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1274func (af *apexFile) SymlinkPaths() []string {
1275 var ret []string
1276 for _, symlink := range af.symlinks {
1277 ret = append(ret, filepath.Join(af.installDir, symlink))
1278 }
1279 return ret
1280}
1281
1282func (af *apexFile) AvailableToPlatform() bool {
1283 if af.module == nil {
1284 return false
1285 }
1286 if am, ok := af.module.(android.ApexModule); ok {
1287 return am.AvailableFor(android.AvailableToPlatform)
1288 }
1289 return false
1290}
1291
Jiyong Park678c8812020-02-07 17:25:49 +09001292type depInfo struct {
1293 to string
1294 from []string
1295 isExternal bool
1296}
1297
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001298type apexBundle struct {
1299 android.ModuleBase
1300 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001301 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001302 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001303
Jiyong Park5d790c32019-11-15 18:40:32 +09001304 properties apexBundleProperties
1305 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001306 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001307
Jooyung Hanf21c7972019-12-16 22:32:06 +09001308 // specific to apex_vndk modules
1309 vndkProperties apexVndkProperties
1310
Colin Crossa4925902018-11-16 11:36:28 -08001311 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001312 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001313 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001314
Jiyong Park03b68dd2019-07-26 23:20:40 +09001315 prebuiltFileToDelete string
1316
Jiyong Park42cca6c2019-04-01 11:15:50 +09001317 public_key_file android.Path
1318 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001319
1320 container_certificate_file android.Path
1321 container_private_key_file android.Path
1322
Jooyung Han54aca7b2019-11-20 02:26:02 +09001323 fileContexts android.Path
1324
Jiyong Park8fd61922018-11-08 02:50:25 +09001325 // list of files to be included in this apex
1326 filesInfo []apexFile
1327
Jiyong Park956305c2020-01-09 12:32:06 +09001328 // list of module names that should be installed along with this APEX
1329 requiredDeps []string
1330
Jiyong Park956305c2020-01-09 12:32:06 +09001331 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001332 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001333
Sundong Ahnabb64432019-10-22 13:58:29 +09001334 testApex bool
1335 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001336 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001337 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001338
Jooyung Han214bf372019-11-12 13:03:50 +09001339 manifestJsonOut android.WritablePath
1340 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001341
Jooyung Han002ab682020-01-08 01:57:58 +09001342 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001343 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001344 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001345 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1346 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001347
1348 // Suffix of module name in Android.mk
1349 // ".flattened", ".apex", ".zipapex", or ""
1350 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001351
1352 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001353
1354 // Whether to create symlink to the system file instead of having a file
1355 // inside the apex or not
1356 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001357
1358 // Struct holding the merged notice file paths in different formats
1359 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001360}
1361
Jiyong Park397e55e2018-10-24 21:09:55 +09001362func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001363 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001364 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001365 // Use *FarVariation* to be able to depend on modules having
1366 // conflicting variations with this module. This is required since
1367 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1368 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001369 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001370 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001371 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001372 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001373 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001374
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001375 ctx.AddFarVariationDependencies(append(target.Variations(),
1376 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1377 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001378
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001379 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001380 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001381 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001382 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001383}
1384
Alex Light9670d332019-01-29 18:07:33 -08001385func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1386 if ctx.Os().Class == android.Device {
1387 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1388 } else {
1389 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1390 if ctx.Os().Bionic() {
1391 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1392 } else {
1393 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1394 }
1395 }
1396}
1397
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001398func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001399 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1400 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1401 }
1402
Jiyong Park397e55e2018-10-24 21:09:55 +09001403 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001404 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001405
1406 a.combineProperties(ctx)
1407
Jiyong Park397e55e2018-10-24 21:09:55 +09001408 has32BitTarget := false
1409 for _, target := range targets {
1410 if target.Arch.ArchType.Multilib == "lib32" {
1411 has32BitTarget = true
1412 }
1413 }
1414 for i, target := range targets {
1415 // When multilib.* is omitted for native_shared_libs, it implies
1416 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001417 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001418 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001419 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001420 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001421
Roland Levillain630846d2019-06-26 12:48:34 +01001422 // When multilib.* is omitted for tests, it implies
1423 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001424 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001425 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001426 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001427 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001428
Jiyong Park397e55e2018-10-24 21:09:55 +09001429 // Add native modules targetting both ABIs
1430 addDependenciesForNativeModules(ctx,
1431 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001432 a.properties.Multilib.Both.Binaries,
1433 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001434 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001435 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001436
Alex Light3d673592019-01-18 14:37:31 -08001437 isPrimaryAbi := i == 0
1438 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 // When multilib.* is omitted for binaries, it implies
1440 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 ctx.AddFarVariationDependencies(append(target.Variations(),
1442 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1443 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001444
1445 // Add native modules targetting the first ABI
1446 addDependenciesForNativeModules(ctx,
1447 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001448 a.properties.Multilib.First.Binaries,
1449 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001451 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001452 }
1453
1454 switch target.Arch.ArchType.Multilib {
1455 case "lib32":
1456 // Add native modules targetting 32-bit ABI
1457 addDependenciesForNativeModules(ctx,
1458 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001459 a.properties.Multilib.Lib32.Binaries,
1460 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001461 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001462 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001463
1464 addDependenciesForNativeModules(ctx,
1465 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001466 a.properties.Multilib.Prefer32.Binaries,
1467 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001468 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001469 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001470 case "lib64":
1471 // Add native modules targetting 64-bit ABI
1472 addDependenciesForNativeModules(ctx,
1473 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001474 a.properties.Multilib.Lib64.Binaries,
1475 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001476 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001477 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001478
1479 if !has32BitTarget {
1480 addDependenciesForNativeModules(ctx,
1481 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001482 a.properties.Multilib.Prefer32.Binaries,
1483 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001485 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001486 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001487
1488 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1489 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1490 if sanitizer == "hwaddress" {
1491 addDependenciesForNativeModules(ctx,
1492 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001493 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001494 break
1495 }
1496 }
1497 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001498 }
1499
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001500 }
1501
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001502 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1503 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1504 // b/144532908
1505 archForPrebuiltEtc := config.Arches()[0]
1506 for _, arch := range config.Arches() {
1507 // Prefer 64-bit arch if there is any
1508 if arch.ArchType.Multilib == "lib64" {
1509 archForPrebuiltEtc = arch
1510 break
1511 }
1512 }
1513 ctx.AddFarVariationDependencies([]blueprint.Variation{
1514 {Mutator: "os", Variation: ctx.Os().String()},
1515 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1516 }, prebuiltTag, a.properties.Prebuilts...)
1517
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001518 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1519 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001520
Ulya Trafimovich44561882020-01-03 13:25:54 +00001521 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1522 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1523 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1524 javaLibTag, "jacocoagent")
1525 }
1526
Jiyong Park23c52b02019-02-02 13:13:47 +09001527 if String(a.properties.Key) == "" {
1528 ctx.ModuleErrorf("key is missing")
1529 return
1530 }
1531 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001532
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001533 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001534 if cert != "" {
1535 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001536 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001537
1538 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1539 if len(a.properties.Uses_sdks) > 0 {
1540 sdkRefs := []android.SdkRef{}
1541 for _, str := range a.properties.Uses_sdks {
1542 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1543 sdkRefs = append(sdkRefs, parsed)
1544 }
1545 a.BuildWithSdks(sdkRefs)
1546 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001547}
1548
Jiyong Park5d790c32019-11-15 18:40:32 +09001549func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1550 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1551 androidAppTag, a.overridableProperties.Apps...)
1552}
1553
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001554func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1555 // direct deps of an APEX bundle are all part of the APEX bundle
1556 return true
1557}
1558
Colin Cross0ea8ba82019-06-06 14:33:29 -07001559func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001560 moduleName := ctx.ModuleName()
1561 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1562 // we check with the pseudo module name to see if its certificate is overridden.
1563 if a.vndkApex {
1564 moduleName = vndkApexName
1565 }
1566 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001567 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001568 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001569 }
1570 return String(a.properties.Certificate)
1571}
1572
Colin Cross41955e82019-05-29 14:40:35 -07001573func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1574 switch tag {
1575 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001576 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001577 default:
1578 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001579 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001580}
1581
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001582func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001583 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001584}
1585
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001586func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1587 return proptools.Bool(a.properties.Test_only_no_hashtree)
1588}
1589
Jiyong Park7c1dc612019-01-05 11:15:24 +09001590func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001591 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001592 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001593 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001594 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001595 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001596 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001597 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001598 }
1599}
1600
Jiyong Parkf97782b2019-02-13 20:28:58 +09001601func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1602 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1603 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1604 }
1605}
1606
Jiyong Park388ef3f2019-01-28 19:47:32 +09001607func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001608 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1609 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001610 }
1611
1612 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001613 globalSanitizerNames := []string{}
1614 if a.Host() {
1615 globalSanitizerNames = ctx.Config().SanitizeHost()
1616 } else {
1617 arches := ctx.Config().SanitizeDeviceArch()
1618 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1619 globalSanitizerNames = ctx.Config().SanitizeDevice()
1620 }
1621 }
1622 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001623}
1624
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001625func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001626 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001627}
1628
1629func (a *apexBundle) PreventInstall() {
1630 a.properties.PreventInstall = true
1631}
1632
1633func (a *apexBundle) HideFromMake() {
1634 a.properties.HideFromMake = true
1635}
1636
Jiyong Park956305c2020-01-09 12:32:06 +09001637func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1638 a.properties.IsCoverageVariant = coverage
1639}
1640
Jiyong Parkf653b052019-11-18 15:39:01 +09001641// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001642func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001643 // Decide the APEX-local directory by the multilib of the library
1644 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001645 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001646 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001647 case "lib32":
1648 dirInApex = "lib"
1649 case "lib64":
1650 dirInApex = "lib64"
1651 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001652 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001653 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001654 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001655 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001656 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001657 // Special case for Bionic libs and other libs installed with them. This is
1658 // to prevent those libs from being included in the search path
1659 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1660 // those libs in the Runtime APEX are available via the legacy paths in
1661 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1662 // to the legacy paths and thus will be loaded into the default linker
1663 // namespace (aka "platform" namespace). If the libs are directly in
1664 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1665 // into the runtime linker namespace, which will result in double loading of
1666 // them, which isn't supported.
1667 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001668 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001669
Jiyong Parkf653b052019-11-18 15:39:01 +09001670 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001671 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001672}
1673
Jiyong Park1833cef2019-12-13 13:28:36 +09001674func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001676 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001677 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001678 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001680 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001681 af.symlinks = cc.Symlinks()
1682 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001683}
1684
Jiyong Park1833cef2019-12-13 13:28:36 +09001685func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 dirInApex := "bin"
1687 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001688 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001689}
Jiyong Park1833cef2019-12-13 13:28:36 +09001690func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001692 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1693 if err != nil {
1694 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001696 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001697 fileToCopy := android.PathForOutput(ctx, s)
1698 // NB: Since go binaries are static we don't need the module for anything here, which is
1699 // good since the go tool is a blueprint.Module not an android.Module like we would
1700 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001701 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001702}
1703
Jiyong Park1833cef2019-12-13 13:28:36 +09001704func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 dirInApex := filepath.Join("bin", sh.SubDir())
1706 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001707 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001708 af.symlinks = sh.Symlinks()
1709 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001710}
1711
Jooyung Han58f26ab2019-12-18 15:34:32 +09001712// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1713type javaLibrary interface {
1714 android.Module
1715 java.Dependency
1716}
1717
1718func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001720 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001721 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1722 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1723 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001724}
1725
Jiyong Park1833cef2019-12-13 13:28:36 +09001726func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1728 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001729 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001730}
1731
atrost6e126252020-01-27 17:01:16 +00001732func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1733 dirInApex := filepath.Join("etc", config.SubDir())
1734 fileToCopy := config.CompatConfig()
1735 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1736}
1737
Jiyong Park1833cef2019-12-13 13:28:36 +09001738func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001739 android.Module
1740 Privileged() bool
1741 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001742 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001743 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001744}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001745 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001747 appDir = "priv-app"
1748 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 dirInApex := filepath.Join(appDir, pkgName)
1750 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001751 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1752 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001753 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001754
1755 if app, ok := aapp.(interface {
1756 OverriddenManifestPackageName() string
1757 }); ok {
1758 af.overriddenPackageName = app.OverriddenManifestPackageName()
1759 }
Jiyong Park618922e2020-01-08 13:35:43 +09001760 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001761}
1762
Roland Levillain935639d2019-08-13 14:55:28 +01001763// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1764type flattenedApexContext struct {
1765 android.ModuleContext
1766}
1767
1768func (c *flattenedApexContext) InstallBypassMake() bool {
1769 return true
1770}
1771
Paul Duffin133608f2020-03-30 15:54:08 +01001772// Function called while walking an APEX's payload dependencies.
1773//
1774// Return true if the `to` module should be visited, false otherwise.
1775type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1776
Jiyong Park201cedd2020-02-07 17:25:49 +09001777// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001778func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001779 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001780 am, ok := child.(android.ApexModule)
1781 if !ok || !am.CanHaveApexVariants() {
1782 return false
1783 }
1784
1785 // Check for the direct dependencies that contribute to the payload
1786 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1787 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001788 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001789 }
Paul Duffin133608f2020-03-30 15:54:08 +01001790 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001791 return false
1792 }
1793
1794 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001795 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001796 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001797 }
1798
Paul Duffin133608f2020-03-30 15:54:08 +01001799 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001800 })
1801}
1802
Jooyung Han0c4e0162020-02-26 22:45:42 +09001803func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1804 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001805 intVer, err := android.ApiStrToNum(ctx, ver)
1806 if err != nil {
1807 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001808 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001809 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001810}
1811
Jiyong Park201cedd2020-02-07 17:25:49 +09001812// Ensures that the dependencies are marked as available for this APEX
1813func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1814 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1815 if ctx.Host() || a.testApex || a.vndkApex {
1816 return
1817 }
1818
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001819 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1820 // Requiring them and their transitive depencies with apex_available is not right
1821 // because they just add noise.
1822 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1823 return
1824 }
1825
Paul Duffin133608f2020-03-30 15:54:08 +01001826 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1827 if externalDep {
1828 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1829 return false
1830 }
1831
Jiyong Park201cedd2020-02-07 17:25:49 +09001832 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001833 fromName := ctx.OtherModuleName(from)
1834 toName := ctx.OtherModuleName(to)
Paul Duffin133608f2020-03-30 15:54:08 +01001835 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1836 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001837 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001838 message := ""
1839 for _, m := range ctx.GetWalkPath()[1:] {
1840 message = fmt.Sprintf("%s\n -> %s", message, m.String())
1841 }
1842 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffin133608f2020-03-30 15:54:08 +01001843 // Visit this module's dependencies to check and report any issues with their availability.
1844 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001845 })
1846}
1847
Jiyong Park678c8812020-02-07 17:25:49 +09001848// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1849func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1850 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001851 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001852 if from.Name() == to.Name() {
1853 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001854 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1855 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001856 }
1857
1858 if info, exists := a.depInfos[to.Name()]; exists {
1859 if !android.InList(from.Name(), info.from) {
1860 info.from = append(info.from, from.Name())
1861 }
1862 info.isExternal = info.isExternal && externalDep
1863 a.depInfos[to.Name()] = info
1864 } else {
1865 a.depInfos[to.Name()] = depInfo{
1866 to: to.Name(),
1867 from: []string{from.Name()},
1868 isExternal: externalDep,
1869 }
1870 }
Paul Duffin133608f2020-03-30 15:54:08 +01001871
1872 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1873 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001874 })
1875}
1876
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001877func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001878 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1879 switch a.properties.ApexType {
1880 case imageApex:
1881 if buildFlattenedAsDefault {
1882 a.suffix = imageApexSuffix
1883 } else {
1884 a.suffix = ""
1885 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001886
1887 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001888 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001889 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001890 }
1891 case zipApex:
1892 if proptools.String(a.properties.Payload_type) == "zip" {
1893 a.suffix = ""
1894 a.primaryApexType = true
1895 } else {
1896 a.suffix = zipApexSuffix
1897 }
1898 case flattenedApex:
1899 if buildFlattenedAsDefault {
1900 a.suffix = ""
1901 a.primaryApexType = true
1902 } else {
1903 a.suffix = flattenedSuffix
1904 }
Alex Light5098a612018-11-29 17:12:15 -08001905 }
1906
Roland Levillain630846d2019-06-26 12:48:34 +01001907 if len(a.properties.Tests) > 0 && !a.testApex {
1908 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1909 return
1910 }
1911
Jiyong Parkfa899442020-01-31 02:49:53 +09001912 a.checkApexAvailability(ctx)
1913
Jiyong Park678c8812020-02-07 17:25:49 +09001914 a.collectDepsInfo(ctx)
1915
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001916 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1917
Jooyung Hane1633032019-08-01 17:41:43 +09001918 // native lib dependencies
1919 var provideNativeLibs []string
1920 var requireNativeLibs []string
1921
Jooyung Han5c998b92019-06-27 11:30:33 +09001922 // Check if "uses" requirements are met with dependent apexBundles
1923 var providedNativeSharedLibs []string
1924 useVendor := proptools.Bool(a.properties.Use_vendor)
1925 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1926 if ctx.OtherModuleDependencyTag(m) != usesTag {
1927 return
1928 }
1929 otherName := ctx.OtherModuleName(m)
1930 other, ok := m.(*apexBundle)
1931 if !ok {
1932 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1933 return
1934 }
1935 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1936 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1937 return
1938 }
1939 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1940 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1941 return
1942 }
1943 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1944 })
1945
Jiyong Parkf653b052019-11-18 15:39:01 +09001946 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001947 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001948 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001949 depTag := ctx.OtherModuleDependencyTag(child)
1950 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001951 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001952 switch depTag {
1953 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001954 if c, ok := child.(*cc.Module); ok {
1955 // bootstrap bionic libs are treated as provided by system
1956 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1957 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001958 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001959 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001960 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001961 } else {
1962 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001963 }
1964 case executableTag:
1965 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001966 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001968 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001970 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001971 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001972 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001973 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001974 } else {
Alex Light778127a2019-02-27 14:19:50 -08001975 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 +09001976 }
1977 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001978 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001979 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001981 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1982 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001983 filesInfo = append(filesInfo, af)
1984 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001985 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001986 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1987 af := apexFileForJavaLibrary(ctx, sdkLib)
1988 if !af.Ok() {
1989 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1990 return false
1991 }
1992 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001993 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001995 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001996 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001997 case androidAppTag:
1998 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1999 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002000 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 return true // track transitive dependencies
2002 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002003 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002004 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2005 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002006 } else {
2007 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2008 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002009 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002010 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002011 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002012 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2013 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 } else {
atrost6e126252020-01-27 17:01:16 +00002015 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002016 }
Roland Levillain630846d2019-06-26 12:48:34 +01002017 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002018 if ccTest, ok := child.(*cc.Module); ok {
2019 if ccTest.IsTestPerSrcAllTestsVariation() {
2020 // Multiple-output test module (where `test_per_src: true`).
2021 //
2022 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2023 // We do not add this variation to `filesInfo`, as it has no output;
2024 // however, we do add the other variations of this module as indirect
2025 // dependencies (see below).
2026 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002027 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002028 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002029 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002030 af.class = nativeTest
2031 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002032 }
Roland Levillain630846d2019-06-26 12:48:34 +01002033 } else {
2034 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2035 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002036 case keyTag:
2037 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002038 a.private_key_file = key.private_key_file
2039 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002040 } else {
2041 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002042 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002043 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002044 case certificateTag:
2045 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002046 a.container_certificate_file = dep.Certificate.Pem
2047 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002048 } else {
2049 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2050 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002051 case android.PrebuiltDepTag:
2052 // If the prebuilt is force disabled, remember to delete the prebuilt file
2053 // that might have been installed in the previous builds
2054 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2055 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2056 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002058 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002059 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002060 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002061 // We cannot use a switch statement on `depTag` here as the checked
2062 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002063 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002064 if cc, ok := child.(*cc.Module); ok {
2065 if android.InList(cc.Name(), providedNativeSharedLibs) {
2066 // If we're using a shared library which is provided from other APEX,
2067 // don't include it in this APEX
2068 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002069 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002070 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002071 // If the dependency is a stubs lib, don't include it in this APEX,
2072 // but make sure that the lib is installed on the device.
2073 // In case no APEX is having the lib, the lib is installed to the system
2074 // partition.
2075 //
2076 // Always include if we are a host-apex however since those won't have any
2077 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002078 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2079 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 }
Jooyung Hane1633032019-08-01 17:41:43 +09002081 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002082 // Don't track further
2083 return false
2084 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002085 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002086 af.transitiveDep = true
2087 filesInfo = append(filesInfo, af)
2088 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002089 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002090 } else if cc.IsTestPerSrcDepTag(depTag) {
2091 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002092 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002093 // Handle modules created as `test_per_src` variations of a single test module:
2094 // use the name of the generated test binary (`fileToCopy`) instead of the name
2095 // of the original test module (`depName`, shared by all `test_per_src`
2096 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002097 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002098 // these are not considered transitive dep
2099 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002100 filesInfo = append(filesInfo, af)
2101 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002102 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002103 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002104 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2105 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002106 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2107 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2108 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2109 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002110 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002111 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002112 }
2113 }
2114 }
2115 return false
2116 })
2117
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002118 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2119 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2120 // via the global boot image config.
2121 if a.artApex {
2122 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2123 dirInApex := filepath.Join("javalib", arch.String())
2124 for _, f := range files {
2125 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002126 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002127 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002128 }
2129 }
2130 }
2131
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002132 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002133 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2134 return
2135 }
2136
Jiyong Park8fd61922018-11-08 02:50:25 +09002137 // remove duplicates in filesInfo
2138 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002139 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002140 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002141 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002142 if e, ok := encountered[dest]; !ok {
2143 encountered[dest] = f
2144 } else {
2145 // If a module is directly included and also transitively depended on
2146 // consider it as directly included.
2147 e.transitiveDep = e.transitiveDep && f.transitiveDep
2148 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002149 }
2150 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002151 var result []apexFile
2152 for _, v := range encountered {
2153 result = append(result, v)
2154 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002155 return result
2156 }
2157 filesInfo = removeDup(filesInfo)
2158
2159 // to have consistent build rules
2160 sort.Slice(filesInfo, func(i, j int) bool {
2161 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2162 })
2163
Jiyong Park8fd61922018-11-08 02:50:25 +09002164 a.installDir = android.PathForModuleInstall(ctx, "apex")
2165 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002166
Jooyung Han54aca7b2019-11-20 02:26:02 +09002167 if a.properties.ApexType != zipApex {
2168 if a.properties.File_contexts == nil {
2169 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2170 } else {
2171 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2172 if a.Platform() {
2173 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2174 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2175 }
2176 }
2177 }
2178 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2179 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2180 return
2181 }
2182 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002183 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2184 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2185 // the same library in the system partition, thus effectively sharing the same libraries
2186 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2187 // in the APEX.
2188 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2189 a.installable() &&
2190 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002191
Jiyong Park9d677202020-02-19 16:29:35 +09002192 // We don't need the optimization for updatable APEXes, as it might give false signal
2193 // to the system health when the APEXes are still bundled (b/149805758)
2194 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2195 a.linkToSystemLib = false
2196 }
2197
Jiyong Park9b964182020-02-26 18:27:19 +09002198 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2199 if ctx.Host() {
2200 a.linkToSystemLib = false
2201 }
2202
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002203 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002204 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2205
2206 a.setCertificateAndPrivateKey(ctx)
2207 if a.properties.ApexType == flattenedApex {
2208 a.buildFlattenedApex(ctx)
2209 } else {
2210 a.buildUnflattenedApex(ctx)
2211 }
2212
Jooyung Han002ab682020-01-08 01:57:58 +09002213 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002214
2215 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002216}
2217
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002218func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002219 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002220 moduleName = normalizeModuleName(moduleName)
2221
2222 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2223 return true
2224 }
2225
2226 key = android.AvailableToAnyApex
2227 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2228 return true
2229 }
2230
2231 return false
2232}
2233
2234func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002235 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2236 // system. Trim the prefix for the check since they are confusing
2237 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2238 if strings.HasPrefix(moduleName, "libclang_rt.") {
2239 // This module has many arch variants that depend on the product being built.
2240 // We don't want to list them all
2241 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002242 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002243 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002244}
2245
Jooyung Han344d5432019-08-23 11:17:39 +09002246func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002247 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002248 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002249 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002250 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002251 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002252 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2253 })
Alex Light5098a612018-11-29 17:12:15 -08002254 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002255 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002256 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002257 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002258 return module
2259}
Jiyong Park30ca9372019-02-07 16:27:23 +09002260
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002261func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002262 bundle := newApexBundle()
2263 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002264 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002265 return bundle
2266}
2267
Jiyong Parkfce0b422020-02-11 03:56:06 +09002268// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2269// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002270func testApexBundleFactory() android.Module {
2271 bundle := newApexBundle()
2272 bundle.testApex = true
2273 return bundle
2274}
2275
Jiyong Parkfce0b422020-02-11 03:56:06 +09002276// apex packages other modules into an APEX file which is a packaging format for system-level
2277// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002278func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002279 return newApexBundle()
2280}
2281
Jiyong Park30ca9372019-02-07 16:27:23 +09002282//
2283// Defaults
2284//
2285type Defaults struct {
2286 android.ModuleBase
2287 android.DefaultsModuleBase
2288}
2289
Jiyong Park30ca9372019-02-07 16:27:23 +09002290func defaultsFactory() android.Module {
2291 return DefaultsFactory()
2292}
2293
2294func DefaultsFactory(props ...interface{}) android.Module {
2295 module := &Defaults{}
2296
2297 module.AddProperties(props...)
2298 module.AddProperties(
2299 &apexBundleProperties{},
2300 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002301 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002302 )
2303
2304 android.InitDefaultsModule(module)
2305 return module
2306}
Jiyong Park5d790c32019-11-15 18:40:32 +09002307
2308//
2309// OverrideApex
2310//
2311type OverrideApex struct {
2312 android.ModuleBase
2313 android.OverrideModuleBase
2314}
2315
2316func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2317 // All the overrides happen in the base module.
2318}
2319
2320// override_apex is used to create an apex module based on another apex module
2321// by overriding some of its properties.
2322func overrideApexFactory() android.Module {
2323 m := &OverrideApex{}
2324 m.AddProperties(&overridableProperties{})
2325
2326 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2327 android.InitOverrideModule(m)
2328 return m
2329}