blob: eb87ecf275358ab6c03c4afa35ac810f10cb8a93 [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
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100865 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900866
Jiyong Parkf760cae2020-02-12 07:53:12 +0900867 mctx.VisitDirectDeps(func(child android.Module) {
868 depName := mctx.OtherModuleName(child)
869 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900870 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800871 android.UpdateApexDependency(apexBundles, depName, directDep)
872 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900873 }
874 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900875}
876
877// Create apex variations if a module is included in APEX(s).
878func apexMutator(mctx android.BottomUpMutatorContext) {
879 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900880 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000881 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900882 // apex bundle itself is mutated so that it and its modules have same
883 // apex variant.
884 apexBundleName := mctx.ModuleName()
885 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900886 } else if o, ok := mctx.Module().(*OverrideApex); ok {
887 apexBundleName := o.GetOverriddenModuleName()
888 if apexBundleName == "" {
889 mctx.ModuleErrorf("base property is not set")
890 return
891 }
892 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900893 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900894
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900895}
Sundong Ahne9b55722019-09-06 17:37:42 +0900896
Jooyung Han7a78a922019-10-08 21:59:58 +0900897var (
898 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
899 apexFileContextsInfosMutex sync.Mutex
900)
901
902func apexFileContextsInfos(config android.Config) *[]string {
903 return config.Once(apexFileContextsInfosKey, func() interface{} {
904 return &[]string{}
905 }).(*[]string)
906}
907
Jooyung Han54aca7b2019-11-20 02:26:02 +0900908func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900909 apexFileContextsInfosMutex.Lock()
910 defer apexFileContextsInfosMutex.Unlock()
911 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900912 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900913}
914
Sundong Ahne9b55722019-09-06 17:37:42 +0900915func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900916 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900917 var variants []string
918 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
919 case "image":
920 variants = append(variants, imageApexType, flattenedApexType)
921 case "zip":
922 variants = append(variants, zipApexType)
923 case "both":
924 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
925 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900926 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900927 return
928 }
929
930 modules := mctx.CreateLocalVariations(variants...)
931
932 for i, v := range variants {
933 switch v {
934 case imageApexType:
935 modules[i].(*apexBundle).properties.ApexType = imageApex
936 case zipApexType:
937 modules[i].(*apexBundle).properties.ApexType = zipApex
938 case flattenedApexType:
939 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900940 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900941 modules[i].(*apexBundle).MakeAsSystemExt()
942 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900943 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900944 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900945 } else if _, ok := mctx.Module().(*OverrideApex); ok {
946 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900947 }
948}
949
Jooyung Han5c998b92019-06-27 11:30:33 +0900950func apexUsesMutator(mctx android.BottomUpMutatorContext) {
951 if ab, ok := mctx.Module().(*apexBundle); ok {
952 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
953 }
954}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900955
Jooyung Handc782442019-11-01 03:14:38 +0900956var (
957 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
958)
959
960// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
961// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
962// which may cause compatibility issues. (e.g. libbinder)
963// Even though libbinder restricts its availability via 'apex_available' property and relies on
964// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
965// to avoid similar problems.
966func useVendorWhitelist(config android.Config) []string {
967 return config.Once(useVendorWhitelistKey, func() interface{} {
968 return []string{
969 // swcodec uses "vendor" variants for smaller size
970 "com.android.media.swcodec",
971 "test_com.android.media.swcodec",
972 }
973 }).([]string)
974}
975
976// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
977// called before the first call to useVendorWhitelist()
978func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
979 config.Once(useVendorWhitelistKey, func() interface{} {
980 return whitelist
981 })
982}
983
Alex Light9670d332019-01-29 18:07:33 -0800984type apexNativeDependencies struct {
985 // List of native libraries
986 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900987
Alex Light9670d332019-01-29 18:07:33 -0800988 // List of native executables
989 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900990
Roland Levillain630846d2019-06-26 12:48:34 +0100991 // List of native tests
992 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800993}
Jooyung Han344d5432019-08-23 11:17:39 +0900994
Alex Light9670d332019-01-29 18:07:33 -0800995type apexMultilibProperties struct {
996 // Native dependencies whose compile_multilib is "first"
997 First apexNativeDependencies
998
999 // Native dependencies whose compile_multilib is "both"
1000 Both apexNativeDependencies
1001
1002 // Native dependencies whose compile_multilib is "prefer32"
1003 Prefer32 apexNativeDependencies
1004
1005 // Native dependencies whose compile_multilib is "32"
1006 Lib32 apexNativeDependencies
1007
1008 // Native dependencies whose compile_multilib is "64"
1009 Lib64 apexNativeDependencies
1010}
1011
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001012type apexBundleProperties struct {
1013 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001014 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001015 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001016
Jiyong Park40e26a22019-02-08 02:53:06 +09001017 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1018 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001019 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001020
Roland Levillain411c5842019-09-19 16:37:20 +01001021 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1022 // device (/apex/<apex_name>).
1023 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001024 Apex_name *string
1025
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001026 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001027 // For platform APEXes, this should points to a file under /system/sepolicy
1028 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1029 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001030
1031 // List of native shared libs that are embedded inside this APEX bundle
1032 Native_shared_libs []string
1033
Roland Levillain630846d2019-06-26 12:48:34 +01001034 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001035 Binaries []string
1036
1037 // List of java libraries that are embedded inside this APEX bundle
1038 Java_libs []string
1039
1040 // List of prebuilt files that are embedded inside this APEX bundle
1041 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001042
Roland Levillain630846d2019-06-26 12:48:34 +01001043 // List of tests that are embedded inside this APEX bundle
1044 Tests []string
1045
Jiyong Parkff1458f2018-10-12 21:49:38 +09001046 // Name of the apex_key module that provides the private key to sign APEX
1047 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001048
Alex Light5098a612018-11-29 17:12:15 -08001049 // The type of APEX to build. Controls what the APEX payload is. Either
1050 // 'image', 'zip' or 'both'. Default: 'image'.
1051 Payload_type *string
1052
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001053 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1054 // or an android_app_certificate module name in the form ":module".
1055 Certificate *string
1056
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001057 // Whether this APEX is installable to one of the partitions. Default: true.
1058 Installable *bool
1059
Jiyong Parkda6eb592018-12-19 17:12:36 +09001060 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1061 // Default is false.
1062 Use_vendor *bool
1063
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001064 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1065 Ignore_system_library_special_case *bool
1066
Alex Light9670d332019-01-29 18:07:33 -08001067 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001068
Jiyong Parkf97782b2019-02-13 20:28:58 +09001069 // List of sanitizer names that this APEX is enabled for
1070 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001071
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001072 PreventInstall bool `blueprint:"mutated"`
1073
1074 HideFromMake bool `blueprint:"mutated"`
1075
Jooyung Han5c998b92019-06-27 11:30:33 +09001076 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1077 Provide_cpp_shared_libs *bool
1078
1079 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1080 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001081
1082 // A txt file containing list of files that are whitelisted to be included in this APEX.
1083 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001084
Sundong Ahnabb64432019-10-22 13:58:29 +09001085 // package format of this apex variant; could be non-flattened, flattened, or zip.
1086 // imageApex, zipApex or flattened
1087 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001088
Jiyong Parkd1063c12019-07-17 20:08:41 +09001089 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1090 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1091 // is implied. This value affects all modules included in this APEX. In other words, they are
1092 // also built with the SDKs specified here.
1093 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001094
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001095 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1096 // Should be only used in tests#.
1097 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001098
Jiyong Park956305c2020-01-09 12:32:06 +09001099 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001100
1101 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1102 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1103 // like symlinking to the system libs. Default is false.
1104 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001105
1106 // The minimum SDK version that this apex must be compatible with.
1107 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001108}
1109
1110type apexTargetBundleProperties struct {
1111 Target struct {
1112 // Multilib properties only for android.
1113 Android struct {
1114 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001115 }
Jooyung Han344d5432019-08-23 11:17:39 +09001116
Alex Light9670d332019-01-29 18:07:33 -08001117 // Multilib properties only for host.
1118 Host struct {
1119 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001120 }
Jooyung Han344d5432019-08-23 11:17:39 +09001121
Alex Light9670d332019-01-29 18:07:33 -08001122 // Multilib properties only for host linux_bionic.
1123 Linux_bionic struct {
1124 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001125 }
Jooyung Han344d5432019-08-23 11:17:39 +09001126
Alex Light9670d332019-01-29 18:07:33 -08001127 // Multilib properties only for host linux_glibc.
1128 Linux_glibc struct {
1129 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001130 }
1131 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001132}
1133
Jiyong Park5d790c32019-11-15 18:40:32 +09001134type overridableProperties struct {
1135 // List of APKs to package inside APEX
1136 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001137
1138 // Names of modules to be overridden. Listed modules can only be other binaries
1139 // (in Make or Soong).
1140 // This does not completely prevent installation of the overridden binaries, but if both
1141 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1142 // from PRODUCT_PACKAGES.
1143 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001144
1145 // Logging Parent value
1146 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001147
1148 // Apex Container Package Name.
1149 // Override value for attribute package:name in AndroidManifest.xml
1150 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001151}
1152
Alex Light5098a612018-11-29 17:12:15 -08001153type apexPackaging int
1154
1155const (
1156 imageApex apexPackaging = iota
1157 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001158 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001159)
1160
Sundong Ahnabb64432019-10-22 13:58:29 +09001161// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001162func (a apexPackaging) suffix() string {
1163 switch a {
1164 case imageApex:
1165 return imageApexSuffix
1166 case zipApex:
1167 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001168 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001169 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001170 }
1171}
1172
1173func (a apexPackaging) name() string {
1174 switch a {
1175 case imageApex:
1176 return imageApexType
1177 case zipApex:
1178 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001179 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001180 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001181 }
1182}
1183
Jiyong Parkf653b052019-11-18 15:39:01 +09001184type apexFileClass int
1185
1186const (
1187 etc apexFileClass = iota
1188 nativeSharedLib
1189 nativeExecutable
1190 shBinary
1191 pyBinary
1192 goBinary
1193 javaSharedLib
1194 nativeTest
1195 app
1196)
1197
Jiyong Park8fd61922018-11-08 02:50:25 +09001198func (class apexFileClass) NameInMake() string {
1199 switch class {
1200 case etc:
1201 return "ETC"
1202 case nativeSharedLib:
1203 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001204 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001205 return "EXECUTABLES"
1206 case javaSharedLib:
1207 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001208 case nativeTest:
1209 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001210 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001211 // b/142537672 Why isn't this APP? We want to have full control over
1212 // the paths and file names of the apk file under the flattend APEX.
1213 // If this is set to APP, then the paths and file names are modified
1214 // by the Make build system. For example, it is installed to
1215 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1216 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1217 // appends module name (which is <apexname>.<Appname> to the path.
1218 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001219 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001220 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001221 }
1222}
1223
Jiyong Parkf653b052019-11-18 15:39:01 +09001224// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001225type apexFile struct {
1226 builtFile android.Path
1227 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001228 installDir string
1229 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001230 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001231 // list of symlinks that will be created in installDir that point to this apexFile
1232 symlinks []string
1233 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001234 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001235
1236 requiredModuleNames []string
1237 targetRequiredModuleNames []string
1238 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001239
Colin Cross503c1d02020-01-28 14:00:53 -08001240 jacocoReportClassesFile android.Path // only for javalibs and apps
1241 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001242 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001243}
1244
Jiyong Park1833cef2019-12-13 13:28:36 +09001245func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1246 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001247 builtFile: builtFile,
1248 moduleName: moduleName,
1249 installDir: installDir,
1250 class: class,
1251 module: module,
1252 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001253 if module != nil {
1254 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001255 ret.requiredModuleNames = module.RequiredModuleNames()
1256 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1257 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001258 }
1259 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001260}
1261
1262func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001263 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001264}
1265
Jiyong Park7cd10e32020-01-14 09:22:18 +09001266// Path() returns path of this apex file relative to the APEX root
1267func (af *apexFile) Path() string {
1268 return filepath.Join(af.installDir, af.builtFile.Base())
1269}
1270
1271// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1272func (af *apexFile) SymlinkPaths() []string {
1273 var ret []string
1274 for _, symlink := range af.symlinks {
1275 ret = append(ret, filepath.Join(af.installDir, symlink))
1276 }
1277 return ret
1278}
1279
1280func (af *apexFile) AvailableToPlatform() bool {
1281 if af.module == nil {
1282 return false
1283 }
1284 if am, ok := af.module.(android.ApexModule); ok {
1285 return am.AvailableFor(android.AvailableToPlatform)
1286 }
1287 return false
1288}
1289
Jiyong Park678c8812020-02-07 17:25:49 +09001290type depInfo struct {
1291 to string
1292 from []string
1293 isExternal bool
1294}
1295
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001296type apexBundle struct {
1297 android.ModuleBase
1298 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001299 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001300 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001301
Jiyong Park5d790c32019-11-15 18:40:32 +09001302 properties apexBundleProperties
1303 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001304 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001305
Jooyung Hanf21c7972019-12-16 22:32:06 +09001306 // specific to apex_vndk modules
1307 vndkProperties apexVndkProperties
1308
Colin Crossa4925902018-11-16 11:36:28 -08001309 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001310 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001311 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001312
Jiyong Park03b68dd2019-07-26 23:20:40 +09001313 prebuiltFileToDelete string
1314
Jiyong Park42cca6c2019-04-01 11:15:50 +09001315 public_key_file android.Path
1316 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001317
1318 container_certificate_file android.Path
1319 container_private_key_file android.Path
1320
Jooyung Han54aca7b2019-11-20 02:26:02 +09001321 fileContexts android.Path
1322
Jiyong Park8fd61922018-11-08 02:50:25 +09001323 // list of files to be included in this apex
1324 filesInfo []apexFile
1325
Jiyong Park956305c2020-01-09 12:32:06 +09001326 // list of module names that should be installed along with this APEX
1327 requiredDeps []string
1328
Jiyong Park956305c2020-01-09 12:32:06 +09001329 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001330 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001331
Sundong Ahnabb64432019-10-22 13:58:29 +09001332 testApex bool
1333 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001334 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001335 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001336
Jooyung Han214bf372019-11-12 13:03:50 +09001337 manifestJsonOut android.WritablePath
1338 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001339
Jooyung Han002ab682020-01-08 01:57:58 +09001340 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001341 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001342 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001343 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1344 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001345
1346 // Suffix of module name in Android.mk
1347 // ".flattened", ".apex", ".zipapex", or ""
1348 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001349
1350 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001351
1352 // Whether to create symlink to the system file instead of having a file
1353 // inside the apex or not
1354 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001355
1356 // Struct holding the merged notice file paths in different formats
1357 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001358}
1359
Jiyong Park397e55e2018-10-24 21:09:55 +09001360func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001361 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001362 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001363 // Use *FarVariation* to be able to depend on modules having
1364 // conflicting variations with this module. This is required since
1365 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1366 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001367 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001368 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001369 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001370 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001371 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001372
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001373 ctx.AddFarVariationDependencies(append(target.Variations(),
1374 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1375 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001376
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001377 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001378 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001379 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001380 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001381}
1382
Alex Light9670d332019-01-29 18:07:33 -08001383func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1384 if ctx.Os().Class == android.Device {
1385 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1386 } else {
1387 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1388 if ctx.Os().Bionic() {
1389 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1390 } else {
1391 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1392 }
1393 }
1394}
1395
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001396func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001397 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1398 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1399 }
1400
Jiyong Park397e55e2018-10-24 21:09:55 +09001401 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001402 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001403
1404 a.combineProperties(ctx)
1405
Jiyong Park397e55e2018-10-24 21:09:55 +09001406 has32BitTarget := false
1407 for _, target := range targets {
1408 if target.Arch.ArchType.Multilib == "lib32" {
1409 has32BitTarget = true
1410 }
1411 }
1412 for i, target := range targets {
1413 // When multilib.* is omitted for native_shared_libs, it implies
1414 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001415 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001416 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001417 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001418 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001419
Roland Levillain630846d2019-06-26 12:48:34 +01001420 // When multilib.* is omitted for tests, it implies
1421 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001422 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001423 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001424 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001425 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001426
Jiyong Park397e55e2018-10-24 21:09:55 +09001427 // Add native modules targetting both ABIs
1428 addDependenciesForNativeModules(ctx,
1429 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001430 a.properties.Multilib.Both.Binaries,
1431 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001432 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001433 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001434
Alex Light3d673592019-01-18 14:37:31 -08001435 isPrimaryAbi := i == 0
1436 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001437 // When multilib.* is omitted for binaries, it implies
1438 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001439 ctx.AddFarVariationDependencies(append(target.Variations(),
1440 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1441 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001442
1443 // Add native modules targetting the first ABI
1444 addDependenciesForNativeModules(ctx,
1445 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001446 a.properties.Multilib.First.Binaries,
1447 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001448 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001449 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001450 }
1451
1452 switch target.Arch.ArchType.Multilib {
1453 case "lib32":
1454 // Add native modules targetting 32-bit ABI
1455 addDependenciesForNativeModules(ctx,
1456 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001457 a.properties.Multilib.Lib32.Binaries,
1458 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001459 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001460 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001461
1462 addDependenciesForNativeModules(ctx,
1463 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001464 a.properties.Multilib.Prefer32.Binaries,
1465 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001466 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001467 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001468 case "lib64":
1469 // Add native modules targetting 64-bit ABI
1470 addDependenciesForNativeModules(ctx,
1471 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001472 a.properties.Multilib.Lib64.Binaries,
1473 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001474 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001475 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001476
1477 if !has32BitTarget {
1478 addDependenciesForNativeModules(ctx,
1479 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001480 a.properties.Multilib.Prefer32.Binaries,
1481 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001482 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001483 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001484 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001485
1486 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1487 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1488 if sanitizer == "hwaddress" {
1489 addDependenciesForNativeModules(ctx,
1490 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001491 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001492 break
1493 }
1494 }
1495 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001496 }
1497
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001498 }
1499
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001500 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1501 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1502 // b/144532908
1503 archForPrebuiltEtc := config.Arches()[0]
1504 for _, arch := range config.Arches() {
1505 // Prefer 64-bit arch if there is any
1506 if arch.ArchType.Multilib == "lib64" {
1507 archForPrebuiltEtc = arch
1508 break
1509 }
1510 }
1511 ctx.AddFarVariationDependencies([]blueprint.Variation{
1512 {Mutator: "os", Variation: ctx.Os().String()},
1513 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1514 }, prebuiltTag, a.properties.Prebuilts...)
1515
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001516 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1517 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001518
Ulya Trafimovich44561882020-01-03 13:25:54 +00001519 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1520 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1521 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1522 javaLibTag, "jacocoagent")
1523 }
1524
Jiyong Park23c52b02019-02-02 13:13:47 +09001525 if String(a.properties.Key) == "" {
1526 ctx.ModuleErrorf("key is missing")
1527 return
1528 }
1529 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001530
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001531 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001532 if cert != "" {
1533 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001534 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001535
1536 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1537 if len(a.properties.Uses_sdks) > 0 {
1538 sdkRefs := []android.SdkRef{}
1539 for _, str := range a.properties.Uses_sdks {
1540 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1541 sdkRefs = append(sdkRefs, parsed)
1542 }
1543 a.BuildWithSdks(sdkRefs)
1544 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001545}
1546
Jiyong Park5d790c32019-11-15 18:40:32 +09001547func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1548 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1549 androidAppTag, a.overridableProperties.Apps...)
1550}
1551
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001552func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1553 // direct deps of an APEX bundle are all part of the APEX bundle
1554 return true
1555}
1556
Colin Cross0ea8ba82019-06-06 14:33:29 -07001557func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001558 moduleName := ctx.ModuleName()
1559 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1560 // we check with the pseudo module name to see if its certificate is overridden.
1561 if a.vndkApex {
1562 moduleName = vndkApexName
1563 }
1564 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001565 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001566 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001567 }
1568 return String(a.properties.Certificate)
1569}
1570
Colin Cross41955e82019-05-29 14:40:35 -07001571func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1572 switch tag {
1573 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001574 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001575 default:
1576 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001577 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001578}
1579
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001580func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001581 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001582}
1583
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001584func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1585 return proptools.Bool(a.properties.Test_only_no_hashtree)
1586}
1587
Jiyong Park7c1dc612019-01-05 11:15:24 +09001588func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001589 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001590 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001591 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001592 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001593 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001594 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001595 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001596 }
1597}
1598
Jiyong Parkf97782b2019-02-13 20:28:58 +09001599func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1600 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1601 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1602 }
1603}
1604
Jiyong Park388ef3f2019-01-28 19:47:32 +09001605func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001606 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1607 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001608 }
1609
1610 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001611 globalSanitizerNames := []string{}
1612 if a.Host() {
1613 globalSanitizerNames = ctx.Config().SanitizeHost()
1614 } else {
1615 arches := ctx.Config().SanitizeDeviceArch()
1616 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1617 globalSanitizerNames = ctx.Config().SanitizeDevice()
1618 }
1619 }
1620 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001621}
1622
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001623func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001624 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001625}
1626
1627func (a *apexBundle) PreventInstall() {
1628 a.properties.PreventInstall = true
1629}
1630
1631func (a *apexBundle) HideFromMake() {
1632 a.properties.HideFromMake = true
1633}
1634
Jiyong Park956305c2020-01-09 12:32:06 +09001635func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1636 a.properties.IsCoverageVariant = coverage
1637}
1638
Jiyong Parkf653b052019-11-18 15:39:01 +09001639// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001640func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001641 // Decide the APEX-local directory by the multilib of the library
1642 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001643 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001644 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001645 case "lib32":
1646 dirInApex = "lib"
1647 case "lib64":
1648 dirInApex = "lib64"
1649 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001650 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001651 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001652 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001653 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001654 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001655 // Special case for Bionic libs and other libs installed with them. This is
1656 // to prevent those libs from being included in the search path
1657 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1658 // those libs in the Runtime APEX are available via the legacy paths in
1659 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1660 // to the legacy paths and thus will be loaded into the default linker
1661 // namespace (aka "platform" namespace). If the libs are directly in
1662 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1663 // into the runtime linker namespace, which will result in double loading of
1664 // them, which isn't supported.
1665 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001666 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001667
Jiyong Parkf653b052019-11-18 15:39:01 +09001668 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001669 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001670}
1671
Jiyong Park1833cef2019-12-13 13:28:36 +09001672func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001673 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001674 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001675 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001676 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001678 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001679 af.symlinks = cc.Symlinks()
1680 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001681}
1682
Jiyong Park1833cef2019-12-13 13:28:36 +09001683func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001684 dirInApex := "bin"
1685 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001686 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001687}
Jiyong Park1833cef2019-12-13 13:28:36 +09001688func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001690 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1691 if err != nil {
1692 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001694 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001695 fileToCopy := android.PathForOutput(ctx, s)
1696 // NB: Since go binaries are static we don't need the module for anything here, which is
1697 // good since the go tool is a blueprint.Module not an android.Module like we would
1698 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001699 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001700}
1701
Jiyong Park1833cef2019-12-13 13:28:36 +09001702func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001703 dirInApex := filepath.Join("bin", sh.SubDir())
1704 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001705 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001706 af.symlinks = sh.Symlinks()
1707 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001708}
1709
Jooyung Han58f26ab2019-12-18 15:34:32 +09001710// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1711type javaLibrary interface {
1712 android.Module
1713 java.Dependency
1714}
1715
1716func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001718 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001719 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1720 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1721 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001722}
1723
Jiyong Park1833cef2019-12-13 13:28:36 +09001724func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001725 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1726 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001727 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001728}
1729
atrost6e126252020-01-27 17:01:16 +00001730func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1731 dirInApex := filepath.Join("etc", config.SubDir())
1732 fileToCopy := config.CompatConfig()
1733 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1734}
1735
Jiyong Park1833cef2019-12-13 13:28:36 +09001736func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001737 android.Module
1738 Privileged() bool
1739 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001740 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001741 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001742}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001743 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001745 appDir = "priv-app"
1746 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001747 dirInApex := filepath.Join(appDir, pkgName)
1748 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001749 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1750 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001751 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001752
1753 if app, ok := aapp.(interface {
1754 OverriddenManifestPackageName() string
1755 }); ok {
1756 af.overriddenPackageName = app.OverriddenManifestPackageName()
1757 }
Jiyong Park618922e2020-01-08 13:35:43 +09001758 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001759}
1760
Roland Levillain935639d2019-08-13 14:55:28 +01001761// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1762type flattenedApexContext struct {
1763 android.ModuleContext
1764}
1765
1766func (c *flattenedApexContext) InstallBypassMake() bool {
1767 return true
1768}
1769
Paul Duffin133608f2020-03-30 15:54:08 +01001770// Function called while walking an APEX's payload dependencies.
1771//
1772// Return true if the `to` module should be visited, false otherwise.
1773type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1774
Jiyong Park201cedd2020-02-07 17:25:49 +09001775// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001776func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001777 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001778 am, ok := child.(android.ApexModule)
1779 if !ok || !am.CanHaveApexVariants() {
1780 return false
1781 }
1782
1783 // Check for the direct dependencies that contribute to the payload
1784 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1785 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001786 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001787 }
Paul Duffin133608f2020-03-30 15:54:08 +01001788 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001789 return false
1790 }
1791
1792 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001793 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001794 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001795 }
1796
Paul Duffin133608f2020-03-30 15:54:08 +01001797 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001798 })
1799}
1800
Jooyung Han0c4e0162020-02-26 22:45:42 +09001801func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1802 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001803 intVer, err := android.ApiStrToNum(ctx, ver)
1804 if err != nil {
1805 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001806 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001807 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001808}
1809
Jiyong Park201cedd2020-02-07 17:25:49 +09001810// Ensures that the dependencies are marked as available for this APEX
1811func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1812 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1813 if ctx.Host() || a.testApex || a.vndkApex {
1814 return
1815 }
1816
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001817 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1818 // Requiring them and their transitive depencies with apex_available is not right
1819 // because they just add noise.
1820 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1821 return
1822 }
1823
Paul Duffin133608f2020-03-30 15:54:08 +01001824 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1825 if externalDep {
1826 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1827 return false
1828 }
1829
Jiyong Park201cedd2020-02-07 17:25:49 +09001830 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001831 fromName := ctx.OtherModuleName(from)
1832 toName := ctx.OtherModuleName(to)
Paul Duffin133608f2020-03-30 15:54:08 +01001833 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1834 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001835 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001836 message := ""
1837 for _, m := range ctx.GetWalkPath()[1:] {
1838 message = fmt.Sprintf("%s\n -> %s", message, m.String())
1839 }
1840 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 +01001841 // Visit this module's dependencies to check and report any issues with their availability.
1842 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001843 })
1844}
1845
Jiyong Park678c8812020-02-07 17:25:49 +09001846// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1847func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1848 a.depInfos = make(map[string]depInfo)
Paul Duffin133608f2020-03-30 15:54:08 +01001849 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park678c8812020-02-07 17:25:49 +09001850 if from.Name() == to.Name() {
1851 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
Paul Duffin133608f2020-03-30 15:54:08 +01001852 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1853 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001854 }
1855
1856 if info, exists := a.depInfos[to.Name()]; exists {
1857 if !android.InList(from.Name(), info.from) {
1858 info.from = append(info.from, from.Name())
1859 }
1860 info.isExternal = info.isExternal && externalDep
1861 a.depInfos[to.Name()] = info
1862 } else {
1863 a.depInfos[to.Name()] = depInfo{
1864 to: to.Name(),
1865 from: []string{from.Name()},
1866 isExternal: externalDep,
1867 }
1868 }
Paul Duffin133608f2020-03-30 15:54:08 +01001869
1870 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1871 return !externalDep
Jiyong Park678c8812020-02-07 17:25:49 +09001872 })
1873}
1874
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001875func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001876 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1877 switch a.properties.ApexType {
1878 case imageApex:
1879 if buildFlattenedAsDefault {
1880 a.suffix = imageApexSuffix
1881 } else {
1882 a.suffix = ""
1883 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001884
1885 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001886 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001887 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001888 }
1889 case zipApex:
1890 if proptools.String(a.properties.Payload_type) == "zip" {
1891 a.suffix = ""
1892 a.primaryApexType = true
1893 } else {
1894 a.suffix = zipApexSuffix
1895 }
1896 case flattenedApex:
1897 if buildFlattenedAsDefault {
1898 a.suffix = ""
1899 a.primaryApexType = true
1900 } else {
1901 a.suffix = flattenedSuffix
1902 }
Alex Light5098a612018-11-29 17:12:15 -08001903 }
1904
Roland Levillain630846d2019-06-26 12:48:34 +01001905 if len(a.properties.Tests) > 0 && !a.testApex {
1906 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1907 return
1908 }
1909
Jiyong Parkfa899442020-01-31 02:49:53 +09001910 a.checkApexAvailability(ctx)
1911
Jiyong Park678c8812020-02-07 17:25:49 +09001912 a.collectDepsInfo(ctx)
1913
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001914 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1915
Jooyung Hane1633032019-08-01 17:41:43 +09001916 // native lib dependencies
1917 var provideNativeLibs []string
1918 var requireNativeLibs []string
1919
Jooyung Han5c998b92019-06-27 11:30:33 +09001920 // Check if "uses" requirements are met with dependent apexBundles
1921 var providedNativeSharedLibs []string
1922 useVendor := proptools.Bool(a.properties.Use_vendor)
1923 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1924 if ctx.OtherModuleDependencyTag(m) != usesTag {
1925 return
1926 }
1927 otherName := ctx.OtherModuleName(m)
1928 other, ok := m.(*apexBundle)
1929 if !ok {
1930 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1931 return
1932 }
1933 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1934 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1935 return
1936 }
1937 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1938 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1939 return
1940 }
1941 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1942 })
1943
Jiyong Parkf653b052019-11-18 15:39:01 +09001944 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001945 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001946 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001947 depTag := ctx.OtherModuleDependencyTag(child)
1948 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001949 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001950 switch depTag {
1951 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001952 if c, ok := child.(*cc.Module); ok {
1953 // bootstrap bionic libs are treated as provided by system
1954 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1955 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001956 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001957 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001958 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001959 } else {
1960 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001961 }
1962 case executableTag:
1963 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001964 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001965 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001966 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001967 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001968 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001970 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001971 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001972 } else {
Alex Light778127a2019-02-27 14:19:50 -08001973 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 +09001974 }
1975 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001976 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001977 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001978 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001979 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1980 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001981 filesInfo = append(filesInfo, af)
1982 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001983 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001984 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1985 af := apexFileForJavaLibrary(ctx, sdkLib)
1986 if !af.Ok() {
1987 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1988 return false
1989 }
1990 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001991 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001992 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001993 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001994 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001995 case androidAppTag:
1996 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1997 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001998 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001999 return true // track transitive dependencies
2000 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002001 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00002002 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
2003 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09002004 } else {
2005 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2006 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002007 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002008 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002009 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002010 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2011 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002012 } else {
atrost6e126252020-01-27 17:01:16 +00002013 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 }
Roland Levillain630846d2019-06-26 12:48:34 +01002015 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002016 if ccTest, ok := child.(*cc.Module); ok {
2017 if ccTest.IsTestPerSrcAllTestsVariation() {
2018 // Multiple-output test module (where `test_per_src: true`).
2019 //
2020 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2021 // We do not add this variation to `filesInfo`, as it has no output;
2022 // however, we do add the other variations of this module as indirect
2023 // dependencies (see below).
2024 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002025 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002026 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002027 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002028 af.class = nativeTest
2029 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002030 }
Roland Levillain630846d2019-06-26 12:48:34 +01002031 } else {
2032 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2033 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002034 case keyTag:
2035 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002036 a.private_key_file = key.private_key_file
2037 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002038 } else {
2039 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002040 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002041 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002042 case certificateTag:
2043 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002044 a.container_certificate_file = dep.Certificate.Pem
2045 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002046 } else {
2047 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2048 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002049 case android.PrebuiltDepTag:
2050 // If the prebuilt is force disabled, remember to delete the prebuilt file
2051 // that might have been installed in the previous builds
2052 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2053 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2054 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002055 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002056 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002057 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002058 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002059 // We cannot use a switch statement on `depTag` here as the checked
2060 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002061 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 if cc, ok := child.(*cc.Module); ok {
2063 if android.InList(cc.Name(), providedNativeSharedLibs) {
2064 // If we're using a shared library which is provided from other APEX,
2065 // don't include it in this APEX
2066 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002067 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002068 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 // If the dependency is a stubs lib, don't include it in this APEX,
2070 // but make sure that the lib is installed on the device.
2071 // In case no APEX is having the lib, the lib is installed to the system
2072 // partition.
2073 //
2074 // Always include if we are a host-apex however since those won't have any
2075 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002076 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2077 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002078 }
Jooyung Hane1633032019-08-01 17:41:43 +09002079 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 // Don't track further
2081 return false
2082 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002083 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002084 af.transitiveDep = true
2085 filesInfo = append(filesInfo, af)
2086 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002087 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002088 } else if cc.IsTestPerSrcDepTag(depTag) {
2089 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002090 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002091 // Handle modules created as `test_per_src` variations of a single test module:
2092 // use the name of the generated test binary (`fileToCopy`) instead of the name
2093 // of the original test module (`depName`, shared by all `test_per_src`
2094 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002095 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002096 // these are not considered transitive dep
2097 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002098 filesInfo = append(filesInfo, af)
2099 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002100 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002101 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002102 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2103 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002104 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2105 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2106 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2107 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002108 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002109 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002110 }
2111 }
2112 }
2113 return false
2114 })
2115
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002116 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2117 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2118 // via the global boot image config.
2119 if a.artApex {
2120 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2121 dirInApex := filepath.Join("javalib", arch.String())
2122 for _, f := range files {
2123 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002124 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002125 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002126 }
2127 }
2128 }
2129
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002130 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002131 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2132 return
2133 }
2134
Jiyong Park8fd61922018-11-08 02:50:25 +09002135 // remove duplicates in filesInfo
2136 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002137 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002138 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002139 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002140 if e, ok := encountered[dest]; !ok {
2141 encountered[dest] = f
2142 } else {
2143 // If a module is directly included and also transitively depended on
2144 // consider it as directly included.
2145 e.transitiveDep = e.transitiveDep && f.transitiveDep
2146 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002147 }
2148 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002149 var result []apexFile
2150 for _, v := range encountered {
2151 result = append(result, v)
2152 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002153 return result
2154 }
2155 filesInfo = removeDup(filesInfo)
2156
2157 // to have consistent build rules
2158 sort.Slice(filesInfo, func(i, j int) bool {
2159 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2160 })
2161
Jiyong Park8fd61922018-11-08 02:50:25 +09002162 a.installDir = android.PathForModuleInstall(ctx, "apex")
2163 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002164
Jooyung Han54aca7b2019-11-20 02:26:02 +09002165 if a.properties.ApexType != zipApex {
2166 if a.properties.File_contexts == nil {
2167 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2168 } else {
2169 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2170 if a.Platform() {
2171 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2172 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2173 }
2174 }
2175 }
2176 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2177 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2178 return
2179 }
2180 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002181 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2182 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2183 // the same library in the system partition, thus effectively sharing the same libraries
2184 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2185 // in the APEX.
2186 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2187 a.installable() &&
2188 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002189
Jiyong Park9d677202020-02-19 16:29:35 +09002190 // We don't need the optimization for updatable APEXes, as it might give false signal
2191 // to the system health when the APEXes are still bundled (b/149805758)
2192 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2193 a.linkToSystemLib = false
2194 }
2195
Jiyong Park9b964182020-02-26 18:27:19 +09002196 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2197 if ctx.Host() {
2198 a.linkToSystemLib = false
2199 }
2200
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002201 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002202 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2203
2204 a.setCertificateAndPrivateKey(ctx)
2205 if a.properties.ApexType == flattenedApex {
2206 a.buildFlattenedApex(ctx)
2207 } else {
2208 a.buildUnflattenedApex(ctx)
2209 }
2210
Jooyung Han002ab682020-01-08 01:57:58 +09002211 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002212
2213 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002214}
2215
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002216func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002217 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002218 moduleName = normalizeModuleName(moduleName)
2219
2220 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2221 return true
2222 }
2223
2224 key = android.AvailableToAnyApex
2225 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2226 return true
2227 }
2228
2229 return false
2230}
2231
2232func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002233 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2234 // system. Trim the prefix for the check since they are confusing
2235 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2236 if strings.HasPrefix(moduleName, "libclang_rt.") {
2237 // This module has many arch variants that depend on the product being built.
2238 // We don't want to list them all
2239 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002240 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002241 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002242}
2243
Jooyung Han344d5432019-08-23 11:17:39 +09002244func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002245 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002246 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002247 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002248 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002249 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002250 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2251 })
Alex Light5098a612018-11-29 17:12:15 -08002252 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002253 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002254 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002255 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002256 return module
2257}
Jiyong Park30ca9372019-02-07 16:27:23 +09002258
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002259func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002260 bundle := newApexBundle()
2261 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002262 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002263 return bundle
2264}
2265
Jiyong Parkfce0b422020-02-11 03:56:06 +09002266// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2267// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002268func testApexBundleFactory() android.Module {
2269 bundle := newApexBundle()
2270 bundle.testApex = true
2271 return bundle
2272}
2273
Jiyong Parkfce0b422020-02-11 03:56:06 +09002274// apex packages other modules into an APEX file which is a packaging format for system-level
2275// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002276func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002277 return newApexBundle()
2278}
2279
Jiyong Park30ca9372019-02-07 16:27:23 +09002280//
2281// Defaults
2282//
2283type Defaults struct {
2284 android.ModuleBase
2285 android.DefaultsModuleBase
2286}
2287
Jiyong Park30ca9372019-02-07 16:27:23 +09002288func defaultsFactory() android.Module {
2289 return DefaultsFactory()
2290}
2291
2292func DefaultsFactory(props ...interface{}) android.Module {
2293 module := &Defaults{}
2294
2295 module.AddProperties(props...)
2296 module.AddProperties(
2297 &apexBundleProperties{},
2298 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002299 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002300 )
2301
2302 android.InitDefaultsModule(module)
2303 return module
2304}
Jiyong Park5d790c32019-11-15 18:40:32 +09002305
2306//
2307// OverrideApex
2308//
2309type OverrideApex struct {
2310 android.ModuleBase
2311 android.OverrideModuleBase
2312}
2313
2314func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2315 // All the overrides happen in the base module.
2316}
2317
2318// override_apex is used to create an apex module based on another apex module
2319// by overriding some of its properties.
2320func overrideApexFactory() android.Module {
2321 m := &OverrideApex{}
2322 m.AddProperties(&overridableProperties{})
2323
2324 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2325 android.InitOverrideModule(m)
2326 return m
2327}