blob: c95ee94a77108141411f9d2ad3ac009ff098230a [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"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090019 "path/filepath"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090020 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090021 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090022 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023
Jiyong Park48ca7dc2018-10-10 14:01:00 +090024 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080025 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070027
28 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080029 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070030 "android/soong/cc"
31 prebuilt_etc "android/soong/etc"
32 "android/soong/java"
33 "android/soong/python"
34 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090035)
36
Jooyung Han72bd2f82019-10-23 16:46:38 +090037const (
38 imageApexSuffix = ".apex"
39 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090040 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080041
Sundong Ahnabb64432019-10-22 13:58:29 +090042 imageApexType = "image"
43 zipApexType = "zip"
44 flattenedApexType = "flattened"
Theotime Combes4ba38c12020-06-12 12:46:59 +000045
46 ext4FsType = "ext4"
47 f2fsFsType = "f2fs"
Jooyung Han72bd2f82019-10-23 16:46:38 +090048)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090049
50type dependencyTag struct {
51 blueprint.BaseDependencyTag
52 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090053
54 // determines if the dependent will be part of the APEX payload
55 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090056}
57
58var (
Jiyong Park0f80c182020-01-31 02:49:53 +090059 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090060 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090061 executableTag = dependencyTag{name: "executable", payload: true}
62 javaLibTag = dependencyTag{name: "javaLib", payload: true}
63 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
64 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090065 keyTag = dependencyTag{name: "key"}
66 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090067 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090068 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090069 rroTag = dependencyTag{name: "rro", payload: true}
markchien2f59ec92020-09-02 16:23:38 +080070 bpfTag = dependencyTag{name: "bpf", payload: true}
Paul Duffin7d74e7b2020-03-06 12:30:13 +000071
Colin Cross440e0d02020-06-11 11:32:11 -070072 apexAvailBaseline = makeApexAvailableBaseline()
73
74 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090075)
76
Paul Duffin7d74e7b2020-03-06 12:30:13 +000077// Transform the map of apex -> modules to module -> apexes.
Colin Cross440e0d02020-06-11 11:32:11 -070078func invertApexBaseline(m map[string][]string) map[string][]string {
Paul Duffin7d74e7b2020-03-06 12:30:13 +000079 r := make(map[string][]string)
80 for apex, modules := range m {
81 for _, module := range modules {
82 r[module] = append(r[module], apex)
83 }
84 }
85 return r
86}
87
Colin Cross440e0d02020-06-11 11:32:11 -070088// Retrieve the baseline of apexes to which the supplied module belongs.
89func BaselineApexAvailable(moduleName string) []string {
90 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
Paul Duffin7d74e7b2020-03-06 12:30:13 +000091}
92
Anton Hanssoneec79eb2020-01-10 15:12:39 +000093// This is a map from apex to modules, which overrides the
94// apex_available setting for that particular module to make
95// it available for the apex regardless of its setting.
96// TODO(b/147364041): remove this
Colin Cross440e0d02020-06-11 11:32:11 -070097func makeApexAvailableBaseline() map[string][]string {
Anton Hanssoneec79eb2020-01-10 15:12:39 +000098 // The "Module separator"s below are employed to minimize merge conflicts.
99 m := make(map[string][]string)
100 //
101 // Module separator
102 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000103 m["com.android.bluetooth.updatable"] = []string{
104 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000105 "android.hardware.bluetooth.a2dp@1.0",
106 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900107 "android.hardware.bluetooth@1.0",
108 "android.hardware.bluetooth@1.1",
109 "android.hardware.graphics.bufferqueue@1.0",
110 "android.hardware.graphics.bufferqueue@2.0",
111 "android.hardware.graphics.common@1.0",
112 "android.hardware.graphics.common@1.1",
113 "android.hardware.graphics.common@1.2",
114 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000115 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900116 "android.hidl.token@1.0",
117 "android.hidl.token@1.0-utils",
118 "avrcp-target-service",
119 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900120 "bluetooth-protos-lite",
121 "bluetooth.mapsapi",
122 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900123 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900124 "ipmemorystore-aidl-interfaces-V5-java",
125 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900126 "internal_include_headers",
127 "lib-bt-packets",
128 "lib-bt-packets-avrcp",
129 "lib-bt-packets-base",
130 "libFraunhoferAAC",
131 "libaudio-a2dp-hw-utils",
132 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900135 "libbluetooth-types",
136 "libbluetooth-types-header",
137 "libbluetooth_gd",
138 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000139 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libbt-audio-hal-interface",
141 "libbt-bta",
142 "libbt-common",
143 "libbt-hci",
144 "libbt-platform-protos-lite",
145 "libbt-protos-lite",
146 "libbt-sbc-decoder",
147 "libbt-sbc-encoder",
148 "libbt-stack",
149 "libbt-utils",
150 "libbtcore",
151 "libbtdevice",
152 "libbte",
153 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000154 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000155 "libevent",
156 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900157 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900158 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900159 "libmedia_headers",
160 "libmodpb64",
161 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900162 "libstagefright_foundation_headers",
163 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000164 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000166 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900167 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000168 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900169 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900170 "net-utils-services-common",
171 "netd_aidl_interface-unstable-java",
172 "netd_event_listener_interface-java",
173 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900174 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900175 "sap-api-java-static",
176 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000177 }
178 //
179 // Module separator
180 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900181 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000182 //
183 // Module separator
184 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900185 m["com.android.neuralnetworks"] = []string{
186 "android.hardware.neuralnetworks@1.0",
187 "android.hardware.neuralnetworks@1.1",
188 "android.hardware.neuralnetworks@1.2",
189 "android.hardware.neuralnetworks@1.3",
190 "android.hidl.allocator@1.0",
191 "android.hidl.memory.token@1.0",
192 "android.hidl.memory@1.0",
193 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900194 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900195 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900196 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900197 "libprocpartition",
198 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900199 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000200 //
201 // Module separator
202 //
203 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000204 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900205 "android.hardware.cas.native@1.0",
206 "android.hardware.cas@1.0",
207 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000208 "android.hardware.configstore@1.0",
209 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000210 "android.hardware.graphics.allocator@2.0",
211 "android.hardware.graphics.allocator@3.0",
212 "android.hardware.graphics.bufferqueue@1.0",
213 "android.hardware.graphics.bufferqueue@2.0",
214 "android.hardware.graphics.common@1.0",
215 "android.hardware.graphics.common@1.1",
216 "android.hardware.graphics.common@1.2",
217 "android.hardware.graphics.mapper@2.0",
218 "android.hardware.graphics.mapper@2.1",
219 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900220 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000221 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900222 "android.hidl.allocator@1.0",
223 "android.hidl.memory.token@1.0",
224 "android.hidl.memory@1.0",
225 "android.hidl.token@1.0",
226 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900227 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900228 "exoplayer2-extractor",
229 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900230 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900231 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900232 "libEGL",
233 "libEGL_blobCache",
234 "libEGL_getProcAddress",
235 "libFLAC",
236 "libFLAC-config",
237 "libFLAC-headers",
238 "libGLESv2",
239 "libaacextractor",
240 "libamrextractor",
241 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "libaudio_system_headers",
243 "libaudioclient",
244 "libaudioclient_headers",
245 "libaudiofoundation",
246 "libaudiofoundation_headers",
247 "libaudiomanager",
248 "libaudiopolicy",
249 "libaudioutils",
250 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900251 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900252 "libbluetooth-types-header",
253 "libbufferhub",
254 "libbufferhub_headers",
255 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900256 "libc_malloc_debug_backtrace",
257 "libcamera_client",
258 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900259 "libdexfile_external_headers",
260 "libdexfile_support",
261 "libdvr_headers",
262 "libexpat",
263 "libfifo",
264 "libflacextractor",
265 "libgrallocusage",
266 "libgraphicsenv",
267 "libgui",
268 "libgui_headers",
269 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900270 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "liblzma",
272 "libmath",
273 "libmedia",
274 "libmedia_codeclist",
275 "libmedia_headers",
276 "libmedia_helper",
277 "libmedia_helper_headers",
278 "libmedia_midiiowrapper",
279 "libmedia_omx",
280 "libmediautils",
281 "libmidiextractor",
282 "libmkvextractor",
283 "libmp3extractor",
284 "libmp4extractor",
285 "libmpeg2extractor",
286 "libnativebase_headers",
287 "libnativebridge-headers",
288 "libnativebridge_lazy",
289 "libnativeloader-headers",
290 "libnativeloader_lazy",
291 "libnativewindow_headers",
292 "libnblog",
293 "liboggextractor",
294 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900295 "libpdx",
296 "libpdx_default_transport",
297 "libpdx_headers",
298 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900299 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900300 "libsonivox",
301 "libspeexresampler",
302 "libspeexresampler",
303 "libstagefright_esds",
304 "libstagefright_flacdec",
305 "libstagefright_flacdec",
306 "libstagefright_foundation",
307 "libstagefright_foundation_headers",
308 "libstagefright_foundation_without_imemory",
309 "libstagefright_headers",
310 "libstagefright_id3",
311 "libstagefright_metadatautils",
312 "libstagefright_mpeg2extractor",
313 "libstagefright_mpeg2support",
314 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 "libui",
316 "libui_headers",
317 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900318 "libvibrator",
319 "libvorbisidec",
320 "libwavextractor",
321 "libwebm",
322 "media_ndk_headers",
323 "media_plugin_headers",
324 "updatable-media",
325 }
326 //
327 // Module separator
328 //
329 m["com.android.media.swcodec"] = []string{
330 "android.frameworks.bufferhub@1.0",
331 "android.hardware.common-ndk_platform",
332 "android.hardware.configstore-utils",
333 "android.hardware.configstore@1.0",
334 "android.hardware.configstore@1.1",
335 "android.hardware.graphics.allocator@2.0",
336 "android.hardware.graphics.allocator@3.0",
337 "android.hardware.graphics.bufferqueue@1.0",
338 "android.hardware.graphics.bufferqueue@2.0",
339 "android.hardware.graphics.common-ndk_platform",
340 "android.hardware.graphics.common@1.0",
341 "android.hardware.graphics.common@1.1",
342 "android.hardware.graphics.common@1.2",
343 "android.hardware.graphics.mapper@2.0",
344 "android.hardware.graphics.mapper@2.1",
345 "android.hardware.graphics.mapper@3.0",
346 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000347 "android.hardware.media.bufferpool@2.0",
348 "android.hardware.media.c2@1.0",
349 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900350 "android.hardware.media@1.0",
351 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000352 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900353 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000354 "android.hidl.safe_union@1.0",
355 "android.hidl.token@1.0",
356 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900357 "libEGL",
358 "libFLAC",
359 "libFLAC-config",
360 "libFLAC-headers",
361 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900362 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900363 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900364 "libaudio_system_headers",
365 "libaudioutils",
366 "libaudioutils",
367 "libaudioutils_fixedfft",
368 "libavcdec",
369 "libavcenc",
370 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000371 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900372 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900373 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "libbluetooth-types-header",
375 "libbufferhub_headers",
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",
Jiyong Park0f80c182020-01-31 02:49:53 +0900479 }
480 //
481 // Module separator
482 //
483 m["com.android.permission"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900484 "kotlin-annotations",
485 "kotlin-stdlib",
486 "kotlin-stdlib-jdk7",
487 "kotlin-stdlib-jdk8",
488 "kotlinx-coroutines-android",
489 "kotlinx-coroutines-android-nodeps",
490 "kotlinx-coroutines-core",
491 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900492 "permissioncontroller-statsd",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000493 }
494 //
495 // Module separator
496 //
497 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900498 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900500 "libc_aeabi",
501 "libc_bionic",
502 "libc_bionic_ndk",
503 "libc_bootstrap",
504 "libc_common",
505 "libc_common_shared",
506 "libc_common_static",
507 "libc_dns",
508 "libc_dynamic_dispatch",
509 "libc_fortify",
510 "libc_freebsd",
511 "libc_freebsd_large_stack",
512 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900513 "libc_init_dynamic",
514 "libc_init_static",
515 "libc_jemalloc_wrapper",
516 "libc_netbsd",
517 "libc_nomalloc",
518 "libc_nopthread",
519 "libc_openbsd",
520 "libc_openbsd_large_stack",
521 "libc_openbsd_ndk",
522 "libc_pthread",
523 "libc_static_dispatch",
524 "libc_syscalls",
525 "libc_tzcode",
526 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900527 "libdebuggerd",
528 "libdebuggerd_common_headers",
529 "libdebuggerd_handler_core",
530 "libdebuggerd_handler_fallback",
531 "libdexfile_external_headers",
532 "libdexfile_support",
533 "libdexfile_support_static",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900534 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900535 "libjemalloc5",
536 "liblinker_main",
537 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900538 "liblz4",
539 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900540 "libprocinfo",
541 "libpropertyinfoparser",
542 "libscudo",
543 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900544 "libsystemproperties",
545 "libtombstoned_client_static",
546 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900547 "libz",
548 "libziparchive",
549 }
550 //
551 // Module separator
552 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900553 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900554 "android.hardware.tetheroffload.config-V1.0-java",
555 "android.hardware.tetheroffload.control-V1.0-java",
556 "android.hidl.base-V1.0-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900557 "libcgrouprc",
558 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900559 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900560 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900561 "net-utils-framework-common",
562 "netd_aidl_interface-V3-java",
563 "netlink-client",
564 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900565 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900566 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000567 }
568 //
569 // Module separator
570 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900571 m["com.android.wifi"] = []string{
572 "PlatformProperties",
573 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900574 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900575 "android.hardware.wifi-V1.1-java",
576 "android.hardware.wifi-V1.2-java",
577 "android.hardware.wifi-V1.3-java",
578 "android.hardware.wifi-V1.4-java",
579 "android.hardware.wifi.hostapd-V1.0-java",
580 "android.hardware.wifi.hostapd-V1.1-java",
581 "android.hardware.wifi.hostapd-V1.2-java",
582 "android.hardware.wifi.supplicant-V1.0-java",
583 "android.hardware.wifi.supplicant-V1.1-java",
584 "android.hardware.wifi.supplicant-V1.2-java",
585 "android.hardware.wifi.supplicant-V1.3-java",
586 "android.hidl.base-V1.0-java",
587 "android.hidl.manager-V1.0-java",
588 "android.hidl.manager-V1.1-java",
589 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900590 "bouncycastle-unbundled",
591 "dnsresolver_aidl_interface-V2-java",
592 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900593 "framework-wifi-pre-jarjar",
594 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900595 "ipmemorystore-aidl-interfaces-V3-java",
596 "ipmemorystore-aidl-interfaces-java",
597 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900598 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900599 "libwifi-jni",
600 "net-utils-services-common",
601 "netd_aidl_interface-V2-java",
602 "netd_aidl_interface-unstable-java",
603 "netd_event_listener_interface-java",
604 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 "networkstack-client",
606 "services.net",
607 "wifi-lite-protos",
608 "wifi-nano-protos",
609 "wifi-service-pre-jarjar",
610 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900611 }
612 //
613 // Module separator
614 //
615 m["com.android.sdkext"] = []string{
616 "fmtlib_ndk",
617 "libbase_ndk",
618 "libprotobuf-cpp-lite-ndk",
619 }
620 //
621 // Module separator
622 //
623 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900624 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900625 }
626 //
627 // Module separator
628 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000629 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900630 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
631 "androidx",
632 "androidx-constraintlayout_constraintlayout",
633 "androidx-constraintlayout_constraintlayout-nodeps",
634 "androidx-constraintlayout_constraintlayout-solver",
635 "androidx-constraintlayout_constraintlayout-solver-nodeps",
636 "com.google.android.material_material",
637 "com.google.android.material_material-nodeps",
638
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900640 "libclang_rt",
641 "libgcc_stripped",
642 "libprofile-clang-extras",
643 "libprofile-clang-extras_ndk",
644 "libprofile-extras",
645 "libprofile-extras_ndk",
646 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000648 return m
649}
650
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900651func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900652 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800653 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900654 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900655 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700656 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900657 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700658 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900659
Jooyung Han31c470b2019-10-18 16:26:59 +0900660 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900661 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900662
663 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
664 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
665 sort.Strings(*apexFileContextsInfos)
666 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
667 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900668}
669
Jooyung Han31c470b2019-10-18 16:26:59 +0900670func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
671 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
672 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
673}
674
Jiyong Parkd1063c12019-07-17 20:08:41 +0900675func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900676 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700677 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900678 ctx.BottomUp("apex", apexMutator).Parallel()
679 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
680 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900681 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900682}
683
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900684// Mark the direct and transitive dependencies of apex bundles so that they
685// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900686func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900687 if !mctx.Module().Enabled() {
688 return
689 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900690 a, ok := mctx.Module().(*apexBundle)
691 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900692 return
693 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900694 apexInfo := android.ApexInfo{
Colin Crosse07f2312020-08-13 11:24:56 -0700695 ApexVariationName: mctx.ModuleName(),
696 MinSdkVersion: a.minSdkVersion(mctx),
Colin Crossaede88c2020-08-11 12:17:01 -0700697 RequiredSdks: a.RequiredSdks(),
Colin Crosse07f2312020-08-13 11:24:56 -0700698 Updatable: a.Updatable(),
Colin Crossaede88c2020-08-11 12:17:01 -0700699 InApexes: []string{mctx.ModuleName()},
Jooyung Han698dd9f2020-07-22 15:17:19 +0900700 }
Jooyung Handf78e212020-07-22 15:54:47 +0900701
702 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
703 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
704 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
705 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
706 return
707 }
708
Jooyung Han698dd9f2020-07-22 15:17:19 +0900709 mctx.WalkDeps(func(child, parent android.Module) bool {
710 am, ok := child.(android.ApexModule)
711 if !ok || !am.CanHaveApexVariants() {
712 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900713 }
Paul Duffina37eca22020-07-22 13:00:54 +0100714 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900715 return false
716 }
Jooyung Handf78e212020-07-22 15:54:47 +0900717 if excludeVndkLibs {
718 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
719 return false
720 }
721 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900722
723 depName := mctx.OtherModuleName(child)
724 // If the parent is apexBundle, this child is directly depended.
725 _, directDep := parent.(*apexBundle)
726 android.UpdateApexDependency(apexInfo, depName, directDep)
727 am.BuildForApex(apexInfo)
728 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900729 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900730}
731
Colin Crossaede88c2020-08-11 12:17:01 -0700732func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
733 if !mctx.Module().Enabled() {
734 return
735 }
736 if am, ok := mctx.Module().(android.ApexModule); ok {
737 // Check if any dependencies use unique apex variations. If so, use unique apex variations
738 // for this module.
739 am.UpdateUniqueApexVariationsForDeps(mctx)
740 }
741}
742
Jiyong Park89e850a2020-04-07 16:37:39 +0900743// mark if a module cannot be available to platform. A module cannot be available
744// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
745// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
746func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
747 // Host and recovery are not considered as platform
748 if mctx.Host() || mctx.Module().InstallInRecovery() {
749 return
750 }
751
752 if am, ok := mctx.Module().(android.ApexModule); ok {
753 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
754
Jiyong Park89e850a2020-04-07 16:37:39 +0900755 // If any of the dep is not available to platform, this module is also considered
756 // as being not available to platform even if it has "//apex_available:platform"
757 mctx.VisitDirectDeps(func(child android.Module) {
758 if !am.DepIsInSameApex(mctx, child) {
759 // if the dependency crosses apex boundary, don't consider it
760 return
761 }
762 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
763 availableToPlatform = false
764 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
765 }
766 })
767
768 // Exception 1: stub libraries and native bridge libraries are always available to platform
769 if cc, ok := mctx.Module().(*cc.Module); ok &&
770 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
771 availableToPlatform = true
772 }
773
774 // Exception 2: bootstrap bionic libraries are also always available to platform
775 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
776 availableToPlatform = true
777 }
778
779 if !availableToPlatform {
780 am.SetNotAvailableForPlatform()
781 }
782 }
783}
784
Paul Duffin65347702020-03-31 15:23:40 +0100785// If a module in an APEX depends on a module from an SDK then it needs an APEX
786// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
787func inAnySdk(module android.Module) bool {
788 if sa, ok := module.(android.SdkAware); ok {
789 return sa.IsInAnySdk()
790 }
791
792 return false
793}
794
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900795// Create apex variations if a module is included in APEX(s).
796func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900797 if !mctx.Module().Enabled() {
798 return
799 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900800 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900801 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000802 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900803 // apex bundle itself is mutated so that it and its modules have same
804 // apex variant.
805 apexBundleName := mctx.ModuleName()
806 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900807 } else if o, ok := mctx.Module().(*OverrideApex); ok {
808 apexBundleName := o.GetOverriddenModuleName()
809 if apexBundleName == "" {
810 mctx.ModuleErrorf("base property is not set")
811 return
812 }
813 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900814 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900815
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900816}
Sundong Ahne9b55722019-09-06 17:37:42 +0900817
Jooyung Han7a78a922019-10-08 21:59:58 +0900818var (
819 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
820 apexFileContextsInfosMutex sync.Mutex
821)
822
823func apexFileContextsInfos(config android.Config) *[]string {
824 return config.Once(apexFileContextsInfosKey, func() interface{} {
825 return &[]string{}
826 }).(*[]string)
827}
828
Jooyung Han54aca7b2019-11-20 02:26:02 +0900829func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900830 apexFileContextsInfosMutex.Lock()
831 defer apexFileContextsInfosMutex.Unlock()
832 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900833 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900834}
835
Sundong Ahne9b55722019-09-06 17:37:42 +0900836func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900837 if !mctx.Module().Enabled() {
838 return
839 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900840 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900841 var variants []string
842 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
843 case "image":
844 variants = append(variants, imageApexType, flattenedApexType)
845 case "zip":
846 variants = append(variants, zipApexType)
847 case "both":
848 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
849 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900850 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900851 return
852 }
853
854 modules := mctx.CreateLocalVariations(variants...)
855
856 for i, v := range variants {
857 switch v {
858 case imageApexType:
859 modules[i].(*apexBundle).properties.ApexType = imageApex
860 case zipApexType:
861 modules[i].(*apexBundle).properties.ApexType = zipApex
862 case flattenedApexType:
863 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900864 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900865 modules[i].(*apexBundle).MakeAsSystemExt()
866 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900867 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900868 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900869 } else if _, ok := mctx.Module().(*OverrideApex); ok {
870 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900871 }
872}
873
Jooyung Han5c998b92019-06-27 11:30:33 +0900874func apexUsesMutator(mctx android.BottomUpMutatorContext) {
875 if ab, ok := mctx.Module().(*apexBundle); ok {
876 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
877 }
878}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900879
Jooyung Handc782442019-11-01 03:14:38 +0900880var (
Colin Cross440e0d02020-06-11 11:32:11 -0700881 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900882)
883
Colin Cross440e0d02020-06-11 11:32:11 -0700884// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900885// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
886// which may cause compatibility issues. (e.g. libbinder)
887// Even though libbinder restricts its availability via 'apex_available' property and relies on
888// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
889// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -0700890func useVendorAllowList(config android.Config) []string {
891 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900892 return []string{
893 // swcodec uses "vendor" variants for smaller size
894 "com.android.media.swcodec",
895 "test_com.android.media.swcodec",
896 }
897 }).([]string)
898}
899
Colin Cross440e0d02020-06-11 11:32:11 -0700900// setUseVendorAllowListForTest overrides useVendorAllowList and must be
901// called before the first call to useVendorAllowList()
902func setUseVendorAllowListForTest(config android.Config, allowList []string) {
903 config.Once(useVendorAllowListKey, func() interface{} {
904 return allowList
Jooyung Handc782442019-11-01 03:14:38 +0900905 })
906}
907
Jooyung Han01a868d2020-02-27 13:40:44 +0900908type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -0800909 // List of native libraries
910 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900911
Jooyung Han643adc42020-02-27 13:50:06 +0900912 // List of JNI libraries
913 Jni_libs []string
914
Alex Light9670d332019-01-29 18:07:33 -0800915 // List of native executables
916 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900917
Roland Levillain630846d2019-06-26 12:48:34 +0100918 // List of native tests
919 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800920}
Jooyung Han344d5432019-08-23 11:17:39 +0900921
Alex Light9670d332019-01-29 18:07:33 -0800922type apexMultilibProperties struct {
923 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +0900924 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800925
926 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +0900927 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800928
929 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900930 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800931
932 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +0900933 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800934
935 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +0900936 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -0800937}
938
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900939type apexBundleProperties struct {
940 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000941 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800942 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900943
Jiyong Park40e26a22019-02-08 02:53:06 +0900944 // AndroidManifest.xml file used for the zip container of this APEX bundle.
945 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800946 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900947
Roland Levillain411c5842019-09-19 16:37:20 +0100948 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
949 // device (/apex/<apex_name>).
950 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900951 Apex_name *string
952
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900953 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900954 // For platform APEXes, this should points to a file under /system/sepolicy
955 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
956 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900957
Jooyung Han01a868d2020-02-27 13:40:44 +0900958 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900959
960 // List of java libraries that are embedded inside this APEX bundle
961 Java_libs []string
962
963 // List of prebuilt files that are embedded inside this APEX bundle
964 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900965
markchien2f59ec92020-09-02 16:23:38 +0800966 // List of BPF programs inside APEX
967 Bpfs []string
968
Jiyong Parkff1458f2018-10-12 21:49:38 +0900969 // Name of the apex_key module that provides the private key to sign APEX
970 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900971
Alex Light5098a612018-11-29 17:12:15 -0800972 // The type of APEX to build. Controls what the APEX payload is. Either
973 // 'image', 'zip' or 'both'. Default: 'image'.
974 Payload_type *string
975
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900976 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
977 // or an android_app_certificate module name in the form ":module".
978 Certificate *string
979
Jiyong Park92c0f9c2018-12-13 23:14:57 +0900980 // Whether this APEX is installable to one of the partitions. Default: true.
981 Installable *bool
982
Jiyong Parkda6eb592018-12-19 17:12:36 +0900983 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
984 // Default is false.
985 Use_vendor *bool
986
Alex Lightfc0bd7c2019-01-29 18:31:59 -0800987 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
988 Ignore_system_library_special_case *bool
989
Alex Light9670d332019-01-29 18:07:33 -0800990 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +0900991
Jiyong Parkf97782b2019-02-13 20:28:58 +0900992 // List of sanitizer names that this APEX is enabled for
993 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +0900994
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900995 PreventInstall bool `blueprint:"mutated"`
996
997 HideFromMake bool `blueprint:"mutated"`
998
Jooyung Han5c998b92019-06-27 11:30:33 +0900999 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1000 Provide_cpp_shared_libs *bool
1001
1002 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1003 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001004
Sundong Ahnabb64432019-10-22 13:58:29 +09001005 // package format of this apex variant; could be non-flattened, flattened, or zip.
1006 // imageApex, zipApex or flattened
1007 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001008
Jiyong Parkd1063c12019-07-17 20:08:41 +09001009 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1010 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1011 // is implied. This value affects all modules included in this APEX. In other words, they are
1012 // also built with the SDKs specified here.
1013 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001014
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001015 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1016 // Should be only used in tests#.
1017 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001018
Dario Frenica913392020-04-27 18:21:11 +01001019 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1020 // Should be only used in tests#.
1021 Test_only_unsigned_payload *bool
1022
Jiyong Park956305c2020-01-09 12:32:06 +09001023 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001024
1025 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001026 // rules for making sure that the APEX is truly updatable.
1027 // - To be updatable, min_sdk_version should be set as well
1028 // This will also disable the size optimizations like symlinking to the system libs.
1029 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001030 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001031
1032 // The minimum SDK version that this apex must be compatibile with.
1033 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001034
1035 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1036 // Should be only used in non-system apexes (e.g. vendor: true).
1037 // Default is false.
1038 Use_vndk_as_stable *bool
Theotime Combes4ba38c12020-06-12 12:46:59 +00001039
1040 // The type of filesystem to use for an image apex. Either 'ext4' or 'f2fs'.
1041 // Default 'ext4'.
1042 Payload_fs_type *string
Alex Light9670d332019-01-29 18:07:33 -08001043}
1044
1045type apexTargetBundleProperties struct {
1046 Target struct {
1047 // Multilib properties only for android.
1048 Android struct {
1049 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001050 }
Jooyung Han344d5432019-08-23 11:17:39 +09001051
Alex Light9670d332019-01-29 18:07:33 -08001052 // Multilib properties only for host.
1053 Host struct {
1054 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001055 }
Jooyung Han344d5432019-08-23 11:17:39 +09001056
Alex Light9670d332019-01-29 18:07:33 -08001057 // Multilib properties only for host linux_bionic.
1058 Linux_bionic struct {
1059 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001060 }
Jooyung Han344d5432019-08-23 11:17:39 +09001061
Alex Light9670d332019-01-29 18:07:33 -08001062 // Multilib properties only for host linux_glibc.
1063 Linux_glibc struct {
1064 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001065 }
1066 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001067}
1068
Jiyong Park5d790c32019-11-15 18:40:32 +09001069type overridableProperties struct {
1070 // List of APKs to package inside APEX
1071 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001072
Jiyong Park69aeba92020-04-24 21:16:36 +09001073 // List of runtime resource overlays (RROs) inside APEX
1074 Rros []string
1075
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001076 // Names of modules to be overridden. Listed modules can only be other binaries
1077 // (in Make or Soong).
1078 // This does not completely prevent installation of the overridden binaries, but if both
1079 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1080 // from PRODUCT_PACKAGES.
1081 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001082
1083 // Logging Parent value
1084 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001085
1086 // Apex Container Package Name.
1087 // Override value for attribute package:name in AndroidManifest.xml
1088 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001089
1090 // A txt file containing list of files that are allowed to be included in this APEX.
1091 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001092}
1093
Alex Light5098a612018-11-29 17:12:15 -08001094type apexPackaging int
1095
1096const (
1097 imageApex apexPackaging = iota
1098 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001099 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001100)
1101
Sundong Ahnabb64432019-10-22 13:58:29 +09001102// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001103func (a apexPackaging) suffix() string {
1104 switch a {
1105 case imageApex:
1106 return imageApexSuffix
1107 case zipApex:
1108 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001109 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001110 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001111 }
1112}
1113
1114func (a apexPackaging) name() string {
1115 switch a {
1116 case imageApex:
1117 return imageApexType
1118 case zipApex:
1119 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001120 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001121 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001122 }
1123}
1124
Jiyong Parkf653b052019-11-18 15:39:01 +09001125type apexFileClass int
1126
1127const (
1128 etc apexFileClass = iota
1129 nativeSharedLib
1130 nativeExecutable
1131 shBinary
1132 pyBinary
1133 goBinary
1134 javaSharedLib
1135 nativeTest
1136 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001137 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001138)
1139
Jiyong Park8fd61922018-11-08 02:50:25 +09001140func (class apexFileClass) NameInMake() string {
1141 switch class {
1142 case etc:
1143 return "ETC"
1144 case nativeSharedLib:
1145 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001146 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001147 return "EXECUTABLES"
1148 case javaSharedLib:
1149 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001150 case nativeTest:
1151 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001152 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001153 // b/142537672 Why isn't this APP? We want to have full control over
1154 // the paths and file names of the apk file under the flattend APEX.
1155 // If this is set to APP, then the paths and file names are modified
1156 // by the Make build system. For example, it is installed to
1157 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1158 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1159 // appends module name (which is <apexname>.<Appname> to the path.
1160 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001161 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001162 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001163 }
1164}
1165
Jiyong Parkf653b052019-11-18 15:39:01 +09001166// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001167type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001168 builtFile android.Path
1169 stem string
1170 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1171 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1172 androidMkModuleName string
1173 installDir string
1174 class apexFileClass
1175 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001176 // list of symlinks that will be created in installDir that point to this apexFile
1177 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001178 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001179 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001180 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001181
1182 requiredModuleNames []string
1183 targetRequiredModuleNames []string
1184 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001185
Colin Cross503c1d02020-01-28 14:00:53 -08001186 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001187 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001188 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001189 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001190
1191 isJniLib bool
Jiyong Park41f637d2020-09-09 13:18:02 +09001192
1193 noticeFiles android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001194}
1195
Yo Chiange8128052020-07-23 20:09:18 +08001196func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001197 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001198 builtFile: builtFile,
1199 androidMkModuleName: androidMkModuleName,
1200 installDir: installDir,
1201 class: class,
1202 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001203 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001204 if module != nil {
1205 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001206 ret.requiredModuleNames = module.RequiredModuleNames()
1207 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1208 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park41f637d2020-09-09 13:18:02 +09001209 ret.noticeFiles = module.NoticeFiles()
Jiyong Park1833cef2019-12-13 13:28:36 +09001210 }
1211 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001212}
1213
1214func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001215 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001216}
1217
Liz Kammer1c14a212020-05-12 15:26:55 -07001218func (af *apexFile) apexRelativePath(path string) string {
1219 return filepath.Join(af.installDir, path)
1220}
1221
Jiyong Park7cd10e32020-01-14 09:22:18 +09001222// Path() returns path of this apex file relative to the APEX root
1223func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001224 return af.apexRelativePath(af.Stem())
1225}
1226
1227func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001228 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001229 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001230 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001231 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001232}
1233
1234// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1235func (af *apexFile) SymlinkPaths() []string {
1236 var ret []string
1237 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001238 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001239 }
1240 return ret
1241}
1242
1243func (af *apexFile) AvailableToPlatform() bool {
1244 if af.module == nil {
1245 return false
1246 }
1247 if am, ok := af.module.(android.ApexModule); ok {
1248 return am.AvailableFor(android.AvailableToPlatform)
1249 }
1250 return false
1251}
1252
Theotime Combes4ba38c12020-06-12 12:46:59 +00001253type fsType int
1254
1255const (
1256 ext4 fsType = iota
1257 f2fs
1258)
1259
1260func (f fsType) string() string {
1261 switch f {
1262 case ext4:
1263 return ext4FsType
1264 case f2fs:
1265 return f2fsFsType
1266 default:
1267 panic(fmt.Errorf("unknown APEX payload type %d", f))
1268 }
1269}
1270
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001271type apexBundle struct {
1272 android.ModuleBase
1273 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001274 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001275 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001276
Jiyong Park5d790c32019-11-15 18:40:32 +09001277 properties apexBundleProperties
1278 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001279 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001280
Jooyung Hanf21c7972019-12-16 22:32:06 +09001281 // specific to apex_vndk modules
1282 vndkProperties apexVndkProperties
1283
Colin Crossa4925902018-11-16 11:36:28 -08001284 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001285 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001286 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001287
Jiyong Park03b68dd2019-07-26 23:20:40 +09001288 prebuiltFileToDelete string
1289
Jiyong Park42cca6c2019-04-01 11:15:50 +09001290 public_key_file android.Path
1291 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001292
1293 container_certificate_file android.Path
1294 container_private_key_file android.Path
1295
Jooyung Han580eb4f2020-06-24 19:33:06 +09001296 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001297
Jiyong Park8fd61922018-11-08 02:50:25 +09001298 // list of files to be included in this apex
1299 filesInfo []apexFile
1300
Jiyong Park956305c2020-01-09 12:32:06 +09001301 // list of module names that should be installed along with this APEX
1302 requiredDeps []string
1303
Jiyong Park956305c2020-01-09 12:32:06 +09001304 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001305 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001306
Sundong Ahnabb64432019-10-22 13:58:29 +09001307 testApex bool
1308 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001309 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001310 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001311
Jooyung Han214bf372019-11-12 13:03:50 +09001312 manifestJsonOut android.WritablePath
1313 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001314
Jooyung Han002ab682020-01-08 01:57:58 +09001315 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001316 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001317 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001318 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1319 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001320
1321 // Suffix of module name in Android.mk
1322 // ".flattened", ".apex", ".zipapex", or ""
1323 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001324
1325 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001326
1327 // Whether to create symlink to the system file instead of having a file
1328 // inside the apex or not
1329 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001330
1331 // Struct holding the merged notice file paths in different formats
1332 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001333
1334 // Optional list of lint report zip files for apexes that contain java or app modules
1335 lintReports android.Paths
Theotime Combes4ba38c12020-06-12 12:46:59 +00001336
1337 payloadFsType fsType
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001338}
1339
Jiyong Park397e55e2018-10-24 21:09:55 +09001340func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001341 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001342 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001343 // Use *FarVariation* to be able to depend on modules having
1344 // conflicting variations with this module. This is required since
1345 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1346 // for native shared libs.
Jiyong Park397e55e2018-10-24 21:09:55 +09001347
Colin Cross42507332020-08-21 16:15:23 -07001348 binVariations := target.Variations()
1349 libVariations := append(target.Variations(),
1350 blueprint.Variation{Mutator: "link", Variation: "shared"})
1351 testVariations := append(target.Variations(),
1352 blueprint.Variation{Mutator: "test_per_src", Variation: ""}) // "" is the all-tests variant
Jooyung Han643adc42020-02-27 13:50:06 +09001353
Colin Cross42507332020-08-21 16:15:23 -07001354 if ctx.Device() {
1355 binVariations = append(binVariations,
1356 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1357 libVariations = append(libVariations,
1358 blueprint.Variation{Mutator: "image", Variation: imageVariation},
1359 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
1360 testVariations = append(testVariations,
1361 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1362 }
Roland Levillain630846d2019-06-26 12:48:34 +01001363
Colin Cross42507332020-08-21 16:15:23 -07001364 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
1365
1366 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
1367
1368 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
1369
1370 ctx.AddFarVariationDependencies(testVariations, testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001371}
1372
Alex Light9670d332019-01-29 18:07:33 -08001373func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1374 if ctx.Os().Class == android.Device {
1375 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1376 } else {
1377 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1378 if ctx.Os().Bionic() {
1379 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1380 } else {
1381 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1382 }
1383 }
1384}
1385
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001386func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001387 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001388 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1389 }
1390
Jiyong Park397e55e2018-10-24 21:09:55 +09001391 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001392 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001393 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001394
1395 a.combineProperties(ctx)
1396
Jiyong Park397e55e2018-10-24 21:09:55 +09001397 has32BitTarget := false
1398 for _, target := range targets {
1399 if target.Arch.ArchType.Multilib == "lib32" {
1400 has32BitTarget = true
1401 }
1402 }
1403 for i, target := range targets {
Jooyung Han643adc42020-02-27 13:50:06 +09001404 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001405 // multilib.both
1406 addDependenciesForNativeModules(ctx,
1407 ApexNativeDependencies{
1408 Native_shared_libs: a.properties.Native_shared_libs,
1409 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001410 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001411 Binaries: nil,
1412 },
Jooyung Han85d61762020-06-24 23:50:26 +09001413 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001414
Jiyong Park397e55e2018-10-24 21:09:55 +09001415 // Add native modules targetting both ABIs
1416 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001417 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001418 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001419 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001420
Alex Light3d673592019-01-18 14:37:31 -08001421 isPrimaryAbi := i == 0
1422 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001423 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001424 // multilib.first
1425 addDependenciesForNativeModules(ctx,
1426 ApexNativeDependencies{
1427 Native_shared_libs: nil,
1428 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001429 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001430 Binaries: a.properties.Binaries,
1431 },
Jooyung Han85d61762020-06-24 23:50:26 +09001432 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001433
1434 // Add native modules targetting the first ABI
1435 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001436 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001437 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001438 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001439 }
1440
1441 switch target.Arch.ArchType.Multilib {
1442 case "lib32":
1443 // Add native modules targetting 32-bit ABI
1444 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001445 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001446 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001447 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001448
1449 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001450 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001451 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001452 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001453 case "lib64":
1454 // Add native modules targetting 64-bit ABI
1455 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001456 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001457 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001458 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001459
1460 if !has32BitTarget {
1461 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001462 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001464 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001465 }
1466 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001467 }
1468
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001469 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1470 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1471 // b/144532908
1472 archForPrebuiltEtc := config.Arches()[0]
1473 for _, arch := range config.Arches() {
1474 // Prefer 64-bit arch if there is any
1475 if arch.ArchType.Multilib == "lib64" {
1476 archForPrebuiltEtc = arch
1477 break
1478 }
1479 }
1480 ctx.AddFarVariationDependencies([]blueprint.Variation{
1481 {Mutator: "os", Variation: ctx.Os().String()},
1482 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1483 }, prebuiltTag, a.properties.Prebuilts...)
1484
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001485 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1486 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001487
markchien2f59ec92020-09-02 16:23:38 +08001488 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1489 bpfTag, a.properties.Bpfs...)
1490
Ulya Trafimovich44561882020-01-03 13:25:54 +00001491 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1492 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1493 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1494 javaLibTag, "jacocoagent")
1495 }
1496
Jiyong Park23c52b02019-02-02 13:13:47 +09001497 if String(a.properties.Key) == "" {
1498 ctx.ModuleErrorf("key is missing")
1499 return
1500 }
1501 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001502
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001503 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001504 if cert != "" {
1505 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001506 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001507
1508 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1509 if len(a.properties.Uses_sdks) > 0 {
1510 sdkRefs := []android.SdkRef{}
1511 for _, str := range a.properties.Uses_sdks {
1512 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1513 sdkRefs = append(sdkRefs, parsed)
1514 }
1515 a.BuildWithSdks(sdkRefs)
1516 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001517}
1518
Jiyong Park5d790c32019-11-15 18:40:32 +09001519func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001520 if a.overridableProperties.Allowed_files != nil {
1521 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1522 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001523 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1524 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001525 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1526 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001527}
1528
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001529func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1530 // direct deps of an APEX bundle are all part of the APEX bundle
1531 return true
1532}
1533
Colin Cross0ea8ba82019-06-06 14:33:29 -07001534func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001535 moduleName := ctx.ModuleName()
1536 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1537 // we check with the pseudo module name to see if its certificate is overridden.
1538 if a.vndkApex {
1539 moduleName = vndkApexName
1540 }
1541 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001542 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001543 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001544 }
1545 return String(a.properties.Certificate)
1546}
1547
Colin Cross41955e82019-05-29 14:40:35 -07001548func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1549 switch tag {
1550 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001551 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001552 default:
1553 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001554 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001555}
1556
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001557func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001558 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001559}
1560
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001561func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1562 return proptools.Bool(a.properties.Test_only_no_hashtree)
1563}
1564
Dario Frenica913392020-04-27 18:21:11 +01001565func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1566 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1567}
1568
Jooyung Han85d61762020-06-24 23:50:26 +09001569func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1570 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001571 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001572 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001573 }
Jooyung Han85d61762020-06-24 23:50:26 +09001574
1575 var prefix string
1576 var vndkVersion string
1577 if deviceConfig.VndkVersion() != "" {
1578 if proptools.Bool(a.properties.Use_vendor) {
1579 prefix = cc.VendorVariationPrefix
1580 vndkVersion = deviceConfig.PlatformVndkVersion()
1581 } else if a.SocSpecific() || a.DeviceSpecific() {
1582 prefix = cc.VendorVariationPrefix
1583 vndkVersion = deviceConfig.VndkVersion()
1584 } else if a.ProductSpecific() {
1585 prefix = cc.ProductVariationPrefix
1586 vndkVersion = deviceConfig.ProductVndkVersion()
1587 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001588 }
Jooyung Han85d61762020-06-24 23:50:26 +09001589 if vndkVersion == "current" {
1590 vndkVersion = deviceConfig.PlatformVndkVersion()
1591 }
1592 if vndkVersion != "" {
1593 return prefix + vndkVersion
1594 }
1595 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001596}
1597
Jiyong Parkf97782b2019-02-13 20:28:58 +09001598func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1599 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1600 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1601 }
1602}
1603
Jiyong Park388ef3f2019-01-28 19:47:32 +09001604func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001605 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1606 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001607 }
1608
1609 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001610 globalSanitizerNames := []string{}
1611 if a.Host() {
1612 globalSanitizerNames = ctx.Config().SanitizeHost()
1613 } else {
1614 arches := ctx.Config().SanitizeDeviceArch()
1615 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1616 globalSanitizerNames = ctx.Config().SanitizeDevice()
1617 }
1618 }
1619 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001620}
1621
Jooyung Han8ce8db92020-05-15 19:05:05 +09001622func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1623 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1624 for _, target := range ctx.MultiTargets() {
1625 if target.Arch.ArchType.Multilib == "lib64" {
1626 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001627 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001628 {Mutator: "link", Variation: "shared"},
1629 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1630 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1631 break
1632 }
1633 }
1634 }
1635}
1636
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001637var _ cc.Coverage = (*apexBundle)(nil)
1638
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001639func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001640 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001641}
1642
1643func (a *apexBundle) PreventInstall() {
1644 a.properties.PreventInstall = true
1645}
1646
1647func (a *apexBundle) HideFromMake() {
1648 a.properties.HideFromMake = true
1649}
1650
Jiyong Park956305c2020-01-09 12:32:06 +09001651func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1652 a.properties.IsCoverageVariant = coverage
1653}
1654
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001655func (a *apexBundle) EnableCoverageIfNeeded() {}
1656
Jiyong Parkf653b052019-11-18 15:39:01 +09001657// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001658func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001659 // Decide the APEX-local directory by the multilib of the library
1660 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001661 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001662 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663 case "lib32":
1664 dirInApex = "lib"
1665 case "lib64":
1666 dirInApex = "lib64"
1667 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001668 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001669 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001670 }
Jooyung Han35155c42020-02-06 17:33:20 +09001671 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001673 // Special case for Bionic libs and other libs installed with them. This is
1674 // to prevent those libs from being included in the search path
1675 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1676 // those libs in the Runtime APEX are available via the legacy paths in
1677 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1678 // to the legacy paths and thus will be loaded into the default linker
1679 // namespace (aka "platform" namespace). If the libs are directly in
1680 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1681 // into the runtime linker namespace, which will result in double loading of
1682 // them, which isn't supported.
1683 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001684 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001685
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001687 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1688 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001689}
1690
Jiyong Park1833cef2019-12-13 13:28:36 +09001691func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001692 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001693 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001694 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001695 }
Jooyung Han35155c42020-02-06 17:33:20 +09001696 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001697 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001698 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1699 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001700 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001701 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001702 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001703}
1704
Jiyong Park1833cef2019-12-13 13:28:36 +09001705func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001706 dirInApex := "bin"
1707 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001708 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001709}
Jiyong Park1833cef2019-12-13 13:28:36 +09001710func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001712 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1713 if err != nil {
1714 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001715 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001716 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 fileToCopy := android.PathForOutput(ctx, s)
1718 // NB: Since go binaries are static we don't need the module for anything here, which is
1719 // good since the go tool is a blueprint.Module not an android.Module like we would
1720 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001721 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001722}
1723
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001724func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001725 dirInApex := filepath.Join("bin", sh.SubDir())
1726 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001727 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001728 af.symlinks = sh.Symlinks()
1729 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001730}
1731
Yo Chiange8128052020-07-23 20:09:18 +08001732type javaModule interface {
1733 android.Module
1734 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001735 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001736 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001737 LintDepSets() java.LintDepSets
1738
Jiyong Parka62aa232020-05-28 23:46:55 +09001739 Stem() string
1740}
1741
Yo Chiange8128052020-07-23 20:09:18 +08001742var _ javaModule = (*java.Library)(nil)
1743var _ javaModule = (*java.SdkLibrary)(nil)
1744var _ javaModule = (*java.DexImport)(nil)
1745var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001746
Yo Chiange8128052020-07-23 20:09:18 +08001747func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001748 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001749 fileToCopy := module.DexJarBuildPath()
1750 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1751 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1752 af.lintDepSets = module.LintDepSets()
1753 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001754 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001755}
1756
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001757func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001758 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001759 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001760 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001761}
1762
atrost6e126252020-01-27 17:01:16 +00001763func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1764 dirInApex := filepath.Join("etc", config.SubDir())
1765 fileToCopy := config.CompatConfig()
1766 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1767}
1768
Jiyong Park1833cef2019-12-13 13:28:36 +09001769func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001770 android.Module
1771 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001772 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001773 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001774 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001775 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001776 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001777}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001778 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001779 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001780 appDir = "priv-app"
1781 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001782 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001783 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001784 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001785 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001786 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001787
1788 if app, ok := aapp.(interface {
1789 OverriddenManifestPackageName() string
1790 }); ok {
1791 af.overriddenPackageName = app.OverriddenManifestPackageName()
1792 }
Jiyong Park618922e2020-01-08 13:35:43 +09001793 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001794}
1795
Jiyong Park69aeba92020-04-24 21:16:36 +09001796func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1797 rroDir := "overlay"
1798 dirInApex := filepath.Join(rroDir, rro.Theme())
1799 fileToCopy := rro.OutputFile()
1800 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1801 af.certificate = rro.Certificate()
1802
1803 if a, ok := rro.(interface {
1804 OverriddenManifestPackageName() string
1805 }); ok {
1806 af.overriddenPackageName = a.OverriddenManifestPackageName()
1807 }
1808 return af
1809}
1810
markchien2f59ec92020-09-02 16:23:38 +08001811func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1812 dirInApex := filepath.Join("etc", "bpf")
1813 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1814}
1815
Roland Levillain935639d2019-08-13 14:55:28 +01001816// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1817type flattenedApexContext struct {
1818 android.ModuleContext
1819}
1820
1821func (c *flattenedApexContext) InstallBypassMake() bool {
1822 return true
1823}
1824
Jiyong Park201cedd2020-02-07 17:25:49 +09001825// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001826func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001827 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001828 am, ok := child.(android.ApexModule)
1829 if !ok || !am.CanHaveApexVariants() {
1830 return false
1831 }
1832
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001833 dt := ctx.OtherModuleDependencyTag(child)
1834
1835 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1836 return false
1837 }
1838
Jiyong Park0f80c182020-01-31 02:49:53 +09001839 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001840 if adt, ok := dt.(dependencyTag); ok {
1841 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001842 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001843 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001844 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001845 return false
1846 }
1847
1848 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Crossaede88c2020-08-11 12:17:01 -07001849 if android.InList(ctx.ModuleName(), am.InApexes()) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001850 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001851 }
1852
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001853 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001854 })
1855}
1856
Jooyung Han03b51852020-02-26 22:45:42 +09001857func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
Jooyung Han749dc692020-04-15 11:03:39 +09001858 ver := proptools.String(a.properties.Min_sdk_version)
1859 if ver == "" {
1860 return android.FutureApiLevel
1861 }
1862 // Treat the current codenames as "current", which means future API version (10000)
1863 // Otherwise, ApiStrToNum converts codename(non-finalized) to a value from [9000...]
1864 // and would fail to build against "current".
1865 if android.InList(ver, ctx.Config().PlatformVersionActiveCodenames()) {
1866 return android.FutureApiLevel
1867 }
1868 // In "REL" branch, "current" is mapped to finalized sdk version
1869 if ctx.Config().PlatformSdkCodename() == "REL" && ver == "current" {
1870 return ctx.Config().PlatformSdkVersionInt()
1871 }
1872 // Finalized codenames are OKAY and will be converted to int
Jooyung Hanaed150d2020-04-02 01:41:41 +09001873 intVer, err := android.ApiStrToNum(ctx, ver)
1874 if err != nil {
1875 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han03b51852020-02-26 22:45:42 +09001876 }
Jooyung Hanaed150d2020-04-02 01:41:41 +09001877 return intVer
Jooyung Han03b51852020-02-26 22:45:42 +09001878}
1879
Artur Satayev849f8442020-04-28 14:57:42 +01001880func (a *apexBundle) Updatable() bool {
1881 return proptools.Bool(a.properties.Updatable)
1882}
1883
1884var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1885
Jiyong Park201cedd2020-02-07 17:25:49 +09001886// Ensures that the dependencies are marked as available for this APEX
1887func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1888 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1889 if ctx.Host() || a.testApex || a.vndkApex {
1890 return
1891 }
1892
Jooyung Han85d61762020-06-24 23:50:26 +09001893 // Because APEXes targeting other than system/system_ext partitions
1894 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09001895 if a.SocSpecific() || a.DeviceSpecific() ||
1896 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001897 return
1898 }
1899
Jiyong Park58d10902020-03-28 14:43:19 +09001900 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1901 // Requiring them and their transitive depencies with apex_available is not right
1902 // because they just add noise.
1903 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1904 return
1905 }
1906
Jooyung Han749dc692020-04-15 11:03:39 +09001907 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001908 if externalDep {
1909 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1910 return false
1911 }
1912
Jiyong Park201cedd2020-02-07 17:25:49 +09001913 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09001914 fromName := ctx.OtherModuleName(from)
1915 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01001916
1917 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1918 // do any of its dependencies.
1919 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1920 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1921 return false
1922 }
1923
Colin Cross440e0d02020-06-11 11:32:11 -07001924 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001925 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001926 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09001927 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 +01001928 // Visit this module's dependencies to check and report any issues with their availability.
1929 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001930 })
1931}
1932
Jooyung Han548640b2020-04-27 12:10:30 +09001933func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01001934 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09001935 if String(a.properties.Min_sdk_version) == "" {
1936 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1937 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01001938
1939 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09001940 }
1941}
1942
Jooyung Han749dc692020-04-15 11:03:39 +09001943func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
1944 if a.testApex || a.vndkApex {
1945 return
1946 }
1947 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
1948 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
1949 return
1950 }
1951 android.CheckMinSdkVersion(a, ctx, a.minSdkVersion(ctx))
1952}
1953
Jiyong Park7d95a512020-05-10 15:16:24 +09001954// Ensures that a lib providing stub isn't statically linked
1955func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
1956 // Practically, we only care about regular APEXes on the device.
1957 if ctx.Host() || a.testApex || a.vndkApex {
1958 return
1959 }
1960
Jooyung Han749dc692020-04-15 11:03:39 +09001961 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09001962 if ccm, ok := to.(*cc.Module); ok {
1963 apexName := ctx.ModuleName()
1964 fromName := ctx.OtherModuleName(from)
1965 toName := ctx.OtherModuleName(to)
1966
1967 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1968 // do any of its dependencies.
1969 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1970 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1971 return false
1972 }
1973
1974 // TODO(jiyong) remove this check when R is published to AOSP. Currently, libstatssocket
1975 // is capable of providing a stub variant, but is being statically linked from the bluetooth
1976 // APEX.
1977 if toName == "libstatssocket" {
1978 return false
1979 }
1980
1981 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
1982 // It can't make the static dependencies dynamic because it can't
1983 // do the dynamic linking for itself.
1984 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
1985 return false
1986 }
1987
1988 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
1989 if isStubLibraryFromOtherApex && !externalDep {
1990 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
1991 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
1992 }
1993
1994 }
1995 return true
1996 })
1997}
1998
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001999func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01002000 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09002001 switch a.properties.ApexType {
2002 case imageApex:
2003 if buildFlattenedAsDefault {
2004 a.suffix = imageApexSuffix
2005 } else {
2006 a.suffix = ""
2007 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002008
2009 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002010 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002011 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002012 }
2013 case zipApex:
2014 if proptools.String(a.properties.Payload_type) == "zip" {
2015 a.suffix = ""
2016 a.primaryApexType = true
2017 } else {
2018 a.suffix = zipApexSuffix
2019 }
2020 case flattenedApex:
2021 if buildFlattenedAsDefault {
2022 a.suffix = ""
2023 a.primaryApexType = true
2024 } else {
2025 a.suffix = flattenedSuffix
2026 }
Alex Light5098a612018-11-29 17:12:15 -08002027 }
2028
Roland Levillain630846d2019-06-26 12:48:34 +01002029 if len(a.properties.Tests) > 0 && !a.testApex {
2030 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2031 return
2032 }
2033
Jiyong Park0f80c182020-01-31 02:49:53 +09002034 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002035 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002036 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002037 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002038
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002039 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2040
Jooyung Hane1633032019-08-01 17:41:43 +09002041 // native lib dependencies
2042 var provideNativeLibs []string
2043 var requireNativeLibs []string
2044
Jooyung Han5c998b92019-06-27 11:30:33 +09002045 // Check if "uses" requirements are met with dependent apexBundles
2046 var providedNativeSharedLibs []string
2047 useVendor := proptools.Bool(a.properties.Use_vendor)
2048 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2049 if ctx.OtherModuleDependencyTag(m) != usesTag {
2050 return
2051 }
2052 otherName := ctx.OtherModuleName(m)
2053 other, ok := m.(*apexBundle)
2054 if !ok {
2055 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2056 return
2057 }
2058 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2059 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2060 return
2061 }
2062 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2063 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2064 return
2065 }
2066 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2067 })
2068
Jiyong Parkf653b052019-11-18 15:39:01 +09002069 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002070 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002071 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002072 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002073 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2074 return false
2075 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002076 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002077 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002078 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002079 case sharedLibTag, jniLibTag:
2080 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002081 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002082 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2083 fi.isJniLib = isJniLib
2084 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002085 // Collect the list of stub-providing libs except:
2086 // - VNDK libs are only for vendors
2087 // - bootstrap bionic libs are treated as provided by system
2088 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002089 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2090 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002091 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002092 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002093 propertyName := "native_shared_libs"
2094 if isJniLib {
2095 propertyName = "jni_libs"
2096 }
2097 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002098 }
2099 case executableTag:
2100 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002101 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002102 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002103 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002104 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002105 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002106 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002107 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002108 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002109 } else {
Alex Light778127a2019-02-27 14:19:50 -08002110 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 +09002111 }
2112 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002113 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002114 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002115 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002116 if !af.Ok() {
2117 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2118 return false
2119 }
2120 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002121 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002122 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002123 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002124 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002125 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002126 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002127 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002128 return true // track transitive dependencies
2129 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002130 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002131 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002132 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002133 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2134 appDir := "app"
2135 if ap.Privileged() {
2136 appDir = "priv-app"
2137 }
Yo Chiange8128052020-07-23 20:09:18 +08002138 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002139 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2140 af.certificate = java.PresignedCertificate
2141 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002142 } else {
2143 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2144 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002145 case rroTag:
2146 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2147 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2148 } else {
2149 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2150 }
markchien2f59ec92020-09-02 16:23:38 +08002151 case bpfTag:
2152 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2153 filesToCopy, _ := bpfProgram.OutputFiles("")
2154 for _, bpfFile := range filesToCopy {
2155 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2156 }
2157 } else {
2158 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2159 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002160 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002161 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002162 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002163 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2164 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002165 } else {
atrost6e126252020-01-27 17:01:16 +00002166 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002167 }
Roland Levillain630846d2019-06-26 12:48:34 +01002168 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002169 if ccTest, ok := child.(*cc.Module); ok {
2170 if ccTest.IsTestPerSrcAllTestsVariation() {
2171 // Multiple-output test module (where `test_per_src: true`).
2172 //
2173 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2174 // We do not add this variation to `filesInfo`, as it has no output;
2175 // however, we do add the other variations of this module as indirect
2176 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002177 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002178 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002179 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002180 af.class = nativeTest
2181 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002182 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002183 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002184 } else {
2185 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2186 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002187 case keyTag:
2188 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002189 a.private_key_file = key.private_key_file
2190 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002191 } else {
2192 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002193 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002194 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002195 case certificateTag:
2196 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002197 a.container_certificate_file = dep.Certificate.Pem
2198 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002199 } else {
2200 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2201 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002202 case android.PrebuiltDepTag:
2203 // If the prebuilt is force disabled, remember to delete the prebuilt file
2204 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002205 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002206 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2207 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002208 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002209 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002210 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002211 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002212 // We cannot use a switch statement on `depTag` here as the checked
2213 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002214 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002215 if cc, ok := child.(*cc.Module); ok {
2216 if android.InList(cc.Name(), providedNativeSharedLibs) {
2217 // If we're using a shared library which is provided from other APEX,
2218 // don't include it in this APEX
2219 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002220 }
Jooyung Handf78e212020-07-22 15:54:47 +09002221 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002222 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002223 return false
2224 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002225 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2226 af.transitiveDep = true
Jooyung Hanefb184e2020-06-25 17:14:25 +09002227 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002228 // If the dependency is a stubs lib, don't include it in this APEX,
2229 // but make sure that the lib is installed on the device.
2230 // In case no APEX is having the lib, the lib is installed to the system
2231 // partition.
2232 //
2233 // Always include if we are a host-apex however since those won't have any
2234 // system libraries.
Jooyung Hanefb184e2020-06-25 17:14:25 +09002235 if !android.DirectlyInAnyApex(ctx, depName) {
2236 // we need a module name for Make
2237 name := cc.BaseModuleName() + cc.Properties.SubName
2238 if proptools.Bool(a.properties.Use_vendor) {
2239 // we don't use subName(.vendor) for a "use_vendor: true" apex
2240 // which is supposed to be installed in /system
2241 name = cc.BaseModuleName()
2242 }
2243 if !android.InList(name, a.requiredDeps) {
2244 a.requiredDeps = append(a.requiredDeps, name)
2245 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002246 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002247 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002248 // Don't track further
2249 return false
2250 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002251 filesInfo = append(filesInfo, af)
2252 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002253 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002254 } else if cc.IsTestPerSrcDepTag(depTag) {
2255 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002256 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002257 // Handle modules created as `test_per_src` variations of a single test module:
2258 // use the name of the generated test binary (`fileToCopy`) instead of the name
2259 // of the original test module (`depName`, shared by all `test_per_src`
2260 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002261 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002262 // these are not considered transitive dep
2263 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002264 filesInfo = append(filesInfo, af)
2265 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002266 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002267 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002268 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2269 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002270 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002271 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002272 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2273 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002274 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002275 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002276 }
2277 }
2278 }
2279 return false
2280 })
2281
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002282 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2283 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2284 // via the global boot image config.
2285 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002286 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002287 dirInApex := filepath.Join("javalib", arch.String())
2288 for _, f := range files {
2289 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002290 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002291 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002292 }
2293 }
2294 }
2295
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002296 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002297 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2298 return
2299 }
2300
Jiyong Park8fd61922018-11-08 02:50:25 +09002301 // remove duplicates in filesInfo
2302 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002303 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002304 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002305 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002306 if e, ok := encountered[dest]; !ok {
2307 encountered[dest] = f
2308 } else {
2309 // If a module is directly included and also transitively depended on
2310 // consider it as directly included.
2311 e.transitiveDep = e.transitiveDep && f.transitiveDep
2312 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002313 }
2314 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002315 var result []apexFile
2316 for _, v := range encountered {
2317 result = append(result, v)
2318 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002319 return result
2320 }
2321 filesInfo = removeDup(filesInfo)
2322
2323 // to have consistent build rules
2324 sort.Slice(filesInfo, func(i, j int) bool {
2325 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2326 })
2327
Jiyong Park8fd61922018-11-08 02:50:25 +09002328 a.installDir = android.PathForModuleInstall(ctx, "apex")
2329 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002330
Theotime Combes4ba38c12020-06-12 12:46:59 +00002331 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2332 case ext4FsType:
2333 a.payloadFsType = ext4
2334 case f2fsFsType:
2335 a.payloadFsType = f2fs
2336 default:
2337 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
2338 }
2339
Jiyong Park7cd10e32020-01-14 09:22:18 +09002340 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2341 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2342 // the same library in the system partition, thus effectively sharing the same libraries
2343 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2344 // in the APEX.
2345 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2346 a.installable() &&
2347 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002348
Jooyung Han85d61762020-06-24 23:50:26 +09002349 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2350 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002351 if a.SocSpecific() || a.DeviceSpecific() ||
2352 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002353 a.linkToSystemLib = false
2354 }
2355
Jiyong Park9d677202020-02-19 16:29:35 +09002356 // We don't need the optimization for updatable APEXes, as it might give false signal
2357 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002358 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002359 a.linkToSystemLib = false
2360 }
2361
Jiyong Park638d30e2020-02-26 18:27:19 +09002362 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2363 if ctx.Host() {
2364 a.linkToSystemLib = false
2365 }
2366
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002367 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002368 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2369
Jooyung Han580eb4f2020-06-24 19:33:06 +09002370 a.buildFileContexts(ctx)
2371
Jooyung Han01a3ee22019-11-02 02:52:25 +09002372 a.setCertificateAndPrivateKey(ctx)
2373 if a.properties.ApexType == flattenedApex {
2374 a.buildFlattenedApex(ctx)
2375 } else {
2376 a.buildUnflattenedApex(ctx)
2377 }
2378
Jooyung Han002ab682020-01-08 01:57:58 +09002379 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002380
2381 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002382
2383 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002384}
2385
Artur Satayev8cf899a2020-04-15 17:29:42 +01002386// Enforce that Java deps of the apex are using stable SDKs to compile
2387func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2388 // Visit direct deps only. As long as we guarantee top-level deps are using
2389 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2390 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2391 tag := ctx.OtherModuleDependencyTag(module)
2392 switch tag {
2393 case javaLibTag, androidAppTag:
2394 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2395 if err := m.CheckStableSdkVersion(); err != nil {
2396 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2397 }
2398 }
2399 }
2400 })
2401}
2402
Colin Cross440e0d02020-06-11 11:32:11 -07002403func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002404 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002405 moduleName = normalizeModuleName(moduleName)
2406
Colin Cross440e0d02020-06-11 11:32:11 -07002407 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002408 return true
2409 }
2410
2411 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002412 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002413 return true
2414 }
2415
2416 return false
2417}
2418
2419func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002420 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2421 // system. Trim the prefix for the check since they are confusing
2422 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2423 if strings.HasPrefix(moduleName, "libclang_rt.") {
2424 // This module has many arch variants that depend on the product being built.
2425 // We don't want to list them all
2426 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002427 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002428 if strings.HasPrefix(moduleName, "androidx.") {
2429 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2430 moduleName = "androidx"
2431 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002432 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002433}
2434
Jooyung Han344d5432019-08-23 11:17:39 +09002435func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002436 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002437 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002438 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002439 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002440 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002441 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002442 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002443 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002444 return module
2445}
Jiyong Park30ca9372019-02-07 16:27:23 +09002446
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002447func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002448 bundle := newApexBundle()
2449 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002450 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002451 return bundle
2452}
2453
Jiyong Parkfce0b422020-02-11 03:56:06 +09002454// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2455// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002456func testApexBundleFactory() android.Module {
2457 bundle := newApexBundle()
2458 bundle.testApex = true
2459 return bundle
2460}
2461
Jiyong Parkfce0b422020-02-11 03:56:06 +09002462// apex packages other modules into an APEX file which is a packaging format for system-level
2463// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002464func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002465 return newApexBundle()
2466}
2467
Jiyong Park30ca9372019-02-07 16:27:23 +09002468//
2469// Defaults
2470//
2471type Defaults struct {
2472 android.ModuleBase
2473 android.DefaultsModuleBase
2474}
2475
Jiyong Park30ca9372019-02-07 16:27:23 +09002476func defaultsFactory() android.Module {
2477 return DefaultsFactory()
2478}
2479
2480func DefaultsFactory(props ...interface{}) android.Module {
2481 module := &Defaults{}
2482
2483 module.AddProperties(props...)
2484 module.AddProperties(
2485 &apexBundleProperties{},
2486 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002487 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002488 )
2489
2490 android.InitDefaultsModule(module)
2491 return module
2492}
Jiyong Park5d790c32019-11-15 18:40:32 +09002493
2494//
2495// OverrideApex
2496//
2497type OverrideApex struct {
2498 android.ModuleBase
2499 android.OverrideModuleBase
2500}
2501
2502func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2503 // All the overrides happen in the base module.
2504}
2505
2506// override_apex is used to create an apex module based on another apex module
2507// by overriding some of its properties.
2508func overrideApexFactory() android.Module {
2509 m := &OverrideApex{}
2510 m.AddProperties(&overridableProperties{})
2511
2512 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2513 android.InitOverrideModule(m)
2514 return m
2515}