blob: 10c16f5b84f1fe491f33be875befbd00647bd5c7 [file] [log] [blame]
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
18 "fmt"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090021 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090022 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090023 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024
25 "android/soong/android"
26 "android/soong/cc"
27 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080028 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090029
30 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080031 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090032 "github.com/google/blueprint/proptools"
33)
34
Jooyung Han72bd2f82019-10-23 16:46:38 +090035const (
36 imageApexSuffix = ".apex"
37 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090038 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080039
Sundong Ahnabb64432019-10-22 13:58:29 +090040 imageApexType = "image"
41 zipApexType = "zip"
42 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090043)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090044
45type dependencyTag struct {
46 blueprint.BaseDependencyTag
47 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090048
49 // determines if the dependent will be part of the APEX payload
50 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090051}
52
53var (
Jiyong Park0f80c182020-01-31 02:49:53 +090054 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090055 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090056 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090064 rroTag = dependencyTag{name: "rro", payload: true}
Anton Hanssoneec79eb2020-01-10 15:12:39 +000065 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin7d74e7b2020-03-06 12:30:13 +000066
67 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090068)
69
Paul Duffin7d74e7b2020-03-06 12:30:13 +000070// Transform the map of apex -> modules to module -> apexes.
71func invertApexWhiteList(m map[string][]string) map[string][]string {
72 r := make(map[string][]string)
73 for apex, modules := range m {
74 for _, module := range modules {
75 r[module] = append(r[module], apex)
76 }
77 }
78 return r
79}
80
81// Retrieve the while list of apexes to which the supplied module belongs.
82func WhitelistedApexAvailable(moduleName string) []string {
83 return inverseApexAvailWl[normalizeModuleName(moduleName)]
84}
85
Anton Hanssoneec79eb2020-01-10 15:12:39 +000086// This is a map from apex to modules, which overrides the
87// apex_available setting for that particular module to make
88// it available for the apex regardless of its setting.
89// TODO(b/147364041): remove this
90func makeApexAvailableWhitelist() map[string][]string {
91 // The "Module separator"s below are employed to minimize merge conflicts.
92 m := make(map[string][]string)
93 //
94 // Module separator
95 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +000096 m["com.android.bluetooth.updatable"] = []string{
97 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +000098 "android.hardware.bluetooth.a2dp@1.0",
99 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900100 "android.hardware.bluetooth@1.0",
101 "android.hardware.bluetooth@1.1",
102 "android.hardware.graphics.bufferqueue@1.0",
103 "android.hardware.graphics.bufferqueue@2.0",
104 "android.hardware.graphics.common@1.0",
105 "android.hardware.graphics.common@1.1",
106 "android.hardware.graphics.common@1.2",
107 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000108 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900109 "android.hidl.token@1.0",
110 "android.hidl.token@1.0-utils",
111 "avrcp-target-service",
112 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900113 "bluetooth-protos-lite",
114 "bluetooth.mapsapi",
115 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900116 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900117 "ipmemorystore-aidl-interfaces-V5-java",
118 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900119 "internal_include_headers",
120 "lib-bt-packets",
121 "lib-bt-packets-avrcp",
122 "lib-bt-packets-base",
123 "libFraunhoferAAC",
124 "libaudio-a2dp-hw-utils",
125 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000127 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900128 "libbluetooth-types",
129 "libbluetooth-types-header",
130 "libbluetooth_gd",
131 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000132 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "libbt-audio-hal-interface",
134 "libbt-bta",
135 "libbt-common",
136 "libbt-hci",
137 "libbt-platform-protos-lite",
138 "libbt-protos-lite",
139 "libbt-sbc-decoder",
140 "libbt-sbc-encoder",
141 "libbt-stack",
142 "libbt-utils",
143 "libbtcore",
144 "libbtdevice",
145 "libbte",
146 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000147 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000148 "libevent",
149 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900150 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900151 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900152 "libmedia_headers",
153 "libmodpb64",
154 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900155 "libstagefright_foundation_headers",
156 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000157 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900158 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000159 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900160 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900163 "net-utils-services-common",
164 "netd_aidl_interface-unstable-java",
165 "netd_event_listener_interface-java",
166 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900167 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900168 "sap-api-java-static",
169 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000170 }
171 //
172 // Module separator
173 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 //
176 // Module separator
177 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900178 m["com.android.conscrypt"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900179 "libnativehelper_header_only",
Jiyong Park0f80c182020-01-31 02:49:53 +0900180 }
181 //
182 // Module separator
183 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900184 m["com.android.neuralnetworks"] = []string{
185 "android.hardware.neuralnetworks@1.0",
186 "android.hardware.neuralnetworks@1.1",
187 "android.hardware.neuralnetworks@1.2",
188 "android.hardware.neuralnetworks@1.3",
189 "android.hidl.allocator@1.0",
190 "android.hidl.memory.token@1.0",
191 "android.hidl.memory@1.0",
192 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900193 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900195 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libprocpartition",
197 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900198 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000199 //
200 // Module separator
201 //
202 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000203 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900204 "android.hardware.cas.native@1.0",
205 "android.hardware.cas@1.0",
206 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000207 "android.hardware.configstore@1.0",
208 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000209 "android.hardware.graphics.allocator@2.0",
210 "android.hardware.graphics.allocator@3.0",
211 "android.hardware.graphics.bufferqueue@1.0",
212 "android.hardware.graphics.bufferqueue@2.0",
213 "android.hardware.graphics.common@1.0",
214 "android.hardware.graphics.common@1.1",
215 "android.hardware.graphics.common@1.2",
216 "android.hardware.graphics.mapper@2.0",
217 "android.hardware.graphics.mapper@2.1",
218 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000220 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900221 "android.hidl.allocator@1.0",
222 "android.hidl.memory.token@1.0",
223 "android.hidl.memory@1.0",
224 "android.hidl.token@1.0",
225 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900226 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900227 "exoplayer2-extractor",
228 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900229 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900230 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900231 "libEGL",
232 "libEGL_blobCache",
233 "libEGL_getProcAddress",
234 "libFLAC",
235 "libFLAC-config",
236 "libFLAC-headers",
237 "libGLESv2",
238 "libaacextractor",
239 "libamrextractor",
240 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900241 "libaudio_system_headers",
242 "libaudioclient",
243 "libaudioclient_headers",
244 "libaudiofoundation",
245 "libaudiofoundation_headers",
246 "libaudiomanager",
247 "libaudiopolicy",
248 "libaudioutils",
249 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900251 "libbluetooth-types-header",
252 "libbufferhub",
253 "libbufferhub_headers",
254 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900255 "libc_malloc_debug_backtrace",
256 "libcamera_client",
257 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900258 "libdexfile_external_headers",
259 "libdexfile_support",
260 "libdvr_headers",
261 "libexpat",
262 "libfifo",
263 "libflacextractor",
264 "libgrallocusage",
265 "libgraphicsenv",
266 "libgui",
267 "libgui_headers",
268 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900269 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 "liblzma",
271 "libmath",
272 "libmedia",
273 "libmedia_codeclist",
274 "libmedia_headers",
275 "libmedia_helper",
276 "libmedia_helper_headers",
277 "libmedia_midiiowrapper",
278 "libmedia_omx",
279 "libmediautils",
280 "libmidiextractor",
281 "libmkvextractor",
282 "libmp3extractor",
283 "libmp4extractor",
284 "libmpeg2extractor",
285 "libnativebase_headers",
286 "libnativebridge-headers",
287 "libnativebridge_lazy",
288 "libnativeloader-headers",
289 "libnativeloader_lazy",
290 "libnativewindow_headers",
291 "libnblog",
292 "liboggextractor",
293 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900294 "libpdx",
295 "libpdx_default_transport",
296 "libpdx_headers",
297 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900298 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 "libsonivox",
300 "libspeexresampler",
301 "libspeexresampler",
302 "libstagefright_esds",
303 "libstagefright_flacdec",
304 "libstagefright_flacdec",
305 "libstagefright_foundation",
306 "libstagefright_foundation_headers",
307 "libstagefright_foundation_without_imemory",
308 "libstagefright_headers",
309 "libstagefright_id3",
310 "libstagefright_metadatautils",
311 "libstagefright_mpeg2extractor",
312 "libstagefright_mpeg2support",
313 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900314 "libui",
315 "libui_headers",
316 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900317 "libvibrator",
318 "libvorbisidec",
319 "libwavextractor",
320 "libwebm",
321 "media_ndk_headers",
322 "media_plugin_headers",
323 "updatable-media",
324 }
325 //
326 // Module separator
327 //
328 m["com.android.media.swcodec"] = []string{
329 "android.frameworks.bufferhub@1.0",
330 "android.hardware.common-ndk_platform",
331 "android.hardware.configstore-utils",
332 "android.hardware.configstore@1.0",
333 "android.hardware.configstore@1.1",
334 "android.hardware.graphics.allocator@2.0",
335 "android.hardware.graphics.allocator@3.0",
336 "android.hardware.graphics.bufferqueue@1.0",
337 "android.hardware.graphics.bufferqueue@2.0",
338 "android.hardware.graphics.common-ndk_platform",
339 "android.hardware.graphics.common@1.0",
340 "android.hardware.graphics.common@1.1",
341 "android.hardware.graphics.common@1.2",
342 "android.hardware.graphics.mapper@2.0",
343 "android.hardware.graphics.mapper@2.1",
344 "android.hardware.graphics.mapper@3.0",
345 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000346 "android.hardware.media.bufferpool@2.0",
347 "android.hardware.media.c2@1.0",
348 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900349 "android.hardware.media@1.0",
350 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000351 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900352 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000353 "android.hidl.safe_union@1.0",
354 "android.hidl.token@1.0",
355 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900356 "libEGL",
357 "libFLAC",
358 "libFLAC-config",
359 "libFLAC-headers",
360 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900361 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900362 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900363 "libaudio_system_headers",
364 "libaudioutils",
365 "libaudioutils",
366 "libaudioutils_fixedfft",
367 "libavcdec",
368 "libavcenc",
369 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000370 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900371 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900372 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900373 "libbluetooth-types-header",
374 "libbufferhub_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900375 "libc_scudo",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000376 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900377 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000378 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libcodec2_hidl@1.1",
380 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000381 "libcodec2_soft_aacdec",
382 "libcodec2_soft_aacenc",
383 "libcodec2_soft_amrnbdec",
384 "libcodec2_soft_amrnbenc",
385 "libcodec2_soft_amrwbdec",
386 "libcodec2_soft_amrwbenc",
387 "libcodec2_soft_av1dec_gav1",
388 "libcodec2_soft_avcdec",
389 "libcodec2_soft_avcenc",
390 "libcodec2_soft_common",
391 "libcodec2_soft_flacdec",
392 "libcodec2_soft_flacenc",
393 "libcodec2_soft_g711alawdec",
394 "libcodec2_soft_g711mlawdec",
395 "libcodec2_soft_gsmdec",
396 "libcodec2_soft_h263dec",
397 "libcodec2_soft_h263enc",
398 "libcodec2_soft_hevcdec",
399 "libcodec2_soft_hevcenc",
400 "libcodec2_soft_mp3dec",
401 "libcodec2_soft_mpeg2dec",
402 "libcodec2_soft_mpeg4dec",
403 "libcodec2_soft_mpeg4enc",
404 "libcodec2_soft_opusdec",
405 "libcodec2_soft_opusenc",
406 "libcodec2_soft_rawdec",
407 "libcodec2_soft_vorbisdec",
408 "libcodec2_soft_vp8dec",
409 "libcodec2_soft_vp8enc",
410 "libcodec2_soft_vp9dec",
411 "libcodec2_soft_vp9enc",
412 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000413 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900414 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000415 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900416 "libfmq",
417 "libgav1",
418 "libgralloctypes",
419 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000420 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900421 "libgsm",
422 "libgui_bufferqueue_static",
423 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000424 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900425 "libhardware_headers",
426 "libhevcdec",
427 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000428 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900429 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000430 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900431 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000432 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900433 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900434 "libmpeg2dec",
435 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000436 "libnativebridge_lazy",
437 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900438 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900439 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000440 "libscudo_wrapper",
441 "libsfplugin_ccodec_utils",
442 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900443 "libstagefright_amrnbdec",
444 "libstagefright_amrnbenc",
445 "libstagefright_amrwbdec",
446 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000447 "libstagefright_bufferpool@2.0.1",
448 "libstagefright_bufferqueue_helper",
449 "libstagefright_enc_common",
450 "libstagefright_flacdec",
451 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libstagefright_foundation_headers",
453 "libstagefright_headers",
454 "libstagefright_m4vh263dec",
455 "libstagefright_m4vh263enc",
456 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000457 "libsync",
458 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900459 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000460 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000461 "libvorbisidec",
462 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900463 "libyuv",
464 "libyuv_static",
465 "media_ndk_headers",
466 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000467 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900468 }
469 //
470 // Module separator
471 //
472 m["com.android.mediaprovider"] = []string{
473 "MediaProvider",
474 "MediaProviderGoogle",
475 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900476 "libbase_ndk",
477 "libfuse",
478 "libfuse_jni",
479 "libnativehelper_header_only",
480 }
481 //
482 // Module separator
483 //
484 m["com.android.permission"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900485 "kotlin-annotations",
486 "kotlin-stdlib",
487 "kotlin-stdlib-jdk7",
488 "kotlin-stdlib-jdk8",
489 "kotlinx-coroutines-android",
490 "kotlinx-coroutines-android-nodeps",
491 "kotlinx-coroutines-core",
492 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900493 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000494 }
495 //
496 // Module separator
497 //
498 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900500 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900501 "libc_aeabi",
502 "libc_bionic",
503 "libc_bionic_ndk",
504 "libc_bootstrap",
505 "libc_common",
506 "libc_common_shared",
507 "libc_common_static",
508 "libc_dns",
509 "libc_dynamic_dispatch",
510 "libc_fortify",
511 "libc_freebsd",
512 "libc_freebsd_large_stack",
513 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900514 "libc_init_dynamic",
515 "libc_init_static",
516 "libc_jemalloc_wrapper",
517 "libc_netbsd",
518 "libc_nomalloc",
519 "libc_nopthread",
520 "libc_openbsd",
521 "libc_openbsd_large_stack",
522 "libc_openbsd_ndk",
523 "libc_pthread",
524 "libc_static_dispatch",
525 "libc_syscalls",
526 "libc_tzcode",
527 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900528 "libdebuggerd",
529 "libdebuggerd_common_headers",
530 "libdebuggerd_handler_core",
531 "libdebuggerd_handler_fallback",
532 "libdexfile_external_headers",
533 "libdexfile_support",
534 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900535 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900536 "libjemalloc5",
537 "liblinker_main",
538 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900539 "liblz4",
540 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900541 "libprocinfo",
542 "libpropertyinfoparser",
543 "libscudo",
544 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900545 "libsystemproperties",
546 "libtombstoned_client_static",
547 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900548 "libz",
549 "libziparchive",
550 }
551 //
552 // Module separator
553 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900554 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900555 "android.hardware.tetheroffload.config-V1.0-java",
556 "android.hardware.tetheroffload.control-V1.0-java",
557 "android.hidl.base-V1.0-java",
558 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900559 "libcgrouprc",
560 "libcgrouprc_format",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900561 "libnativehelper_compat_libc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900563 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900564 "net-utils-framework-common",
565 "netd_aidl_interface-V3-java",
566 "netlink-client",
567 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900568 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900569 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000570 }
571 //
572 // Module separator
573 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 m["com.android.wifi"] = []string{
575 "PlatformProperties",
576 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900577 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "android.hardware.wifi-V1.1-java",
579 "android.hardware.wifi-V1.2-java",
580 "android.hardware.wifi-V1.3-java",
581 "android.hardware.wifi-V1.4-java",
582 "android.hardware.wifi.hostapd-V1.0-java",
583 "android.hardware.wifi.hostapd-V1.1-java",
584 "android.hardware.wifi.hostapd-V1.2-java",
585 "android.hardware.wifi.supplicant-V1.0-java",
586 "android.hardware.wifi.supplicant-V1.1-java",
587 "android.hardware.wifi.supplicant-V1.2-java",
588 "android.hardware.wifi.supplicant-V1.3-java",
589 "android.hidl.base-V1.0-java",
590 "android.hidl.manager-V1.0-java",
591 "android.hidl.manager-V1.1-java",
592 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900593 "bouncycastle-unbundled",
594 "dnsresolver_aidl_interface-V2-java",
595 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900596 "framework-wifi-pre-jarjar",
597 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900598 "ipmemorystore-aidl-interfaces-V3-java",
599 "ipmemorystore-aidl-interfaces-java",
600 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900601 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900602 "libwifi-jni",
603 "net-utils-services-common",
604 "netd_aidl_interface-V2-java",
605 "netd_aidl_interface-unstable-java",
606 "netd_event_listener_interface-java",
607 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900608 "networkstack-client",
609 "services.net",
610 "wifi-lite-protos",
611 "wifi-nano-protos",
612 "wifi-service-pre-jarjar",
613 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900614 }
615 //
616 // Module separator
617 //
618 m["com.android.sdkext"] = []string{
619 "fmtlib_ndk",
620 "libbase_ndk",
621 "libprotobuf-cpp-lite-ndk",
622 }
623 //
624 // Module separator
625 //
626 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900627 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900628 }
629 //
630 // Module separator
631 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000632 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900633 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
634 "androidx",
635 "androidx-constraintlayout_constraintlayout",
636 "androidx-constraintlayout_constraintlayout-nodeps",
637 "androidx-constraintlayout_constraintlayout-solver",
638 "androidx-constraintlayout_constraintlayout-solver-nodeps",
639 "com.google.android.material_material",
640 "com.google.android.material_material-nodeps",
641
Jiyong Park0f80c182020-01-31 02:49:53 +0900642 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900643 "libclang_rt",
644 "libgcc_stripped",
645 "libprofile-clang-extras",
646 "libprofile-clang-extras_ndk",
647 "libprofile-extras",
648 "libprofile-extras_ndk",
649 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900650 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000651 return m
652}
653
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900654func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900655 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800656 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900657 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900658 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700659 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900660 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700661 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900662
Jooyung Han31c470b2019-10-18 16:26:59 +0900663 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900664 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900665
666 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
667 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
668 sort.Strings(*apexFileContextsInfos)
669 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
670 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900671}
672
Jooyung Han31c470b2019-10-18 16:26:59 +0900673func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
674 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
675 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
676}
677
Jiyong Parkd1063c12019-07-17 20:08:41 +0900678func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900679 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900680 ctx.BottomUp("apex", apexMutator).Parallel()
681 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
682 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900683 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900684}
685
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900686// Mark the direct and transitive dependencies of apex bundles so that they
687// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900688func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900689 if !mctx.Module().Enabled() {
690 return
691 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800692 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900693 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000694 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han49f67012020-04-17 13:43:10 +0900695 apexBundles = []android.ApexInfo{{
Jooyung Han5417f772020-03-12 18:37:20 +0900696 ApexName: mctx.ModuleName(),
697 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev849f8442020-04-28 14:57:42 +0100698 Updatable: a.Updatable(),
Jooyung Han5e9013b2020-03-10 06:23:13 +0900699 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900700 directDep = true
701 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800702 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900703 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900704 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900705
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800706 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900707 return
708 }
709
Paul Duffin923e8a52020-03-30 15:33:32 +0100710 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Han5e9013b2020-03-10 06:23:13 +0900711
Jiyong Parkf760cae2020-02-12 07:53:12 +0900712 mctx.VisitDirectDeps(func(child android.Module) {
713 depName := mctx.OtherModuleName(child)
714 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffin65347702020-03-31 15:23:40 +0100715 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800716 android.UpdateApexDependency(apexBundles, depName, directDep)
717 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900718 }
719 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900720}
721
Jiyong Park89e850a2020-04-07 16:37:39 +0900722// mark if a module cannot be available to platform. A module cannot be available
723// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
724// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
725func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
726 // Host and recovery are not considered as platform
727 if mctx.Host() || mctx.Module().InstallInRecovery() {
728 return
729 }
730
731 if am, ok := mctx.Module().(android.ApexModule); ok {
732 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
733
734 // In a rare case when a lib is marked as available only to an apex
735 // but the apex doesn't exist. This can happen in a partial manifest branch
736 // like master-art. Currently, libstatssocket in the stats APEX is causing
737 // this problem.
738 // Include the lib in platform because the module SDK that ought to provide
739 // it doesn't exist, so it would otherwise be left out completely.
740 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
741 // this check for libraries provided by SDKs.
742 if !availableToPlatform && !android.InAnyApex(am.Name()) {
743 availableToPlatform = true
744 }
745
746 // If any of the dep is not available to platform, this module is also considered
747 // as being not available to platform even if it has "//apex_available:platform"
748 mctx.VisitDirectDeps(func(child android.Module) {
749 if !am.DepIsInSameApex(mctx, child) {
750 // if the dependency crosses apex boundary, don't consider it
751 return
752 }
753 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
754 availableToPlatform = false
755 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
756 }
757 })
758
759 // Exception 1: stub libraries and native bridge libraries are always available to platform
760 if cc, ok := mctx.Module().(*cc.Module); ok &&
761 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
762 availableToPlatform = true
763 }
764
765 // Exception 2: bootstrap bionic libraries are also always available to platform
766 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
767 availableToPlatform = true
768 }
769
770 if !availableToPlatform {
771 am.SetNotAvailableForPlatform()
772 }
773 }
774}
775
Paul Duffin65347702020-03-31 15:23:40 +0100776// If a module in an APEX depends on a module from an SDK then it needs an APEX
777// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
778func inAnySdk(module android.Module) bool {
779 if sa, ok := module.(android.SdkAware); ok {
780 return sa.IsInAnySdk()
781 }
782
783 return false
784}
785
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900786// Create apex variations if a module is included in APEX(s).
787func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900788 if !mctx.Module().Enabled() {
789 return
790 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900791 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900792 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000793 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900794 // apex bundle itself is mutated so that it and its modules have same
795 // apex variant.
796 apexBundleName := mctx.ModuleName()
797 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900798 } else if o, ok := mctx.Module().(*OverrideApex); ok {
799 apexBundleName := o.GetOverriddenModuleName()
800 if apexBundleName == "" {
801 mctx.ModuleErrorf("base property is not set")
802 return
803 }
804 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900805 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900806
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900807}
Sundong Ahne9b55722019-09-06 17:37:42 +0900808
Jooyung Han7a78a922019-10-08 21:59:58 +0900809var (
810 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
811 apexFileContextsInfosMutex sync.Mutex
812)
813
814func apexFileContextsInfos(config android.Config) *[]string {
815 return config.Once(apexFileContextsInfosKey, func() interface{} {
816 return &[]string{}
817 }).(*[]string)
818}
819
Jooyung Han54aca7b2019-11-20 02:26:02 +0900820func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900821 apexFileContextsInfosMutex.Lock()
822 defer apexFileContextsInfosMutex.Unlock()
823 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900824 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900825}
826
Sundong Ahne9b55722019-09-06 17:37:42 +0900827func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900828 if !mctx.Module().Enabled() {
829 return
830 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900831 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900832 var variants []string
833 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
834 case "image":
835 variants = append(variants, imageApexType, flattenedApexType)
836 case "zip":
837 variants = append(variants, zipApexType)
838 case "both":
839 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
840 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900841 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900842 return
843 }
844
845 modules := mctx.CreateLocalVariations(variants...)
846
847 for i, v := range variants {
848 switch v {
849 case imageApexType:
850 modules[i].(*apexBundle).properties.ApexType = imageApex
851 case zipApexType:
852 modules[i].(*apexBundle).properties.ApexType = zipApex
853 case flattenedApexType:
854 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900855 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900856 modules[i].(*apexBundle).MakeAsSystemExt()
857 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900858 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900859 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900860 } else if _, ok := mctx.Module().(*OverrideApex); ok {
861 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900862 }
863}
864
Jooyung Han5c998b92019-06-27 11:30:33 +0900865func apexUsesMutator(mctx android.BottomUpMutatorContext) {
866 if ab, ok := mctx.Module().(*apexBundle); ok {
867 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
868 }
869}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900870
Jooyung Handc782442019-11-01 03:14:38 +0900871var (
872 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
873)
874
875// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
876// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
877// which may cause compatibility issues. (e.g. libbinder)
878// Even though libbinder restricts its availability via 'apex_available' property and relies on
879// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
880// to avoid similar problems.
881func useVendorWhitelist(config android.Config) []string {
882 return config.Once(useVendorWhitelistKey, func() interface{} {
883 return []string{
884 // swcodec uses "vendor" variants for smaller size
885 "com.android.media.swcodec",
886 "test_com.android.media.swcodec",
887 }
888 }).([]string)
889}
890
891// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
892// called before the first call to useVendorWhitelist()
893func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
894 config.Once(useVendorWhitelistKey, func() interface{} {
895 return whitelist
896 })
897}
898
Jooyung Han01a868d2020-02-27 13:40:44 +0900899type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800900 // List of native libraries
901 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900902
Jooyung Han643adc42020-02-27 13:50:06 +0900903 // List of JNI libraries
904 Jni_libs []string
905
Alex Light9670d332019-01-29 18:07:33 -0800906 // List of native executables
907 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900908
Roland Levillain630846d2019-06-26 12:48:34 +0100909 // List of native tests
910 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800911}
Jooyung Han344d5432019-08-23 11:17:39 +0900912
Alex Light9670d332019-01-29 18:07:33 -0800913type apexMultilibProperties struct {
914 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900915 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800916
917 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900918 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800919
920 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900921 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800922
923 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900924 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800925
926 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900927 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800928}
929
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900930type apexBundleProperties struct {
931 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000932 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800933 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900934
Jiyong Park40e26a22019-02-08 02:53:06 +0900935 // AndroidManifest.xml file used for the zip container of this APEX bundle.
936 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800937 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900938
Roland Levillain411c5842019-09-19 16:37:20 +0100939 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
940 // device (/apex/<apex_name>).
941 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900942 Apex_name *string
943
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900944 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900945 // For platform APEXes, this should points to a file under /system/sepolicy
946 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
947 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900948
Jooyung Han01a868d2020-02-27 13:40:44 +0900949 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900950
951 // List of java libraries that are embedded inside this APEX bundle
952 Java_libs []string
953
954 // List of prebuilt files that are embedded inside this APEX bundle
955 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900956
957 // Name of the apex_key module that provides the private key to sign APEX
958 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900959
Alex Light5098a612018-11-29 17:12:15 -0800960 // The type of APEX to build. Controls what the APEX payload is. Either
961 // 'image', 'zip' or 'both'. Default: 'image'.
962 Payload_type *string
963
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900964 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
965 // or an android_app_certificate module name in the form ":module".
966 Certificate *string
967
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900968 // Whether this APEX is installable to one of the partitions. Default: true.
969 Installable *bool
970
Jiyong Parkda6eb592018-12-19 17:12:36 +0900971 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
972 // Default is false.
973 Use_vendor *bool
974
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800975 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
976 Ignore_system_library_special_case *bool
977
Alex Light9670d332019-01-29 18:07:33 -0800978 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900979
Jiyong Parkf97782b2019-02-13 20:28:58 +0900980 // List of sanitizer names that this APEX is enabled for
981 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900982
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900983 PreventInstall bool `blueprint:"mutated"`
984
985 HideFromMake bool `blueprint:"mutated"`
986
Jooyung Han5c998b92019-06-27 11:30:33 +0900987 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
988 Provide_cpp_shared_libs *bool
989
990 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
991 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +0100992
993 // A txt file containing list of files that are whitelisted to be included in this APEX.
994 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900995
Sundong Ahnabb64432019-10-22 13:58:29 +0900996 // package format of this apex variant; could be non-flattened, flattened, or zip.
997 // imageApex, zipApex or flattened
998 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +0900999
Jiyong Parkd1063c12019-07-17 20:08:41 +09001000 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1001 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1002 // is implied. This value affects all modules included in this APEX. In other words, they are
1003 // also built with the SDKs specified here.
1004 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001005
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001006 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1007 // Should be only used in tests#.
1008 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001009
Dario Frenica913392020-04-27 18:21:11 +01001010 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1011 // Should be only used in tests#.
1012 Test_only_unsigned_payload *bool
1013
Jiyong Park956305c2020-01-09 12:32:06 +09001014 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001015
1016 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001017 // rules for making sure that the APEX is truly updatable.
1018 // - To be updatable, min_sdk_version should be set as well
1019 // This will also disable the size optimizations like symlinking to the system libs.
1020 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001021 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001022
1023 // The minimum SDK version that this apex must be compatibile with.
1024 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001025}
1026
1027type apexTargetBundleProperties struct {
1028 Target struct {
1029 // Multilib properties only for android.
1030 Android struct {
1031 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001032 }
Jooyung Han344d5432019-08-23 11:17:39 +09001033
Alex Light9670d332019-01-29 18:07:33 -08001034 // Multilib properties only for host.
1035 Host struct {
1036 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001037 }
Jooyung Han344d5432019-08-23 11:17:39 +09001038
Alex Light9670d332019-01-29 18:07:33 -08001039 // Multilib properties only for host linux_bionic.
1040 Linux_bionic struct {
1041 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001042 }
Jooyung Han344d5432019-08-23 11:17:39 +09001043
Alex Light9670d332019-01-29 18:07:33 -08001044 // Multilib properties only for host linux_glibc.
1045 Linux_glibc struct {
1046 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001047 }
1048 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049}
1050
Jiyong Park5d790c32019-11-15 18:40:32 +09001051type overridableProperties struct {
1052 // List of APKs to package inside APEX
1053 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001054
Jiyong Park69aeba92020-04-24 21:16:36 +09001055 // List of runtime resource overlays (RROs) inside APEX
1056 Rros []string
1057
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001058 // Names of modules to be overridden. Listed modules can only be other binaries
1059 // (in Make or Soong).
1060 // This does not completely prevent installation of the overridden binaries, but if both
1061 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1062 // from PRODUCT_PACKAGES.
1063 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001064
1065 // Logging Parent value
1066 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001067
1068 // Apex Container Package Name.
1069 // Override value for attribute package:name in AndroidManifest.xml
1070 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001071}
1072
Alex Light5098a612018-11-29 17:12:15 -08001073type apexPackaging int
1074
1075const (
1076 imageApex apexPackaging = iota
1077 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001078 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001079)
1080
Sundong Ahnabb64432019-10-22 13:58:29 +09001081// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001082func (a apexPackaging) suffix() string {
1083 switch a {
1084 case imageApex:
1085 return imageApexSuffix
1086 case zipApex:
1087 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001088 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001089 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001090 }
1091}
1092
1093func (a apexPackaging) name() string {
1094 switch a {
1095 case imageApex:
1096 return imageApexType
1097 case zipApex:
1098 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001099 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001100 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001101 }
1102}
1103
Jiyong Parkf653b052019-11-18 15:39:01 +09001104type apexFileClass int
1105
1106const (
1107 etc apexFileClass = iota
1108 nativeSharedLib
1109 nativeExecutable
1110 shBinary
1111 pyBinary
1112 goBinary
1113 javaSharedLib
1114 nativeTest
1115 app
1116)
1117
Jiyong Park8fd61922018-11-08 02:50:25 +09001118func (class apexFileClass) NameInMake() string {
1119 switch class {
1120 case etc:
1121 return "ETC"
1122 case nativeSharedLib:
1123 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001124 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001125 return "EXECUTABLES"
1126 case javaSharedLib:
1127 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001128 case nativeTest:
1129 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001130 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001131 // b/142537672 Why isn't this APP? We want to have full control over
1132 // the paths and file names of the apk file under the flattend APEX.
1133 // If this is set to APP, then the paths and file names are modified
1134 // by the Make build system. For example, it is installed to
1135 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1136 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1137 // appends module name (which is <apexname>.<Appname> to the path.
1138 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001139 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001140 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001141 }
1142}
1143
Jiyong Parkf653b052019-11-18 15:39:01 +09001144// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001145type apexFile struct {
1146 builtFile android.Path
Jiyong Parka62aa232020-05-28 23:46:55 +09001147 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001148 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001149 installDir string
1150 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001151 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001152 // list of symlinks that will be created in installDir that point to this apexFile
1153 symlinks []string
Liz Kammer1c14a212020-05-12 15:26:55 -07001154 dataPaths android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001155 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001156 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001157
1158 requiredModuleNames []string
1159 targetRequiredModuleNames []string
1160 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001161
Colin Cross503c1d02020-01-28 14:00:53 -08001162 jacocoReportClassesFile android.Path // only for javalibs and apps
1163 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001164 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001165
1166 isJniLib bool
Jiyong Parkf653b052019-11-18 15:39:01 +09001167}
1168
Jiyong Park1833cef2019-12-13 13:28:36 +09001169func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1170 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001171 builtFile: builtFile,
1172 moduleName: moduleName,
1173 installDir: installDir,
1174 class: class,
1175 module: module,
1176 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001177 if module != nil {
1178 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001179 ret.requiredModuleNames = module.RequiredModuleNames()
1180 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1181 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001182 }
1183 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001184}
1185
1186func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001187 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001188}
1189
Liz Kammer1c14a212020-05-12 15:26:55 -07001190func (af *apexFile) apexRelativePath(path string) string {
1191 return filepath.Join(af.installDir, path)
1192}
1193
Jiyong Park7cd10e32020-01-14 09:22:18 +09001194// Path() returns path of this apex file relative to the APEX root
1195func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001196 return af.apexRelativePath(af.Stem())
1197}
1198
1199func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001200 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001201 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001202 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001203 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001204}
1205
1206// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1207func (af *apexFile) SymlinkPaths() []string {
1208 var ret []string
1209 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001210 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001211 }
1212 return ret
1213}
1214
1215func (af *apexFile) AvailableToPlatform() bool {
1216 if af.module == nil {
1217 return false
1218 }
1219 if am, ok := af.module.(android.ApexModule); ok {
1220 return am.AvailableFor(android.AvailableToPlatform)
1221 }
1222 return false
1223}
1224
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001225type apexBundle struct {
1226 android.ModuleBase
1227 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001228 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001229 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001230
Jiyong Park5d790c32019-11-15 18:40:32 +09001231 properties apexBundleProperties
1232 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001233 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001234
Jooyung Hanf21c7972019-12-16 22:32:06 +09001235 // specific to apex_vndk modules
1236 vndkProperties apexVndkProperties
1237
Colin Crossa4925902018-11-16 11:36:28 -08001238 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001239 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001240 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001241
Jiyong Park03b68dd2019-07-26 23:20:40 +09001242 prebuiltFileToDelete string
1243
Jiyong Park42cca6c2019-04-01 11:15:50 +09001244 public_key_file android.Path
1245 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001246
1247 container_certificate_file android.Path
1248 container_private_key_file android.Path
1249
Jooyung Han54aca7b2019-11-20 02:26:02 +09001250 fileContexts android.Path
1251
Jiyong Park8fd61922018-11-08 02:50:25 +09001252 // list of files to be included in this apex
1253 filesInfo []apexFile
1254
Jiyong Park956305c2020-01-09 12:32:06 +09001255 // list of module names that should be installed along with this APEX
1256 requiredDeps []string
1257
Jiyong Park956305c2020-01-09 12:32:06 +09001258 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001259 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001260
Sundong Ahnabb64432019-10-22 13:58:29 +09001261 testApex bool
1262 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001263 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001264 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001265
Jooyung Han214bf372019-11-12 13:03:50 +09001266 manifestJsonOut android.WritablePath
1267 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001268
Jooyung Han002ab682020-01-08 01:57:58 +09001269 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001270 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001271 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001272 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1273 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001274
1275 // Suffix of module name in Android.mk
1276 // ".flattened", ".apex", ".zipapex", or ""
1277 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001278
1279 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001280
1281 // Whether to create symlink to the system file instead of having a file
1282 // inside the apex or not
1283 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001284
1285 // Struct holding the merged notice file paths in different formats
1286 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001287}
1288
Jiyong Park397e55e2018-10-24 21:09:55 +09001289func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001290 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001291 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001292 // Use *FarVariation* to be able to depend on modules having
1293 // conflicting variations with this module. This is required since
1294 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1295 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001296 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001297 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001298 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001299 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001300 }...), sharedLibTag, nativeModules.Native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001301
Jooyung Han643adc42020-02-27 13:50:06 +09001302 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1303 {Mutator: "image", Variation: imageVariation},
1304 {Mutator: "link", Variation: "shared"},
1305 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1306 }...), jniLibTag, nativeModules.Jni_libs...)
1307
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001308 ctx.AddFarVariationDependencies(append(target.Variations(),
1309 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
Jooyung Han01a868d2020-02-27 13:40:44 +09001310 executableTag, nativeModules.Binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001311
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001312 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001313 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001314 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Jooyung Han01a868d2020-02-27 13:40:44 +09001315 }...), testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001316}
1317
Alex Light9670d332019-01-29 18:07:33 -08001318func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1319 if ctx.Os().Class == android.Device {
1320 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1321 } else {
1322 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1323 if ctx.Os().Bionic() {
1324 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1325 } else {
1326 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1327 }
1328 }
1329}
1330
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001331func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001332 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1333 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1334 }
1335
Jiyong Park397e55e2018-10-24 21:09:55 +09001336 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001337 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001338
1339 a.combineProperties(ctx)
1340
Jiyong Park397e55e2018-10-24 21:09:55 +09001341 has32BitTarget := false
1342 for _, target := range targets {
1343 if target.Arch.ArchType.Multilib == "lib32" {
1344 has32BitTarget = true
1345 }
1346 }
1347 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001348 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001349 // multilib.both
1350 addDependenciesForNativeModules(ctx,
1351 ApexNativeDependencies{
1352 Native_shared_libs: a.properties.Native_shared_libs,
1353 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001354 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001355 Binaries: nil,
1356 },
1357 target, a.getImageVariation(config))
Roland Levillain630846d2019-06-26 12:48:34 +01001358
Jiyong Park397e55e2018-10-24 21:09:55 +09001359 // Add native modules targetting both ABIs
1360 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001361 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001362 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001363 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001364
Alex Light3d673592019-01-18 14:37:31 -08001365 isPrimaryAbi := i == 0
1366 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001367 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001368 // multilib.first
1369 addDependenciesForNativeModules(ctx,
1370 ApexNativeDependencies{
1371 Native_shared_libs: nil,
1372 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001373 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001374 Binaries: a.properties.Binaries,
1375 },
1376 target, a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001377
1378 // Add native modules targetting the first ABI
1379 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001380 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001382 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001383 }
1384
1385 switch target.Arch.ArchType.Multilib {
1386 case "lib32":
1387 // Add native modules targetting 32-bit ABI
1388 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001389 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001390 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001391 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001392
1393 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001394 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001395 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001396 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001397 case "lib64":
1398 // Add native modules targetting 64-bit ABI
1399 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001400 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001401 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001402 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001403
1404 if !has32BitTarget {
1405 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001406 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001407 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001408 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001409 }
1410 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001411 }
1412
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001413 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1414 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1415 // b/144532908
1416 archForPrebuiltEtc := config.Arches()[0]
1417 for _, arch := range config.Arches() {
1418 // Prefer 64-bit arch if there is any
1419 if arch.ArchType.Multilib == "lib64" {
1420 archForPrebuiltEtc = arch
1421 break
1422 }
1423 }
1424 ctx.AddFarVariationDependencies([]blueprint.Variation{
1425 {Mutator: "os", Variation: ctx.Os().String()},
1426 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1427 }, prebuiltTag, a.properties.Prebuilts...)
1428
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001429 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1430 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001431
Ulya Trafimovich44561882020-01-03 13:25:54 +00001432 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1433 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1434 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1435 javaLibTag, "jacocoagent")
1436 }
1437
Jiyong Park23c52b02019-02-02 13:13:47 +09001438 if String(a.properties.Key) == "" {
1439 ctx.ModuleErrorf("key is missing")
1440 return
1441 }
1442 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001443
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001444 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001445 if cert != "" {
1446 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001447 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001448
1449 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1450 if len(a.properties.Uses_sdks) > 0 {
1451 sdkRefs := []android.SdkRef{}
1452 for _, str := range a.properties.Uses_sdks {
1453 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1454 sdkRefs = append(sdkRefs, parsed)
1455 }
1456 a.BuildWithSdks(sdkRefs)
1457 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001458}
1459
Jiyong Park5d790c32019-11-15 18:40:32 +09001460func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1461 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1462 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001463 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1464 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001465}
1466
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001467func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1468 // direct deps of an APEX bundle are all part of the APEX bundle
1469 return true
1470}
1471
Colin Cross0ea8ba82019-06-06 14:33:29 -07001472func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001473 moduleName := ctx.ModuleName()
1474 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1475 // we check with the pseudo module name to see if its certificate is overridden.
1476 if a.vndkApex {
1477 moduleName = vndkApexName
1478 }
1479 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001480 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001481 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001482 }
1483 return String(a.properties.Certificate)
1484}
1485
Colin Cross41955e82019-05-29 14:40:35 -07001486func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1487 switch tag {
1488 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001489 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001490 default:
1491 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001492 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001493}
1494
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001495func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001496 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001497}
1498
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001499func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1500 return proptools.Bool(a.properties.Test_only_no_hashtree)
1501}
1502
Dario Frenica913392020-04-27 18:21:11 +01001503func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1504 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1505}
1506
Jiyong Park7c1dc612019-01-05 11:15:24 +09001507func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001508 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001509 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001510 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001511 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001512 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001513 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001514 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001515 }
1516}
1517
Jiyong Parkf97782b2019-02-13 20:28:58 +09001518func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1519 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1520 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1521 }
1522}
1523
Jiyong Park388ef3f2019-01-28 19:47:32 +09001524func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001525 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1526 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001527 }
1528
1529 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001530 globalSanitizerNames := []string{}
1531 if a.Host() {
1532 globalSanitizerNames = ctx.Config().SanitizeHost()
1533 } else {
1534 arches := ctx.Config().SanitizeDeviceArch()
1535 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1536 globalSanitizerNames = ctx.Config().SanitizeDevice()
1537 }
1538 }
1539 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001540}
1541
Jooyung Han8ce8db92020-05-15 19:05:05 +09001542func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1543 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1544 for _, target := range ctx.MultiTargets() {
1545 if target.Arch.ArchType.Multilib == "lib64" {
1546 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
1547 {Mutator: "image", Variation: a.getImageVariation(ctx.DeviceConfig())},
1548 {Mutator: "link", Variation: "shared"},
1549 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1550 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1551 break
1552 }
1553 }
1554 }
1555}
1556
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001557var _ cc.Coverage = (*apexBundle)(nil)
1558
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001559func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001560 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001561}
1562
1563func (a *apexBundle) PreventInstall() {
1564 a.properties.PreventInstall = true
1565}
1566
1567func (a *apexBundle) HideFromMake() {
1568 a.properties.HideFromMake = true
1569}
1570
Jiyong Park956305c2020-01-09 12:32:06 +09001571func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1572 a.properties.IsCoverageVariant = coverage
1573}
1574
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001575func (a *apexBundle) EnableCoverageIfNeeded() {}
1576
Jiyong Parkf653b052019-11-18 15:39:01 +09001577// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001578func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001579 // Decide the APEX-local directory by the multilib of the library
1580 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001581 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001582 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001583 case "lib32":
1584 dirInApex = "lib"
1585 case "lib64":
1586 dirInApex = "lib64"
1587 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001588 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001589 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001590 }
Jooyung Han35155c42020-02-06 17:33:20 +09001591 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001592 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001593 // Special case for Bionic libs and other libs installed with them. This is
1594 // to prevent those libs from being included in the search path
1595 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1596 // those libs in the Runtime APEX are available via the legacy paths in
1597 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1598 // to the legacy paths and thus will be loaded into the default linker
1599 // namespace (aka "platform" namespace). If the libs are directly in
1600 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1601 // into the runtime linker namespace, which will result in double loading of
1602 // them, which isn't supported.
1603 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001604 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001605
Jiyong Parkf653b052019-11-18 15:39:01 +09001606 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001607 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001608}
1609
Jiyong Park1833cef2019-12-13 13:28:36 +09001610func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001611 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001612 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001613 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001614 }
Jooyung Han35155c42020-02-06 17:33:20 +09001615 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001616 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001617 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001618 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001619 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001620 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001621}
1622
Jiyong Park1833cef2019-12-13 13:28:36 +09001623func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001624 dirInApex := "bin"
1625 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001626 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001627}
Jiyong Park1833cef2019-12-13 13:28:36 +09001628func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001629 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001630 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1631 if err != nil {
1632 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001633 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001634 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001635 fileToCopy := android.PathForOutput(ctx, s)
1636 // NB: Since go binaries are static we don't need the module for anything here, which is
1637 // good since the go tool is a blueprint.Module not an android.Module like we would
1638 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001639 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001640}
1641
Jiyong Park1833cef2019-12-13 13:28:36 +09001642func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001643 dirInApex := filepath.Join("bin", sh.SubDir())
1644 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001645 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001646 af.symlinks = sh.Symlinks()
1647 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001648}
1649
Jiyong Parka62aa232020-05-28 23:46:55 +09001650type javaDependency interface {
1651 java.Dependency
1652 Stem() string
1653}
1654
1655func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001656 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001657 fileToCopy := lib.DexJar()
Paul Duffin581bbbe2020-05-14 20:49:32 +01001658 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001659 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Jiyong Parka62aa232020-05-28 23:46:55 +09001660 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001661 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001662}
1663
Jiyong Park1833cef2019-12-13 13:28:36 +09001664func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001665 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1666 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001667 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001668}
1669
atrost6e126252020-01-27 17:01:16 +00001670func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1671 dirInApex := filepath.Join("etc", config.SubDir())
1672 fileToCopy := config.CompatConfig()
1673 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1674}
1675
Jiyong Park1833cef2019-12-13 13:28:36 +09001676func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001677 android.Module
1678 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001679 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001680 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001681 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001682 Certificate() java.Certificate
Jooyung Han39ee1192020-03-23 20:21:11 +09001683}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001684 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001685 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001686 appDir = "priv-app"
1687 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001688 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001689 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001690 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1691 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001692 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001693
1694 if app, ok := aapp.(interface {
1695 OverriddenManifestPackageName() string
1696 }); ok {
1697 af.overriddenPackageName = app.OverriddenManifestPackageName()
1698 }
Jiyong Park618922e2020-01-08 13:35:43 +09001699 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001700}
1701
Jiyong Park69aeba92020-04-24 21:16:36 +09001702func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1703 rroDir := "overlay"
1704 dirInApex := filepath.Join(rroDir, rro.Theme())
1705 fileToCopy := rro.OutputFile()
1706 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1707 af.certificate = rro.Certificate()
1708
1709 if a, ok := rro.(interface {
1710 OverriddenManifestPackageName() string
1711 }); ok {
1712 af.overriddenPackageName = a.OverriddenManifestPackageName()
1713 }
1714 return af
1715}
1716
Roland Levillain935639d2019-08-13 14:55:28 +01001717// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1718type flattenedApexContext struct {
1719 android.ModuleContext
1720}
1721
1722func (c *flattenedApexContext) InstallBypassMake() bool {
1723 return true
1724}
1725
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001726// Function called while walking an APEX's payload dependencies.
1727//
1728// Return true if the `to` module should be visited, false otherwise.
1729type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1730
Jiyong Park201cedd2020-02-07 17:25:49 +09001731// Visit dependencies that contributes to the payload of this APEX
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001732func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001733 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001734 am, ok := child.(android.ApexModule)
1735 if !ok || !am.CanHaveApexVariants() {
1736 return false
1737 }
1738
1739 // Check for the direct dependencies that contribute to the payload
1740 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1741 if dt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001742 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001743 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001744 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001745 return false
1746 }
1747
1748 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Han5e9013b2020-03-10 06:23:13 +09001749 if am.ApexName() != "" {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001750 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001751 }
1752
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001753 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001754 })
1755}
1756
Jooyung Han03b51852020-02-26 22:45:42 +09001757func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1758 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Hanaed150d2020-04-02 01:41:41 +09001759 intVer, err := android.ApiStrToNum(ctx, ver)
1760 if err != nil {
1761 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001762 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001763 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001764}
1765
Artur Satayev849f8442020-04-28 14:57:42 +01001766func (a *apexBundle) Updatable() bool {
1767 return proptools.Bool(a.properties.Updatable)
1768}
1769
1770var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1771
Jiyong Park201cedd2020-02-07 17:25:49 +09001772// Ensures that the dependencies are marked as available for this APEX
1773func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1774 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1775 if ctx.Host() || a.testApex || a.vndkApex {
1776 return
1777 }
1778
Jiyong Park58d10902020-03-28 14:43:19 +09001779 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1780 // Requiring them and their transitive depencies with apex_available is not right
1781 // because they just add noise.
1782 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1783 return
1784 }
1785
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001786 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1787 if externalDep {
1788 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1789 return false
1790 }
1791
Jiyong Park201cedd2020-02-07 17:25:49 +09001792 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001793 fromName := ctx.OtherModuleName(from)
1794 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001795
1796 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1797 // do any of its dependencies.
1798 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1799 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1800 return false
1801 }
1802
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001803 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1804 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001805 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001806 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 +01001807 // Visit this module's dependencies to check and report any issues with their availability.
1808 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001809 })
1810}
1811
Jooyung Han548640b2020-04-27 12:10:30 +09001812func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001813 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001814 if String(a.properties.Min_sdk_version) == "" {
1815 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1816 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001817
1818 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001819 }
1820}
1821
Jiyong Park7d95a512020-05-10 15:16:24 +09001822// Ensures that a lib providing stub isn't statically linked
1823func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1824 // Practically, we only care about regular APEXes on the device.
1825 if ctx.Host() || a.testApex || a.vndkApex {
1826 return
1827 }
1828
1829 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1830 if ccm, ok := to.(*cc.Module); ok {
1831 apexName := ctx.ModuleName()
1832 fromName := ctx.OtherModuleName(from)
1833 toName := ctx.OtherModuleName(to)
1834
1835 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1836 // do any of its dependencies.
1837 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1838 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1839 return false
1840 }
1841
1842 // TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
1843 // is capable of providing a stub variant, but is being statically linked from the bluetooth
1844 // APEX.
1845 if toName == "libstatssocket" {
1846 return false
1847 }
1848
1849 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1850 // It can't make the static dependencies dynamic because it can't
1851 // do the dynamic linking for itself.
1852 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1853 return false
1854 }
1855
1856 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1857 if isStubLibraryFromOtherApex && !externalDep {
1858 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1859 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1860 }
1861
1862 }
1863 return true
1864 })
1865}
1866
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001867func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001868 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1869 switch a.properties.ApexType {
1870 case imageApex:
1871 if buildFlattenedAsDefault {
1872 a.suffix = imageApexSuffix
1873 } else {
1874 a.suffix = ""
1875 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001876
1877 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001878 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001879 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001880 }
1881 case zipApex:
1882 if proptools.String(a.properties.Payload_type) == "zip" {
1883 a.suffix = ""
1884 a.primaryApexType = true
1885 } else {
1886 a.suffix = zipApexSuffix
1887 }
1888 case flattenedApex:
1889 if buildFlattenedAsDefault {
1890 a.suffix = ""
1891 a.primaryApexType = true
1892 } else {
1893 a.suffix = flattenedSuffix
1894 }
Alex Light5098a612018-11-29 17:12:15 -08001895 }
1896
Roland Levillain630846d2019-06-26 12:48:34 +01001897 if len(a.properties.Tests) > 0 && !a.testApex {
1898 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1899 return
1900 }
1901
Jiyong Park0f80c182020-01-31 02:49:53 +09001902 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001903 a.checkUpdatable(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09001904 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001905
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001906 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1907
Jooyung Hane1633032019-08-01 17:41:43 +09001908 // native lib dependencies
1909 var provideNativeLibs []string
1910 var requireNativeLibs []string
1911
Jooyung Han5c998b92019-06-27 11:30:33 +09001912 // Check if "uses" requirements are met with dependent apexBundles
1913 var providedNativeSharedLibs []string
1914 useVendor := proptools.Bool(a.properties.Use_vendor)
1915 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1916 if ctx.OtherModuleDependencyTag(m) != usesTag {
1917 return
1918 }
1919 otherName := ctx.OtherModuleName(m)
1920 other, ok := m.(*apexBundle)
1921 if !ok {
1922 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1923 return
1924 }
1925 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1926 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1927 return
1928 }
1929 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1930 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1931 return
1932 }
1933 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1934 })
1935
Jiyong Parkf653b052019-11-18 15:39:01 +09001936 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001937 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001938 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001939 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01001940 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1941 return false
1942 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001943 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001944 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001945 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09001946 case sharedLibTag, jniLibTag:
1947 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001948 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09001949 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1950 fi.isJniLib = isJniLib
1951 filesInfo = append(filesInfo, fi)
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001952 // bootstrap bionic libs are treated as provided by system
1953 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1954 provideNativeLibs = append(provideNativeLibs, fi.Stem())
1955 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001956 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001957 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09001958 propertyName := "native_shared_libs"
1959 if isJniLib {
1960 propertyName = "jni_libs"
1961 }
1962 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001963 }
1964 case executableTag:
1965 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001966 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001967 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001968 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001969 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001970 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001971 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001972 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001973 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001974 } else {
Alex Light778127a2019-02-27 14:19:50 -08001975 ctx.PropertyErrorf("binaries", "%q is neither cc_binary, (embedded) py_binary, (host) blueprint_go_binary, (host) bootstrap_go_binary, nor sh_binary", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001976 }
1977 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001978 if javaLib, ok := child.(*java.Library); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001979 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001980 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001981 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1982 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001983 filesInfo = append(filesInfo, af)
1984 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001985 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001986 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffin581bbbe2020-05-14 20:49:32 +01001987 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001988 if !af.Ok() {
1989 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1990 return false
1991 }
1992 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001993 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001995 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001996 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001997 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001998 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09001999 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002000 return true // track transitive dependencies
2001 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002002 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002003 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002004 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002005 } else {
2006 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2007 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002008 case rroTag:
2009 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2010 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2011 } else {
2012 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2013 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002014 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002015 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002016 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002017 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2018 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002019 } else {
atrost6e126252020-01-27 17:01:16 +00002020 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002021 }
Roland Levillain630846d2019-06-26 12:48:34 +01002022 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002023 if ccTest, ok := child.(*cc.Module); ok {
2024 if ccTest.IsTestPerSrcAllTestsVariation() {
2025 // Multiple-output test module (where `test_per_src: true`).
2026 //
2027 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2028 // We do not add this variation to `filesInfo`, as it has no output;
2029 // however, we do add the other variations of this module as indirect
2030 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002031 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002032 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002033 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002034 af.class = nativeTest
2035 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002036 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002037 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002038 } else {
2039 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2040 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002041 case keyTag:
2042 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002043 a.private_key_file = key.private_key_file
2044 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002045 } else {
2046 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002047 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002048 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002049 case certificateTag:
2050 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002051 a.container_certificate_file = dep.Certificate.Pem
2052 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002053 } else {
2054 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2055 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002056 case android.PrebuiltDepTag:
2057 // If the prebuilt is force disabled, remember to delete the prebuilt file
2058 // that might have been installed in the previous builds
2059 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2060 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2061 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002062 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002063 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002064 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002065 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002066 // We cannot use a switch statement on `depTag` here as the checked
2067 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002068 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002069 if cc, ok := child.(*cc.Module); ok {
2070 if android.InList(cc.Name(), providedNativeSharedLibs) {
2071 // If we're using a shared library which is provided from other APEX,
2072 // don't include it in this APEX
2073 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002074 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002075 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2076 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002077 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002078 // If the dependency is a stubs lib, don't include it in this APEX,
2079 // but make sure that the lib is installed on the device.
2080 // In case no APEX is having the lib, the lib is installed to the system
2081 // partition.
2082 //
2083 // Always include if we are a host-apex however since those won't have any
2084 // system libraries.
Yo Chiang29555d52020-05-06 15:59:59 +08002085 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.BaseModuleName(), a.requiredDeps) {
2086 a.requiredDeps = append(a.requiredDeps, cc.BaseModuleName())
Roland Levillainf89cd092019-07-29 16:22:59 +01002087 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002088 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002089 // Don't track further
2090 return false
2091 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002092 filesInfo = append(filesInfo, af)
2093 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002094 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002095 } else if cc.IsTestPerSrcDepTag(depTag) {
2096 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002097 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002098 // Handle modules created as `test_per_src` variations of a single test module:
2099 // use the name of the generated test binary (`fileToCopy`) instead of the name
2100 // of the original test module (`depName`, shared by all `test_per_src`
2101 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002102 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002103 // these are not considered transitive dep
2104 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002105 filesInfo = append(filesInfo, af)
2106 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002107 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002108 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002109 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2110 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002111 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2112 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2113 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2114 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002115 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002116 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002117 }
2118 }
2119 }
2120 return false
2121 })
2122
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002123 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2124 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2125 // via the global boot image config.
2126 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002127 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002128 dirInApex := filepath.Join("javalib", arch.String())
2129 for _, f := range files {
2130 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002131 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002132 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002133 }
2134 }
2135 }
2136
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002137 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002138 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2139 return
2140 }
2141
Jiyong Park8fd61922018-11-08 02:50:25 +09002142 // remove duplicates in filesInfo
2143 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002144 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002145 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002146 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002147 if e, ok := encountered[dest]; !ok {
2148 encountered[dest] = f
2149 } else {
2150 // If a module is directly included and also transitively depended on
2151 // consider it as directly included.
2152 e.transitiveDep = e.transitiveDep && f.transitiveDep
2153 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002154 }
2155 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002156 var result []apexFile
2157 for _, v := range encountered {
2158 result = append(result, v)
2159 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002160 return result
2161 }
2162 filesInfo = removeDup(filesInfo)
2163
2164 // to have consistent build rules
2165 sort.Slice(filesInfo, func(i, j int) bool {
2166 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2167 })
2168
Jiyong Park8fd61922018-11-08 02:50:25 +09002169 a.installDir = android.PathForModuleInstall(ctx, "apex")
2170 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002171
Jooyung Han54aca7b2019-11-20 02:26:02 +09002172 if a.properties.ApexType != zipApex {
2173 if a.properties.File_contexts == nil {
2174 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2175 } else {
2176 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2177 if a.Platform() {
2178 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2179 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2180 }
2181 }
2182 }
2183 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2184 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2185 return
2186 }
2187 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002188 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2189 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2190 // the same library in the system partition, thus effectively sharing the same libraries
2191 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2192 // in the APEX.
2193 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2194 a.installable() &&
2195 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002196
Jiyong Park9d677202020-02-19 16:29:35 +09002197 // We don't need the optimization for updatable APEXes, as it might give false signal
2198 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002199 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002200 a.linkToSystemLib = false
2201 }
2202
Jiyong Park638d30e2020-02-26 18:27:19 +09002203 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2204 if ctx.Host() {
2205 a.linkToSystemLib = false
2206 }
2207
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002208 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002209 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2210
2211 a.setCertificateAndPrivateKey(ctx)
2212 if a.properties.ApexType == flattenedApex {
2213 a.buildFlattenedApex(ctx)
2214 } else {
2215 a.buildUnflattenedApex(ctx)
2216 }
2217
Jooyung Han002ab682020-01-08 01:57:58 +09002218 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002219
2220 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002221}
2222
Artur Satayev8cf899a2020-04-15 17:29:42 +01002223// Enforce that Java deps of the apex are using stable SDKs to compile
2224func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2225 // Visit direct deps only. As long as we guarantee top-level deps are using
2226 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2227 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2228 tag := ctx.OtherModuleDependencyTag(module)
2229 switch tag {
2230 case javaLibTag, androidAppTag:
2231 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2232 if err := m.CheckStableSdkVersion(); err != nil {
2233 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2234 }
2235 }
2236 }
2237 })
2238}
2239
Jooyung Han5e9013b2020-03-10 06:23:13 +09002240func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002241 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002242 moduleName = normalizeModuleName(moduleName)
2243
2244 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2245 return true
2246 }
2247
2248 key = android.AvailableToAnyApex
2249 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2250 return true
2251 }
2252
2253 return false
2254}
2255
2256func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002257 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2258 // system. Trim the prefix for the check since they are confusing
2259 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2260 if strings.HasPrefix(moduleName, "libclang_rt.") {
2261 // This module has many arch variants that depend on the product being built.
2262 // We don't want to list them all
2263 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002264 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002265 if strings.HasPrefix(moduleName, "androidx.") {
2266 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2267 moduleName = "androidx"
2268 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002269 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002270}
2271
Jooyung Han344d5432019-08-23 11:17:39 +09002272func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002273 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002274 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002275 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002276 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002277 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002278 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2279 })
Alex Light5098a612018-11-29 17:12:15 -08002280 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002281 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002282 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002283 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002284 return module
2285}
Jiyong Park30ca9372019-02-07 16:27:23 +09002286
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002287func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002288 bundle := newApexBundle()
2289 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002290 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002291 return bundle
2292}
2293
Jiyong Parkfce0b422020-02-11 03:56:06 +09002294// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2295// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002296func testApexBundleFactory() android.Module {
2297 bundle := newApexBundle()
2298 bundle.testApex = true
2299 return bundle
2300}
2301
Jiyong Parkfce0b422020-02-11 03:56:06 +09002302// apex packages other modules into an APEX file which is a packaging format for system-level
2303// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002304func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002305 return newApexBundle()
2306}
2307
Jiyong Park30ca9372019-02-07 16:27:23 +09002308//
2309// Defaults
2310//
2311type Defaults struct {
2312 android.ModuleBase
2313 android.DefaultsModuleBase
2314}
2315
Jiyong Park30ca9372019-02-07 16:27:23 +09002316func defaultsFactory() android.Module {
2317 return DefaultsFactory()
2318}
2319
2320func DefaultsFactory(props ...interface{}) android.Module {
2321 module := &Defaults{}
2322
2323 module.AddProperties(props...)
2324 module.AddProperties(
2325 &apexBundleProperties{},
2326 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002327 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002328 )
2329
2330 android.InitDefaultsModule(module)
2331 return module
2332}
Jiyong Park5d790c32019-11-15 18:40:32 +09002333
2334//
2335// OverrideApex
2336//
2337type OverrideApex struct {
2338 android.ModuleBase
2339 android.OverrideModuleBase
2340}
2341
2342func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2343 // All the overrides happen in the base module.
2344}
2345
2346// override_apex is used to create an apex module based on another apex module
2347// by overriding some of its properties.
2348func overrideApexFactory() android.Module {
2349 m := &OverrideApex{}
2350 m.AddProperties(&overridableProperties{})
2351
2352 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2353 android.InitOverrideModule(m)
2354 return m
2355}