blob: 9670f81df023de60e89ee371ffed26eadd69c88f [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()
Jiyong Park48ca7dc2018-10-10 14:01:00 +090064)
65
Anton Hansson5053c292020-01-10 15:12:39 +000066// This is a map from apex to modules, which overrides the
67// apex_available setting for that particular module to make
68// it available for the apex regardless of its setting.
69// TODO(b/147364041): remove this
70func makeApexAvailableWhitelist() map[string][]string {
71 // The "Module separator"s below are employed to minimize merge conflicts.
72 m := make(map[string][]string)
73 //
74 // Module separator
75 //
Jiyong Parkfa899442020-01-31 02:49:53 +090076 m["com.android.adbd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090077 "libadbd_auth",
Jiyong Parkfa899442020-01-31 02:49:53 +090078 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +090079 "libcap",
Jiyong Parkfa899442020-01-31 02:49:53 +090080 "libmdnssd",
81 "libminijail",
82 "libminijail_gen_constants",
83 "libminijail_gen_constants_obj",
84 "libminijail_gen_syscall",
85 "libminijail_gen_syscall_obj",
86 "libminijail_generated",
87 "libpackagelistparser",
88 "libpcre2",
89 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090090 }
91 //
92 // Module separator
93 //
Anton Hansson5053c292020-01-10 15:12:39 +000094 m["com.android.art"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090095 "art_cmdlineparser_headers",
96 "art_disassembler_headers",
97 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090098 "bionic_libc_platform_headers",
99 "core-repackaged-icu4j",
100 "cpp-define-generator-asm-support",
101 "cpp-define-generator-definitions",
102 "crtbegin_dynamic",
103 "crtbegin_dynamic1",
104 "crtbegin_so1",
105 "crtbrand",
106 "conscrypt.module.intra.core.api.stubs",
107 "dex2oat_headers",
108 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900110 "javavm_headers",
111 "jni_platform_headers",
112 "libPlatformProperties",
113 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000114 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900115 "libandroidicuinit",
116 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000117 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900118 "libasync_safe",
Jiyong Parkfa899442020-01-31 02:49:53 +0900119 "libdexfile_all_headers",
120 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000121 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900122 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000123 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "libfdlibm",
125 "libgtest_prod",
126 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000127 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "libicuuc_headers",
129 "libicuuc_stubdata",
130 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900131 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000132 "liblzma",
133 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900134 "libnativebridge-headers",
135 "libnativehelper_header_only",
136 "libnativeloader-headers",
137 "libnpt_headers",
138 "libopenjdkjvmti_headers",
139 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000142 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900143 "libv8",
144 "libv8base",
145 "libv8gen",
146 "libv8platform",
147 "libv8sampler",
148 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000149 "libvixl",
150 "libvixld",
151 "libz",
152 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900153 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000154 }
155 //
156 // Module separator
157 //
158 m["com.android.bluetooth.updatable"] = []string{
159 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "android.hardware.bluetooth.a2dp@1.0",
161 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "android.hardware.bluetooth@1.0",
163 "android.hardware.bluetooth@1.1",
164 "android.hardware.graphics.bufferqueue@1.0",
165 "android.hardware.graphics.bufferqueue@2.0",
166 "android.hardware.graphics.common@1.0",
167 "android.hardware.graphics.common@1.1",
168 "android.hardware.graphics.common@1.2",
169 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000170 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "android.hidl.token@1.0",
172 "android.hidl.token@1.0-utils",
173 "avrcp-target-service",
174 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900175 "bluetooth-protos-lite",
176 "bluetooth.mapsapi",
177 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900178 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900179 "ipmemorystore-aidl-interfaces-V5-java",
180 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900181 "internal_include_headers",
182 "lib-bt-packets",
183 "lib-bt-packets-avrcp",
184 "lib-bt-packets-base",
185 "libFraunhoferAAC",
186 "libaudio-a2dp-hw-utils",
187 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000189 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 "libbluetooth-types",
191 "libbluetooth-types-header",
192 "libbluetooth_gd",
193 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000194 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "libbt-audio-hal-interface",
196 "libbt-bta",
197 "libbt-common",
198 "libbt-hci",
199 "libbt-platform-protos-lite",
200 "libbt-protos-lite",
201 "libbt-sbc-decoder",
202 "libbt-sbc-encoder",
203 "libbt-stack",
204 "libbt-utils",
205 "libbtcore",
206 "libbtdevice",
207 "libbte",
208 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000210 "libevent",
211 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900212 "libg722codec",
213 "libgtest_prod",
214 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libmedia_headers",
216 "libmodpb64",
217 "libosi",
Anton Hansson5053c292020-01-10 15:12:39 +0000218 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900219 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900220 "libstagefright_foundation_headers",
221 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000222 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900223 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000224 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900225 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000226 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900227 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900228 "net-utils-services-common",
229 "netd_aidl_interface-unstable-java",
230 "netd_event_listener_interface-java",
231 "netlink-client",
232 "networkstack-aidl-interfaces-unstable-java",
233 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900234 "sap-api-java-static",
235 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000236 }
237 //
238 // Module separator
239 //
240 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
241 //
242 // Module separator
243 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900244 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "boringssl_self_test",
Jiyong Parkfa899442020-01-31 02:49:53 +0900246 "libnativehelper_header_only",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900247 "unsupportedappusage",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 }
Anton Hansson5053c292020-01-10 15:12:39 +0000249 //
250 // Module separator
251 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900252 m["com.android.extservices"] = []string{
253 "flatbuffer_headers",
254 "liblua",
255 "libtextclassifier",
256 "libtextclassifier_hash_static",
257 "libtflite_static",
258 "libutf",
259 "libz_current",
260 "tensorflow_headers",
261 }
262 //
263 // Module separator
264 //
265 m["com.android.cronet"] = []string{
266 "cronet_impl_common_java",
267 "cronet_impl_native_java",
268 "cronet_impl_platform_java",
269 "libcronet.80.0.3986.0",
270 "org.chromium.net.cronet",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900271 "org.chromium.net.cronet.xml",
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 "prebuilt_libcronet.80.0.3986.0",
273 }
274 //
275 // Module separator
276 //
277 m["com.android.neuralnetworks"] = []string{
278 "android.hardware.neuralnetworks@1.0",
279 "android.hardware.neuralnetworks@1.1",
280 "android.hardware.neuralnetworks@1.2",
281 "android.hardware.neuralnetworks@1.3",
282 "android.hidl.allocator@1.0",
283 "android.hidl.memory.token@1.0",
284 "android.hidl.memory@1.0",
285 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900286 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900287 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900289 "libprocessgroup",
290 "libprocessgroup_headers",
291 "libprocpartition",
292 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900293 }
Anton Hansson5053c292020-01-10 15:12:39 +0000294 //
295 // Module separator
296 //
Anton Hansson5053c292020-01-10 15:12:39 +0000297 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900298 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000299 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900300 "android.hardware.cas@1.0",
301 "android.hardware.configstore-utils",
302 "android.hardware.configstore@1.0",
303 "android.hardware.configstore@1.1",
304 "android.hardware.graphics.allocator@2.0",
305 "android.hardware.graphics.allocator@3.0",
306 "android.hardware.graphics.bufferqueue@1.0",
307 "android.hardware.graphics.bufferqueue@2.0",
308 "android.hardware.graphics.common@1.0",
309 "android.hardware.graphics.common@1.1",
310 "android.hardware.graphics.common@1.2",
311 "android.hardware.graphics.mapper@2.0",
312 "android.hardware.graphics.mapper@2.1",
313 "android.hardware.graphics.mapper@3.0",
314 "android.hardware.media.omx@1.0",
315 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000316 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000317 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000319 "android.hidl.token@1.0",
320 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900321 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900322 "gl_headers",
323 "libEGL",
324 "libEGL_blobCache",
325 "libEGL_getProcAddress",
326 "libFLAC",
327 "libFLAC-config",
328 "libFLAC-headers",
329 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000330 "libaacextractor",
331 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900332 "libarect",
333 "libasync_safe",
334 "libaudio_system_headers",
335 "libaudioclient",
336 "libaudioclient_headers",
337 "libaudiofoundation",
338 "libaudiofoundation_headers",
339 "libaudiomanager",
340 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000341 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900342 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900343 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900344 "libbluetooth-types-header",
345 "libbufferhub",
346 "libbufferhub_headers",
347 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900348 "libc_malloc_debug_backtrace",
349 "libcamera_client",
350 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900351 "libdexfile_external_headers",
352 "libdexfile_support",
353 "libdvr_headers",
354 "libexpat",
355 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000356 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900357 "libgrallocusage",
358 "libgraphicsenv",
359 "libgui",
360 "libgui_headers",
361 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "liblzma",
364 "libmath",
365 "libmedia",
366 "libmedia_codeclist",
367 "libmedia_headers",
368 "libmedia_helper",
369 "libmedia_helper_headers",
370 "libmedia_midiiowrapper",
371 "libmedia_omx",
372 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000373 "libmidiextractor",
374 "libmkvextractor",
375 "libmp3extractor",
376 "libmp4extractor",
377 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900378 "libnativebase_headers",
379 "libnativebridge-headers",
380 "libnativebridge_lazy",
381 "libnativeloader-headers",
382 "libnativeloader_lazy",
383 "libnativewindow_headers",
384 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000385 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900386 "libpackagelistparser",
387 "libpcre2",
388 "libpdx",
389 "libpdx_default_transport",
390 "libpdx_headers",
391 "libpdx_uds",
Anton Hansson5053c292020-01-10 15:12:39 +0000392 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900393 "libprocessgroup_headers",
394 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libsonivox",
Anton Hansson5053c292020-01-10 15:12:39 +0000396 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900397 "libspeexresampler",
398 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000399 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900400 "libstagefright_flacdec",
401 "libstagefright_foundation",
402 "libstagefright_foundation_headers",
403 "libstagefright_foundation_without_imemory",
404 "libstagefright_headers",
405 "libstagefright_id3",
406 "libstagefright_metadatautils",
407 "libstagefright_mpeg2extractor",
408 "libstagefright_mpeg2support",
409 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900410 "libui",
411 "libui_headers",
412 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900413 "libvibrator",
414 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000415 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900416 "libwebm",
417 "media_ndk_headers",
418 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000419 "updatable-media",
420 }
421 //
422 // Module separator
423 //
424 m["com.android.media.swcodec"] = []string{
425 "android.frameworks.bufferhub@1.0",
426 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900427 "android.hardware.configstore-utils",
428 "android.hardware.configstore@1.0",
429 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000430 "android.hardware.graphics.allocator@2.0",
431 "android.hardware.graphics.allocator@3.0",
432 "android.hardware.graphics.allocator@4.0",
433 "android.hardware.graphics.bufferqueue@1.0",
434 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900435 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000436 "android.hardware.graphics.common@1.0",
437 "android.hardware.graphics.common@1.1",
438 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000439 "android.hardware.graphics.mapper@2.0",
440 "android.hardware.graphics.mapper@2.1",
441 "android.hardware.graphics.mapper@3.0",
442 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000443 "android.hardware.media.bufferpool@2.0",
444 "android.hardware.media.c2@1.0",
445 "android.hardware.media.c2@1.1",
446 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "android.hardware.media@1.0",
448 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000451 "android.hidl.safe_union@1.0",
452 "android.hidl.token@1.0",
453 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "libEGL",
455 "libFLAC",
456 "libFLAC-config",
457 "libFLAC-headers",
458 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900459 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900460 "libarect",
461 "libasync_safe",
462 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900464 "libaudioutils",
465 "libaudioutils_fixedfft",
466 "libavcdec",
467 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000468 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900469 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900470 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900471 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900472 "libbluetooth-types-header",
473 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900474 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000475 "libcap",
476 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900477 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000478 "libcodec2_hidl@1.0",
479 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900480 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000481 "libcodec2_soft_aacdec",
482 "libcodec2_soft_aacenc",
483 "libcodec2_soft_amrnbdec",
484 "libcodec2_soft_amrnbenc",
485 "libcodec2_soft_amrwbdec",
486 "libcodec2_soft_amrwbenc",
487 "libcodec2_soft_av1dec_gav1",
488 "libcodec2_soft_avcdec",
489 "libcodec2_soft_avcenc",
490 "libcodec2_soft_common",
491 "libcodec2_soft_flacdec",
492 "libcodec2_soft_flacenc",
493 "libcodec2_soft_g711alawdec",
494 "libcodec2_soft_g711mlawdec",
495 "libcodec2_soft_gsmdec",
496 "libcodec2_soft_h263dec",
497 "libcodec2_soft_h263enc",
498 "libcodec2_soft_hevcdec",
499 "libcodec2_soft_hevcenc",
500 "libcodec2_soft_mp3dec",
501 "libcodec2_soft_mpeg2dec",
502 "libcodec2_soft_mpeg4dec",
503 "libcodec2_soft_mpeg4enc",
504 "libcodec2_soft_opusdec",
505 "libcodec2_soft_opusenc",
506 "libcodec2_soft_rawdec",
507 "libcodec2_soft_vorbisdec",
508 "libcodec2_soft_vp8dec",
509 "libcodec2_soft_vp8enc",
510 "libcodec2_soft_vp9dec",
511 "libcodec2_soft_vp9enc",
512 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900513 "libdexfile_support",
514 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000515 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900516 "libfmq",
517 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000518 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900519 "libgrallocusage",
520 "libgraphicsenv",
521 "libgsm",
522 "libgui_bufferqueue_static",
523 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000524 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900525 "libhardware_headers",
526 "libhevcdec",
527 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000528 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900529 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900530 "liblzma",
531 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000532 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 "libmedia_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000534 "libminijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "libminijail_gen_constants",
536 "libminijail_gen_constants_obj",
537 "libminijail_gen_syscall",
538 "libminijail_gen_syscall_obj",
539 "libminijail_generated",
540 "libmpeg2dec",
541 "libnativebase_headers",
542 "libnativebridge_lazy",
543 "libnativeloader_lazy",
544 "libnativewindow_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000545 "libopus",
Jiyong Parkfa899442020-01-31 02:49:53 +0900546 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000547 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900548 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000549 "libscudo_wrapper",
550 "libsfplugin_ccodec_utils",
551 "libspeexresampler",
552 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900553 "libstagefright_amrnbdec",
554 "libstagefright_amrnbenc",
555 "libstagefright_amrwbdec",
556 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000557 "libstagefright_bufferpool@2.0.1",
558 "libstagefright_bufferqueue_helper",
559 "libstagefright_enc_common",
560 "libstagefright_flacdec",
561 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900562 "libstagefright_foundation_headers",
563 "libstagefright_headers",
564 "libstagefright_m4vh263dec",
565 "libstagefright_m4vh263enc",
566 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000567 "libsync",
568 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900569 "libui_headers",
570 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000571 "libvorbisidec",
572 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libyuv",
574 "libyuv_static",
575 "media_ndk_headers",
576 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000578 }
579 //
580 // Module separator
581 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 m["com.android.mediaprovider"] = []string{
583 "MediaProvider",
584 "MediaProviderGoogle",
585 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900586 "libbase_ndk",
587 "libfuse",
588 "libfuse_jni",
589 "libnativehelper_header_only",
590 }
591 //
592 // Module separator
593 //
594 m["com.android.permission"] = []string{
595 "androidx.annotation_annotation",
596 "androidx.annotation_annotation-nodeps",
597 "androidx.lifecycle_lifecycle-common",
598 "androidx.lifecycle_lifecycle-common-java8",
599 "androidx.lifecycle_lifecycle-common-java8-nodeps",
600 "androidx.lifecycle_lifecycle-common-nodeps",
601 "kotlin-annotations",
602 "kotlin-stdlib",
603 "kotlin-stdlib-jdk7",
604 "kotlin-stdlib-jdk8",
605 "kotlinx-coroutines-android",
606 "kotlinx-coroutines-android-nodeps",
607 "kotlinx-coroutines-core",
608 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900609 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900610 "GooglePermissionController",
611 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900612 }
Anton Hansson5053c292020-01-10 15:12:39 +0000613 //
614 // Module separator
615 //
Anton Hansson5053c292020-01-10 15:12:39 +0000616 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900617 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900618 "libarm-optimized-routines-math",
619 "libasync_safe",
620 "libasync_safe_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900621 "libc_aeabi",
622 "libc_bionic",
623 "libc_bionic_ndk",
624 "libc_bootstrap",
625 "libc_common",
626 "libc_common_shared",
627 "libc_common_static",
628 "libc_dns",
629 "libc_dynamic_dispatch",
630 "libc_fortify",
631 "libc_freebsd",
632 "libc_freebsd_large_stack",
633 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900634 "libc_init_dynamic",
635 "libc_init_static",
636 "libc_jemalloc_wrapper",
637 "libc_netbsd",
638 "libc_nomalloc",
639 "libc_nopthread",
640 "libc_openbsd",
641 "libc_openbsd_large_stack",
642 "libc_openbsd_ndk",
643 "libc_pthread",
644 "libc_static_dispatch",
645 "libc_syscalls",
646 "libc_tzcode",
647 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900648 "libdebuggerd",
649 "libdebuggerd_common_headers",
650 "libdebuggerd_handler_core",
651 "libdebuggerd_handler_fallback",
652 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000653 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900655 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900656 "libgtest_prod",
657 "libjemalloc5",
658 "liblinker_main",
659 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900660 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000661 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900662 "libprocessgroup_headers",
663 "libprocinfo",
664 "libpropertyinfoparser",
665 "libscudo",
666 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 "libsystemproperties",
668 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000669 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900670 "libz",
671 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000672 }
673 //
674 // Module separator
675 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900676 m["com.android.resolv"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "dnsresolver_aidl_interface-unstable-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900678 "libgtest_prod",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "libnativehelper_header_only",
680 "libnetd_client_headers",
681 "libnetd_resolv",
682 "libnetdutils",
683 "libprocessgroup",
684 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900685 "libstatslog_resolv",
686 "libstatspush_compat",
687 "libstatssocket",
688 "libstatssocket_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900689 "libsysutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900690 "netd_event_listener_interface-ndk_platform",
691 "server_configurable_flags",
692 "stats_proto",
693 }
Anton Hansson5053c292020-01-10 15:12:39 +0000694 //
695 // Module separator
696 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 "libnativehelper_compat_libc++",
699 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900700 "libcgrouprc",
701 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900702 "libprocessgroup",
703 "libprocessgroup_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900705 "libvndksupport",
706 "tethering-aidl-interfaces-java",
707 }
Anton Hansson5053c292020-01-10 15:12:39 +0000708 //
709 // Module separator
710 //
711 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900712 "PlatformProperties",
713 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900714 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900715 "android.hardware.wifi-V1.1-java",
716 "android.hardware.wifi-V1.2-java",
717 "android.hardware.wifi-V1.3-java",
718 "android.hardware.wifi-V1.4-java",
719 "android.hardware.wifi.hostapd-V1.0-java",
720 "android.hardware.wifi.hostapd-V1.1-java",
721 "android.hardware.wifi.hostapd-V1.2-java",
722 "android.hardware.wifi.supplicant-V1.0-java",
723 "android.hardware.wifi.supplicant-V1.1-java",
724 "android.hardware.wifi.supplicant-V1.2-java",
725 "android.hardware.wifi.supplicant-V1.3-java",
726 "android.hidl.base-V1.0-java",
727 "android.hidl.manager-V1.0-java",
728 "android.hidl.manager-V1.1-java",
729 "android.hidl.manager-V1.2-java",
730 "androidx.annotation_annotation",
731 "androidx.annotation_annotation-nodeps",
732 "bouncycastle-unbundled",
733 "dnsresolver_aidl_interface-V2-java",
734 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900735 "framework-wifi-pre-jarjar",
736 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900737 "ipmemorystore-aidl-interfaces-V3-java",
738 "ipmemorystore-aidl-interfaces-java",
739 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900740 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000741 "libprocessgroup",
Jiyong Parkfa899442020-01-31 02:49:53 +0900742 "libprocessgroup_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000743 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900744 "net-utils-services-common",
745 "netd_aidl_interface-V2-java",
746 "netd_aidl_interface-unstable-java",
747 "netd_event_listener_interface-java",
748 "netlink-client",
749 "networkstack-aidl-interfaces-unstable-java",
750 "networkstack-client",
751 "services.net",
752 "wifi-lite-protos",
753 "wifi-nano-protos",
754 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000755 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900756 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000757 }
758 //
759 // Module separator
760 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900761 m["com.android.sdkext"] = []string{
762 "fmtlib_ndk",
763 "libbase_ndk",
764 "libprotobuf-cpp-lite-ndk",
765 }
766 //
767 // Module separator
768 //
769 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900770 "libprocessgroup_headers",
771 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900772 }
773 //
774 // Module separator
775 //
776 m["//any"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900777 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900778 "libclang_rt",
779 "libgcc_stripped",
780 "libprofile-clang-extras",
781 "libprofile-clang-extras_ndk",
782 "libprofile-extras",
783 "libprofile-extras_ndk",
784 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900785 }
Anton Hansson5053c292020-01-10 15:12:39 +0000786 return m
787}
788
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900789func init() {
Jooyung Hane17caa62020-04-08 14:13:04 +0900790 android.AddNeverAllowRules(android.NeverAllow().
791 ModuleType("apex").
792 With("updatable", "true").
793 With("min_sdk_version", "").
794 Because("All updatable apexes should set min_sdk_version."))
795
Jiyong Parkd1063c12019-07-17 20:08:41 +0900796 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800797 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900798 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900799 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700800 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900801 android.RegisterModuleType("override_apex", overrideApexFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900802
Jooyung Han31c470b2019-10-18 16:26:59 +0900803 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900804 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900805
806 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
807 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
808 sort.Strings(*apexFileContextsInfos)
809 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
810 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900811}
812
Jooyung Han31c470b2019-10-18 16:26:59 +0900813func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
814 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
815 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
816}
817
Jiyong Parkd1063c12019-07-17 20:08:41 +0900818func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900819 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900820 ctx.BottomUp("apex", apexMutator).Parallel()
821 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
822 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900823}
824
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900825// Mark the direct and transitive dependencies of apex bundles so that they
826// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900827func apexDepsMutator(mctx android.TopDownMutatorContext) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800828 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900829 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000830 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900831 apexBundles = []android.ApexInfo{android.ApexInfo{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900832 ApexName: mctx.ModuleName(),
833 MinSdkVersion: a.minSdkVersion(mctx),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900834 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900835 directDep = true
836 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800837 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900838 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900839 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900840
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800841 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900842 return
843 }
844
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900845 cur := mctx.Module().(interface {
846 DepIsInSameApex(android.BaseModuleContext, android.Module) bool
847 })
848
Jiyong Parkf760cae2020-02-12 07:53:12 +0900849 mctx.VisitDirectDeps(func(child android.Module) {
850 depName := mctx.OtherModuleName(child)
851 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900852 cur.DepIsInSameApex(mctx, child) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800853 android.UpdateApexDependency(apexBundles, depName, directDep)
854 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900855 }
856 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900857}
858
859// Create apex variations if a module is included in APEX(s).
860func apexMutator(mctx android.BottomUpMutatorContext) {
861 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900862 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000863 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900864 // apex bundle itself is mutated so that it and its modules have same
865 // apex variant.
866 apexBundleName := mctx.ModuleName()
867 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900868 } else if o, ok := mctx.Module().(*OverrideApex); ok {
869 apexBundleName := o.GetOverriddenModuleName()
870 if apexBundleName == "" {
871 mctx.ModuleErrorf("base property is not set")
872 return
873 }
874 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900875 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900876
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900877}
Sundong Ahne9b55722019-09-06 17:37:42 +0900878
Jooyung Han7a78a922019-10-08 21:59:58 +0900879var (
880 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
881 apexFileContextsInfosMutex sync.Mutex
882)
883
884func apexFileContextsInfos(config android.Config) *[]string {
885 return config.Once(apexFileContextsInfosKey, func() interface{} {
886 return &[]string{}
887 }).(*[]string)
888}
889
Jooyung Han54aca7b2019-11-20 02:26:02 +0900890func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900891 apexFileContextsInfosMutex.Lock()
892 defer apexFileContextsInfosMutex.Unlock()
893 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900894 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900895}
896
Sundong Ahne9b55722019-09-06 17:37:42 +0900897func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Sundong Ahne8fb7242019-09-17 13:50:45 +0900898 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900899 var variants []string
900 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
901 case "image":
902 variants = append(variants, imageApexType, flattenedApexType)
903 case "zip":
904 variants = append(variants, zipApexType)
905 case "both":
906 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
907 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900908 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900909 return
910 }
911
912 modules := mctx.CreateLocalVariations(variants...)
913
914 for i, v := range variants {
915 switch v {
916 case imageApexType:
917 modules[i].(*apexBundle).properties.ApexType = imageApex
918 case zipApexType:
919 modules[i].(*apexBundle).properties.ApexType = zipApex
920 case flattenedApexType:
921 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900922 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900923 modules[i].(*apexBundle).MakeAsSystemExt()
924 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900925 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900926 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900927 } else if _, ok := mctx.Module().(*OverrideApex); ok {
928 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900929 }
930}
931
Jooyung Han5c998b92019-06-27 11:30:33 +0900932func apexUsesMutator(mctx android.BottomUpMutatorContext) {
933 if ab, ok := mctx.Module().(*apexBundle); ok {
934 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
935 }
936}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900937
Jooyung Handc782442019-11-01 03:14:38 +0900938var (
939 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
940)
941
942// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
943// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
944// which may cause compatibility issues. (e.g. libbinder)
945// Even though libbinder restricts its availability via 'apex_available' property and relies on
946// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
947// to avoid similar problems.
948func useVendorWhitelist(config android.Config) []string {
949 return config.Once(useVendorWhitelistKey, func() interface{} {
950 return []string{
951 // swcodec uses "vendor" variants for smaller size
952 "com.android.media.swcodec",
953 "test_com.android.media.swcodec",
954 }
955 }).([]string)
956}
957
958// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
959// called before the first call to useVendorWhitelist()
960func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
961 config.Once(useVendorWhitelistKey, func() interface{} {
962 return whitelist
963 })
964}
965
Alex Light9670d332019-01-29 18:07:33 -0800966type apexNativeDependencies struct {
967 // List of native libraries
968 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900969
Alex Light9670d332019-01-29 18:07:33 -0800970 // List of native executables
971 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900972
Roland Levillain630846d2019-06-26 12:48:34 +0100973 // List of native tests
974 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800975}
Jooyung Han344d5432019-08-23 11:17:39 +0900976
Alex Light9670d332019-01-29 18:07:33 -0800977type apexMultilibProperties struct {
978 // Native dependencies whose compile_multilib is "first"
979 First apexNativeDependencies
980
981 // Native dependencies whose compile_multilib is "both"
982 Both apexNativeDependencies
983
984 // Native dependencies whose compile_multilib is "prefer32"
985 Prefer32 apexNativeDependencies
986
987 // Native dependencies whose compile_multilib is "32"
988 Lib32 apexNativeDependencies
989
990 // Native dependencies whose compile_multilib is "64"
991 Lib64 apexNativeDependencies
992}
993
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900994type apexBundleProperties struct {
995 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000996 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800997 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900998
Jiyong Park40e26a22019-02-08 02:53:06 +0900999 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1000 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001001 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001002
Roland Levillain411c5842019-09-19 16:37:20 +01001003 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1004 // device (/apex/<apex_name>).
1005 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001006 Apex_name *string
1007
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001008 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001009 // For platform APEXes, this should points to a file under /system/sepolicy
1010 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1011 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001012
1013 // List of native shared libs that are embedded inside this APEX bundle
1014 Native_shared_libs []string
1015
Roland Levillain630846d2019-06-26 12:48:34 +01001016 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001017 Binaries []string
1018
1019 // List of java libraries that are embedded inside this APEX bundle
1020 Java_libs []string
1021
1022 // List of prebuilt files that are embedded inside this APEX bundle
1023 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001024
Roland Levillain630846d2019-06-26 12:48:34 +01001025 // List of tests that are embedded inside this APEX bundle
1026 Tests []string
1027
Jiyong Parkff1458f2018-10-12 21:49:38 +09001028 // Name of the apex_key module that provides the private key to sign APEX
1029 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001030
Alex Light5098a612018-11-29 17:12:15 -08001031 // The type of APEX to build. Controls what the APEX payload is. Either
1032 // 'image', 'zip' or 'both'. Default: 'image'.
1033 Payload_type *string
1034
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001035 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1036 // or an android_app_certificate module name in the form ":module".
1037 Certificate *string
1038
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001039 // Whether this APEX is installable to one of the partitions. Default: true.
1040 Installable *bool
1041
Jiyong Parkda6eb592018-12-19 17:12:36 +09001042 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1043 // Default is false.
1044 Use_vendor *bool
1045
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001046 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1047 Ignore_system_library_special_case *bool
1048
Alex Light9670d332019-01-29 18:07:33 -08001049 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001050
Jiyong Parkf97782b2019-02-13 20:28:58 +09001051 // List of sanitizer names that this APEX is enabled for
1052 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001053
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001054 PreventInstall bool `blueprint:"mutated"`
1055
1056 HideFromMake bool `blueprint:"mutated"`
1057
Jooyung Han5c998b92019-06-27 11:30:33 +09001058 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1059 Provide_cpp_shared_libs *bool
1060
1061 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1062 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001063
1064 // A txt file containing list of files that are whitelisted to be included in this APEX.
1065 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001066
Sundong Ahnabb64432019-10-22 13:58:29 +09001067 // package format of this apex variant; could be non-flattened, flattened, or zip.
1068 // imageApex, zipApex or flattened
1069 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001070
Jiyong Parkd1063c12019-07-17 20:08:41 +09001071 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1072 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1073 // is implied. This value affects all modules included in this APEX. In other words, they are
1074 // also built with the SDKs specified here.
1075 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001076
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001077 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1078 // Should be only used in tests#.
1079 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001080
Jiyong Park956305c2020-01-09 12:32:06 +09001081 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001082
1083 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
1084 // rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
1085 // like symlinking to the system libs. Default is false.
1086 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001087
1088 // The minimum SDK version that this apex must be compatible with.
1089 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001090}
1091
1092type apexTargetBundleProperties struct {
1093 Target struct {
1094 // Multilib properties only for android.
1095 Android struct {
1096 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001097 }
Jooyung Han344d5432019-08-23 11:17:39 +09001098
Alex Light9670d332019-01-29 18:07:33 -08001099 // Multilib properties only for host.
1100 Host struct {
1101 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001102 }
Jooyung Han344d5432019-08-23 11:17:39 +09001103
Alex Light9670d332019-01-29 18:07:33 -08001104 // Multilib properties only for host linux_bionic.
1105 Linux_bionic struct {
1106 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001107 }
Jooyung Han344d5432019-08-23 11:17:39 +09001108
Alex Light9670d332019-01-29 18:07:33 -08001109 // Multilib properties only for host linux_glibc.
1110 Linux_glibc struct {
1111 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001112 }
1113 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001114}
1115
Jiyong Park5d790c32019-11-15 18:40:32 +09001116type overridableProperties struct {
1117 // List of APKs to package inside APEX
1118 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001119
1120 // Names of modules to be overridden. Listed modules can only be other binaries
1121 // (in Make or Soong).
1122 // This does not completely prevent installation of the overridden binaries, but if both
1123 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1124 // from PRODUCT_PACKAGES.
1125 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001126
1127 // Logging Parent value
1128 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001129
1130 // Apex Container Package Name.
1131 // Override value for attribute package:name in AndroidManifest.xml
1132 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001133}
1134
Alex Light5098a612018-11-29 17:12:15 -08001135type apexPackaging int
1136
1137const (
1138 imageApex apexPackaging = iota
1139 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001140 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001141)
1142
Sundong Ahnabb64432019-10-22 13:58:29 +09001143// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001144func (a apexPackaging) suffix() string {
1145 switch a {
1146 case imageApex:
1147 return imageApexSuffix
1148 case zipApex:
1149 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001150 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001151 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001152 }
1153}
1154
1155func (a apexPackaging) name() string {
1156 switch a {
1157 case imageApex:
1158 return imageApexType
1159 case zipApex:
1160 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001161 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001162 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001163 }
1164}
1165
Jiyong Parkf653b052019-11-18 15:39:01 +09001166type apexFileClass int
1167
1168const (
1169 etc apexFileClass = iota
1170 nativeSharedLib
1171 nativeExecutable
1172 shBinary
1173 pyBinary
1174 goBinary
1175 javaSharedLib
1176 nativeTest
1177 app
1178)
1179
Jiyong Park8fd61922018-11-08 02:50:25 +09001180func (class apexFileClass) NameInMake() string {
1181 switch class {
1182 case etc:
1183 return "ETC"
1184 case nativeSharedLib:
1185 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001186 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001187 return "EXECUTABLES"
1188 case javaSharedLib:
1189 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001190 case nativeTest:
1191 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001192 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001193 // b/142537672 Why isn't this APP? We want to have full control over
1194 // the paths and file names of the apk file under the flattend APEX.
1195 // If this is set to APP, then the paths and file names are modified
1196 // by the Make build system. For example, it is installed to
1197 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1198 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1199 // appends module name (which is <apexname>.<Appname> to the path.
1200 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001201 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001202 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001203 }
1204}
1205
Jiyong Parkf653b052019-11-18 15:39:01 +09001206// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001207type apexFile struct {
1208 builtFile android.Path
1209 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001210 installDir string
1211 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001212 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001213 // list of symlinks that will be created in installDir that point to this apexFile
1214 symlinks []string
1215 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001216 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001217
1218 requiredModuleNames []string
1219 targetRequiredModuleNames []string
1220 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001221
Colin Cross503c1d02020-01-28 14:00:53 -08001222 jacocoReportClassesFile android.Path // only for javalibs and apps
1223 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001224 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001225}
1226
Jiyong Park1833cef2019-12-13 13:28:36 +09001227func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1228 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001229 builtFile: builtFile,
1230 moduleName: moduleName,
1231 installDir: installDir,
1232 class: class,
1233 module: module,
1234 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001235 if module != nil {
1236 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001237 ret.requiredModuleNames = module.RequiredModuleNames()
1238 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1239 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001240 }
1241 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001242}
1243
1244func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001245 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001246}
1247
Jiyong Park7cd10e32020-01-14 09:22:18 +09001248// Path() returns path of this apex file relative to the APEX root
1249func (af *apexFile) Path() string {
1250 return filepath.Join(af.installDir, af.builtFile.Base())
1251}
1252
1253// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1254func (af *apexFile) SymlinkPaths() []string {
1255 var ret []string
1256 for _, symlink := range af.symlinks {
1257 ret = append(ret, filepath.Join(af.installDir, symlink))
1258 }
1259 return ret
1260}
1261
1262func (af *apexFile) AvailableToPlatform() bool {
1263 if af.module == nil {
1264 return false
1265 }
1266 if am, ok := af.module.(android.ApexModule); ok {
1267 return am.AvailableFor(android.AvailableToPlatform)
1268 }
1269 return false
1270}
1271
Jiyong Park678c8812020-02-07 17:25:49 +09001272type depInfo struct {
1273 to string
1274 from []string
1275 isExternal bool
1276}
1277
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001278type apexBundle struct {
1279 android.ModuleBase
1280 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001281 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001282 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001283
Jiyong Park5d790c32019-11-15 18:40:32 +09001284 properties apexBundleProperties
1285 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001286 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001287
Jooyung Hanf21c7972019-12-16 22:32:06 +09001288 // specific to apex_vndk modules
1289 vndkProperties apexVndkProperties
1290
Colin Crossa4925902018-11-16 11:36:28 -08001291 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001292 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001293 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001294
Jiyong Park03b68dd2019-07-26 23:20:40 +09001295 prebuiltFileToDelete string
1296
Jiyong Park42cca6c2019-04-01 11:15:50 +09001297 public_key_file android.Path
1298 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001299
1300 container_certificate_file android.Path
1301 container_private_key_file android.Path
1302
Jooyung Han54aca7b2019-11-20 02:26:02 +09001303 fileContexts android.Path
1304
Jiyong Park8fd61922018-11-08 02:50:25 +09001305 // list of files to be included in this apex
1306 filesInfo []apexFile
1307
Jiyong Park956305c2020-01-09 12:32:06 +09001308 // list of module names that should be installed along with this APEX
1309 requiredDeps []string
1310
Jiyong Park956305c2020-01-09 12:32:06 +09001311 // list of module names that this APEX is including (to be shown via *-deps-info target)
Jiyong Park678c8812020-02-07 17:25:49 +09001312 depInfos map[string]depInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001313
Sundong Ahnabb64432019-10-22 13:58:29 +09001314 testApex bool
1315 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001316 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001317 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001318
Jooyung Han214bf372019-11-12 13:03:50 +09001319 manifestJsonOut android.WritablePath
1320 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001321
Jooyung Han002ab682020-01-08 01:57:58 +09001322 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001323 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001324 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001325 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1326 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001327
1328 // Suffix of module name in Android.mk
1329 // ".flattened", ".apex", ".zipapex", or ""
1330 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001331
1332 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001333
1334 // Whether to create symlink to the system file instead of having a file
1335 // inside the apex or not
1336 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001337
1338 // Struct holding the merged notice file paths in different formats
1339 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001340}
1341
Jiyong Park397e55e2018-10-24 21:09:55 +09001342func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001343 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001344 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001345 // Use *FarVariation* to be able to depend on modules having
1346 // conflicting variations with this module. This is required since
1347 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1348 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001349 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001350 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001351 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001352 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001353 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001354
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001355 ctx.AddFarVariationDependencies(append(target.Variations(),
1356 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1357 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001358
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001359 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001360 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001361 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001362 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001363}
1364
Alex Light9670d332019-01-29 18:07:33 -08001365func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1366 if ctx.Os().Class == android.Device {
1367 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1368 } else {
1369 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1370 if ctx.Os().Bionic() {
1371 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1372 } else {
1373 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1374 }
1375 }
1376}
1377
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001378func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001379 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1380 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1381 }
1382
Jiyong Park397e55e2018-10-24 21:09:55 +09001383 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001384 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001385
1386 a.combineProperties(ctx)
1387
Jiyong Park397e55e2018-10-24 21:09:55 +09001388 has32BitTarget := false
1389 for _, target := range targets {
1390 if target.Arch.ArchType.Multilib == "lib32" {
1391 has32BitTarget = true
1392 }
1393 }
1394 for i, target := range targets {
1395 // When multilib.* is omitted for native_shared_libs, it implies
1396 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001397 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001398 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001399 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001400 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001401
Roland Levillain630846d2019-06-26 12:48:34 +01001402 // When multilib.* is omitted for tests, it implies
1403 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001404 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001405 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001406 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001407 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001408
Jiyong Park397e55e2018-10-24 21:09:55 +09001409 // Add native modules targetting both ABIs
1410 addDependenciesForNativeModules(ctx,
1411 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001412 a.properties.Multilib.Both.Binaries,
1413 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001414 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001415 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001416
Alex Light3d673592019-01-18 14:37:31 -08001417 isPrimaryAbi := i == 0
1418 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001419 // When multilib.* is omitted for binaries, it implies
1420 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001421 ctx.AddFarVariationDependencies(append(target.Variations(),
1422 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1423 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001424
1425 // Add native modules targetting the first ABI
1426 addDependenciesForNativeModules(ctx,
1427 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001428 a.properties.Multilib.First.Binaries,
1429 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001430 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001431 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001432 }
1433
1434 switch target.Arch.ArchType.Multilib {
1435 case "lib32":
1436 // Add native modules targetting 32-bit ABI
1437 addDependenciesForNativeModules(ctx,
1438 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001439 a.properties.Multilib.Lib32.Binaries,
1440 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001441 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001442 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001443
1444 addDependenciesForNativeModules(ctx,
1445 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001446 a.properties.Multilib.Prefer32.Binaries,
1447 a.properties.Multilib.Prefer32.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 case "lib64":
1451 // Add native modules targetting 64-bit ABI
1452 addDependenciesForNativeModules(ctx,
1453 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001454 a.properties.Multilib.Lib64.Binaries,
1455 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001456 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001457 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001458
1459 if !has32BitTarget {
1460 addDependenciesForNativeModules(ctx,
1461 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001462 a.properties.Multilib.Prefer32.Binaries,
1463 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001464 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001465 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001466 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001467
1468 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1469 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1470 if sanitizer == "hwaddress" {
1471 addDependenciesForNativeModules(ctx,
1472 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001473 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001474 break
1475 }
1476 }
1477 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001478 }
1479
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001480 }
1481
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001482 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1483 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1484 // b/144532908
1485 archForPrebuiltEtc := config.Arches()[0]
1486 for _, arch := range config.Arches() {
1487 // Prefer 64-bit arch if there is any
1488 if arch.ArchType.Multilib == "lib64" {
1489 archForPrebuiltEtc = arch
1490 break
1491 }
1492 }
1493 ctx.AddFarVariationDependencies([]blueprint.Variation{
1494 {Mutator: "os", Variation: ctx.Os().String()},
1495 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1496 }, prebuiltTag, a.properties.Prebuilts...)
1497
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001498 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1499 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001500
Ulya Trafimovich44561882020-01-03 13:25:54 +00001501 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1502 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1503 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1504 javaLibTag, "jacocoagent")
1505 }
1506
Jiyong Park23c52b02019-02-02 13:13:47 +09001507 if String(a.properties.Key) == "" {
1508 ctx.ModuleErrorf("key is missing")
1509 return
1510 }
1511 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001512
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001513 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001514 if cert != "" {
1515 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001516 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001517
1518 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1519 if len(a.properties.Uses_sdks) > 0 {
1520 sdkRefs := []android.SdkRef{}
1521 for _, str := range a.properties.Uses_sdks {
1522 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1523 sdkRefs = append(sdkRefs, parsed)
1524 }
1525 a.BuildWithSdks(sdkRefs)
1526 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001527}
1528
Jiyong Park5d790c32019-11-15 18:40:32 +09001529func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1530 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1531 androidAppTag, a.overridableProperties.Apps...)
1532}
1533
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001534func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1535 // direct deps of an APEX bundle are all part of the APEX bundle
1536 return true
1537}
1538
Colin Cross0ea8ba82019-06-06 14:33:29 -07001539func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001540 moduleName := ctx.ModuleName()
1541 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1542 // we check with the pseudo module name to see if its certificate is overridden.
1543 if a.vndkApex {
1544 moduleName = vndkApexName
1545 }
1546 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001547 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001548 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001549 }
1550 return String(a.properties.Certificate)
1551}
1552
Colin Cross41955e82019-05-29 14:40:35 -07001553func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1554 switch tag {
1555 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001556 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001557 default:
1558 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001559 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001560}
1561
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001562func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001563 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001564}
1565
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001566func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1567 return proptools.Bool(a.properties.Test_only_no_hashtree)
1568}
1569
Jiyong Park7c1dc612019-01-05 11:15:24 +09001570func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001571 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001572 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001573 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001574 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001575 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001576 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001577 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001578 }
1579}
1580
Jiyong Parkf97782b2019-02-13 20:28:58 +09001581func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1582 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1583 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1584 }
1585}
1586
Jiyong Park388ef3f2019-01-28 19:47:32 +09001587func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001588 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1589 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001590 }
1591
1592 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001593 globalSanitizerNames := []string{}
1594 if a.Host() {
1595 globalSanitizerNames = ctx.Config().SanitizeHost()
1596 } else {
1597 arches := ctx.Config().SanitizeDeviceArch()
1598 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1599 globalSanitizerNames = ctx.Config().SanitizeDevice()
1600 }
1601 }
1602 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001603}
1604
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001605func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001606 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001607}
1608
1609func (a *apexBundle) PreventInstall() {
1610 a.properties.PreventInstall = true
1611}
1612
1613func (a *apexBundle) HideFromMake() {
1614 a.properties.HideFromMake = true
1615}
1616
Jiyong Park956305c2020-01-09 12:32:06 +09001617func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1618 a.properties.IsCoverageVariant = coverage
1619}
1620
Jiyong Parkf653b052019-11-18 15:39:01 +09001621// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001622func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001623 // Decide the APEX-local directory by the multilib of the library
1624 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001625 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001626 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001627 case "lib32":
1628 dirInApex = "lib"
1629 case "lib64":
1630 dirInApex = "lib64"
1631 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001632 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001633 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001634 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001635 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001636 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001637 // Special case for Bionic libs and other libs installed with them. This is
1638 // to prevent those libs from being included in the search path
1639 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1640 // those libs in the Runtime APEX are available via the legacy paths in
1641 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1642 // to the legacy paths and thus will be loaded into the default linker
1643 // namespace (aka "platform" namespace). If the libs are directly in
1644 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1645 // into the runtime linker namespace, which will result in double loading of
1646 // them, which isn't supported.
1647 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001648 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001649
Jiyong Parkf653b052019-11-18 15:39:01 +09001650 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001651 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001652}
1653
Jiyong Park1833cef2019-12-13 13:28:36 +09001654func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001655 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001656 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001657 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001658 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001659 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001660 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 af.symlinks = cc.Symlinks()
1662 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663}
1664
Jiyong Park1833cef2019-12-13 13:28:36 +09001665func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001666 dirInApex := "bin"
1667 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001668 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001669}
Jiyong Park1833cef2019-12-13 13:28:36 +09001670func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001671 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001672 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1673 if err != nil {
1674 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001676 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 fileToCopy := android.PathForOutput(ctx, s)
1678 // NB: Since go binaries are static we don't need the module for anything here, which is
1679 // good since the go tool is a blueprint.Module not an android.Module like we would
1680 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001681 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001682}
1683
Jiyong Park1833cef2019-12-13 13:28:36 +09001684func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 dirInApex := filepath.Join("bin", sh.SubDir())
1686 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001687 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 af.symlinks = sh.Symlinks()
1689 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001690}
1691
Jooyung Han58f26ab2019-12-18 15:34:32 +09001692// TODO(b/146586360): replace javaLibrary(in apex/apex.go) with java.Dependency
1693type javaLibrary interface {
1694 android.Module
1695 java.Dependency
1696}
1697
1698func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaLibrary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001699 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001700 fileToCopy := lib.DexJar()
Jiyong Park618922e2020-01-08 13:35:43 +09001701 af := newApexFile(ctx, fileToCopy, lib.Name(), dirInApex, javaSharedLib, lib)
1702 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1703 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001704}
1705
Jiyong Park1833cef2019-12-13 13:28:36 +09001706func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001707 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1708 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001709 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001710}
1711
atrost6e126252020-01-27 17:01:16 +00001712func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1713 dirInApex := filepath.Join("etc", config.SubDir())
1714 fileToCopy := config.CompatConfig()
1715 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1716}
1717
Jiyong Park1833cef2019-12-13 13:28:36 +09001718func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 android.Module
1720 Privileged() bool
1721 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001722 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001723 Certificate() java.Certificate
Jiyong Parkf653b052019-11-18 15:39:01 +09001724}, pkgName string) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001725 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001726 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001727 appDir = "priv-app"
1728 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001729 dirInApex := filepath.Join(appDir, pkgName)
1730 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001731 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1732 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001733 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001734
1735 if app, ok := aapp.(interface {
1736 OverriddenManifestPackageName() string
1737 }); ok {
1738 af.overriddenPackageName = app.OverriddenManifestPackageName()
1739 }
Jiyong Park618922e2020-01-08 13:35:43 +09001740 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001741}
1742
Roland Levillain935639d2019-08-13 14:55:28 +01001743// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1744type flattenedApexContext struct {
1745 android.ModuleContext
1746}
1747
1748func (c *flattenedApexContext) InstallBypassMake() bool {
1749 return true
1750}
1751
Jiyong Park201cedd2020-02-07 17:25:49 +09001752// Visit dependencies that contributes to the payload of this APEX
1753func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext,
1754 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
Jiyong Parkfa899442020-01-31 02:49:53 +09001755 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
1756 am, ok := child.(android.ApexModule)
1757 if !ok || !am.CanHaveApexVariants() {
1758 return false
1759 }
1760
1761 // Check for the direct dependencies that contribute to the payload
1762 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1763 if dt.payload {
Jiyong Park201cedd2020-02-07 17:25:49 +09001764 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001765 return true
1766 }
1767 return false
1768 }
1769
1770 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001771 if am.ApexName() != "" {
Jiyong Park201cedd2020-02-07 17:25:49 +09001772 do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001773 return true
1774 }
1775
Jiyong Park201cedd2020-02-07 17:25:49 +09001776 do(ctx, parent, am, true /* externalDep */)
1777
Jiyong Parkfa899442020-01-31 02:49:53 +09001778 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1779 return false
1780 })
1781}
1782
Jooyung Han0c4e0162020-02-26 22:45:42 +09001783func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1784 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001785 intVer, err := android.ApiStrToNum(ctx, ver)
1786 if err != nil {
1787 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001788 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001789 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001790}
1791
Jiyong Park201cedd2020-02-07 17:25:49 +09001792// Ensures that the dependencies are marked as available for this APEX
1793func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1794 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1795 if ctx.Host() || a.testApex || a.vndkApex {
1796 return
1797 }
1798
1799 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1800 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001801 fromName := ctx.OtherModuleName(from)
1802 toName := ctx.OtherModuleName(to)
1803 if externalDep || to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
Jiyong Park201cedd2020-02-07 17:25:49 +09001804 return
1805 }
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001806 ctx.ModuleErrorf("%q requires %q that is not available for the APEX.", fromName, toName)
Jiyong Park201cedd2020-02-07 17:25:49 +09001807 })
1808}
1809
Jiyong Park678c8812020-02-07 17:25:49 +09001810// Collects the list of module names that directly or indirectly contributes to the payload of this APEX
1811func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
1812 a.depInfos = make(map[string]depInfo)
1813 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
1814 if from.Name() == to.Name() {
1815 // This can happen for cc.reuseObjTag. We are not interested in tracking this.
1816 return
1817 }
1818
1819 if info, exists := a.depInfos[to.Name()]; exists {
1820 if !android.InList(from.Name(), info.from) {
1821 info.from = append(info.from, from.Name())
1822 }
1823 info.isExternal = info.isExternal && externalDep
1824 a.depInfos[to.Name()] = info
1825 } else {
1826 a.depInfos[to.Name()] = depInfo{
1827 to: to.Name(),
1828 from: []string{from.Name()},
1829 isExternal: externalDep,
1830 }
1831 }
1832 })
1833}
1834
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001835func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001836 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1837 switch a.properties.ApexType {
1838 case imageApex:
1839 if buildFlattenedAsDefault {
1840 a.suffix = imageApexSuffix
1841 } else {
1842 a.suffix = ""
1843 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001844
1845 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001846 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001847 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001848 }
1849 case zipApex:
1850 if proptools.String(a.properties.Payload_type) == "zip" {
1851 a.suffix = ""
1852 a.primaryApexType = true
1853 } else {
1854 a.suffix = zipApexSuffix
1855 }
1856 case flattenedApex:
1857 if buildFlattenedAsDefault {
1858 a.suffix = ""
1859 a.primaryApexType = true
1860 } else {
1861 a.suffix = flattenedSuffix
1862 }
Alex Light5098a612018-11-29 17:12:15 -08001863 }
1864
Roland Levillain630846d2019-06-26 12:48:34 +01001865 if len(a.properties.Tests) > 0 && !a.testApex {
1866 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1867 return
1868 }
1869
Jiyong Parkfa899442020-01-31 02:49:53 +09001870 a.checkApexAvailability(ctx)
1871
Jiyong Park678c8812020-02-07 17:25:49 +09001872 a.collectDepsInfo(ctx)
1873
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001874 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1875
Jooyung Hane1633032019-08-01 17:41:43 +09001876 // native lib dependencies
1877 var provideNativeLibs []string
1878 var requireNativeLibs []string
1879
Jooyung Han5c998b92019-06-27 11:30:33 +09001880 // Check if "uses" requirements are met with dependent apexBundles
1881 var providedNativeSharedLibs []string
1882 useVendor := proptools.Bool(a.properties.Use_vendor)
1883 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1884 if ctx.OtherModuleDependencyTag(m) != usesTag {
1885 return
1886 }
1887 otherName := ctx.OtherModuleName(m)
1888 other, ok := m.(*apexBundle)
1889 if !ok {
1890 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1891 return
1892 }
1893 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1894 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1895 return
1896 }
1897 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1898 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1899 return
1900 }
1901 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1902 })
1903
Jiyong Parkf653b052019-11-18 15:39:01 +09001904 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001905 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001906 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001907 depTag := ctx.OtherModuleDependencyTag(child)
1908 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001909 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001910 switch depTag {
1911 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001912 if c, ok := child.(*cc.Module); ok {
1913 // bootstrap bionic libs are treated as provided by system
1914 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1915 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001916 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001917 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001918 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001919 } else {
1920 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001921 }
1922 case executableTag:
1923 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001924 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001926 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001927 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001928 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001929 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001930 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001931 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001932 } else {
Alex Light778127a2019-02-27 14:19:50 -08001933 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 +09001934 }
1935 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001936 if javaLib, ok := child.(*java.Library); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001937 af := apexFileForJavaLibrary(ctx, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001938 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001939 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1940 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001941 filesInfo = append(filesInfo, af)
1942 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001943 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001944 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
1945 af := apexFileForJavaLibrary(ctx, sdkLib)
1946 if !af.Ok() {
1947 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1948 return false
1949 }
1950 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001951 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001952 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001953 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001954 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001955 case androidAppTag:
1956 pkgName := ctx.DeviceConfig().OverridePackageNameFor(depName)
1957 if ap, ok := child.(*java.AndroidApp); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001958 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001959 return true // track transitive dependencies
1960 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001961 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Dario Freni6f3937c2019-12-20 22:58:03 +00001962 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
1963 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap, pkgName))
Jiyong Parkf653b052019-11-18 15:39:01 +09001964 } else {
1965 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1966 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001967 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09001968 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001970 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1971 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001972 } else {
atrost6e126252020-01-27 17:01:16 +00001973 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001974 }
Roland Levillain630846d2019-06-26 12:48:34 +01001975 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001976 if ccTest, ok := child.(*cc.Module); ok {
1977 if ccTest.IsTestPerSrcAllTestsVariation() {
1978 // Multiple-output test module (where `test_per_src: true`).
1979 //
1980 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
1981 // We do not add this variation to `filesInfo`, as it has no output;
1982 // however, we do add the other variations of this module as indirect
1983 // dependencies (see below).
1984 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01001985 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01001986 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09001987 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 af.class = nativeTest
1989 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01001990 }
Roland Levillain630846d2019-06-26 12:48:34 +01001991 } else {
1992 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
1993 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 case keyTag:
1995 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001996 a.private_key_file = key.private_key_file
1997 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09001998 } else {
1999 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002000 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002002 case certificateTag:
2003 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002004 a.container_certificate_file = dep.Certificate.Pem
2005 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002006 } else {
2007 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2008 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002009 case android.PrebuiltDepTag:
2010 // If the prebuilt is force disabled, remember to delete the prebuilt file
2011 // that might have been installed in the previous builds
2012 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2013 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2014 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002015 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002016 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002017 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002018 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002019 // We cannot use a switch statement on `depTag` here as the checked
2020 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002021 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002022 if cc, ok := child.(*cc.Module); ok {
2023 if android.InList(cc.Name(), providedNativeSharedLibs) {
2024 // If we're using a shared library which is provided from other APEX,
2025 // don't include it in this APEX
2026 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002027 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002028 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002029 // If the dependency is a stubs lib, don't include it in this APEX,
2030 // but make sure that the lib is installed on the device.
2031 // In case no APEX is having the lib, the lib is installed to the system
2032 // partition.
2033 //
2034 // Always include if we are a host-apex however since those won't have any
2035 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002036 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2037 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002038 }
Jooyung Hane1633032019-08-01 17:41:43 +09002039 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002040 // Don't track further
2041 return false
2042 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002043 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002044 af.transitiveDep = true
2045 filesInfo = append(filesInfo, af)
2046 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002047 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002048 } else if cc.IsTestPerSrcDepTag(depTag) {
2049 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002050 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 // Handle modules created as `test_per_src` variations of a single test module:
2052 // use the name of the generated test binary (`fileToCopy`) instead of the name
2053 // of the original test module (`depName`, shared by all `test_per_src`
2054 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002055 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002056 // these are not considered transitive dep
2057 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002058 filesInfo = append(filesInfo, af)
2059 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002061 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002062 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2063 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002064 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2065 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2066 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2067 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002068 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002070 }
2071 }
2072 }
2073 return false
2074 })
2075
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002076 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2077 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2078 // via the global boot image config.
2079 if a.artApex {
2080 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2081 dirInApex := filepath.Join("javalib", arch.String())
2082 for _, f := range files {
2083 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002085 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002086 }
2087 }
2088 }
2089
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002090 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002091 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2092 return
2093 }
2094
Jiyong Park8fd61922018-11-08 02:50:25 +09002095 // remove duplicates in filesInfo
2096 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002097 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002098 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002099 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002100 if e, ok := encountered[dest]; !ok {
2101 encountered[dest] = f
2102 } else {
2103 // If a module is directly included and also transitively depended on
2104 // consider it as directly included.
2105 e.transitiveDep = e.transitiveDep && f.transitiveDep
2106 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002107 }
2108 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002109 var result []apexFile
2110 for _, v := range encountered {
2111 result = append(result, v)
2112 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002113 return result
2114 }
2115 filesInfo = removeDup(filesInfo)
2116
2117 // to have consistent build rules
2118 sort.Slice(filesInfo, func(i, j int) bool {
2119 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2120 })
2121
Jiyong Park8fd61922018-11-08 02:50:25 +09002122 a.installDir = android.PathForModuleInstall(ctx, "apex")
2123 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002124
Jooyung Han54aca7b2019-11-20 02:26:02 +09002125 if a.properties.ApexType != zipApex {
2126 if a.properties.File_contexts == nil {
2127 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2128 } else {
2129 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2130 if a.Platform() {
2131 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2132 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2133 }
2134 }
2135 }
2136 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2137 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2138 return
2139 }
2140 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002141 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2142 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2143 // the same library in the system partition, thus effectively sharing the same libraries
2144 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2145 // in the APEX.
2146 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2147 a.installable() &&
2148 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002149
Jiyong Park9d677202020-02-19 16:29:35 +09002150 // We don't need the optimization for updatable APEXes, as it might give false signal
2151 // to the system health when the APEXes are still bundled (b/149805758)
2152 if proptools.Bool(a.properties.Updatable) && a.properties.ApexType == imageApex {
2153 a.linkToSystemLib = false
2154 }
2155
Jiyong Park9b964182020-02-26 18:27:19 +09002156 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2157 if ctx.Host() {
2158 a.linkToSystemLib = false
2159 }
2160
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002161 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002162 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2163
2164 a.setCertificateAndPrivateKey(ctx)
2165 if a.properties.ApexType == flattenedApex {
2166 a.buildFlattenedApex(ctx)
2167 } else {
2168 a.buildUnflattenedApex(ctx)
2169 }
2170
Jooyung Han002ab682020-01-08 01:57:58 +09002171 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002172
2173 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002174}
2175
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002176func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002177 key := apex
2178 key = strings.Replace(key, "test_", "", 1)
2179 key = strings.Replace(key, "com.android.art.debug", "com.android.art", 1)
2180 key = strings.Replace(key, "com.android.art.release", "com.android.art", 1)
2181
Jiyong Parkfa899442020-01-31 02:49:53 +09002182 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2183 // system. Trim the prefix for the check since they are confusing
2184 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2185 if strings.HasPrefix(moduleName, "libclang_rt.") {
2186 // This module has many arch variants that depend on the product being built.
2187 // We don't want to list them all
2188 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002189 }
2190
2191 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2192 return true
2193 }
2194
Jiyong Parkfa899442020-01-31 02:49:53 +09002195 key = "//any"
2196 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2197 return true
2198 }
2199
Anton Hansson5053c292020-01-10 15:12:39 +00002200 return false
2201}
2202
Jooyung Han344d5432019-08-23 11:17:39 +09002203func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002204 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002205 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002206 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002207 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002208 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002209 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2210 })
Alex Light5098a612018-11-29 17:12:15 -08002211 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002212 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002213 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002214 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002215 return module
2216}
Jiyong Park30ca9372019-02-07 16:27:23 +09002217
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002218func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002219 bundle := newApexBundle()
2220 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002221 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002222 return bundle
2223}
2224
Jiyong Parkfce0b422020-02-11 03:56:06 +09002225// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2226// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002227func testApexBundleFactory() android.Module {
2228 bundle := newApexBundle()
2229 bundle.testApex = true
2230 return bundle
2231}
2232
Jiyong Parkfce0b422020-02-11 03:56:06 +09002233// apex packages other modules into an APEX file which is a packaging format for system-level
2234// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002235func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002236 return newApexBundle()
2237}
2238
Jiyong Park30ca9372019-02-07 16:27:23 +09002239//
2240// Defaults
2241//
2242type Defaults struct {
2243 android.ModuleBase
2244 android.DefaultsModuleBase
2245}
2246
Jiyong Park30ca9372019-02-07 16:27:23 +09002247func defaultsFactory() android.Module {
2248 return DefaultsFactory()
2249}
2250
2251func DefaultsFactory(props ...interface{}) android.Module {
2252 module := &Defaults{}
2253
2254 module.AddProperties(props...)
2255 module.AddProperties(
2256 &apexBundleProperties{},
2257 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002258 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002259 )
2260
2261 android.InitDefaultsModule(module)
2262 return module
2263}
Jiyong Park5d790c32019-11-15 18:40:32 +09002264
2265//
2266// OverrideApex
2267//
2268type OverrideApex struct {
2269 android.ModuleBase
2270 android.OverrideModuleBase
2271}
2272
2273func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2274 // All the overrides happen in the base module.
2275}
2276
2277// override_apex is used to create an apex module based on another apex module
2278// by overriding some of its properties.
2279func overrideApexFactory() android.Module {
2280 m := &OverrideApex{}
2281 m.AddProperties(&overridableProperties{})
2282
2283 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2284 android.InitOverrideModule(m)
2285 return m
2286}