blob: b9fc4e18e35c4eaa67f7e3b58aeddbaefd47260d [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
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080026 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090027 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070028
29 "android/soong/android"
30 "android/soong/cc"
31 prebuilt_etc "android/soong/etc"
32 "android/soong/java"
33 "android/soong/python"
34 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090035)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090045)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090046
47type dependencyTag struct {
48 blueprint.BaseDependencyTag
49 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090050
51 // determines if the dependent will be part of the APEX payload
52 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090053}
54
55var (
Jiyong Park0f80c182020-01-31 02:49:53 +090056 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090057 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090058 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090066 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000067 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000068
69 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090070)
71
Paul Duffin7d74e7b2020-03-06 12:30:13 +000072// Transform the map of apex -> modules to module -> apexes.
73func invertApexWhiteList(m map[string][]string) map[string][]string {
74 r := make(map[string][]string)
75 for apex, modules := range m {
76 for _, module := range modules {
77 r[module] = append(r[module], apex)
78 }
79 }
80 return r
81}
82
83// Retrieve the while list of apexes to which the supplied module belongs.
84func WhitelistedApexAvailable(moduleName string) []string {
85 return inverseApexAvailWl[normalizeModuleName(moduleName)]
86}
87
Anton Hanssoneec79eb2020-01-10 15:12:39 +000088// This is a map from apex to modules, which overrides the
89// apex_available setting for that particular module to make
90// it available for the apex regardless of its setting.
91// TODO(b/147364041): remove this
92func makeApexAvailableWhitelist() map[string][]string {
93 // The "Module separator"s below are employed to minimize merge conflicts.
94 m := make(map[string][]string)
95 //
96 // Module separator
97 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +000098 m["com.android.bluetooth.updatable"] = []string{
99 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000100 "android.hardware.bluetooth.a2dp@1.0",
101 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900102 "android.hardware.bluetooth@1.0",
103 "android.hardware.bluetooth@1.1",
104 "android.hardware.graphics.bufferqueue@1.0",
105 "android.hardware.graphics.bufferqueue@2.0",
106 "android.hardware.graphics.common@1.0",
107 "android.hardware.graphics.common@1.1",
108 "android.hardware.graphics.common@1.2",
109 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000110 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900111 "android.hidl.token@1.0",
112 "android.hidl.token@1.0-utils",
113 "avrcp-target-service",
114 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900115 "bluetooth-protos-lite",
116 "bluetooth.mapsapi",
117 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900118 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900119 "ipmemorystore-aidl-interfaces-V5-java",
120 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900121 "internal_include_headers",
122 "lib-bt-packets",
123 "lib-bt-packets-avrcp",
124 "lib-bt-packets-base",
125 "libFraunhoferAAC",
126 "libaudio-a2dp-hw-utils",
127 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000129 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900130 "libbluetooth-types",
131 "libbluetooth-types-header",
132 "libbluetooth_gd",
133 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900135 "libbt-audio-hal-interface",
136 "libbt-bta",
137 "libbt-common",
138 "libbt-hci",
139 "libbt-platform-protos-lite",
140 "libbt-protos-lite",
141 "libbt-sbc-decoder",
142 "libbt-sbc-encoder",
143 "libbt-stack",
144 "libbt-utils",
145 "libbtcore",
146 "libbtdevice",
147 "libbte",
148 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000149 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000150 "libevent",
151 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900153 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900154 "libmedia_headers",
155 "libmodpb64",
156 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900157 "libstagefright_foundation_headers",
158 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000163 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900165 "net-utils-services-common",
166 "netd_aidl_interface-unstable-java",
167 "netd_event_listener_interface-java",
168 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900169 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900170 "sap-api-java-static",
171 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000172 }
173 //
174 // Module separator
175 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 //
178 // Module separator
179 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900180 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900181 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 }
183 //
184 // Module separator
185 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900186 m["com.android.neuralnetworks"] = []string{
187 "android.hardware.neuralnetworks@1.0",
188 "android.hardware.neuralnetworks@1.1",
189 "android.hardware.neuralnetworks@1.2",
190 "android.hardware.neuralnetworks@1.3",
191 "android.hidl.allocator@1.0",
192 "android.hidl.memory.token@1.0",
193 "android.hidl.memory@1.0",
194 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900195 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 "libprocpartition",
199 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900200 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000201 //
202 // Module separator
203 //
204 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000205 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900206 "android.hardware.cas.native@1.0",
207 "android.hardware.cas@1.0",
208 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000209 "android.hardware.configstore@1.0",
210 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000211 "android.hardware.graphics.allocator@2.0",
212 "android.hardware.graphics.allocator@3.0",
213 "android.hardware.graphics.bufferqueue@1.0",
214 "android.hardware.graphics.bufferqueue@2.0",
215 "android.hardware.graphics.common@1.0",
216 "android.hardware.graphics.common@1.1",
217 "android.hardware.graphics.common@1.2",
218 "android.hardware.graphics.mapper@2.0",
219 "android.hardware.graphics.mapper@2.1",
220 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900221 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000222 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900223 "android.hidl.allocator@1.0",
224 "android.hidl.memory.token@1.0",
225 "android.hidl.memory@1.0",
226 "android.hidl.token@1.0",
227 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900228 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900229 "exoplayer2-extractor",
230 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900232 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900233 "libEGL",
234 "libEGL_blobCache",
235 "libEGL_getProcAddress",
236 "libFLAC",
237 "libFLAC-config",
238 "libFLAC-headers",
239 "libGLESv2",
240 "libaacextractor",
241 "libamrextractor",
242 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900243 "libaudio_system_headers",
244 "libaudioclient",
245 "libaudioclient_headers",
246 "libaudiofoundation",
247 "libaudiofoundation_headers",
248 "libaudiomanager",
249 "libaudiopolicy",
250 "libaudioutils",
251 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900252 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900253 "libbluetooth-types-header",
254 "libbufferhub",
255 "libbufferhub_headers",
256 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900257 "libc_malloc_debug_backtrace",
258 "libcamera_client",
259 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900260 "libdexfile_external_headers",
261 "libdexfile_support",
262 "libdvr_headers",
263 "libexpat",
264 "libfifo",
265 "libflacextractor",
266 "libgrallocusage",
267 "libgraphicsenv",
268 "libgui",
269 "libgui_headers",
270 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "liblzma",
273 "libmath",
274 "libmedia",
275 "libmedia_codeclist",
276 "libmedia_headers",
277 "libmedia_helper",
278 "libmedia_helper_headers",
279 "libmedia_midiiowrapper",
280 "libmedia_omx",
281 "libmediautils",
282 "libmidiextractor",
283 "libmkvextractor",
284 "libmp3extractor",
285 "libmp4extractor",
286 "libmpeg2extractor",
287 "libnativebase_headers",
288 "libnativebridge-headers",
289 "libnativebridge_lazy",
290 "libnativeloader-headers",
291 "libnativeloader_lazy",
292 "libnativewindow_headers",
293 "libnblog",
294 "liboggextractor",
295 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900296 "libpdx",
297 "libpdx_default_transport",
298 "libpdx_headers",
299 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900301 "libsonivox",
302 "libspeexresampler",
303 "libspeexresampler",
304 "libstagefright_esds",
305 "libstagefright_flacdec",
306 "libstagefright_flacdec",
307 "libstagefright_foundation",
308 "libstagefright_foundation_headers",
309 "libstagefright_foundation_without_imemory",
310 "libstagefright_headers",
311 "libstagefright_id3",
312 "libstagefright_metadatautils",
313 "libstagefright_mpeg2extractor",
314 "libstagefright_mpeg2support",
315 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900316 "libui",
317 "libui_headers",
318 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 "libvibrator",
320 "libvorbisidec",
321 "libwavextractor",
322 "libwebm",
323 "media_ndk_headers",
324 "media_plugin_headers",
325 "updatable-media",
326 }
327 //
328 // Module separator
329 //
330 m["com.android.media.swcodec"] = []string{
331 "android.frameworks.bufferhub@1.0",
332 "android.hardware.common-ndk_platform",
333 "android.hardware.configstore-utils",
334 "android.hardware.configstore@1.0",
335 "android.hardware.configstore@1.1",
336 "android.hardware.graphics.allocator@2.0",
337 "android.hardware.graphics.allocator@3.0",
338 "android.hardware.graphics.bufferqueue@1.0",
339 "android.hardware.graphics.bufferqueue@2.0",
340 "android.hardware.graphics.common-ndk_platform",
341 "android.hardware.graphics.common@1.0",
342 "android.hardware.graphics.common@1.1",
343 "android.hardware.graphics.common@1.2",
344 "android.hardware.graphics.mapper@2.0",
345 "android.hardware.graphics.mapper@2.1",
346 "android.hardware.graphics.mapper@3.0",
347 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000348 "android.hardware.media.bufferpool@2.0",
349 "android.hardware.media.c2@1.0",
350 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900351 "android.hardware.media@1.0",
352 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000353 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900354 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000355 "android.hidl.safe_union@1.0",
356 "android.hidl.token@1.0",
357 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900358 "libEGL",
359 "libFLAC",
360 "libFLAC-config",
361 "libFLAC-headers",
362 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900363 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900364 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900365 "libaudio_system_headers",
366 "libaudioutils",
367 "libaudioutils",
368 "libaudioutils_fixedfft",
369 "libavcdec",
370 "libavcenc",
371 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000372 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900374 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900375 "libbluetooth-types-header",
376 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000378 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000380 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900381 "libcodec2_hidl@1.1",
382 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000383 "libcodec2_soft_aacdec",
384 "libcodec2_soft_aacenc",
385 "libcodec2_soft_amrnbdec",
386 "libcodec2_soft_amrnbenc",
387 "libcodec2_soft_amrwbdec",
388 "libcodec2_soft_amrwbenc",
389 "libcodec2_soft_av1dec_gav1",
390 "libcodec2_soft_avcdec",
391 "libcodec2_soft_avcenc",
392 "libcodec2_soft_common",
393 "libcodec2_soft_flacdec",
394 "libcodec2_soft_flacenc",
395 "libcodec2_soft_g711alawdec",
396 "libcodec2_soft_g711mlawdec",
397 "libcodec2_soft_gsmdec",
398 "libcodec2_soft_h263dec",
399 "libcodec2_soft_h263enc",
400 "libcodec2_soft_hevcdec",
401 "libcodec2_soft_hevcenc",
402 "libcodec2_soft_mp3dec",
403 "libcodec2_soft_mpeg2dec",
404 "libcodec2_soft_mpeg4dec",
405 "libcodec2_soft_mpeg4enc",
406 "libcodec2_soft_opusdec",
407 "libcodec2_soft_opusenc",
408 "libcodec2_soft_rawdec",
409 "libcodec2_soft_vorbisdec",
410 "libcodec2_soft_vp8dec",
411 "libcodec2_soft_vp8enc",
412 "libcodec2_soft_vp9dec",
413 "libcodec2_soft_vp9enc",
414 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000415 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900416 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000417 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900418 "libfmq",
419 "libgav1",
420 "libgralloctypes",
421 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000422 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900423 "libgsm",
424 "libgui_bufferqueue_static",
425 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000426 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900427 "libhardware_headers",
428 "libhevcdec",
429 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000430 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000432 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900433 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000434 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900436 "libmpeg2dec",
437 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000438 "libnativebridge_lazy",
439 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900440 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900441 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000442 "libscudo_wrapper",
443 "libsfplugin_ccodec_utils",
444 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libstagefright_amrnbdec",
446 "libstagefright_amrnbenc",
447 "libstagefright_amrwbdec",
448 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000449 "libstagefright_bufferpool@2.0.1",
450 "libstagefright_bufferqueue_helper",
451 "libstagefright_enc_common",
452 "libstagefright_flacdec",
453 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900454 "libstagefright_foundation_headers",
455 "libstagefright_headers",
456 "libstagefright_m4vh263dec",
457 "libstagefright_m4vh263enc",
458 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000459 "libsync",
460 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900461 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000462 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000463 "libvorbisidec",
464 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900465 "libyuv",
466 "libyuv_static",
467 "media_ndk_headers",
468 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000469 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900470 }
471 //
472 // Module separator
473 //
474 m["com.android.mediaprovider"] = []string{
475 "MediaProvider",
476 "MediaProviderGoogle",
477 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900478 "libbase_ndk",
479 "libfuse",
480 "libfuse_jni",
481 "libnativehelper_header_only",
482 }
483 //
484 // Module separator
485 //
486 m["com.android.permission"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900487 "kotlin-annotations",
488 "kotlin-stdlib",
489 "kotlin-stdlib-jdk7",
490 "kotlin-stdlib-jdk8",
491 "kotlinx-coroutines-android",
492 "kotlinx-coroutines-android-nodeps",
493 "kotlinx-coroutines-core",
494 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900495 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000496 }
497 //
498 // Module separator
499 //
500 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900501 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900502 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900503 "libc_aeabi",
504 "libc_bionic",
505 "libc_bionic_ndk",
506 "libc_bootstrap",
507 "libc_common",
508 "libc_common_shared",
509 "libc_common_static",
510 "libc_dns",
511 "libc_dynamic_dispatch",
512 "libc_fortify",
513 "libc_freebsd",
514 "libc_freebsd_large_stack",
515 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900516 "libc_init_dynamic",
517 "libc_init_static",
518 "libc_jemalloc_wrapper",
519 "libc_netbsd",
520 "libc_nomalloc",
521 "libc_nopthread",
522 "libc_openbsd",
523 "libc_openbsd_large_stack",
524 "libc_openbsd_ndk",
525 "libc_pthread",
526 "libc_static_dispatch",
527 "libc_syscalls",
528 "libc_tzcode",
529 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900530 "libdebuggerd",
531 "libdebuggerd_common_headers",
532 "libdebuggerd_handler_core",
533 "libdebuggerd_handler_fallback",
534 "libdexfile_external_headers",
535 "libdexfile_support",
536 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900537 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900538 "libjemalloc5",
539 "liblinker_main",
540 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900541 "liblz4",
542 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900543 "libprocinfo",
544 "libpropertyinfoparser",
545 "libscudo",
546 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libsystemproperties",
548 "libtombstoned_client_static",
549 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900550 "libz",
551 "libziparchive",
552 }
553 //
554 // Module separator
555 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900556 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900557 "android.hardware.tetheroffload.config-V1.0-java",
558 "android.hardware.tetheroffload.control-V1.0-java",
559 "android.hidl.base-V1.0-java",
560 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "libcgrouprc",
562 "libcgrouprc_format",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900563 "libnativehelper_compat_libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900564 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900566 "net-utils-framework-common",
567 "netd_aidl_interface-V3-java",
568 "netlink-client",
569 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900570 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900571 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000572 }
573 //
574 // Module separator
575 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900576 m["com.android.wifi"] = []string{
577 "PlatformProperties",
578 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900579 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "android.hardware.wifi-V1.1-java",
581 "android.hardware.wifi-V1.2-java",
582 "android.hardware.wifi-V1.3-java",
583 "android.hardware.wifi-V1.4-java",
584 "android.hardware.wifi.hostapd-V1.0-java",
585 "android.hardware.wifi.hostapd-V1.1-java",
586 "android.hardware.wifi.hostapd-V1.2-java",
587 "android.hardware.wifi.supplicant-V1.0-java",
588 "android.hardware.wifi.supplicant-V1.1-java",
589 "android.hardware.wifi.supplicant-V1.2-java",
590 "android.hardware.wifi.supplicant-V1.3-java",
591 "android.hidl.base-V1.0-java",
592 "android.hidl.manager-V1.0-java",
593 "android.hidl.manager-V1.1-java",
594 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "bouncycastle-unbundled",
596 "dnsresolver_aidl_interface-V2-java",
597 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900598 "framework-wifi-pre-jarjar",
599 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900600 "ipmemorystore-aidl-interfaces-V3-java",
601 "ipmemorystore-aidl-interfaces-java",
602 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900603 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900604 "libwifi-jni",
605 "net-utils-services-common",
606 "netd_aidl_interface-V2-java",
607 "netd_aidl_interface-unstable-java",
608 "netd_event_listener_interface-java",
609 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900610 "networkstack-client",
611 "services.net",
612 "wifi-lite-protos",
613 "wifi-nano-protos",
614 "wifi-service-pre-jarjar",
615 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900616 }
617 //
618 // Module separator
619 //
620 m["com.android.sdkext"] = []string{
621 "fmtlib_ndk",
622 "libbase_ndk",
623 "libprotobuf-cpp-lite-ndk",
624 }
625 //
626 // Module separator
627 //
628 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900630 }
631 //
632 // Module separator
633 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000634 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900635 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
636 "androidx",
637 "androidx-constraintlayout_constraintlayout",
638 "androidx-constraintlayout_constraintlayout-nodeps",
639 "androidx-constraintlayout_constraintlayout-solver",
640 "androidx-constraintlayout_constraintlayout-solver-nodeps",
641 "com.google.android.material_material",
642 "com.google.android.material_material-nodeps",
643
Jiyong Park0f80c182020-01-31 02:49:53 +0900644 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900645 "libclang_rt",
646 "libgcc_stripped",
647 "libprofile-clang-extras",
648 "libprofile-clang-extras_ndk",
649 "libprofile-extras",
650 "libprofile-extras_ndk",
651 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900652 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000653 return m
654}
655
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900656func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900657 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800658 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900659 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900660 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700661 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900662 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700663 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900664
Jooyung Han31c470b2019-10-18 16:26:59 +0900665 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900666 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900667
668 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
669 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
670 sort.Strings(*apexFileContextsInfos)
671 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
672 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900673}
674
Jooyung Han31c470b2019-10-18 16:26:59 +0900675func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
676 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
677 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
678}
679
Jiyong Parkd1063c12019-07-17 20:08:41 +0900680func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900681 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900682 ctx.BottomUp("apex", apexMutator).Parallel()
683 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
684 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900685 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900686}
687
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900688// Mark the direct and transitive dependencies of apex bundles so that they
689// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900690func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900691 if !mctx.Module().Enabled() {
692 return
693 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800694 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900695 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000696 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900697 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900698 ApexName: mctx.ModuleName(),
699 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev849f8442020-04-28 14:57:42 +0100700 Updatable: a.Updatable(),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900701 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900702 directDep = true
703 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800704 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900705 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900706 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900707
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800708 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900709 return
710 }
711
Paul Duffin923e8a52020-03-30 15:33:32 +0100712 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900713
Jiyong Parkf760cae2020-02-12 07:53:12 +0900714 mctx.VisitDirectDeps(func(child android.Module) {
715 depName := mctx.OtherModuleName(child)
716 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100717 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800718 android.UpdateApexDependency(apexBundles, depName, directDep)
719 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900720 }
721 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900722}
723
Jiyong Park89e850a2020-04-07 16:37:39 +0900724// mark if a module cannot be available to platform. A module cannot be available
725// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
726// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
727func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
728 // Host and recovery are not considered as platform
729 if mctx.Host() || mctx.Module().InstallInRecovery() {
730 return
731 }
732
733 if am, ok := mctx.Module().(android.ApexModule); ok {
734 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
735
736 // In a rare case when a lib is marked as available only to an apex
737 // but the apex doesn't exist. This can happen in a partial manifest branch
738 // like master-art. Currently, libstatssocket in the stats APEX is causing
739 // this problem.
740 // Include the lib in platform because the module SDK that ought to provide
741 // it doesn't exist, so it would otherwise be left out completely.
742 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
743 // this check for libraries provided by SDKs.
744 if !availableToPlatform && !android.InAnyApex(am.Name()) {
745 availableToPlatform = true
746 }
747
748 // If any of the dep is not available to platform, this module is also considered
749 // as being not available to platform even if it has "//apex_available:platform"
750 mctx.VisitDirectDeps(func(child android.Module) {
751 if !am.DepIsInSameApex(mctx, child) {
752 // if the dependency crosses apex boundary, don't consider it
753 return
754 }
755 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
756 availableToPlatform = false
757 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
758 }
759 })
760
761 // Exception 1: stub libraries and native bridge libraries are always available to platform
762 if cc, ok := mctx.Module().(*cc.Module); ok &&
763 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
764 availableToPlatform = true
765 }
766
767 // Exception 2: bootstrap bionic libraries are also always available to platform
768 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
769 availableToPlatform = true
770 }
771
772 if !availableToPlatform {
773 am.SetNotAvailableForPlatform()
774 }
775 }
776}
777
Paul Duffin65347702020-03-31 15:23:40 +0100778// If a module in an APEX depends on a module from an SDK then it needs an APEX
779// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
780func inAnySdk(module android.Module) bool {
781 if sa, ok := module.(android.SdkAware); ok {
782 return sa.IsInAnySdk()
783 }
784
785 return false
786}
787
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900788// Create apex variations if a module is included in APEX(s).
789func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900790 if !mctx.Module().Enabled() {
791 return
792 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900793 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900794 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000795 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900796 // apex bundle itself is mutated so that it and its modules have same
797 // apex variant.
798 apexBundleName := mctx.ModuleName()
799 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900800 } else if o, ok := mctx.Module().(*OverrideApex); ok {
801 apexBundleName := o.GetOverriddenModuleName()
802 if apexBundleName == "" {
803 mctx.ModuleErrorf("base property is not set")
804 return
805 }
806 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900807 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900808
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900809}
Sundong Ahne9b55722019-09-06 17:37:42 +0900810
Jooyung Han7a78a922019-10-08 21:59:58 +0900811var (
812 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
813 apexFileContextsInfosMutex sync.Mutex
814)
815
816func apexFileContextsInfos(config android.Config) *[]string {
817 return config.Once(apexFileContextsInfosKey, func() interface{} {
818 return &[]string{}
819 }).(*[]string)
820}
821
Jooyung Han54aca7b2019-11-20 02:26:02 +0900822func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900823 apexFileContextsInfosMutex.Lock()
824 defer apexFileContextsInfosMutex.Unlock()
825 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900826 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900827}
828
Sundong Ahne9b55722019-09-06 17:37:42 +0900829func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900830 if !mctx.Module().Enabled() {
831 return
832 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900833 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900834 var variants []string
835 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
836 case "image":
837 variants = append(variants, imageApexType, flattenedApexType)
838 case "zip":
839 variants = append(variants, zipApexType)
840 case "both":
841 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
842 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900843 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900844 return
845 }
846
847 modules := mctx.CreateLocalVariations(variants...)
848
849 for i, v := range variants {
850 switch v {
851 case imageApexType:
852 modules[i].(*apexBundle).properties.ApexType = imageApex
853 case zipApexType:
854 modules[i].(*apexBundle).properties.ApexType = zipApex
855 case flattenedApexType:
856 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900857 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900858 modules[i].(*apexBundle).MakeAsSystemExt()
859 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900860 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900861 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900862 } else if _, ok := mctx.Module().(*OverrideApex); ok {
863 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900864 }
865}
866
Jooyung Han5c998b92019-06-27 11:30:33 +0900867func apexUsesMutator(mctx android.BottomUpMutatorContext) {
868 if ab, ok := mctx.Module().(*apexBundle); ok {
869 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
870 }
871}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900872
Jooyung Handc782442019-11-01 03:14:38 +0900873var (
874 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
875)
876
877// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
878// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
879// which may cause compatibility issues. (e.g. libbinder)
880// Even though libbinder restricts its availability via 'apex_available' property and relies on
881// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
882// to avoid similar problems.
883func useVendorWhitelist(config android.Config) []string {
884 return config.Once(useVendorWhitelistKey, func() interface{} {
885 return []string{
886 // swcodec uses "vendor" variants for smaller size
887 "com.android.media.swcodec",
888 "test_com.android.media.swcodec",
889 }
890 }).([]string)
891}
892
893// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
894// called before the first call to useVendorWhitelist()
895func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
896 config.Once(useVendorWhitelistKey, func() interface{} {
897 return whitelist
898 })
899}
900
Jooyung Han01a868d2020-02-27 13:40:44 +0900901type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800902 // List of native libraries
903 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900904
Jooyung Han643adc42020-02-27 13:50:06 +0900905 // List of JNI libraries
906 Jni_libs []string
907
Alex Light9670d332019-01-29 18:07:33 -0800908 // List of native executables
909 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900910
Roland Levillain630846d2019-06-26 12:48:34 +0100911 // List of native tests
912 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800913}
Jooyung Han344d5432019-08-23 11:17:39 +0900914
Alex Light9670d332019-01-29 18:07:33 -0800915type apexMultilibProperties struct {
916 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900917 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800918
919 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900920 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800921
922 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900923 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800924
925 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900926 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800927
928 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900929 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800930}
931
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900932type apexBundleProperties struct {
933 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000934 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800935 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900936
Jiyong Park40e26a22019-02-08 02:53:06 +0900937 // AndroidManifest.xml file used for the zip container of this APEX bundle.
938 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800939 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900940
Roland Levillain411c5842019-09-19 16:37:20 +0100941 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
942 // device (/apex/<apex_name>).
943 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900944 Apex_name *string
945
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900946 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900947 // For platform APEXes, this should points to a file under /system/sepolicy
948 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
949 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900950
Jooyung Han01a868d2020-02-27 13:40:44 +0900951 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900952
953 // List of java libraries that are embedded inside this APEX bundle
954 Java_libs []string
955
956 // List of prebuilt files that are embedded inside this APEX bundle
957 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900958
959 // Name of the apex_key module that provides the private key to sign APEX
960 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900961
Alex Light5098a612018-11-29 17:12:15 -0800962 // The type of APEX to build. Controls what the APEX payload is. Either
963 // 'image', 'zip' or 'both'. Default: 'image'.
964 Payload_type *string
965
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900966 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
967 // or an android_app_certificate module name in the form ":module".
968 Certificate *string
969
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900970 // Whether this APEX is installable to one of the partitions. Default: true.
971 Installable *bool
972
Jiyong Parkda6eb592018-12-19 17:12:36 +0900973 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
974 // Default is false.
975 Use_vendor *bool
976
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800977 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
978 Ignore_system_library_special_case *bool
979
Alex Light9670d332019-01-29 18:07:33 -0800980 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900981
Jiyong Parkf97782b2019-02-13 20:28:58 +0900982 // List of sanitizer names that this APEX is enabled for
983 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900984
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900985 PreventInstall bool `blueprint:"mutated"`
986
987 HideFromMake bool `blueprint:"mutated"`
988
Jooyung Han5c998b92019-06-27 11:30:33 +0900989 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
990 Provide_cpp_shared_libs *bool
991
992 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
993 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100994
995 // A txt file containing list of files that are whitelisted to be included in this APEX.
996 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900997
Sundong Ahnabb64432019-10-22 13:58:29 +0900998 // package format of this apex variant; could be non-flattened, flattened, or zip.
999 // imageApex, zipApex or flattened
1000 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001001
Jiyong Parkd1063c12019-07-17 20:08:41 +09001002 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1003 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1004 // is implied. This value affects all modules included in this APEX. In other words, they are
1005 // also built with the SDKs specified here.
1006 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001007
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001008 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1009 // Should be only used in tests#.
1010 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001011
Dario Frenica913392020-04-27 18:21:11 +01001012 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1013 // Should be only used in tests#.
1014 Test_only_unsigned_payload *bool
1015
Jiyong Park956305c2020-01-09 12:32:06 +09001016 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001017
1018 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001019 // rules for making sure that the APEX is truly updatable.
1020 // - To be updatable, min_sdk_version should be set as well
1021 // This will also disable the size optimizations like symlinking to the system libs.
1022 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001023 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001024
1025 // The minimum SDK version that this apex must be compatibile with.
1026 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001027}
1028
1029type apexTargetBundleProperties struct {
1030 Target struct {
1031 // Multilib properties only for android.
1032 Android struct {
1033 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001034 }
Jooyung Han344d5432019-08-23 11:17:39 +09001035
Alex Light9670d332019-01-29 18:07:33 -08001036 // Multilib properties only for host.
1037 Host struct {
1038 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001039 }
Jooyung Han344d5432019-08-23 11:17:39 +09001040
Alex Light9670d332019-01-29 18:07:33 -08001041 // Multilib properties only for host linux_bionic.
1042 Linux_bionic struct {
1043 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001044 }
Jooyung Han344d5432019-08-23 11:17:39 +09001045
Alex Light9670d332019-01-29 18:07:33 -08001046 // Multilib properties only for host linux_glibc.
1047 Linux_glibc struct {
1048 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001049 }
1050 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001051}
1052
Jiyong Park5d790c32019-11-15 18:40:32 +09001053type overridableProperties struct {
1054 // List of APKs to package inside APEX
1055 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001056
Jiyong Park69aeba92020-04-24 21:16:36 +09001057 // List of runtime resource overlays (RROs) inside APEX
1058 Rros []string
1059
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001060 // Names of modules to be overridden. Listed modules can only be other binaries
1061 // (in Make or Soong).
1062 // This does not completely prevent installation of the overridden binaries, but if both
1063 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1064 // from PRODUCT_PACKAGES.
1065 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001066
1067 // Logging Parent value
1068 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001069
1070 // Apex Container Package Name.
1071 // Override value for attribute package:name in AndroidManifest.xml
1072 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001073}
1074
Alex Light5098a612018-11-29 17:12:15 -08001075type apexPackaging int
1076
1077const (
1078 imageApex apexPackaging = iota
1079 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001080 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001081)
1082
Sundong Ahnabb64432019-10-22 13:58:29 +09001083// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001084func (a apexPackaging) suffix() string {
1085 switch a {
1086 case imageApex:
1087 return imageApexSuffix
1088 case zipApex:
1089 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001090 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001091 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001092 }
1093}
1094
1095func (a apexPackaging) name() string {
1096 switch a {
1097 case imageApex:
1098 return imageApexType
1099 case zipApex:
1100 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001101 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001102 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001103 }
1104}
1105
Jiyong Parkf653b052019-11-18 15:39:01 +09001106type apexFileClass int
1107
1108const (
1109 etc apexFileClass = iota
1110 nativeSharedLib
1111 nativeExecutable
1112 shBinary
1113 pyBinary
1114 goBinary
1115 javaSharedLib
1116 nativeTest
1117 app
1118)
1119
Jiyong Park8fd61922018-11-08 02:50:25 +09001120func (class apexFileClass) NameInMake() string {
1121 switch class {
1122 case etc:
1123 return "ETC"
1124 case nativeSharedLib:
1125 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001126 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001127 return "EXECUTABLES"
1128 case javaSharedLib:
1129 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001130 case nativeTest:
1131 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001132 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001133 // b/142537672 Why isn't this APP? We want to have full control over
1134 // the paths and file names of the apk file under the flattend APEX.
1135 // If this is set to APP, then the paths and file names are modified
1136 // by the Make build system. For example, it is installed to
1137 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1138 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1139 // appends module name (which is <apexname>.<Appname> to the path.
1140 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001141 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001142 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001143 }
1144}
1145
Jiyong Parkf653b052019-11-18 15:39:01 +09001146// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001147type apexFile struct {
1148 builtFile android.Path
Jiyong Parka62aa232020-05-28 23:46:55 +09001149 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001150 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001151 installDir string
1152 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001153 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001154 // list of symlinks that will be created in installDir that point to this apexFile
1155 symlinks []string
Liz Kammer1c14a212020-05-12 15:26:55 -07001156 dataPaths android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001157 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001158 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001159
1160 requiredModuleNames []string
1161 targetRequiredModuleNames []string
1162 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001163
Colin Cross503c1d02020-01-28 14:00:53 -08001164 jacocoReportClassesFile android.Path // only for javalibs and apps
1165 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001166 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001167
1168 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001169}
1170
Jiyong Park1833cef2019-12-13 13:28:36 +09001171func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1172 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001173 builtFile: builtFile,
1174 moduleName: moduleName,
1175 installDir: installDir,
1176 class: class,
1177 module: module,
1178 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001179 if module != nil {
1180 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001181 ret.requiredModuleNames = module.RequiredModuleNames()
1182 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1183 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001184 }
1185 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001186}
1187
1188func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001189 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001190}
1191
Liz Kammer1c14a212020-05-12 15:26:55 -07001192func (af *apexFile) apexRelativePath(path string) string {
1193 return filepath.Join(af.installDir, path)
1194}
1195
Jiyong Park7cd10e32020-01-14 09:22:18 +09001196// Path() returns path of this apex file relative to the APEX root
1197func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001198 return af.apexRelativePath(af.Stem())
1199}
1200
1201func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001202 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001203 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001204 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001205 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001206}
1207
1208// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1209func (af *apexFile) SymlinkPaths() []string {
1210 var ret []string
1211 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001212 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001213 }
1214 return ret
1215}
1216
1217func (af *apexFile) AvailableToPlatform() bool {
1218 if af.module == nil {
1219 return false
1220 }
1221 if am, ok := af.module.(android.ApexModule); ok {
1222 return am.AvailableFor(android.AvailableToPlatform)
1223 }
1224 return false
1225}
1226
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001227type apexBundle struct {
1228 android.ModuleBase
1229 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001230 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001231 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001232
Jiyong Park5d790c32019-11-15 18:40:32 +09001233 properties apexBundleProperties
1234 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001235 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001236
Jooyung Hanf21c7972019-12-16 22:32:06 +09001237 // specific to apex_vndk modules
1238 vndkProperties apexVndkProperties
1239
Colin Crossa4925902018-11-16 11:36:28 -08001240 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001241 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001242 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001243
Jiyong Park03b68dd2019-07-26 23:20:40 +09001244 prebuiltFileToDelete string
1245
Jiyong Park42cca6c2019-04-01 11:15:50 +09001246 public_key_file android.Path
1247 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001248
1249 container_certificate_file android.Path
1250 container_private_key_file android.Path
1251
Jooyung Han54aca7b2019-11-20 02:26:02 +09001252 fileContexts android.Path
1253
Jiyong Park8fd61922018-11-08 02:50:25 +09001254 // list of files to be included in this apex
1255 filesInfo []apexFile
1256
Jiyong Park956305c2020-01-09 12:32:06 +09001257 // list of module names that should be installed along with this APEX
1258 requiredDeps []string
1259
Jiyong Park956305c2020-01-09 12:32:06 +09001260 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001261 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001262
Sundong Ahnabb64432019-10-22 13:58:29 +09001263 testApex bool
1264 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001265 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001266 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001267
Jooyung Han214bf372019-11-12 13:03:50 +09001268 manifestJsonOut android.WritablePath
1269 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001270
Jooyung Han002ab682020-01-08 01:57:58 +09001271 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001272 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001273 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001274 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1275 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001276
1277 // Suffix of module name in Android.mk
1278 // ".flattened", ".apex", ".zipapex", or ""
1279 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001280
1281 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001282
1283 // Whether to create symlink to the system file instead of having a file
1284 // inside the apex or not
1285 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001286
1287 // Struct holding the merged notice file paths in different formats
1288 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001289}
1290
Jiyong Park397e55e2018-10-24 21:09:55 +09001291func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001292 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001293 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001294 // Use *FarVariation* to be able to depend on modules having
1295 // conflicting variations with this module. This is required since
1296 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1297 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001298 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001299 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001300 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001301 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001302 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001303
Jooyung Han643adc42020-02-27 13:50:06 +09001304 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1305 {Mutator: "image", Variation: imageVariation},
1306 {Mutator: "link", Variation: "shared"},
1307 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1308 }...), jniLibTag, nativeModules.Jni_libs...)
1309
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001310 ctx.AddFarVariationDependencies(append(target.Variations(),
1311 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001312 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001313
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001314 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001315 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001316 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001317 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001318}
1319
Alex Light9670d332019-01-29 18:07:33 -08001320func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1321 if ctx.Os().Class == android.Device {
1322 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1323 } else {
1324 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1325 if ctx.Os().Bionic() {
1326 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1327 } else {
1328 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1329 }
1330 }
1331}
1332
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001333func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001334 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1335 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1336 }
1337
Jiyong Park397e55e2018-10-24 21:09:55 +09001338 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001339 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001340
1341 a.combineProperties(ctx)
1342
Jiyong Park397e55e2018-10-24 21:09:55 +09001343 has32BitTarget := false
1344 for _, target := range targets {
1345 if target.Arch.ArchType.Multilib == "lib32" {
1346 has32BitTarget = true
1347 }
1348 }
1349 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001350 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001351 // multilib.both
1352 addDependenciesForNativeModules(ctx,
1353 ApexNativeDependencies{
1354 Native_shared_libs: a.properties.Native_shared_libs,
1355 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001356 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001357 Binaries: nil,
1358 },
1359 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001360
Jiyong Park397e55e2018-10-24 21:09:55 +09001361 // Add native modules targetting both ABIs
1362 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001363 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001364 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001365 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001366
Alex Light3d673592019-01-18 14:37:31 -08001367 isPrimaryAbi := i == 0
1368 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001369 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001370 // multilib.first
1371 addDependenciesForNativeModules(ctx,
1372 ApexNativeDependencies{
1373 Native_shared_libs: nil,
1374 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001375 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001376 Binaries: a.properties.Binaries,
1377 },
1378 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001379
1380 // Add native modules targetting the first ABI
1381 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001382 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001383 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001384 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001385 }
1386
1387 switch target.Arch.ArchType.Multilib {
1388 case "lib32":
1389 // Add native modules targetting 32-bit ABI
1390 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001391 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001392 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001393 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001394
1395 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001396 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001397 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001398 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001399 case "lib64":
1400 // Add native modules targetting 64-bit ABI
1401 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001402 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001403 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001404 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001405
1406 if !has32BitTarget {
1407 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001408 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001409 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001410 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001411 }
1412 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001413 }
1414
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001415 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1416 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1417 // b/144532908
1418 archForPrebuiltEtc := config.Arches()[0]
1419 for _, arch := range config.Arches() {
1420 // Prefer 64-bit arch if there is any
1421 if arch.ArchType.Multilib == "lib64" {
1422 archForPrebuiltEtc = arch
1423 break
1424 }
1425 }
1426 ctx.AddFarVariationDependencies([]blueprint.Variation{
1427 {Mutator: "os", Variation: ctx.Os().String()},
1428 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1429 }, prebuiltTag, a.properties.Prebuilts...)
1430
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001431 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1432 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001433
Ulya Trafimovich44561882020-01-03 13:25:54 +00001434 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1435 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1436 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1437 javaLibTag, "jacocoagent")
1438 }
1439
Jiyong Park23c52b02019-02-02 13:13:47 +09001440 if String(a.properties.Key) == "" {
1441 ctx.ModuleErrorf("key is missing")
1442 return
1443 }
1444 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001445
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001446 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001447 if cert != "" {
1448 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001449 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001450
1451 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1452 if len(a.properties.Uses_sdks) > 0 {
1453 sdkRefs := []android.SdkRef{}
1454 for _, str := range a.properties.Uses_sdks {
1455 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1456 sdkRefs = append(sdkRefs, parsed)
1457 }
1458 a.BuildWithSdks(sdkRefs)
1459 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001460}
1461
Jiyong Park5d790c32019-11-15 18:40:32 +09001462func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1463 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1464 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001465 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1466 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001467}
1468
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001469func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1470 // direct deps of an APEX bundle are all part of the APEX bundle
1471 return true
1472}
1473
Colin Cross0ea8ba82019-06-06 14:33:29 -07001474func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001475 moduleName := ctx.ModuleName()
1476 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1477 // we check with the pseudo module name to see if its certificate is overridden.
1478 if a.vndkApex {
1479 moduleName = vndkApexName
1480 }
1481 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001482 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001483 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001484 }
1485 return String(a.properties.Certificate)
1486}
1487
Colin Cross41955e82019-05-29 14:40:35 -07001488func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1489 switch tag {
1490 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001491 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001492 default:
1493 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001494 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001495}
1496
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001497func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001498 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001499}
1500
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001501func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1502 return proptools.Bool(a.properties.Test_only_no_hashtree)
1503}
1504
Dario Frenica913392020-04-27 18:21:11 +01001505func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1506 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1507}
1508
Jiyong Park7c1dc612019-01-05 11:15:24 +09001509func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001510 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001511 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001512 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001513 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001514 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001515 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001516 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001517 }
1518}
1519
Jiyong Parkf97782b2019-02-13 20:28:58 +09001520func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1521 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1522 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1523 }
1524}
1525
Jiyong Park388ef3f2019-01-28 19:47:32 +09001526func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001527 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1528 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001529 }
1530
1531 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001532 globalSanitizerNames := []string{}
1533 if a.Host() {
1534 globalSanitizerNames = ctx.Config().SanitizeHost()
1535 } else {
1536 arches := ctx.Config().SanitizeDeviceArch()
1537 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1538 globalSanitizerNames = ctx.Config().SanitizeDevice()
1539 }
1540 }
1541 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001542}
1543
Jooyung Han8ce8db92020-05-15 19:05:05 +09001544func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1545 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1546 for _, target := range ctx.MultiTargets() {
1547 if target.Arch.ArchType.Multilib == "lib64" {
1548 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1549 {Mutator: "image", Variation: a.getImageVariation(ctx.DeviceConfig())},
1550 {Mutator: "link", Variation: "shared"},
1551 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1552 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1553 break
1554 }
1555 }
1556 }
1557}
1558
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001559var _ cc.Coverage = (*apexBundle)(nil)
1560
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001561func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001562 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001563}
1564
1565func (a *apexBundle) PreventInstall() {
1566 a.properties.PreventInstall = true
1567}
1568
1569func (a *apexBundle) HideFromMake() {
1570 a.properties.HideFromMake = true
1571}
1572
Jiyong Park956305c2020-01-09 12:32:06 +09001573func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1574 a.properties.IsCoverageVariant = coverage
1575}
1576
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001577func (a *apexBundle) EnableCoverageIfNeeded() {}
1578
Jiyong Parkf653b052019-11-18 15:39:01 +09001579// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001580func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001581 // Decide the APEX-local directory by the multilib of the library
1582 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001583 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001584 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001585 case "lib32":
1586 dirInApex = "lib"
1587 case "lib64":
1588 dirInApex = "lib64"
1589 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001590 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001591 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001592 }
Jooyung Han35155c42020-02-06 17:33:20 +09001593 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001594 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001595 // Special case for Bionic libs and other libs installed with them. This is
1596 // to prevent those libs from being included in the search path
1597 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1598 // those libs in the Runtime APEX are available via the legacy paths in
1599 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1600 // to the legacy paths and thus will be loaded into the default linker
1601 // namespace (aka "platform" namespace). If the libs are directly in
1602 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1603 // into the runtime linker namespace, which will result in double loading of
1604 // them, which isn't supported.
1605 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001606 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001607
Jiyong Parkf653b052019-11-18 15:39:01 +09001608 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001609 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001610}
1611
Jiyong Park1833cef2019-12-13 13:28:36 +09001612func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001613 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001614 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001615 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001616 }
Jooyung Han35155c42020-02-06 17:33:20 +09001617 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001618 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001619 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001620 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001621 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001622 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001623}
1624
Jiyong Park1833cef2019-12-13 13:28:36 +09001625func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001626 dirInApex := "bin"
1627 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001628 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001629}
Jiyong Park1833cef2019-12-13 13:28:36 +09001630func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001631 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001632 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1633 if err != nil {
1634 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001635 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001636 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001637 fileToCopy := android.PathForOutput(ctx, s)
1638 // NB: Since go binaries are static we don't need the module for anything here, which is
1639 // good since the go tool is a blueprint.Module not an android.Module like we would
1640 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001641 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001642}
1643
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001644func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001645 dirInApex := filepath.Join("bin", sh.SubDir())
1646 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001647 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001648 af.symlinks = sh.Symlinks()
1649 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001650}
1651
Jiyong Parka62aa232020-05-28 23:46:55 +09001652type javaDependency interface {
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001653 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001654 JacocoReportClassesFile() android.Path
Jiyong Parka62aa232020-05-28 23:46:55 +09001655 Stem() string
1656}
1657
1658func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001659 dirInApex := "javalib"
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001660 fileToCopy := lib.DexJarBuildPath()
Paul Duffin581bbbe2020-05-14 20:49:32 +01001661 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001662 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Jiyong Parka62aa232020-05-28 23:46:55 +09001663 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001664 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001665}
1666
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001667func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001668 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1669 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001670 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001671}
1672
atrost6e126252020-01-27 17:01:16 +00001673func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1674 dirInApex := filepath.Join("etc", config.SubDir())
1675 fileToCopy := config.CompatConfig()
1676 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1677}
1678
Jiyong Park1833cef2019-12-13 13:28:36 +09001679func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 android.Module
1681 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001682 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001683 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001684 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001685 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001686}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001687 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001688 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001689 appDir = "priv-app"
1690 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001691 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001692 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001693 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1694 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001695 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001696
1697 if app, ok := aapp.(interface {
1698 OverriddenManifestPackageName() string
1699 }); ok {
1700 af.overriddenPackageName = app.OverriddenManifestPackageName()
1701 }
Jiyong Park618922e2020-01-08 13:35:43 +09001702 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001703}
1704
Jiyong Park69aeba92020-04-24 21:16:36 +09001705func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1706 rroDir := "overlay"
1707 dirInApex := filepath.Join(rroDir, rro.Theme())
1708 fileToCopy := rro.OutputFile()
1709 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1710 af.certificate = rro.Certificate()
1711
1712 if a, ok := rro.(interface {
1713 OverriddenManifestPackageName() string
1714 }); ok {
1715 af.overriddenPackageName = a.OverriddenManifestPackageName()
1716 }
1717 return af
1718}
1719
Roland Levillain935639d2019-08-13 14:55:28 +01001720// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1721type flattenedApexContext struct {
1722 android.ModuleContext
1723}
1724
1725func (c *flattenedApexContext) InstallBypassMake() bool {
1726 return true
1727}
1728
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001729// Function called while walking an APEX's payload dependencies.
1730//
1731// Return true if the `to` module should be visited, false otherwise.
1732type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1733
Jiyong Park201cedd2020-02-07 17:25:49 +09001734// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001735func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001736 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001737 am, ok := child.(android.ApexModule)
1738 if !ok || !am.CanHaveApexVariants() {
1739 return false
1740 }
1741
1742 // Check for the direct dependencies that contribute to the payload
1743 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1744 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001745 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001746 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001747 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001748 return false
1749 }
1750
1751 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001752 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001753 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001754 }
1755
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001756 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001757 })
1758}
1759
Jooyung Han03b51852020-02-26 22:45:42 +09001760func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1761 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001762 intVer, err := android.ApiStrToNum(ctx, ver)
1763 if err != nil {
1764 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001765 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001766 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001767}
1768
Artur Satayev849f8442020-04-28 14:57:42 +01001769func (a *apexBundle) Updatable() bool {
1770 return proptools.Bool(a.properties.Updatable)
1771}
1772
1773var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1774
Jiyong Park201cedd2020-02-07 17:25:49 +09001775// Ensures that the dependencies are marked as available for this APEX
1776func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1777 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1778 if ctx.Host() || a.testApex || a.vndkApex {
1779 return
1780 }
1781
Jiyong Park58d10902020-03-28 14:43:19 +09001782 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1783 // Requiring them and their transitive depencies with apex_available is not right
1784 // because they just add noise.
1785 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1786 return
1787 }
1788
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001789 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1790 if externalDep {
1791 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1792 return false
1793 }
1794
Jiyong Park201cedd2020-02-07 17:25:49 +09001795 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001796 fromName := ctx.OtherModuleName(from)
1797 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001798
1799 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1800 // do any of its dependencies.
1801 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1802 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1803 return false
1804 }
1805
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001806 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1807 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001808 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001809 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001810 // Visit this module's dependencies to check and report any issues with their availability.
1811 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001812 })
1813}
1814
Jooyung Han548640b2020-04-27 12:10:30 +09001815func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001816 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001817 if String(a.properties.Min_sdk_version) == "" {
1818 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1819 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001820
1821 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001822 }
1823}
1824
Jiyong Park7d95a512020-05-10 15:16:24 +09001825// Ensures that a lib providing stub isn't statically linked
1826func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1827 // Practically, we only care about regular APEXes on the device.
1828 if ctx.Host() || a.testApex || a.vndkApex {
1829 return
1830 }
1831
1832 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1833 if ccm, ok := to.(*cc.Module); ok {
1834 apexName := ctx.ModuleName()
1835 fromName := ctx.OtherModuleName(from)
1836 toName := ctx.OtherModuleName(to)
1837
1838 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1839 // do any of its dependencies.
1840 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1841 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1842 return false
1843 }
1844
1845 // TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
1846 // is capable of providing a stub variant, but is being statically linked from the bluetooth
1847 // APEX.
1848 if toName == "libstatssocket" {
1849 return false
1850 }
1851
1852 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1853 // It can't make the static dependencies dynamic because it can't
1854 // do the dynamic linking for itself.
1855 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1856 return false
1857 }
1858
1859 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1860 if isStubLibraryFromOtherApex && !externalDep {
1861 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1862 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1863 }
1864
1865 }
1866 return true
1867 })
1868}
1869
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001870func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001871 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1872 switch a.properties.ApexType {
1873 case imageApex:
1874 if buildFlattenedAsDefault {
1875 a.suffix = imageApexSuffix
1876 } else {
1877 a.suffix = ""
1878 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001879
1880 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001881 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001882 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001883 }
1884 case zipApex:
1885 if proptools.String(a.properties.Payload_type) == "zip" {
1886 a.suffix = ""
1887 a.primaryApexType = true
1888 } else {
1889 a.suffix = zipApexSuffix
1890 }
1891 case flattenedApex:
1892 if buildFlattenedAsDefault {
1893 a.suffix = ""
1894 a.primaryApexType = true
1895 } else {
1896 a.suffix = flattenedSuffix
1897 }
Alex Light5098a612018-11-29 17:12:15 -08001898 }
1899
Roland Levillain630846d2019-06-26 12:48:34 +01001900 if len(a.properties.Tests) > 0 && !a.testApex {
1901 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1902 return
1903 }
1904
Jiyong Park0f80c182020-01-31 02:49:53 +09001905 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001906 a.checkUpdatable(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001907 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001908
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001909 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1910
Jooyung Hane1633032019-08-01 17:41:43 +09001911 // native lib dependencies
1912 var provideNativeLibs []string
1913 var requireNativeLibs []string
1914
Jooyung Han5c998b92019-06-27 11:30:33 +09001915 // Check if "uses" requirements are met with dependent apexBundles
1916 var providedNativeSharedLibs []string
1917 useVendor := proptools.Bool(a.properties.Use_vendor)
1918 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1919 if ctx.OtherModuleDependencyTag(m) != usesTag {
1920 return
1921 }
1922 otherName := ctx.OtherModuleName(m)
1923 other, ok := m.(*apexBundle)
1924 if !ok {
1925 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1926 return
1927 }
1928 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1929 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1930 return
1931 }
1932 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1933 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1934 return
1935 }
1936 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1937 })
1938
Jiyong Parkf653b052019-11-18 15:39:01 +09001939 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001940 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001941 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001942 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001943 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1944 return false
1945 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001946 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001947 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001948 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001949 case sharedLibTag, jniLibTag:
1950 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001951 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001952 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1953 fi.isJniLib = isJniLib
1954 filesInfo = append(filesInfo, fi)
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001955 // bootstrap bionic libs are treated as provided by system
1956 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1957 provideNativeLibs = append(provideNativeLibs, fi.Stem())
1958 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001959 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001960 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001961 propertyName := "native_shared_libs"
1962 if isJniLib {
1963 propertyName = "jni_libs"
1964 }
1965 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001966 }
1967 case executableTag:
1968 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001970 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001971 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001972 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001973 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001974 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001975 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001976 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001977 } else {
Alex Light778127a2019-02-27 14:19:50 -08001978 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 +09001979 }
1980 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09001981 switch child.(type) {
1982 case *java.Library, *java.SdkLibrary, *java.DexImport:
1983 af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001984 if !af.Ok() {
1985 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1986 return false
1987 }
1988 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001989 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09001990 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001991 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001992 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001993 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001994 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001995 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001996 return true // track transitive dependencies
1997 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001998 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001999 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002000 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002001 } else {
2002 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2003 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002004 case rroTag:
2005 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2006 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2007 } else {
2008 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2009 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002010 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002011 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002012 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002013 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2014 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002015 } else {
atrost6e126252020-01-27 17:01:16 +00002016 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002017 }
Roland Levillain630846d2019-06-26 12:48:34 +01002018 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002019 if ccTest, ok := child.(*cc.Module); ok {
2020 if ccTest.IsTestPerSrcAllTestsVariation() {
2021 // Multiple-output test module (where `test_per_src: true`).
2022 //
2023 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2024 // We do not add this variation to `filesInfo`, as it has no output;
2025 // however, we do add the other variations of this module as indirect
2026 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002027 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002028 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002029 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002030 af.class = nativeTest
2031 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002032 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002033 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002034 } else {
2035 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2036 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002037 case keyTag:
2038 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002039 a.private_key_file = key.private_key_file
2040 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002041 } else {
2042 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002043 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002044 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002045 case certificateTag:
2046 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002047 a.container_certificate_file = dep.Certificate.Pem
2048 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002049 } else {
2050 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2051 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002052 case android.PrebuiltDepTag:
2053 // If the prebuilt is force disabled, remember to delete the prebuilt file
2054 // that might have been installed in the previous builds
2055 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2056 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2057 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002058 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002059 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002060 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002061 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 // We cannot use a switch statement on `depTag` here as the checked
2063 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002064 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002065 if cc, ok := child.(*cc.Module); ok {
2066 if android.InList(cc.Name(), providedNativeSharedLibs) {
2067 // If we're using a shared library which is provided from other APEX,
2068 // don't include it in this APEX
2069 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002070 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002071 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2072 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002073 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 // If the dependency is a stubs lib, don't include it in this APEX,
2075 // but make sure that the lib is installed on the device.
2076 // In case no APEX is having the lib, the lib is installed to the system
2077 // partition.
2078 //
2079 // Always include if we are a host-apex however since those won't have any
2080 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002081 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2082 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002083 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002084 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002085 // Don't track further
2086 return false
2087 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002088 filesInfo = append(filesInfo, af)
2089 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002090 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002091 } else if cc.IsTestPerSrcDepTag(depTag) {
2092 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002093 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002094 // Handle modules created as `test_per_src` variations of a single test module:
2095 // use the name of the generated test binary (`fileToCopy`) instead of the name
2096 // of the original test module (`depName`, shared by all `test_per_src`
2097 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002098 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002099 // these are not considered transitive dep
2100 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002101 filesInfo = append(filesInfo, af)
2102 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002103 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002104 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002105 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2106 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002107 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002108 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002109 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2110 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002111 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002112 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002113 }
2114 }
2115 }
2116 return false
2117 })
2118
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002119 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2120 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2121 // via the global boot image config.
2122 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002123 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002124 dirInApex := filepath.Join("javalib", arch.String())
2125 for _, f := range files {
2126 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002127 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002128 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002129 }
2130 }
2131 }
2132
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002133 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002134 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2135 return
2136 }
2137
Jiyong Park8fd61922018-11-08 02:50:25 +09002138 // remove duplicates in filesInfo
2139 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002140 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002141 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002142 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002143 if e, ok := encountered[dest]; !ok {
2144 encountered[dest] = f
2145 } else {
2146 // If a module is directly included and also transitively depended on
2147 // consider it as directly included.
2148 e.transitiveDep = e.transitiveDep && f.transitiveDep
2149 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002150 }
2151 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002152 var result []apexFile
2153 for _, v := range encountered {
2154 result = append(result, v)
2155 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002156 return result
2157 }
2158 filesInfo = removeDup(filesInfo)
2159
2160 // to have consistent build rules
2161 sort.Slice(filesInfo, func(i, j int) bool {
2162 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2163 })
2164
Jiyong Park8fd61922018-11-08 02:50:25 +09002165 a.installDir = android.PathForModuleInstall(ctx, "apex")
2166 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002167
Jooyung Han54aca7b2019-11-20 02:26:02 +09002168 if a.properties.ApexType != zipApex {
2169 if a.properties.File_contexts == nil {
2170 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2171 } else {
2172 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2173 if a.Platform() {
2174 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2175 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2176 }
2177 }
2178 }
2179 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2180 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2181 return
2182 }
2183 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002184 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2185 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2186 // the same library in the system partition, thus effectively sharing the same libraries
2187 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2188 // in the APEX.
2189 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2190 a.installable() &&
2191 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002192
Jiyong Park9d677202020-02-19 16:29:35 +09002193 // We don't need the optimization for updatable APEXes, as it might give false signal
2194 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002195 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002196 a.linkToSystemLib = false
2197 }
2198
Jiyong Park638d30e2020-02-26 18:27:19 +09002199 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2200 if ctx.Host() {
2201 a.linkToSystemLib = false
2202 }
2203
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002204 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002205 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2206
2207 a.setCertificateAndPrivateKey(ctx)
2208 if a.properties.ApexType == flattenedApex {
2209 a.buildFlattenedApex(ctx)
2210 } else {
2211 a.buildUnflattenedApex(ctx)
2212 }
2213
Jooyung Han002ab682020-01-08 01:57:58 +09002214 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002215
2216 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002217}
2218
Artur Satayev8cf899a2020-04-15 17:29:42 +01002219// Enforce that Java deps of the apex are using stable SDKs to compile
2220func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2221 // Visit direct deps only. As long as we guarantee top-level deps are using
2222 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2223 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2224 tag := ctx.OtherModuleDependencyTag(module)
2225 switch tag {
2226 case javaLibTag, androidAppTag:
2227 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2228 if err := m.CheckStableSdkVersion(); err != nil {
2229 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2230 }
2231 }
2232 }
2233 })
2234}
2235
Jooyung Han5e9013b2020-03-10 06:23:13 +09002236func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002237 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002238 moduleName = normalizeModuleName(moduleName)
2239
2240 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2241 return true
2242 }
2243
2244 key = android.AvailableToAnyApex
2245 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2246 return true
2247 }
2248
2249 return false
2250}
2251
2252func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002253 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2254 // system. Trim the prefix for the check since they are confusing
2255 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2256 if strings.HasPrefix(moduleName, "libclang_rt.") {
2257 // This module has many arch variants that depend on the product being built.
2258 // We don't want to list them all
2259 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002260 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002261 if strings.HasPrefix(moduleName, "androidx.") {
2262 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2263 moduleName = "androidx"
2264 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002265 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002266}
2267
Jooyung Han344d5432019-08-23 11:17:39 +09002268func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002269 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002270 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002271 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002272 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002273 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002274 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2275 })
Alex Light5098a612018-11-29 17:12:15 -08002276 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002277 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002278 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002279 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002280 return module
2281}
Jiyong Park30ca9372019-02-07 16:27:23 +09002282
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002283func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002284 bundle := newApexBundle()
2285 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002286 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002287 return bundle
2288}
2289
Jiyong Parkfce0b422020-02-11 03:56:06 +09002290// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2291// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002292func testApexBundleFactory() android.Module {
2293 bundle := newApexBundle()
2294 bundle.testApex = true
2295 return bundle
2296}
2297
Jiyong Parkfce0b422020-02-11 03:56:06 +09002298// apex packages other modules into an APEX file which is a packaging format for system-level
2299// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002300func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002301 return newApexBundle()
2302}
2303
Jiyong Park30ca9372019-02-07 16:27:23 +09002304//
2305// Defaults
2306//
2307type Defaults struct {
2308 android.ModuleBase
2309 android.DefaultsModuleBase
2310}
2311
Jiyong Park30ca9372019-02-07 16:27:23 +09002312func defaultsFactory() android.Module {
2313 return DefaultsFactory()
2314}
2315
2316func DefaultsFactory(props ...interface{}) android.Module {
2317 module := &Defaults{}
2318
2319 module.AddProperties(props...)
2320 module.AddProperties(
2321 &apexBundleProperties{},
2322 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002323 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002324 )
2325
2326 android.InitDefaultsModule(module)
2327 return module
2328}
Jiyong Park5d790c32019-11-15 18:40:32 +09002329
2330//
2331// OverrideApex
2332//
2333type OverrideApex struct {
2334 android.ModuleBase
2335 android.OverrideModuleBase
2336}
2337
2338func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2339 // All the overrides happen in the base module.
2340}
2341
2342// override_apex is used to create an apex module based on another apex module
2343// by overriding some of its properties.
2344func overrideApexFactory() android.Module {
2345 m := &OverrideApex{}
2346 m.AddProperties(&overridableProperties{})
2347
2348 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2349 android.InitOverrideModule(m)
2350 return m
2351}