blob: 0108c0f0d0db2cf14c038df050f6694cf31bd01f [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 //
Jiyong Park8b399192020-04-29 22:34:13 +0900103 m["com.android.appsearch"] = []string{
104 "icing-java-proto-lite",
105 "libprotobuf-java-lite",
106 }
107 //
108 // Module separator
109 //
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000110 m["com.android.bluetooth.updatable"] = []string{
111 "android.hardware.audio.common@5.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000112 "android.hardware.bluetooth.a2dp@1.0",
113 "android.hardware.bluetooth.audio@2.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900114 "android.hardware.bluetooth@1.0",
115 "android.hardware.bluetooth@1.1",
116 "android.hardware.graphics.bufferqueue@1.0",
117 "android.hardware.graphics.bufferqueue@2.0",
118 "android.hardware.graphics.common@1.0",
119 "android.hardware.graphics.common@1.1",
120 "android.hardware.graphics.common@1.2",
121 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000122 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900123 "android.hidl.token@1.0",
124 "android.hidl.token@1.0-utils",
125 "avrcp-target-service",
126 "avrcp_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900127 "bluetooth-protos-lite",
128 "bluetooth.mapsapi",
129 "com.android.vcard",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900130 "dnsresolver_aidl_interface-V2-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900131 "ipmemorystore-aidl-interfaces-V5-java",
132 "ipmemorystore-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900133 "internal_include_headers",
134 "lib-bt-packets",
135 "lib-bt-packets-avrcp",
136 "lib-bt-packets-base",
137 "libFraunhoferAAC",
138 "libaudio-a2dp-hw-utils",
139 "libaudio-hearing-aid-hw-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900140 "libbinder_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000141 "libbluetooth",
Jiyong Park0f80c182020-01-31 02:49:53 +0900142 "libbluetooth-types",
143 "libbluetooth-types-header",
144 "libbluetooth_gd",
145 "libbluetooth_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000146 "libbluetooth_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900147 "libbt-audio-hal-interface",
148 "libbt-bta",
149 "libbt-common",
150 "libbt-hci",
151 "libbt-platform-protos-lite",
152 "libbt-protos-lite",
153 "libbt-sbc-decoder",
154 "libbt-sbc-encoder",
155 "libbt-stack",
156 "libbt-utils",
157 "libbtcore",
158 "libbtdevice",
159 "libbte",
160 "libbtif",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000161 "libchrome",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000162 "libevent",
163 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900164 "libg722codec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900165 "libgui_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900166 "libmedia_headers",
167 "libmodpb64",
168 "libosi",
Jiyong Park0f80c182020-01-31 02:49:53 +0900169 "libstagefright_foundation_headers",
170 "libstagefright_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000171 "libstatslog",
Jiyong Park0f80c182020-01-31 02:49:53 +0900172 "libstatssocket",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000173 "libtinyxml2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900174 "libudrv-uipc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000175 "libz",
Jiyong Park0f80c182020-01-31 02:49:53 +0900176 "media_plugin_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900177 "net-utils-services-common",
178 "netd_aidl_interface-unstable-java",
179 "netd_event_listener_interface-java",
180 "netlink-client",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900181 "networkstack-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900182 "sap-api-java-static",
183 "services.net",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000184 }
185 //
186 // Module separator
187 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900188 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000189 //
190 // Module separator
191 //
Jooyung Han040ff3d2020-05-19 15:47:01 +0900192 m["com.android.extservices"] = []string{
193 "error_prone_annotations",
194 "ExtServices-core",
195 "ExtServices",
196 "libtextclassifier-java",
197 "libz_current",
198 "textclassifier-statsd",
199 "TextClassifierNotificationLibNoManifest",
200 "TextClassifierServiceLibNoManifest",
201 }
202 //
203 // Module separator
204 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900205 m["com.android.neuralnetworks"] = []string{
206 "android.hardware.neuralnetworks@1.0",
207 "android.hardware.neuralnetworks@1.1",
208 "android.hardware.neuralnetworks@1.2",
209 "android.hardware.neuralnetworks@1.3",
210 "android.hidl.allocator@1.0",
211 "android.hidl.memory.token@1.0",
212 "android.hidl.memory@1.0",
213 "android.hidl.safe_union@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900214 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900215 "libbuildversion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900216 "libmath",
Jiyong Park0f80c182020-01-31 02:49:53 +0900217 "libprocpartition",
218 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900219 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000220 //
221 // Module separator
222 //
223 m["com.android.media"] = []string{
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000224 "android.frameworks.bufferhub@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900225 "android.hardware.cas.native@1.0",
226 "android.hardware.cas@1.0",
227 "android.hardware.configstore-utils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000228 "android.hardware.configstore@1.0",
229 "android.hardware.configstore@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000230 "android.hardware.graphics.allocator@2.0",
231 "android.hardware.graphics.allocator@3.0",
232 "android.hardware.graphics.bufferqueue@1.0",
233 "android.hardware.graphics.bufferqueue@2.0",
234 "android.hardware.graphics.common@1.0",
235 "android.hardware.graphics.common@1.1",
236 "android.hardware.graphics.common@1.2",
237 "android.hardware.graphics.mapper@2.0",
238 "android.hardware.graphics.mapper@2.1",
239 "android.hardware.graphics.mapper@3.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900240 "android.hardware.media.omx@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000241 "android.hardware.media@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900242 "android.hidl.allocator@1.0",
243 "android.hidl.memory.token@1.0",
244 "android.hidl.memory@1.0",
245 "android.hidl.token@1.0",
246 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900247 "bionic_libc_platform_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900248 "exoplayer2-extractor",
249 "exoplayer2-extractor-annotation-stubs",
Jiyong Park0f80c182020-01-31 02:49:53 +0900250 "gl_headers",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900251 "jsr305",
Jiyong Park0f80c182020-01-31 02:49:53 +0900252 "libEGL",
253 "libEGL_blobCache",
254 "libEGL_getProcAddress",
255 "libFLAC",
256 "libFLAC-config",
257 "libFLAC-headers",
258 "libGLESv2",
259 "libaacextractor",
260 "libamrextractor",
261 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900262 "libaudio_system_headers",
263 "libaudioclient",
264 "libaudioclient_headers",
265 "libaudiofoundation",
266 "libaudiofoundation_headers",
267 "libaudiomanager",
268 "libaudiopolicy",
269 "libaudioutils",
270 "libaudioutils_fixedfft",
Jiyong Park0f80c182020-01-31 02:49:53 +0900271 "libbinder_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900272 "libbluetooth-types-header",
273 "libbufferhub",
274 "libbufferhub_headers",
275 "libbufferhubqueue",
Jiyong Park0f80c182020-01-31 02:49:53 +0900276 "libc_malloc_debug_backtrace",
277 "libcamera_client",
278 "libcamera_metadata",
Jiyong Park0f80c182020-01-31 02:49:53 +0900279 "libdexfile_external_headers",
280 "libdexfile_support",
281 "libdvr_headers",
282 "libexpat",
283 "libfifo",
284 "libflacextractor",
285 "libgrallocusage",
286 "libgraphicsenv",
287 "libgui",
288 "libgui_headers",
289 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900290 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900291 "liblzma",
292 "libmath",
293 "libmedia",
294 "libmedia_codeclist",
295 "libmedia_headers",
296 "libmedia_helper",
297 "libmedia_helper_headers",
298 "libmedia_midiiowrapper",
299 "libmedia_omx",
300 "libmediautils",
301 "libmidiextractor",
302 "libmkvextractor",
303 "libmp3extractor",
304 "libmp4extractor",
305 "libmpeg2extractor",
306 "libnativebase_headers",
307 "libnativebridge-headers",
308 "libnativebridge_lazy",
309 "libnativeloader-headers",
310 "libnativeloader_lazy",
311 "libnativewindow_headers",
312 "libnblog",
313 "liboggextractor",
314 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900315 "libpdx",
316 "libpdx_default_transport",
317 "libpdx_headers",
318 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900319 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900320 "libspeexresampler",
321 "libspeexresampler",
322 "libstagefright_esds",
323 "libstagefright_flacdec",
324 "libstagefright_flacdec",
325 "libstagefright_foundation",
326 "libstagefright_foundation_headers",
327 "libstagefright_foundation_without_imemory",
328 "libstagefright_headers",
329 "libstagefright_id3",
330 "libstagefright_metadatautils",
331 "libstagefright_mpeg2extractor",
332 "libstagefright_mpeg2support",
333 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900334 "libui",
335 "libui_headers",
336 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900337 "libvibrator",
338 "libvorbisidec",
339 "libwavextractor",
340 "libwebm",
341 "media_ndk_headers",
342 "media_plugin_headers",
343 "updatable-media",
344 }
345 //
346 // Module separator
347 //
348 m["com.android.media.swcodec"] = []string{
349 "android.frameworks.bufferhub@1.0",
350 "android.hardware.common-ndk_platform",
351 "android.hardware.configstore-utils",
352 "android.hardware.configstore@1.0",
353 "android.hardware.configstore@1.1",
354 "android.hardware.graphics.allocator@2.0",
355 "android.hardware.graphics.allocator@3.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000356 "android.hardware.graphics.allocator@4.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900357 "android.hardware.graphics.bufferqueue@1.0",
358 "android.hardware.graphics.bufferqueue@2.0",
359 "android.hardware.graphics.common-ndk_platform",
360 "android.hardware.graphics.common@1.0",
361 "android.hardware.graphics.common@1.1",
362 "android.hardware.graphics.common@1.2",
363 "android.hardware.graphics.mapper@2.0",
364 "android.hardware.graphics.mapper@2.1",
365 "android.hardware.graphics.mapper@3.0",
366 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000367 "android.hardware.media.bufferpool@2.0",
368 "android.hardware.media.c2@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000369 "android.hardware.media.c2@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000370 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900371 "android.hardware.media@1.0",
372 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000373 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900374 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000375 "android.hidl.safe_union@1.0",
376 "android.hidl.token@1.0",
377 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libEGL",
379 "libFLAC",
380 "libFLAC-config",
381 "libFLAC-headers",
382 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900383 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900384 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900385 "libaudio_system_headers",
386 "libaudioutils",
387 "libaudioutils",
388 "libaudioutils_fixedfft",
389 "libavcdec",
390 "libavcenc",
391 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000392 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900393 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900394 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900395 "libbluetooth-types-header",
396 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000397 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900398 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000399 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900400 "libcodec2_hidl@1.1",
401 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000402 "libcodec2_soft_aacdec",
403 "libcodec2_soft_aacenc",
404 "libcodec2_soft_amrnbdec",
405 "libcodec2_soft_amrnbenc",
406 "libcodec2_soft_amrwbdec",
407 "libcodec2_soft_amrwbenc",
408 "libcodec2_soft_av1dec_gav1",
409 "libcodec2_soft_avcdec",
410 "libcodec2_soft_avcenc",
411 "libcodec2_soft_common",
412 "libcodec2_soft_flacdec",
413 "libcodec2_soft_flacenc",
414 "libcodec2_soft_g711alawdec",
415 "libcodec2_soft_g711mlawdec",
416 "libcodec2_soft_gsmdec",
417 "libcodec2_soft_h263dec",
418 "libcodec2_soft_h263enc",
419 "libcodec2_soft_hevcdec",
420 "libcodec2_soft_hevcenc",
421 "libcodec2_soft_mp3dec",
422 "libcodec2_soft_mpeg2dec",
423 "libcodec2_soft_mpeg4dec",
424 "libcodec2_soft_mpeg4enc",
425 "libcodec2_soft_opusdec",
426 "libcodec2_soft_opusenc",
427 "libcodec2_soft_rawdec",
428 "libcodec2_soft_vorbisdec",
429 "libcodec2_soft_vp8dec",
430 "libcodec2_soft_vp8enc",
431 "libcodec2_soft_vp9dec",
432 "libcodec2_soft_vp9enc",
433 "libcodec2_vndk",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000434 "libdexfile_support",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000436 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900437 "libfmq",
438 "libgav1",
439 "libgralloctypes",
440 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000441 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900442 "libgsm",
443 "libgui_bufferqueue_static",
444 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000445 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900446 "libhardware_headers",
447 "libhevcdec",
448 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000449 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900450 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000451 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900452 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000453 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900454 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900455 "libmpeg2dec",
456 "libnativebase_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000457 "libnativebridge_lazy",
458 "libnativeloader_lazy",
Jiyong Park0f80c182020-01-31 02:49:53 +0900459 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900460 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000461 "libscudo_wrapper",
462 "libsfplugin_ccodec_utils",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "libspeexresampler",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000464 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900465 "libstagefright_amrnbdec",
466 "libstagefright_amrnbenc",
467 "libstagefright_amrwbdec",
468 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000469 "libstagefright_bufferpool@2.0.1",
470 "libstagefright_bufferqueue_helper",
471 "libstagefright_enc_common",
472 "libstagefright_flacdec",
473 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900474 "libstagefright_foundation_headers",
475 "libstagefright_headers",
476 "libstagefright_m4vh263dec",
477 "libstagefright_m4vh263enc",
478 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000479 "libsync",
480 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900481 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000482 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000483 "libvorbisidec",
484 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900485 "libyuv",
486 "libyuv_static",
487 "media_ndk_headers",
488 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000489 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900490 }
491 //
492 // Module separator
493 //
494 m["com.android.mediaprovider"] = []string{
495 "MediaProvider",
496 "MediaProviderGoogle",
497 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900498 "libbase_ndk",
499 "libfuse",
500 "libfuse_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900501 }
502 //
503 // Module separator
504 //
505 m["com.android.permission"] = []string{
Jooyung Han040ff3d2020-05-19 15:47:01 +0900506 "car-ui-lib",
507 "iconloader",
Jiyong Park0f80c182020-01-31 02:49:53 +0900508 "kotlin-annotations",
509 "kotlin-stdlib",
510 "kotlin-stdlib-jdk7",
511 "kotlin-stdlib-jdk8",
512 "kotlinx-coroutines-android",
513 "kotlinx-coroutines-android-nodeps",
514 "kotlinx-coroutines-core",
515 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900516 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900517 "GooglePermissionController",
518 "PermissionController",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900519 "SettingsLibActionBarShadow",
520 "SettingsLibAppPreference",
521 "SettingsLibBarChartPreference",
522 "SettingsLibLayoutPreference",
523 "SettingsLibProgressBar",
524 "SettingsLibSearchWidget",
525 "SettingsLibSettingsTheme",
526 "SettingsLibRestrictedLockUtils",
527 "SettingsLibHelpUtils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000528 }
529 //
530 // Module separator
531 //
532 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900533 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900534 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900535 "libc_aeabi",
536 "libc_bionic",
537 "libc_bionic_ndk",
538 "libc_bootstrap",
539 "libc_common",
540 "libc_common_shared",
541 "libc_common_static",
542 "libc_dns",
543 "libc_dynamic_dispatch",
544 "libc_fortify",
545 "libc_freebsd",
546 "libc_freebsd_large_stack",
547 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900548 "libc_init_dynamic",
549 "libc_init_static",
550 "libc_jemalloc_wrapper",
551 "libc_netbsd",
552 "libc_nomalloc",
553 "libc_nopthread",
554 "libc_openbsd",
555 "libc_openbsd_large_stack",
556 "libc_openbsd_ndk",
557 "libc_pthread",
558 "libc_static_dispatch",
559 "libc_syscalls",
560 "libc_tzcode",
561 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900562 "libdebuggerd",
563 "libdebuggerd_common_headers",
564 "libdebuggerd_handler_core",
565 "libdebuggerd_handler_fallback",
566 "libdexfile_external_headers",
567 "libdexfile_support",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900568 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900569 "libjemalloc5",
570 "liblinker_main",
571 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900572 "liblz4",
573 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900574 "libprocinfo",
575 "libpropertyinfoparser",
576 "libscudo",
577 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900578 "libsystemproperties",
579 "libtombstoned_client_static",
580 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900581 "libz",
582 "libziparchive",
583 }
584 //
585 // Module separator
586 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900587 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900588 "android.hardware.tetheroffload.config-V1.0-java",
589 "android.hardware.tetheroffload.control-V1.0-java",
590 "android.hidl.base-V1.0-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900591 "libcgrouprc",
592 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900593 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900595 "net-utils-framework-common",
596 "netd_aidl_interface-V3-java",
597 "netlink-client",
598 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900599 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900600 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000601 }
602 //
603 // Module separator
604 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900605 m["com.android.wifi"] = []string{
606 "PlatformProperties",
607 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900608 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900609 "android.hardware.wifi-V1.1-java",
610 "android.hardware.wifi-V1.2-java",
611 "android.hardware.wifi-V1.3-java",
612 "android.hardware.wifi-V1.4-java",
613 "android.hardware.wifi.hostapd-V1.0-java",
614 "android.hardware.wifi.hostapd-V1.1-java",
615 "android.hardware.wifi.hostapd-V1.2-java",
616 "android.hardware.wifi.supplicant-V1.0-java",
617 "android.hardware.wifi.supplicant-V1.1-java",
618 "android.hardware.wifi.supplicant-V1.2-java",
619 "android.hardware.wifi.supplicant-V1.3-java",
620 "android.hidl.base-V1.0-java",
621 "android.hidl.manager-V1.0-java",
622 "android.hidl.manager-V1.1-java",
623 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900624 "bouncycastle-unbundled",
625 "dnsresolver_aidl_interface-V2-java",
626 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900627 "framework-wifi-pre-jarjar",
628 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900629 "ipmemorystore-aidl-interfaces-V3-java",
630 "ipmemorystore-aidl-interfaces-java",
631 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900632 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900633 "libwifi-jni",
634 "net-utils-services-common",
635 "netd_aidl_interface-V2-java",
636 "netd_aidl_interface-unstable-java",
637 "netd_event_listener_interface-java",
638 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900639 "networkstack-client",
640 "services.net",
641 "wifi-lite-protos",
642 "wifi-nano-protos",
643 "wifi-service-pre-jarjar",
644 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900645 }
646 //
647 // Module separator
648 //
649 m["com.android.sdkext"] = []string{
650 "fmtlib_ndk",
651 "libbase_ndk",
652 "libprotobuf-cpp-lite-ndk",
653 }
654 //
655 // Module separator
656 //
657 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900658 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900659 }
660 //
661 // Module separator
662 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000663 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900664 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
665 "androidx",
666 "androidx-constraintlayout_constraintlayout",
667 "androidx-constraintlayout_constraintlayout-nodeps",
668 "androidx-constraintlayout_constraintlayout-solver",
669 "androidx-constraintlayout_constraintlayout-solver-nodeps",
670 "com.google.android.material_material",
671 "com.google.android.material_material-nodeps",
672
Jiyong Park0f80c182020-01-31 02:49:53 +0900673 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900674 "libclang_rt",
675 "libgcc_stripped",
676 "libprofile-clang-extras",
677 "libprofile-clang-extras_ndk",
678 "libprofile-extras",
679 "libprofile-extras_ndk",
680 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900681 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000682 return m
683}
684
Andrei Onea115e7e72020-06-05 21:14:03 +0100685// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
686// Adding code to the bootclasspath in new packages will cause issues on module update.
687func qModulesPackages() map[string][]string {
688 return map[string][]string{
689 "com.android.conscrypt": []string{
690 "android.net.ssl",
691 "com.android.org.conscrypt",
692 },
693 "com.android.media": []string{
694 "android.media",
695 },
696 }
697}
698
699// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
700// Adding code to the bootclasspath in new packages will cause issues on module update.
701func rModulesPackages() map[string][]string {
702 return map[string][]string{
703 "com.android.mediaprovider": []string{
704 "android.provider",
705 },
706 "com.android.permission": []string{
707 "android.permission",
708 "android.app.role",
709 "com.android.permission",
710 "com.android.role",
711 },
712 "com.android.sdkext": []string{
713 "android.os.ext",
714 },
715 "com.android.os.statsd": []string{
716 "android.app",
717 "android.os",
718 "android.util",
719 "com.android.internal.statsd",
720 "com.android.server.stats",
721 },
722 "com.android.wifi": []string{
723 "com.android.server.wifi",
724 "com.android.wifi.x",
725 "android.hardware.wifi",
726 "android.net.wifi",
727 },
728 "com.android.tethering": []string{
729 "android.net",
730 },
731 }
732}
733
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900734func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900735 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800736 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900737 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900738 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700739 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900740 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700741 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900742
Jooyung Han31c470b2019-10-18 16:26:59 +0900743 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900744 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900745
746 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
747 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
748 sort.Strings(*apexFileContextsInfos)
749 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
750 })
Andrei Onea115e7e72020-06-05 21:14:03 +0100751
752 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
753 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
754}
755
756func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
757 rules := make([]android.Rule, 0, len(modules_packages))
758 for module_name, module_packages := range modules_packages {
759 permitted_packages_rule := android.NeverAllow().
760 BootclasspathJar().
761 With("apex_available", module_name).
762 WithMatcher("permitted_packages", android.NotInList(module_packages)).
763 Because("jars that are part of the " + module_name +
764 " module may only allow these packages: " + strings.Join(module_packages, ",") +
765 ". Please jarjar or move code around.")
766 rules = append(rules, permitted_packages_rule)
767 }
768 return rules
Jiyong Parkd1063c12019-07-17 20:08:41 +0900769}
770
Jooyung Han31c470b2019-10-18 16:26:59 +0900771func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
772 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
773 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
774}
775
Jiyong Parkd1063c12019-07-17 20:08:41 +0900776func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900777 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700778 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900779 ctx.BottomUp("apex", apexMutator).Parallel()
780 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
781 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900782 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900783}
784
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900785// Mark the direct and transitive dependencies of apex bundles so that they
786// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900787func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900788 if !mctx.Module().Enabled() {
789 return
790 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900791 a, ok := mctx.Module().(*apexBundle)
792 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900793 return
794 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900795 apexInfo := android.ApexInfo{
Colin Crosse07f2312020-08-13 11:24:56 -0700796 ApexVariationName: mctx.ModuleName(),
Dan Albertc8060532020-07-22 22:32:17 -0700797 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
Colin Crossaede88c2020-08-11 12:17:01 -0700798 RequiredSdks: a.RequiredSdks(),
Colin Crosse07f2312020-08-13 11:24:56 -0700799 Updatable: a.Updatable(),
Colin Crossaede88c2020-08-11 12:17:01 -0700800 InApexes: []string{mctx.ModuleName()},
Jooyung Han698dd9f2020-07-22 15:17:19 +0900801 }
Jooyung Handf78e212020-07-22 15:54:47 +0900802
803 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
804 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
805 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
806 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
807 return
808 }
809
Jooyung Han698dd9f2020-07-22 15:17:19 +0900810 mctx.WalkDeps(func(child, parent android.Module) bool {
811 am, ok := child.(android.ApexModule)
812 if !ok || !am.CanHaveApexVariants() {
813 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900814 }
Paul Duffina37eca22020-07-22 13:00:54 +0100815 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900816 return false
817 }
Jooyung Handf78e212020-07-22 15:54:47 +0900818 if excludeVndkLibs {
819 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
820 return false
821 }
822 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900823
824 depName := mctx.OtherModuleName(child)
825 // If the parent is apexBundle, this child is directly depended.
826 _, directDep := parent.(*apexBundle)
827 android.UpdateApexDependency(apexInfo, depName, directDep)
828 am.BuildForApex(apexInfo)
829 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900830 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900831}
832
Colin Crossaede88c2020-08-11 12:17:01 -0700833func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
834 if !mctx.Module().Enabled() {
835 return
836 }
837 if am, ok := mctx.Module().(android.ApexModule); ok {
838 // Check if any dependencies use unique apex variations. If so, use unique apex variations
839 // for this module.
840 am.UpdateUniqueApexVariationsForDeps(mctx)
841 }
842}
843
Jiyong Park89e850a2020-04-07 16:37:39 +0900844// mark if a module cannot be available to platform. A module cannot be available
845// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
846// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
847func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
848 // Host and recovery are not considered as platform
849 if mctx.Host() || mctx.Module().InstallInRecovery() {
850 return
851 }
852
853 if am, ok := mctx.Module().(android.ApexModule); ok {
854 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
855
Jiyong Park89e850a2020-04-07 16:37:39 +0900856 // If any of the dep is not available to platform, this module is also considered
857 // as being not available to platform even if it has "//apex_available:platform"
858 mctx.VisitDirectDeps(func(child android.Module) {
859 if !am.DepIsInSameApex(mctx, child) {
860 // if the dependency crosses apex boundary, don't consider it
861 return
862 }
863 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
864 availableToPlatform = false
865 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
866 }
867 })
868
869 // Exception 1: stub libraries and native bridge libraries are always available to platform
870 if cc, ok := mctx.Module().(*cc.Module); ok &&
871 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
872 availableToPlatform = true
873 }
874
875 // Exception 2: bootstrap bionic libraries are also always available to platform
876 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
877 availableToPlatform = true
878 }
879
880 if !availableToPlatform {
881 am.SetNotAvailableForPlatform()
882 }
883 }
884}
885
Paul Duffin65347702020-03-31 15:23:40 +0100886// If a module in an APEX depends on a module from an SDK then it needs an APEX
887// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
888func inAnySdk(module android.Module) bool {
889 if sa, ok := module.(android.SdkAware); ok {
890 return sa.IsInAnySdk()
891 }
892
893 return false
894}
895
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900896// Create apex variations if a module is included in APEX(s).
897func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900898 if !mctx.Module().Enabled() {
899 return
900 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900901 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900902 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000903 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900904 // apex bundle itself is mutated so that it and its modules have same
905 // apex variant.
906 apexBundleName := mctx.ModuleName()
907 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900908 } else if o, ok := mctx.Module().(*OverrideApex); ok {
909 apexBundleName := o.GetOverriddenModuleName()
910 if apexBundleName == "" {
911 mctx.ModuleErrorf("base property is not set")
912 return
913 }
914 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900915 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900916
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900917}
Sundong Ahne9b55722019-09-06 17:37:42 +0900918
Jooyung Han7a78a922019-10-08 21:59:58 +0900919var (
920 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
921 apexFileContextsInfosMutex sync.Mutex
922)
923
924func apexFileContextsInfos(config android.Config) *[]string {
925 return config.Once(apexFileContextsInfosKey, func() interface{} {
926 return &[]string{}
927 }).(*[]string)
928}
929
Jooyung Han54aca7b2019-11-20 02:26:02 +0900930func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900931 apexFileContextsInfosMutex.Lock()
932 defer apexFileContextsInfosMutex.Unlock()
933 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900934 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900935}
936
Sundong Ahne9b55722019-09-06 17:37:42 +0900937func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900938 if !mctx.Module().Enabled() {
939 return
940 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900941 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900942 var variants []string
943 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
944 case "image":
945 variants = append(variants, imageApexType, flattenedApexType)
946 case "zip":
947 variants = append(variants, zipApexType)
948 case "both":
949 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
950 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900951 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900952 return
953 }
954
955 modules := mctx.CreateLocalVariations(variants...)
956
957 for i, v := range variants {
958 switch v {
959 case imageApexType:
960 modules[i].(*apexBundle).properties.ApexType = imageApex
961 case zipApexType:
962 modules[i].(*apexBundle).properties.ApexType = zipApex
963 case flattenedApexType:
964 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900965 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900966 modules[i].(*apexBundle).MakeAsSystemExt()
967 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900968 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900969 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900970 } else if _, ok := mctx.Module().(*OverrideApex); ok {
971 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900972 }
973}
974
Jooyung Han5c998b92019-06-27 11:30:33 +0900975func apexUsesMutator(mctx android.BottomUpMutatorContext) {
976 if ab, ok := mctx.Module().(*apexBundle); ok {
977 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
978 }
979}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900980
Jooyung Handc782442019-11-01 03:14:38 +0900981var (
Colin Cross440e0d02020-06-11 11:32:11 -0700982 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900983)
984
Colin Cross440e0d02020-06-11 11:32:11 -0700985// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900986// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
987// which may cause compatibility issues. (e.g. libbinder)
988// Even though libbinder restricts its availability via 'apex_available' property and relies on
989// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
990// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -0700991func useVendorAllowList(config android.Config) []string {
992 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900993 return []string{
994 // swcodec uses "vendor" variants for smaller size
995 "com.android.media.swcodec",
996 "test_com.android.media.swcodec",
997 }
998 }).([]string)
999}
1000
Colin Cross440e0d02020-06-11 11:32:11 -07001001// setUseVendorAllowListForTest overrides useVendorAllowList and must be
1002// called before the first call to useVendorAllowList()
1003func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1004 config.Once(useVendorAllowListKey, func() interface{} {
1005 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001006 })
1007}
1008
Jooyung Han01a868d2020-02-27 13:40:44 +09001009type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001010 // List of native libraries
1011 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001012
Jooyung Han643adc42020-02-27 13:50:06 +09001013 // List of JNI libraries
1014 Jni_libs []string
1015
Alex Light9670d332019-01-29 18:07:33 -08001016 // List of native executables
1017 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001018
Roland Levillain630846d2019-06-26 12:48:34 +01001019 // List of native tests
1020 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001021}
Jooyung Han344d5432019-08-23 11:17:39 +09001022
Alex Light9670d332019-01-29 18:07:33 -08001023type apexMultilibProperties struct {
1024 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001025 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001026
1027 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001028 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001029
1030 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001031 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001032
1033 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001034 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001035
1036 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001037 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001038}
1039
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001040type apexBundleProperties struct {
1041 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001042 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001043 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001044
Jiyong Park40e26a22019-02-08 02:53:06 +09001045 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1046 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001047 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001048
Roland Levillain411c5842019-09-19 16:37:20 +01001049 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1050 // device (/apex/<apex_name>).
1051 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001052 Apex_name *string
1053
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001054 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001055 // For platform APEXes, this should points to a file under /system/sepolicy
1056 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1057 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001058
Jooyung Han01a868d2020-02-27 13:40:44 +09001059 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001060
1061 // List of java libraries that are embedded inside this APEX bundle
1062 Java_libs []string
1063
1064 // List of prebuilt files that are embedded inside this APEX bundle
1065 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001066
markchien2f59ec92020-09-02 16:23:38 +08001067 // List of BPF programs inside APEX
1068 Bpfs []string
1069
Jiyong Parkff1458f2018-10-12 21:49:38 +09001070 // Name of the apex_key module that provides the private key to sign APEX
1071 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001072
Alex Light5098a612018-11-29 17:12:15 -08001073 // The type of APEX to build. Controls what the APEX payload is. Either
1074 // 'image', 'zip' or 'both'. Default: 'image'.
1075 Payload_type *string
1076
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001077 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1078 // or an android_app_certificate module name in the form ":module".
1079 Certificate *string
1080
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001081 // Whether this APEX is installable to one of the partitions. Default: true.
1082 Installable *bool
1083
Jiyong Parkda6eb592018-12-19 17:12:36 +09001084 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1085 // Default is false.
1086 Use_vendor *bool
1087
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001088 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1089 Ignore_system_library_special_case *bool
1090
Alex Light9670d332019-01-29 18:07:33 -08001091 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001092
Jiyong Parkf97782b2019-02-13 20:28:58 +09001093 // List of sanitizer names that this APEX is enabled for
1094 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001095
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001096 PreventInstall bool `blueprint:"mutated"`
1097
1098 HideFromMake bool `blueprint:"mutated"`
1099
Jooyung Han5c998b92019-06-27 11:30:33 +09001100 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1101 Provide_cpp_shared_libs *bool
1102
1103 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1104 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001105
Sundong Ahnabb64432019-10-22 13:58:29 +09001106 // package format of this apex variant; could be non-flattened, flattened, or zip.
1107 // imageApex, zipApex or flattened
1108 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001109
Jiyong Parkd1063c12019-07-17 20:08:41 +09001110 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1111 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1112 // is implied. This value affects all modules included in this APEX. In other words, they are
1113 // also built with the SDKs specified here.
1114 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001115
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001116 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1117 // Should be only used in tests#.
1118 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001119
Dario Frenica913392020-04-27 18:21:11 +01001120 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1121 // Should be only used in tests#.
1122 Test_only_unsigned_payload *bool
1123
Jiyong Park956305c2020-01-09 12:32:06 +09001124 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001125
1126 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001127 // rules for making sure that the APEX is truly updatable.
1128 // - To be updatable, min_sdk_version should be set as well
1129 // This will also disable the size optimizations like symlinking to the system libs.
1130 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001131 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001132
1133 // The minimum SDK version that this apex must be compatibile with.
1134 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001135
1136 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1137 // Should be only used in non-system apexes (e.g. vendor: true).
1138 // Default is false.
1139 Use_vndk_as_stable *bool
Theotime Combes4ba38c12020-06-12 12:46:59 +00001140
1141 // The type of filesystem to use for an image apex. Either 'ext4' or 'f2fs'.
1142 // Default 'ext4'.
1143 Payload_fs_type *string
Alex Light9670d332019-01-29 18:07:33 -08001144}
1145
1146type apexTargetBundleProperties struct {
1147 Target struct {
1148 // Multilib properties only for android.
1149 Android struct {
1150 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001151 }
Jooyung Han344d5432019-08-23 11:17:39 +09001152
Alex Light9670d332019-01-29 18:07:33 -08001153 // Multilib properties only for host.
1154 Host struct {
1155 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001156 }
Jooyung Han344d5432019-08-23 11:17:39 +09001157
Alex Light9670d332019-01-29 18:07:33 -08001158 // Multilib properties only for host linux_bionic.
1159 Linux_bionic struct {
1160 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001161 }
Jooyung Han344d5432019-08-23 11:17:39 +09001162
Alex Light9670d332019-01-29 18:07:33 -08001163 // Multilib properties only for host linux_glibc.
1164 Linux_glibc struct {
1165 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001166 }
1167 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001168}
1169
Jiyong Park5d790c32019-11-15 18:40:32 +09001170type overridableProperties struct {
1171 // List of APKs to package inside APEX
1172 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001173
Jiyong Park69aeba92020-04-24 21:16:36 +09001174 // List of runtime resource overlays (RROs) inside APEX
1175 Rros []string
1176
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001177 // Names of modules to be overridden. Listed modules can only be other binaries
1178 // (in Make or Soong).
1179 // This does not completely prevent installation of the overridden binaries, but if both
1180 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1181 // from PRODUCT_PACKAGES.
1182 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001183
1184 // Logging Parent value
1185 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001186
1187 // Apex Container Package Name.
1188 // Override value for attribute package:name in AndroidManifest.xml
1189 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001190
1191 // A txt file containing list of files that are allowed to be included in this APEX.
1192 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001193}
1194
Alex Light5098a612018-11-29 17:12:15 -08001195type apexPackaging int
1196
1197const (
1198 imageApex apexPackaging = iota
1199 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001200 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001201)
1202
Sundong Ahnabb64432019-10-22 13:58:29 +09001203// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001204func (a apexPackaging) suffix() string {
1205 switch a {
1206 case imageApex:
1207 return imageApexSuffix
1208 case zipApex:
1209 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001210 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001211 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001212 }
1213}
1214
1215func (a apexPackaging) name() string {
1216 switch a {
1217 case imageApex:
1218 return imageApexType
1219 case zipApex:
1220 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001221 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001222 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001223 }
1224}
1225
Jiyong Parkf653b052019-11-18 15:39:01 +09001226type apexFileClass int
1227
1228const (
1229 etc apexFileClass = iota
1230 nativeSharedLib
1231 nativeExecutable
1232 shBinary
1233 pyBinary
1234 goBinary
1235 javaSharedLib
1236 nativeTest
1237 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001238 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001239)
1240
Jiyong Park8fd61922018-11-08 02:50:25 +09001241func (class apexFileClass) NameInMake() string {
1242 switch class {
1243 case etc:
1244 return "ETC"
1245 case nativeSharedLib:
1246 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001247 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001248 return "EXECUTABLES"
1249 case javaSharedLib:
1250 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001251 case nativeTest:
1252 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001253 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001254 // b/142537672 Why isn't this APP? We want to have full control over
1255 // the paths and file names of the apk file under the flattend APEX.
1256 // If this is set to APP, then the paths and file names are modified
1257 // by the Make build system. For example, it is installed to
1258 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1259 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1260 // appends module name (which is <apexname>.<Appname> to the path.
1261 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001262 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001263 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001264 }
1265}
1266
Jiyong Parkf653b052019-11-18 15:39:01 +09001267// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001268type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001269 builtFile android.Path
1270 stem string
1271 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1272 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1273 androidMkModuleName string
1274 installDir string
1275 class apexFileClass
1276 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001277 // list of symlinks that will be created in installDir that point to this apexFile
1278 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001279 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001280 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001281 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001282
1283 requiredModuleNames []string
1284 targetRequiredModuleNames []string
1285 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001286
Colin Cross503c1d02020-01-28 14:00:53 -08001287 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001288 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001289 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001290 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001291
1292 isJniLib bool
Jiyong Park41f637d2020-09-09 13:18:02 +09001293
1294 noticeFiles android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001295}
1296
Yo Chiange8128052020-07-23 20:09:18 +08001297func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001298 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001299 builtFile: builtFile,
1300 androidMkModuleName: androidMkModuleName,
1301 installDir: installDir,
1302 class: class,
1303 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001304 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001305 if module != nil {
1306 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001307 ret.requiredModuleNames = module.RequiredModuleNames()
1308 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1309 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park41f637d2020-09-09 13:18:02 +09001310 ret.noticeFiles = module.NoticeFiles()
Jiyong Park1833cef2019-12-13 13:28:36 +09001311 }
1312 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001313}
1314
1315func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001316 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001317}
1318
Liz Kammer1c14a212020-05-12 15:26:55 -07001319func (af *apexFile) apexRelativePath(path string) string {
1320 return filepath.Join(af.installDir, path)
1321}
1322
Jiyong Park7cd10e32020-01-14 09:22:18 +09001323// Path() returns path of this apex file relative to the APEX root
1324func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001325 return af.apexRelativePath(af.Stem())
1326}
1327
1328func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001329 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001330 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001331 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001332 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001333}
1334
1335// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1336func (af *apexFile) SymlinkPaths() []string {
1337 var ret []string
1338 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001339 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001340 }
1341 return ret
1342}
1343
1344func (af *apexFile) AvailableToPlatform() bool {
1345 if af.module == nil {
1346 return false
1347 }
1348 if am, ok := af.module.(android.ApexModule); ok {
1349 return am.AvailableFor(android.AvailableToPlatform)
1350 }
1351 return false
1352}
1353
Theotime Combes4ba38c12020-06-12 12:46:59 +00001354type fsType int
1355
1356const (
1357 ext4 fsType = iota
1358 f2fs
1359)
1360
1361func (f fsType) string() string {
1362 switch f {
1363 case ext4:
1364 return ext4FsType
1365 case f2fs:
1366 return f2fsFsType
1367 default:
1368 panic(fmt.Errorf("unknown APEX payload type %d", f))
1369 }
1370}
1371
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001372type apexBundle struct {
1373 android.ModuleBase
1374 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001375 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001376 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001377
Jiyong Park5d790c32019-11-15 18:40:32 +09001378 properties apexBundleProperties
1379 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001380 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001381
Jooyung Hanf21c7972019-12-16 22:32:06 +09001382 // specific to apex_vndk modules
1383 vndkProperties apexVndkProperties
1384
Colin Crossa4925902018-11-16 11:36:28 -08001385 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001386 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001387 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001388
Jiyong Park03b68dd2019-07-26 23:20:40 +09001389 prebuiltFileToDelete string
1390
Jiyong Park42cca6c2019-04-01 11:15:50 +09001391 public_key_file android.Path
1392 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001393
1394 container_certificate_file android.Path
1395 container_private_key_file android.Path
1396
Jooyung Han580eb4f2020-06-24 19:33:06 +09001397 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001398
Jiyong Park8fd61922018-11-08 02:50:25 +09001399 // list of files to be included in this apex
1400 filesInfo []apexFile
1401
Jiyong Park956305c2020-01-09 12:32:06 +09001402 // list of module names that should be installed along with this APEX
1403 requiredDeps []string
1404
Jiyong Park956305c2020-01-09 12:32:06 +09001405 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001406 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001407
Sundong Ahnabb64432019-10-22 13:58:29 +09001408 testApex bool
1409 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001410 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001411 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001412
Jooyung Han214bf372019-11-12 13:03:50 +09001413 manifestJsonOut android.WritablePath
1414 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001415
Jooyung Han002ab682020-01-08 01:57:58 +09001416 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001417 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001418 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001419 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1420 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001421
1422 // Suffix of module name in Android.mk
1423 // ".flattened", ".apex", ".zipapex", or ""
1424 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001425
1426 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001427
1428 // Whether to create symlink to the system file instead of having a file
1429 // inside the apex or not
1430 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001431
1432 // Struct holding the merged notice file paths in different formats
1433 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001434
1435 // Optional list of lint report zip files for apexes that contain java or app modules
1436 lintReports android.Paths
Theotime Combes4ba38c12020-06-12 12:46:59 +00001437
1438 payloadFsType fsType
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001439}
1440
Jiyong Park397e55e2018-10-24 21:09:55 +09001441func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001442 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001443 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001444 // Use *FarVariation* to be able to depend on modules having
1445 // conflicting variations with this module. This is required since
1446 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1447 // for native shared libs.
Jiyong Park397e55e2018-10-24 21:09:55 +09001448
Colin Cross42507332020-08-21 16:15:23 -07001449 binVariations := target.Variations()
1450 libVariations := append(target.Variations(),
1451 blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han643adc42020-02-27 13:50:06 +09001452
Colin Cross42507332020-08-21 16:15:23 -07001453 if ctx.Device() {
1454 binVariations = append(binVariations,
1455 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1456 libVariations = append(libVariations,
1457 blueprint.Variation{Mutator: "image", Variation: imageVariation},
1458 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
Colin Cross42507332020-08-21 16:15:23 -07001459 }
Roland Levillain630846d2019-06-26 12:48:34 +01001460
Colin Cross42507332020-08-21 16:15:23 -07001461 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
1462
1463 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
1464
1465 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
1466
Colin Cross90dab342020-08-21 15:55:50 -07001467 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001468}
1469
Alex Light9670d332019-01-29 18:07:33 -08001470func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1471 if ctx.Os().Class == android.Device {
1472 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1473 } else {
1474 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1475 if ctx.Os().Bionic() {
1476 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1477 } else {
1478 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1479 }
1480 }
1481}
1482
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001483func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001484 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001485 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1486 }
1487
Jiyong Park397e55e2018-10-24 21:09:55 +09001488 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001489 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001490 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001491
1492 a.combineProperties(ctx)
1493
Jiyong Park397e55e2018-10-24 21:09:55 +09001494 has32BitTarget := false
1495 for _, target := range targets {
1496 if target.Arch.ArchType.Multilib == "lib32" {
1497 has32BitTarget = true
1498 }
1499 }
1500 for i, target := range targets {
Jiyong Parkccb406f2020-09-29 10:58:10 +09001501 if target.HostCross {
1502 // Don't include artifats for the host cross targets because there is no way
1503 // for us to run those artifacts natively on host
1504 continue
1505 }
1506
Jooyung Han643adc42020-02-27 13:50:06 +09001507 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001508 // multilib.both
1509 addDependenciesForNativeModules(ctx,
1510 ApexNativeDependencies{
1511 Native_shared_libs: a.properties.Native_shared_libs,
1512 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001513 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001514 Binaries: nil,
1515 },
Jooyung Han85d61762020-06-24 23:50:26 +09001516 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001517
Jiyong Park397e55e2018-10-24 21:09:55 +09001518 // Add native modules targetting both ABIs
1519 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001520 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001521 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001522 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001523
Alex Light3d673592019-01-18 14:37:31 -08001524 isPrimaryAbi := i == 0
1525 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001526 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001527 // multilib.first
1528 addDependenciesForNativeModules(ctx,
1529 ApexNativeDependencies{
1530 Native_shared_libs: nil,
1531 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001532 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001533 Binaries: a.properties.Binaries,
1534 },
Jooyung Han85d61762020-06-24 23:50:26 +09001535 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001536
1537 // Add native modules targetting the first ABI
1538 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001539 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001540 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001541 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001542 }
1543
1544 switch target.Arch.ArchType.Multilib {
1545 case "lib32":
1546 // Add native modules targetting 32-bit ABI
1547 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001548 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001549 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001550 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001551
1552 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001553 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001554 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001555 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001556 case "lib64":
1557 // Add native modules targetting 64-bit ABI
1558 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001559 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001560 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001561 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001562
1563 if !has32BitTarget {
1564 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001565 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001566 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001567 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001568 }
1569 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001570 }
1571
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001572 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1573 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1574 // b/144532908
1575 archForPrebuiltEtc := config.Arches()[0]
1576 for _, arch := range config.Arches() {
1577 // Prefer 64-bit arch if there is any
1578 if arch.ArchType.Multilib == "lib64" {
1579 archForPrebuiltEtc = arch
1580 break
1581 }
1582 }
1583 ctx.AddFarVariationDependencies([]blueprint.Variation{
1584 {Mutator: "os", Variation: ctx.Os().String()},
1585 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1586 }, prebuiltTag, a.properties.Prebuilts...)
1587
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001588 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1589 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001590
markchien2f59ec92020-09-02 16:23:38 +08001591 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1592 bpfTag, a.properties.Bpfs...)
1593
Ulya Trafimovich44561882020-01-03 13:25:54 +00001594 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1595 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1596 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1597 javaLibTag, "jacocoagent")
1598 }
1599
Jiyong Park23c52b02019-02-02 13:13:47 +09001600 if String(a.properties.Key) == "" {
1601 ctx.ModuleErrorf("key is missing")
1602 return
1603 }
1604 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001605
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001606 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001607 if cert != "" {
1608 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001609 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001610
1611 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1612 if len(a.properties.Uses_sdks) > 0 {
1613 sdkRefs := []android.SdkRef{}
1614 for _, str := range a.properties.Uses_sdks {
1615 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1616 sdkRefs = append(sdkRefs, parsed)
1617 }
1618 a.BuildWithSdks(sdkRefs)
1619 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001620}
1621
Jiyong Park5d790c32019-11-15 18:40:32 +09001622func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001623 if a.overridableProperties.Allowed_files != nil {
1624 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1625 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001626 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1627 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001628 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1629 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001630}
1631
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001632func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1633 // direct deps of an APEX bundle are all part of the APEX bundle
1634 return true
1635}
1636
Colin Cross0ea8ba82019-06-06 14:33:29 -07001637func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001638 moduleName := ctx.ModuleName()
1639 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1640 // we check with the pseudo module name to see if its certificate is overridden.
1641 if a.vndkApex {
1642 moduleName = vndkApexName
1643 }
1644 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001645 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001646 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001647 }
1648 return String(a.properties.Certificate)
1649}
1650
Colin Cross41955e82019-05-29 14:40:35 -07001651func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1652 switch tag {
1653 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001654 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001655 default:
1656 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001657 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001658}
1659
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001660func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001661 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001662}
1663
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001664func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1665 return proptools.Bool(a.properties.Test_only_no_hashtree)
1666}
1667
Dario Frenica913392020-04-27 18:21:11 +01001668func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1669 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1670}
1671
Jooyung Han85d61762020-06-24 23:50:26 +09001672func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1673 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001674 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001675 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001676 }
Jooyung Han85d61762020-06-24 23:50:26 +09001677
1678 var prefix string
1679 var vndkVersion string
1680 if deviceConfig.VndkVersion() != "" {
1681 if proptools.Bool(a.properties.Use_vendor) {
1682 prefix = cc.VendorVariationPrefix
1683 vndkVersion = deviceConfig.PlatformVndkVersion()
1684 } else if a.SocSpecific() || a.DeviceSpecific() {
1685 prefix = cc.VendorVariationPrefix
1686 vndkVersion = deviceConfig.VndkVersion()
1687 } else if a.ProductSpecific() {
1688 prefix = cc.ProductVariationPrefix
1689 vndkVersion = deviceConfig.ProductVndkVersion()
1690 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001691 }
Jooyung Han85d61762020-06-24 23:50:26 +09001692 if vndkVersion == "current" {
1693 vndkVersion = deviceConfig.PlatformVndkVersion()
1694 }
1695 if vndkVersion != "" {
1696 return prefix + vndkVersion
1697 }
1698 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001699}
1700
Jiyong Parkf97782b2019-02-13 20:28:58 +09001701func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1702 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1703 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1704 }
1705}
1706
Jiyong Park388ef3f2019-01-28 19:47:32 +09001707func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001708 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1709 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001710 }
1711
1712 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001713 globalSanitizerNames := []string{}
1714 if a.Host() {
1715 globalSanitizerNames = ctx.Config().SanitizeHost()
1716 } else {
1717 arches := ctx.Config().SanitizeDeviceArch()
1718 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1719 globalSanitizerNames = ctx.Config().SanitizeDevice()
1720 }
1721 }
1722 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001723}
1724
Jooyung Han8ce8db92020-05-15 19:05:05 +09001725func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1726 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1727 for _, target := range ctx.MultiTargets() {
1728 if target.Arch.ArchType.Multilib == "lib64" {
1729 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001730 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001731 {Mutator: "link", Variation: "shared"},
1732 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1733 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1734 break
1735 }
1736 }
1737 }
1738}
1739
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001740var _ cc.Coverage = (*apexBundle)(nil)
1741
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001742func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001743 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001744}
1745
1746func (a *apexBundle) PreventInstall() {
1747 a.properties.PreventInstall = true
1748}
1749
1750func (a *apexBundle) HideFromMake() {
1751 a.properties.HideFromMake = true
1752}
1753
Jiyong Park956305c2020-01-09 12:32:06 +09001754func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1755 a.properties.IsCoverageVariant = coverage
1756}
1757
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001758func (a *apexBundle) EnableCoverageIfNeeded() {}
1759
Jiyong Parkf653b052019-11-18 15:39:01 +09001760// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001761func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001762 // Decide the APEX-local directory by the multilib of the library
1763 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001764 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001765 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001766 case "lib32":
1767 dirInApex = "lib"
1768 case "lib64":
1769 dirInApex = "lib64"
1770 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001771 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001772 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001773 }
Jooyung Han35155c42020-02-06 17:33:20 +09001774 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001775 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001776 // Special case for Bionic libs and other libs installed with them. This is
1777 // to prevent those libs from being included in the search path
1778 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1779 // those libs in the Runtime APEX are available via the legacy paths in
1780 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1781 // to the legacy paths and thus will be loaded into the default linker
1782 // namespace (aka "platform" namespace). If the libs are directly in
1783 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1784 // into the runtime linker namespace, which will result in double loading of
1785 // them, which isn't supported.
1786 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001787 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001788
Jiyong Parkf653b052019-11-18 15:39:01 +09001789 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001790 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1791 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001792}
1793
Jiyong Park1833cef2019-12-13 13:28:36 +09001794func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001795 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001796 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001797 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001798 }
Jooyung Han35155c42020-02-06 17:33:20 +09001799 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001800 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001801 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1802 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001803 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001804 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001805 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001806}
1807
Jiyong Park1833cef2019-12-13 13:28:36 +09001808func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001809 dirInApex := "bin"
1810 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001811 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001812}
Jiyong Park1833cef2019-12-13 13:28:36 +09001813func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001814 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001815 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1816 if err != nil {
1817 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001818 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001819 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001820 fileToCopy := android.PathForOutput(ctx, s)
1821 // NB: Since go binaries are static we don't need the module for anything here, which is
1822 // good since the go tool is a blueprint.Module not an android.Module like we would
1823 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001824 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001825}
1826
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001827func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001828 dirInApex := filepath.Join("bin", sh.SubDir())
1829 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001830 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001831 af.symlinks = sh.Symlinks()
1832 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001833}
1834
Yo Chiange8128052020-07-23 20:09:18 +08001835type javaModule interface {
1836 android.Module
1837 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001838 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001839 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001840 LintDepSets() java.LintDepSets
1841
Jiyong Parka62aa232020-05-28 23:46:55 +09001842 Stem() string
1843}
1844
Yo Chiange8128052020-07-23 20:09:18 +08001845var _ javaModule = (*java.Library)(nil)
1846var _ javaModule = (*java.SdkLibrary)(nil)
1847var _ javaModule = (*java.DexImport)(nil)
1848var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001849
Yo Chiange8128052020-07-23 20:09:18 +08001850func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001851 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001852 fileToCopy := module.DexJarBuildPath()
1853 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1854 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1855 af.lintDepSets = module.LintDepSets()
1856 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001857 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001858}
1859
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001860func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001861 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001862 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001863 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001864}
1865
atrost6e126252020-01-27 17:01:16 +00001866func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1867 dirInApex := filepath.Join("etc", config.SubDir())
1868 fileToCopy := config.CompatConfig()
1869 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1870}
1871
Jiyong Park1833cef2019-12-13 13:28:36 +09001872func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001873 android.Module
1874 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001875 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001876 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001877 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001878 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001879 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001880}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001881 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001882 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001883 appDir = "priv-app"
1884 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001885 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001886 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001887 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001888 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001889 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001890
1891 if app, ok := aapp.(interface {
1892 OverriddenManifestPackageName() string
1893 }); ok {
1894 af.overriddenPackageName = app.OverriddenManifestPackageName()
1895 }
Jiyong Park618922e2020-01-08 13:35:43 +09001896 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001897}
1898
Jiyong Park69aeba92020-04-24 21:16:36 +09001899func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1900 rroDir := "overlay"
1901 dirInApex := filepath.Join(rroDir, rro.Theme())
1902 fileToCopy := rro.OutputFile()
1903 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1904 af.certificate = rro.Certificate()
1905
1906 if a, ok := rro.(interface {
1907 OverriddenManifestPackageName() string
1908 }); ok {
1909 af.overriddenPackageName = a.OverriddenManifestPackageName()
1910 }
1911 return af
1912}
1913
markchien2f59ec92020-09-02 16:23:38 +08001914func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1915 dirInApex := filepath.Join("etc", "bpf")
1916 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1917}
1918
Roland Levillain935639d2019-08-13 14:55:28 +01001919// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1920type flattenedApexContext struct {
1921 android.ModuleContext
1922}
1923
1924func (c *flattenedApexContext) InstallBypassMake() bool {
1925 return true
1926}
1927
Jiyong Park201cedd2020-02-07 17:25:49 +09001928// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001929func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001930 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001931 am, ok := child.(android.ApexModule)
1932 if !ok || !am.CanHaveApexVariants() {
1933 return false
1934 }
1935
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001936 dt := ctx.OtherModuleDependencyTag(child)
1937
1938 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1939 return false
1940 }
1941
Jiyong Park0f80c182020-01-31 02:49:53 +09001942 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001943 if adt, ok := dt.(dependencyTag); ok {
1944 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001945 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001946 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001947 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001948 return false
1949 }
1950
1951 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Crossaede88c2020-08-11 12:17:01 -07001952 if android.InList(ctx.ModuleName(), am.InApexes()) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001953 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001954 }
1955
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001956 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001957 })
1958}
1959
Dan Albertc8060532020-07-22 22:32:17 -07001960func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
Jooyung Han749dc692020-04-15 11:03:39 +09001961 ver := proptools.String(a.properties.Min_sdk_version)
1962 if ver == "" {
Dan Albert0b176c82020-07-23 16:43:25 -07001963 return android.FutureApiLevel
Jooyung Han749dc692020-04-15 11:03:39 +09001964 }
Dan Albertc8060532020-07-22 22:32:17 -07001965 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
Jooyung Hanaed150d2020-04-02 01:41:41 +09001966 if err != nil {
1967 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Dan Albertc8060532020-07-22 22:32:17 -07001968 return android.NoneApiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09001969 }
Dan Albertc8060532020-07-22 22:32:17 -07001970 if apiLevel.IsPreview() {
1971 // All codenames should build against "current".
Dan Albert0b176c82020-07-23 16:43:25 -07001972 return android.FutureApiLevel
Dan Albertc8060532020-07-22 22:32:17 -07001973 }
1974 return apiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09001975}
1976
Artur Satayev849f8442020-04-28 14:57:42 +01001977func (a *apexBundle) Updatable() bool {
1978 return proptools.Bool(a.properties.Updatable)
1979}
1980
1981var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1982
Jiyong Park201cedd2020-02-07 17:25:49 +09001983// Ensures that the dependencies are marked as available for this APEX
1984func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1985 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1986 if ctx.Host() || a.testApex || a.vndkApex {
1987 return
1988 }
1989
Jooyung Han85d61762020-06-24 23:50:26 +09001990 // Because APEXes targeting other than system/system_ext partitions
1991 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09001992 if a.SocSpecific() || a.DeviceSpecific() ||
1993 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09001994 return
1995 }
1996
Jiyong Park58d10902020-03-28 14:43:19 +09001997 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1998 // Requiring them and their transitive depencies with apex_available is not right
1999 // because they just add noise.
2000 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2001 return
2002 }
2003
Jooyung Han749dc692020-04-15 11:03:39 +09002004 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002005 if externalDep {
2006 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2007 return false
2008 }
2009
Jiyong Park201cedd2020-02-07 17:25:49 +09002010 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002011 fromName := ctx.OtherModuleName(from)
2012 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01002013
2014 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2015 // do any of its dependencies.
2016 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2017 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2018 return false
2019 }
2020
Colin Cross440e0d02020-06-11 11:32:11 -07002021 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002022 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002023 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09002024 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 +01002025 // Visit this module's dependencies to check and report any issues with their availability.
2026 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002027 })
2028}
2029
Jooyung Han548640b2020-04-27 12:10:30 +09002030func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01002031 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09002032 if String(a.properties.Min_sdk_version) == "" {
2033 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2034 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01002035
2036 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002037 }
2038}
2039
Jooyung Han749dc692020-04-15 11:03:39 +09002040func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2041 if a.testApex || a.vndkApex {
2042 return
2043 }
2044 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
2045 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
2046 return
2047 }
Dan Albertc8060532020-07-22 22:32:17 -07002048 // apexBundle::minSdkVersion reports its own errors.
2049 minSdkVersion := a.minSdkVersion(ctx)
2050 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002051}
2052
Jiyong Park7d95a512020-05-10 15:16:24 +09002053// Ensures that a lib providing stub isn't statically linked
2054func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2055 // Practically, we only care about regular APEXes on the device.
2056 if ctx.Host() || a.testApex || a.vndkApex {
2057 return
2058 }
2059
Jooyung Han749dc692020-04-15 11:03:39 +09002060 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09002061 if ccm, ok := to.(*cc.Module); ok {
2062 apexName := ctx.ModuleName()
2063 fromName := ctx.OtherModuleName(from)
2064 toName := ctx.OtherModuleName(to)
2065
2066 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2067 // do any of its dependencies.
2068 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2069 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2070 return false
2071 }
2072
Jiyong Park7d95a512020-05-10 15:16:24 +09002073 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
2074 // It can't make the static dependencies dynamic because it can't
2075 // do the dynamic linking for itself.
2076 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2077 return false
2078 }
2079
2080 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !android.DirectlyInApex(apexName, toName)
2081 if isStubLibraryFromOtherApex && !externalDep {
2082 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2083 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2084 }
2085
2086 }
2087 return true
2088 })
2089}
2090
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002091func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01002092 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09002093 switch a.properties.ApexType {
2094 case imageApex:
2095 if buildFlattenedAsDefault {
2096 a.suffix = imageApexSuffix
2097 } else {
2098 a.suffix = ""
2099 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002100
2101 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002102 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002103 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002104 }
2105 case zipApex:
2106 if proptools.String(a.properties.Payload_type) == "zip" {
2107 a.suffix = ""
2108 a.primaryApexType = true
2109 } else {
2110 a.suffix = zipApexSuffix
2111 }
2112 case flattenedApex:
2113 if buildFlattenedAsDefault {
2114 a.suffix = ""
2115 a.primaryApexType = true
2116 } else {
2117 a.suffix = flattenedSuffix
2118 }
Alex Light5098a612018-11-29 17:12:15 -08002119 }
2120
Roland Levillain630846d2019-06-26 12:48:34 +01002121 if len(a.properties.Tests) > 0 && !a.testApex {
2122 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2123 return
2124 }
2125
Jiyong Park0f80c182020-01-31 02:49:53 +09002126 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002127 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002128 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002129 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002130
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002131 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2132
Jooyung Hane1633032019-08-01 17:41:43 +09002133 // native lib dependencies
2134 var provideNativeLibs []string
2135 var requireNativeLibs []string
2136
Jooyung Han5c998b92019-06-27 11:30:33 +09002137 // Check if "uses" requirements are met with dependent apexBundles
2138 var providedNativeSharedLibs []string
2139 useVendor := proptools.Bool(a.properties.Use_vendor)
2140 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2141 if ctx.OtherModuleDependencyTag(m) != usesTag {
2142 return
2143 }
2144 otherName := ctx.OtherModuleName(m)
2145 other, ok := m.(*apexBundle)
2146 if !ok {
2147 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2148 return
2149 }
2150 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2151 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2152 return
2153 }
2154 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2155 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2156 return
2157 }
2158 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2159 })
2160
Jiyong Parkf653b052019-11-18 15:39:01 +09002161 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002162 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002163 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002164 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002165 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2166 return false
2167 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002168 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002169 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002170 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002171 case sharedLibTag, jniLibTag:
2172 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002173 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002174 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2175 fi.isJniLib = isJniLib
2176 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002177 // Collect the list of stub-providing libs except:
2178 // - VNDK libs are only for vendors
2179 // - bootstrap bionic libs are treated as provided by system
2180 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002181 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2182 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002183 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002184 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002185 propertyName := "native_shared_libs"
2186 if isJniLib {
2187 propertyName = "jni_libs"
2188 }
2189 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002190 }
2191 case executableTag:
2192 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002193 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002194 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002195 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002196 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002197 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002198 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002199 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002200 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002201 } else {
Alex Light778127a2019-02-27 14:19:50 -08002202 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 +09002203 }
2204 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002205 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002206 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002207 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002208 if !af.Ok() {
2209 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2210 return false
2211 }
2212 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002213 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002214 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002215 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002216 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002217 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002218 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002219 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002220 return true // track transitive dependencies
2221 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002222 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002223 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002224 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002225 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2226 appDir := "app"
2227 if ap.Privileged() {
2228 appDir = "priv-app"
2229 }
Yo Chiange8128052020-07-23 20:09:18 +08002230 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002231 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2232 af.certificate = java.PresignedCertificate
2233 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002234 } else {
2235 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2236 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002237 case rroTag:
2238 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2239 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2240 } else {
2241 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2242 }
markchien2f59ec92020-09-02 16:23:38 +08002243 case bpfTag:
2244 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2245 filesToCopy, _ := bpfProgram.OutputFiles("")
2246 for _, bpfFile := range filesToCopy {
2247 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2248 }
2249 } else {
2250 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2251 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002252 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002253 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002254 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002255 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2256 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002257 } else {
atrost6e126252020-01-27 17:01:16 +00002258 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002259 }
Roland Levillain630846d2019-06-26 12:48:34 +01002260 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002261 if ccTest, ok := child.(*cc.Module); ok {
2262 if ccTest.IsTestPerSrcAllTestsVariation() {
2263 // Multiple-output test module (where `test_per_src: true`).
2264 //
2265 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2266 // We do not add this variation to `filesInfo`, as it has no output;
2267 // however, we do add the other variations of this module as indirect
2268 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002269 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002270 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002271 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002272 af.class = nativeTest
2273 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002274 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002275 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002276 } else {
2277 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2278 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002279 case keyTag:
2280 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002281 a.private_key_file = key.private_key_file
2282 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002283 } else {
2284 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002285 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002286 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002287 case certificateTag:
2288 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002289 a.container_certificate_file = dep.Certificate.Pem
2290 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002291 } else {
2292 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2293 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002294 case android.PrebuiltDepTag:
2295 // If the prebuilt is force disabled, remember to delete the prebuilt file
2296 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002297 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002298 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2299 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002300 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002301 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002302 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002303 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002304 // We cannot use a switch statement on `depTag` here as the checked
2305 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002306 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002307 if cc, ok := child.(*cc.Module); ok {
2308 if android.InList(cc.Name(), providedNativeSharedLibs) {
2309 // If we're using a shared library which is provided from other APEX,
2310 // don't include it in this APEX
2311 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002312 }
Jooyung Handf78e212020-07-22 15:54:47 +09002313 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002314 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002315 return false
2316 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002317 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2318 af.transitiveDep = true
Jooyung Hanefb184e2020-06-25 17:14:25 +09002319 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002320 // If the dependency is a stubs lib, don't include it in this APEX,
2321 // but make sure that the lib is installed on the device.
2322 // In case no APEX is having the lib, the lib is installed to the system
2323 // partition.
2324 //
2325 // Always include if we are a host-apex however since those won't have any
2326 // system libraries.
Jooyung Hanefb184e2020-06-25 17:14:25 +09002327 if !android.DirectlyInAnyApex(ctx, depName) {
2328 // we need a module name for Make
2329 name := cc.BaseModuleName() + cc.Properties.SubName
2330 if proptools.Bool(a.properties.Use_vendor) {
2331 // we don't use subName(.vendor) for a "use_vendor: true" apex
2332 // which is supposed to be installed in /system
2333 name = cc.BaseModuleName()
2334 }
2335 if !android.InList(name, a.requiredDeps) {
2336 a.requiredDeps = append(a.requiredDeps, name)
2337 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002338 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002339 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002340 // Don't track further
2341 return false
2342 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002343 filesInfo = append(filesInfo, af)
2344 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002345 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002346 } else if cc.IsTestPerSrcDepTag(depTag) {
2347 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002348 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002349 // Handle modules created as `test_per_src` variations of a single test module:
2350 // use the name of the generated test binary (`fileToCopy`) instead of the name
2351 // of the original test module (`depName`, shared by all `test_per_src`
2352 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002353 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002354 // these are not considered transitive dep
2355 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002356 filesInfo = append(filesInfo, af)
2357 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002358 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002359 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002360 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2361 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002362 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002363 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002364 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2365 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002366 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002367 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002368 }
2369 }
2370 }
2371 return false
2372 })
2373
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002374 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2375 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2376 // via the global boot image config.
2377 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002378 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002379 dirInApex := filepath.Join("javalib", arch.String())
2380 for _, f := range files {
2381 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002382 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002383 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002384 }
2385 }
2386 }
2387
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002388 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002389 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2390 return
2391 }
2392
Jiyong Park8fd61922018-11-08 02:50:25 +09002393 // remove duplicates in filesInfo
2394 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002395 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002396 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002397 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002398 if e, ok := encountered[dest]; !ok {
2399 encountered[dest] = f
2400 } else {
2401 // If a module is directly included and also transitively depended on
2402 // consider it as directly included.
2403 e.transitiveDep = e.transitiveDep && f.transitiveDep
2404 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002405 }
2406 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002407 var result []apexFile
2408 for _, v := range encountered {
2409 result = append(result, v)
2410 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002411 return result
2412 }
2413 filesInfo = removeDup(filesInfo)
2414
2415 // to have consistent build rules
2416 sort.Slice(filesInfo, func(i, j int) bool {
2417 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2418 })
2419
Jiyong Park8fd61922018-11-08 02:50:25 +09002420 a.installDir = android.PathForModuleInstall(ctx, "apex")
2421 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002422
Theotime Combes4ba38c12020-06-12 12:46:59 +00002423 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2424 case ext4FsType:
2425 a.payloadFsType = ext4
2426 case f2fsFsType:
2427 a.payloadFsType = f2fs
2428 default:
2429 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
2430 }
2431
Jiyong Park7cd10e32020-01-14 09:22:18 +09002432 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2433 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2434 // the same library in the system partition, thus effectively sharing the same libraries
2435 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2436 // in the APEX.
2437 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2438 a.installable() &&
2439 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002440
Jooyung Han85d61762020-06-24 23:50:26 +09002441 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2442 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002443 if a.SocSpecific() || a.DeviceSpecific() ||
2444 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002445 a.linkToSystemLib = false
2446 }
2447
Jiyong Park9d677202020-02-19 16:29:35 +09002448 // We don't need the optimization for updatable APEXes, as it might give false signal
2449 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002450 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002451 a.linkToSystemLib = false
2452 }
2453
Jiyong Park638d30e2020-02-26 18:27:19 +09002454 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2455 if ctx.Host() {
2456 a.linkToSystemLib = false
2457 }
2458
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002459 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002460 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2461
Jooyung Han580eb4f2020-06-24 19:33:06 +09002462 a.buildFileContexts(ctx)
2463
Jooyung Han01a3ee22019-11-02 02:52:25 +09002464 a.setCertificateAndPrivateKey(ctx)
2465 if a.properties.ApexType == flattenedApex {
2466 a.buildFlattenedApex(ctx)
2467 } else {
2468 a.buildUnflattenedApex(ctx)
2469 }
2470
Jooyung Han002ab682020-01-08 01:57:58 +09002471 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002472
2473 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002474
2475 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002476}
2477
Artur Satayev8cf899a2020-04-15 17:29:42 +01002478// Enforce that Java deps of the apex are using stable SDKs to compile
2479func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2480 // Visit direct deps only. As long as we guarantee top-level deps are using
2481 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2482 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2483 tag := ctx.OtherModuleDependencyTag(module)
2484 switch tag {
2485 case javaLibTag, androidAppTag:
2486 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2487 if err := m.CheckStableSdkVersion(); err != nil {
2488 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2489 }
2490 }
2491 }
2492 })
2493}
2494
Colin Cross440e0d02020-06-11 11:32:11 -07002495func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002496 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002497 moduleName = normalizeModuleName(moduleName)
2498
Colin Cross440e0d02020-06-11 11:32:11 -07002499 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002500 return true
2501 }
2502
2503 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002504 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002505 return true
2506 }
2507
2508 return false
2509}
2510
2511func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002512 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2513 // system. Trim the prefix for the check since they are confusing
2514 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2515 if strings.HasPrefix(moduleName, "libclang_rt.") {
2516 // This module has many arch variants that depend on the product being built.
2517 // We don't want to list them all
2518 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002519 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002520 if strings.HasPrefix(moduleName, "androidx.") {
2521 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2522 moduleName = "androidx"
2523 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002524 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002525}
2526
Jooyung Han344d5432019-08-23 11:17:39 +09002527func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002528 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002529 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002530 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002531 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002532 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002533 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002534 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002535 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002536 return module
2537}
Jiyong Park30ca9372019-02-07 16:27:23 +09002538
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002539func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002540 bundle := newApexBundle()
2541 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002542 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002543 return bundle
2544}
2545
Jiyong Parkfce0b422020-02-11 03:56:06 +09002546// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2547// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002548func testApexBundleFactory() android.Module {
2549 bundle := newApexBundle()
2550 bundle.testApex = true
2551 return bundle
2552}
2553
Jiyong Parkfce0b422020-02-11 03:56:06 +09002554// apex packages other modules into an APEX file which is a packaging format for system-level
2555// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002556func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002557 return newApexBundle()
2558}
2559
Jiyong Park30ca9372019-02-07 16:27:23 +09002560//
2561// Defaults
2562//
2563type Defaults struct {
2564 android.ModuleBase
2565 android.DefaultsModuleBase
2566}
2567
Jiyong Park30ca9372019-02-07 16:27:23 +09002568func defaultsFactory() android.Module {
2569 return DefaultsFactory()
2570}
2571
2572func DefaultsFactory(props ...interface{}) android.Module {
2573 module := &Defaults{}
2574
2575 module.AddProperties(props...)
2576 module.AddProperties(
2577 &apexBundleProperties{},
2578 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002579 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002580 )
2581
2582 android.InitDefaultsModule(module)
2583 return module
2584}
Jiyong Park5d790c32019-11-15 18:40:32 +09002585
2586//
2587// OverrideApex
2588//
2589type OverrideApex struct {
2590 android.ModuleBase
2591 android.OverrideModuleBase
2592}
2593
2594func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2595 // All the overrides happen in the base module.
2596}
2597
2598// override_apex is used to create an apex module based on another apex module
2599// by overriding some of its properties.
2600func overrideApexFactory() android.Module {
2601 m := &OverrideApex{}
2602 m.AddProperties(&overridableProperties{})
2603
2604 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2605 android.InitOverrideModule(m)
2606 return m
2607}