blob: a9a58a66dc48af618e6e33311050b0730a79561f [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"
22
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080024 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025 "github.com/google/blueprint/proptools"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070026
27 "android/soong/android"
markchien2f59ec92020-09-02 16:23:38 +080028 "android/soong/bpf"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070029 "android/soong/cc"
30 prebuilt_etc "android/soong/etc"
31 "android/soong/java"
32 "android/soong/python"
33 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090034)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Theotime Combes4ba38c12020-06-12 12:46:59 +000044
45 ext4FsType = "ext4"
46 f2fsFsType = "f2fs"
Jooyung Han72bd2f82019-10-23 16:46:38 +090047)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090048
49type dependencyTag struct {
50 blueprint.BaseDependencyTag
51 name string
Jiyong Park0f80c182020-01-31 02:49:53 +090052
53 // determines if the dependent will be part of the APEX payload
54 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090055}
56
57var (
Jiyong Park0f80c182020-01-31 02:49:53 +090058 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
Jooyung Han643adc42020-02-27 13:50:06 +090059 jniLibTag = dependencyTag{name: "jniLib", payload: true}
Jiyong Park0f80c182020-01-31 02:49:53 +090060 executableTag = dependencyTag{name: "executable", payload: true}
61 javaLibTag = dependencyTag{name: "javaLib", payload: true}
62 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
63 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090064 keyTag = dependencyTag{name: "key"}
65 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090066 usesTag = dependencyTag{name: "uses"}
Jiyong Park0f80c182020-01-31 02:49:53 +090067 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Jiyong Park69aeba92020-04-24 21:16:36 +090068 rroTag = dependencyTag{name: "rro", payload: true}
markchien2f59ec92020-09-02 16:23:38 +080069 bpfTag = dependencyTag{name: "bpf", payload: true}
Colin Cross56a83212020-09-15 18:30:11 -070070 testForTag = dependencyTag{name: "test for"}
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
Andrei Onea115e7e72020-06-05 21:14:03 +0100746 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
747 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
748}
749
750func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
751 rules := make([]android.Rule, 0, len(modules_packages))
752 for module_name, module_packages := range modules_packages {
753 permitted_packages_rule := android.NeverAllow().
754 BootclasspathJar().
755 With("apex_available", module_name).
756 WithMatcher("permitted_packages", android.NotInList(module_packages)).
757 Because("jars that are part of the " + module_name +
758 " module may only allow these packages: " + strings.Join(module_packages, ",") +
759 ". Please jarjar or move code around.")
760 rules = append(rules, permitted_packages_rule)
761 }
762 return rules
Jiyong Parkd1063c12019-07-17 20:08:41 +0900763}
764
Jooyung Han31c470b2019-10-18 16:26:59 +0900765func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
766 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
767 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
768}
769
Jiyong Parkd1063c12019-07-17 20:08:41 +0900770func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900771 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700772 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Colin Cross56a83212020-09-15 18:30:11 -0700773 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
774 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900775 ctx.BottomUp("apex", apexMutator).Parallel()
Colin Cross56a83212020-09-15 18:30:11 -0700776 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900777 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
778 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900779 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900780}
781
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900782// Mark the direct and transitive dependencies of apex bundles so that they
783// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900784func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900785 if !mctx.Module().Enabled() {
786 return
787 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900788 a, ok := mctx.Module().(*apexBundle)
789 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900790 return
791 }
Jooyung Handf78e212020-07-22 15:54:47 +0900792
793 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
794 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
795 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
796 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
797 return
798 }
799
Colin Cross56a83212020-09-15 18:30:11 -0700800 contents := make(map[string]android.ApexMembership)
801
802 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900803 am, ok := child.(android.ApexModule)
804 if !ok || !am.CanHaveApexVariants() {
805 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900806 }
Paul Duffina37eca22020-07-22 13:00:54 +0100807 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900808 return false
809 }
Jooyung Handf78e212020-07-22 15:54:47 +0900810 if excludeVndkLibs {
811 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
812 return false
813 }
814 }
Colin Cross56a83212020-09-15 18:30:11 -0700815 return true
816 }
817
818 mctx.WalkDeps(func(child, parent android.Module) bool {
819 if !continueApexDepsWalk(child, parent) {
820 return false
821 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900822
823 depName := mctx.OtherModuleName(child)
824 // If the parent is apexBundle, this child is directly depended.
825 _, directDep := parent.(*apexBundle)
Colin Cross56a83212020-09-15 18:30:11 -0700826 contents[depName] = contents[depName].Add(directDep)
827 return true
828 })
829
830 apexContents := android.NewApexContents(mctx.ModuleName(), contents)
831 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
832 Contents: apexContents,
833 })
834
835 apexInfo := android.ApexInfo{
836 ApexVariationName: mctx.ModuleName(),
837 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
838 RequiredSdks: a.RequiredSdks(),
839 Updatable: a.Updatable(),
840 InApexes: []string{mctx.ModuleName()},
841 ApexContents: []*android.ApexContents{apexContents},
842 }
843
844 mctx.WalkDeps(func(child, parent android.Module) bool {
845 if !continueApexDepsWalk(child, parent) {
846 return false
847 }
848
849 child.(android.ApexModule).BuildForApex(apexInfo)
Jooyung Han698dd9f2020-07-22 15:17:19 +0900850 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900851 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900852}
853
Colin Crossaede88c2020-08-11 12:17:01 -0700854func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
855 if !mctx.Module().Enabled() {
856 return
857 }
858 if am, ok := mctx.Module().(android.ApexModule); ok {
859 // Check if any dependencies use unique apex variations. If so, use unique apex variations
860 // for this module.
Colin Cross56a83212020-09-15 18:30:11 -0700861 android.UpdateUniqueApexVariationsForDeps(mctx, am)
862 }
863}
864
865func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
866 if !mctx.Module().Enabled() {
867 return
868 }
869 // Check if this module is a test for an apex. If so, add a dependency on the apex
870 // in order to retrieve its contents later.
871 if am, ok := mctx.Module().(android.ApexModule); ok {
872 if testFor := am.TestFor(); len(testFor) > 0 {
873 mctx.AddFarVariationDependencies([]blueprint.Variation{
874 {Mutator: "os", Variation: am.Target().OsVariation()},
875 {"arch", "common"},
876 }, testForTag, testFor...)
877 }
878 }
879}
880
881func apexTestForMutator(mctx android.BottomUpMutatorContext) {
882 if !mctx.Module().Enabled() {
883 return
884 }
885
886 if _, ok := mctx.Module().(android.ApexModule); ok {
887 var contents []*android.ApexContents
888 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
889 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
890 contents = append(contents, abInfo.Contents)
891 }
892 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
893 ApexContents: contents,
894 })
Colin Crossaede88c2020-08-11 12:17:01 -0700895 }
896}
897
Jiyong Park89e850a2020-04-07 16:37:39 +0900898// mark if a module cannot be available to platform. A module cannot be available
899// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
900// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
901func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
902 // Host and recovery are not considered as platform
903 if mctx.Host() || mctx.Module().InstallInRecovery() {
904 return
905 }
906
907 if am, ok := mctx.Module().(android.ApexModule); ok {
908 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
909
Jiyong Park89e850a2020-04-07 16:37:39 +0900910 // If any of the dep is not available to platform, this module is also considered
911 // as being not available to platform even if it has "//apex_available:platform"
912 mctx.VisitDirectDeps(func(child android.Module) {
913 if !am.DepIsInSameApex(mctx, child) {
914 // if the dependency crosses apex boundary, don't consider it
915 return
916 }
917 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
918 availableToPlatform = false
919 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
920 }
921 })
922
923 // Exception 1: stub libraries and native bridge libraries are always available to platform
924 if cc, ok := mctx.Module().(*cc.Module); ok &&
925 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
926 availableToPlatform = true
927 }
928
929 // Exception 2: bootstrap bionic libraries are also always available to platform
930 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
931 availableToPlatform = true
932 }
933
934 if !availableToPlatform {
935 am.SetNotAvailableForPlatform()
936 }
937 }
938}
939
Paul Duffin65347702020-03-31 15:23:40 +0100940// If a module in an APEX depends on a module from an SDK then it needs an APEX
941// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
942func inAnySdk(module android.Module) bool {
943 if sa, ok := module.(android.SdkAware); ok {
944 return sa.IsInAnySdk()
945 }
946
947 return false
948}
949
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900950// Create apex variations if a module is included in APEX(s).
951func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900952 if !mctx.Module().Enabled() {
953 return
954 }
Colin Cross56a83212020-09-15 18:30:11 -0700955
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900956 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700957 android.CreateApexVariations(mctx, am)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000958 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900959 // apex bundle itself is mutated so that it and its modules have same
960 // apex variant.
961 apexBundleName := mctx.ModuleName()
962 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900963 } else if o, ok := mctx.Module().(*OverrideApex); ok {
964 apexBundleName := o.GetOverriddenModuleName()
965 if apexBundleName == "" {
966 mctx.ModuleErrorf("base property is not set")
967 return
968 }
969 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900970 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900971
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900972}
Sundong Ahne9b55722019-09-06 17:37:42 +0900973
Colin Cross56a83212020-09-15 18:30:11 -0700974func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
975 if !mctx.Module().Enabled() {
976 return
977 }
978 if am, ok := mctx.Module().(android.ApexModule); ok {
979 android.UpdateDirectlyInAnyApex(mctx, am)
980 }
981}
982
Sundong Ahne9b55722019-09-06 17:37:42 +0900983func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900984 if !mctx.Module().Enabled() {
985 return
986 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900987 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900988 var variants []string
989 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
990 case "image":
991 variants = append(variants, imageApexType, flattenedApexType)
992 case "zip":
993 variants = append(variants, zipApexType)
994 case "both":
995 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
996 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900997 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900998 return
999 }
1000
1001 modules := mctx.CreateLocalVariations(variants...)
1002
1003 for i, v := range variants {
1004 switch v {
1005 case imageApexType:
1006 modules[i].(*apexBundle).properties.ApexType = imageApex
1007 case zipApexType:
1008 modules[i].(*apexBundle).properties.ApexType = zipApex
1009 case flattenedApexType:
1010 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001011 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001012 modules[i].(*apexBundle).MakeAsSystemExt()
1013 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001014 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001015 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001016 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1017 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001018 }
1019}
1020
Jooyung Han5c998b92019-06-27 11:30:33 +09001021func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1022 if ab, ok := mctx.Module().(*apexBundle); ok {
1023 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1024 }
1025}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001026
Jooyung Handc782442019-11-01 03:14:38 +09001027var (
Colin Cross440e0d02020-06-11 11:32:11 -07001028 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001029)
1030
Colin Cross440e0d02020-06-11 11:32:11 -07001031// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +09001032// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1033// which may cause compatibility issues. (e.g. libbinder)
1034// Even though libbinder restricts its availability via 'apex_available' property and relies on
1035// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1036// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -07001037func useVendorAllowList(config android.Config) []string {
1038 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001039 return []string{
1040 // swcodec uses "vendor" variants for smaller size
1041 "com.android.media.swcodec",
1042 "test_com.android.media.swcodec",
1043 }
1044 }).([]string)
1045}
1046
Colin Cross440e0d02020-06-11 11:32:11 -07001047// setUseVendorAllowListForTest overrides useVendorAllowList and must be
1048// called before the first call to useVendorAllowList()
1049func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1050 config.Once(useVendorAllowListKey, func() interface{} {
1051 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001052 })
1053}
1054
Jooyung Han01a868d2020-02-27 13:40:44 +09001055type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001056 // List of native libraries
1057 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001058
Jooyung Han643adc42020-02-27 13:50:06 +09001059 // List of JNI libraries
1060 Jni_libs []string
1061
Alex Light9670d332019-01-29 18:07:33 -08001062 // List of native executables
1063 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001064
Roland Levillain630846d2019-06-26 12:48:34 +01001065 // List of native tests
1066 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001067}
Jooyung Han344d5432019-08-23 11:17:39 +09001068
Alex Light9670d332019-01-29 18:07:33 -08001069type apexMultilibProperties struct {
1070 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001071 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001072
1073 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001074 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001075
1076 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001077 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001078
1079 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001080 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001081
1082 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001083 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001084}
1085
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001086type apexBundleProperties struct {
1087 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001088 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001089 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001090
Jiyong Park40e26a22019-02-08 02:53:06 +09001091 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1092 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001093 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001094
Roland Levillain411c5842019-09-19 16:37:20 +01001095 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1096 // device (/apex/<apex_name>).
1097 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001098 Apex_name *string
1099
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001100 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001101 // For platform APEXes, this should points to a file under /system/sepolicy
1102 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1103 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001104
Jooyung Han01a868d2020-02-27 13:40:44 +09001105 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001106
1107 // List of java libraries that are embedded inside this APEX bundle
1108 Java_libs []string
1109
1110 // List of prebuilt files that are embedded inside this APEX bundle
1111 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001112
markchien2f59ec92020-09-02 16:23:38 +08001113 // List of BPF programs inside APEX
1114 Bpfs []string
1115
Jiyong Parkff1458f2018-10-12 21:49:38 +09001116 // Name of the apex_key module that provides the private key to sign APEX
1117 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001118
Alex Light5098a612018-11-29 17:12:15 -08001119 // The type of APEX to build. Controls what the APEX payload is. Either
1120 // 'image', 'zip' or 'both'. Default: 'image'.
1121 Payload_type *string
1122
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001123 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1124 // or an android_app_certificate module name in the form ":module".
1125 Certificate *string
1126
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001127 // Whether this APEX is installable to one of the partitions. Default: true.
1128 Installable *bool
1129
Jiyong Parkda6eb592018-12-19 17:12:36 +09001130 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1131 // Default is false.
1132 Use_vendor *bool
1133
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001134 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1135 Ignore_system_library_special_case *bool
1136
Alex Light9670d332019-01-29 18:07:33 -08001137 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001138
Jiyong Parkf97782b2019-02-13 20:28:58 +09001139 // List of sanitizer names that this APEX is enabled for
1140 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001141
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001142 PreventInstall bool `blueprint:"mutated"`
1143
1144 HideFromMake bool `blueprint:"mutated"`
1145
Jooyung Han5c998b92019-06-27 11:30:33 +09001146 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1147 Provide_cpp_shared_libs *bool
1148
1149 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1150 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001151
Sundong Ahnabb64432019-10-22 13:58:29 +09001152 // package format of this apex variant; could be non-flattened, flattened, or zip.
1153 // imageApex, zipApex or flattened
1154 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001155
Jiyong Parkd1063c12019-07-17 20:08:41 +09001156 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1157 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1158 // is implied. This value affects all modules included in this APEX. In other words, they are
1159 // also built with the SDKs specified here.
1160 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001161
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001162 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1163 // Should be only used in tests#.
1164 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001165
Dario Frenica913392020-04-27 18:21:11 +01001166 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1167 // Should be only used in tests#.
1168 Test_only_unsigned_payload *bool
1169
Jiyong Park956305c2020-01-09 12:32:06 +09001170 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001171
1172 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001173 // rules for making sure that the APEX is truly updatable.
1174 // - To be updatable, min_sdk_version should be set as well
1175 // This will also disable the size optimizations like symlinking to the system libs.
1176 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001177 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001178
1179 // The minimum SDK version that this apex must be compatibile with.
1180 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001181
1182 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1183 // Should be only used in non-system apexes (e.g. vendor: true).
1184 // Default is false.
1185 Use_vndk_as_stable *bool
Theotime Combes4ba38c12020-06-12 12:46:59 +00001186
1187 // The type of filesystem to use for an image apex. Either 'ext4' or 'f2fs'.
1188 // Default 'ext4'.
1189 Payload_fs_type *string
Alex Light9670d332019-01-29 18:07:33 -08001190}
1191
Colin Cross56a83212020-09-15 18:30:11 -07001192type ApexBundleInfo struct {
1193 Contents *android.ApexContents
1194}
1195
1196var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
1197
Alex Light9670d332019-01-29 18:07:33 -08001198type apexTargetBundleProperties struct {
1199 Target struct {
1200 // Multilib properties only for android.
1201 Android struct {
1202 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001203 }
Jooyung Han344d5432019-08-23 11:17:39 +09001204
Alex Light9670d332019-01-29 18:07:33 -08001205 // Multilib properties only for host.
1206 Host struct {
1207 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001208 }
Jooyung Han344d5432019-08-23 11:17:39 +09001209
Alex Light9670d332019-01-29 18:07:33 -08001210 // Multilib properties only for host linux_bionic.
1211 Linux_bionic struct {
1212 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001213 }
Jooyung Han344d5432019-08-23 11:17:39 +09001214
Alex Light9670d332019-01-29 18:07:33 -08001215 // Multilib properties only for host linux_glibc.
1216 Linux_glibc struct {
1217 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001218 }
1219 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001220}
1221
Jiyong Park5d790c32019-11-15 18:40:32 +09001222type overridableProperties struct {
1223 // List of APKs to package inside APEX
1224 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001225
Jiyong Park69aeba92020-04-24 21:16:36 +09001226 // List of runtime resource overlays (RROs) inside APEX
1227 Rros []string
1228
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001229 // Names of modules to be overridden. Listed modules can only be other binaries
1230 // (in Make or Soong).
1231 // This does not completely prevent installation of the overridden binaries, but if both
1232 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1233 // from PRODUCT_PACKAGES.
1234 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001235
1236 // Logging Parent value
1237 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001238
1239 // Apex Container Package Name.
1240 // Override value for attribute package:name in AndroidManifest.xml
1241 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001242
1243 // A txt file containing list of files that are allowed to be included in this APEX.
1244 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001245}
1246
Alex Light5098a612018-11-29 17:12:15 -08001247type apexPackaging int
1248
1249const (
1250 imageApex apexPackaging = iota
1251 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001252 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001253)
1254
Sundong Ahnabb64432019-10-22 13:58:29 +09001255// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001256func (a apexPackaging) suffix() string {
1257 switch a {
1258 case imageApex:
1259 return imageApexSuffix
1260 case zipApex:
1261 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001262 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001263 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001264 }
1265}
1266
1267func (a apexPackaging) name() string {
1268 switch a {
1269 case imageApex:
1270 return imageApexType
1271 case zipApex:
1272 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001273 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001274 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001275 }
1276}
1277
Jiyong Parkf653b052019-11-18 15:39:01 +09001278type apexFileClass int
1279
1280const (
1281 etc apexFileClass = iota
1282 nativeSharedLib
1283 nativeExecutable
1284 shBinary
1285 pyBinary
1286 goBinary
1287 javaSharedLib
1288 nativeTest
1289 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001290 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001291)
1292
Jiyong Park8fd61922018-11-08 02:50:25 +09001293func (class apexFileClass) NameInMake() string {
1294 switch class {
1295 case etc:
1296 return "ETC"
1297 case nativeSharedLib:
1298 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001299 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001300 return "EXECUTABLES"
1301 case javaSharedLib:
1302 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001303 case nativeTest:
1304 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001305 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001306 // b/142537672 Why isn't this APP? We want to have full control over
1307 // the paths and file names of the apk file under the flattend APEX.
1308 // If this is set to APP, then the paths and file names are modified
1309 // by the Make build system. For example, it is installed to
1310 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1311 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1312 // appends module name (which is <apexname>.<Appname> to the path.
1313 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001314 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001315 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001316 }
1317}
1318
Jiyong Parkf653b052019-11-18 15:39:01 +09001319// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001320type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001321 builtFile android.Path
1322 stem string
1323 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1324 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1325 androidMkModuleName string
1326 installDir string
1327 class apexFileClass
1328 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001329 // list of symlinks that will be created in installDir that point to this apexFile
1330 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001331 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001332 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001333 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001334
1335 requiredModuleNames []string
1336 targetRequiredModuleNames []string
1337 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001338
Colin Cross503c1d02020-01-28 14:00:53 -08001339 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001340 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001341 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001342 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001343
1344 isJniLib bool
Jiyong Park41f637d2020-09-09 13:18:02 +09001345
1346 noticeFiles android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001347}
1348
Yo Chiange8128052020-07-23 20:09:18 +08001349func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001350 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001351 builtFile: builtFile,
1352 androidMkModuleName: androidMkModuleName,
1353 installDir: installDir,
1354 class: class,
1355 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001356 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001357 if module != nil {
1358 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001359 ret.requiredModuleNames = module.RequiredModuleNames()
1360 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1361 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park41f637d2020-09-09 13:18:02 +09001362 ret.noticeFiles = module.NoticeFiles()
Jiyong Park1833cef2019-12-13 13:28:36 +09001363 }
1364 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001365}
1366
1367func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001368 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001369}
1370
Liz Kammer1c14a212020-05-12 15:26:55 -07001371func (af *apexFile) apexRelativePath(path string) string {
1372 return filepath.Join(af.installDir, path)
1373}
1374
Jiyong Park7cd10e32020-01-14 09:22:18 +09001375// Path() returns path of this apex file relative to the APEX root
1376func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001377 return af.apexRelativePath(af.Stem())
1378}
1379
1380func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001381 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001382 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001383 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001384 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001385}
1386
1387// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1388func (af *apexFile) SymlinkPaths() []string {
1389 var ret []string
1390 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001391 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001392 }
1393 return ret
1394}
1395
1396func (af *apexFile) AvailableToPlatform() bool {
1397 if af.module == nil {
1398 return false
1399 }
1400 if am, ok := af.module.(android.ApexModule); ok {
1401 return am.AvailableFor(android.AvailableToPlatform)
1402 }
1403 return false
1404}
1405
Theotime Combes4ba38c12020-06-12 12:46:59 +00001406type fsType int
1407
1408const (
1409 ext4 fsType = iota
1410 f2fs
1411)
1412
1413func (f fsType) string() string {
1414 switch f {
1415 case ext4:
1416 return ext4FsType
1417 case f2fs:
1418 return f2fsFsType
1419 default:
1420 panic(fmt.Errorf("unknown APEX payload type %d", f))
1421 }
1422}
1423
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001424type apexBundle struct {
1425 android.ModuleBase
1426 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001427 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001428 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001429
Jiyong Park5d790c32019-11-15 18:40:32 +09001430 properties apexBundleProperties
1431 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001432 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001433
Jooyung Hanf21c7972019-12-16 22:32:06 +09001434 // specific to apex_vndk modules
1435 vndkProperties apexVndkProperties
1436
Colin Crossa4925902018-11-16 11:36:28 -08001437 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001438 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001439 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001440
Jiyong Park03b68dd2019-07-26 23:20:40 +09001441 prebuiltFileToDelete string
1442
Jiyong Park42cca6c2019-04-01 11:15:50 +09001443 public_key_file android.Path
1444 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001445
1446 container_certificate_file android.Path
1447 container_private_key_file android.Path
1448
Jooyung Han580eb4f2020-06-24 19:33:06 +09001449 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001450
Jiyong Park8fd61922018-11-08 02:50:25 +09001451 // list of files to be included in this apex
1452 filesInfo []apexFile
1453
Jiyong Park956305c2020-01-09 12:32:06 +09001454 // list of module names that should be installed along with this APEX
1455 requiredDeps []string
1456
Jiyong Park956305c2020-01-09 12:32:06 +09001457 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001458 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001459
Sundong Ahnabb64432019-10-22 13:58:29 +09001460 testApex bool
1461 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001462 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001463 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001464
Jooyung Han214bf372019-11-12 13:03:50 +09001465 manifestJsonOut android.WritablePath
1466 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001467
Jooyung Han002ab682020-01-08 01:57:58 +09001468 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001469 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001470 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001471 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1472 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001473
1474 // Suffix of module name in Android.mk
1475 // ".flattened", ".apex", ".zipapex", or ""
1476 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001477
1478 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001479
1480 // Whether to create symlink to the system file instead of having a file
1481 // inside the apex or not
1482 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001483
1484 // Struct holding the merged notice file paths in different formats
1485 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001486
1487 // Optional list of lint report zip files for apexes that contain java or app modules
1488 lintReports android.Paths
Theotime Combes4ba38c12020-06-12 12:46:59 +00001489
1490 payloadFsType fsType
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001491}
1492
Jiyong Park397e55e2018-10-24 21:09:55 +09001493func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001494 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001495 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001496 // Use *FarVariation* to be able to depend on modules having
1497 // conflicting variations with this module. This is required since
1498 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1499 // for native shared libs.
Jiyong Park397e55e2018-10-24 21:09:55 +09001500
Colin Cross42507332020-08-21 16:15:23 -07001501 binVariations := target.Variations()
1502 libVariations := append(target.Variations(),
1503 blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han643adc42020-02-27 13:50:06 +09001504
Colin Cross42507332020-08-21 16:15:23 -07001505 if ctx.Device() {
1506 binVariations = append(binVariations,
1507 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1508 libVariations = append(libVariations,
1509 blueprint.Variation{Mutator: "image", Variation: imageVariation},
1510 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
Colin Cross42507332020-08-21 16:15:23 -07001511 }
Roland Levillain630846d2019-06-26 12:48:34 +01001512
Colin Cross42507332020-08-21 16:15:23 -07001513 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
1514
1515 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
1516
1517 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
1518
Colin Cross90dab342020-08-21 15:55:50 -07001519 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001520}
1521
Alex Light9670d332019-01-29 18:07:33 -08001522func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1523 if ctx.Os().Class == android.Device {
1524 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1525 } else {
1526 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1527 if ctx.Os().Bionic() {
1528 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1529 } else {
1530 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1531 }
1532 }
1533}
1534
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001535func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001536 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001537 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1538 }
1539
Jiyong Park397e55e2018-10-24 21:09:55 +09001540 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001541 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001542 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001543
1544 a.combineProperties(ctx)
1545
Jiyong Park397e55e2018-10-24 21:09:55 +09001546 has32BitTarget := false
1547 for _, target := range targets {
1548 if target.Arch.ArchType.Multilib == "lib32" {
1549 has32BitTarget = true
1550 }
1551 }
1552 for i, target := range targets {
Jiyong Parkccb406f2020-09-29 10:58:10 +09001553 if target.HostCross {
1554 // Don't include artifats for the host cross targets because there is no way
1555 // for us to run those artifacts natively on host
1556 continue
1557 }
1558
Jooyung Han643adc42020-02-27 13:50:06 +09001559 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001560 // multilib.both
1561 addDependenciesForNativeModules(ctx,
1562 ApexNativeDependencies{
1563 Native_shared_libs: a.properties.Native_shared_libs,
1564 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001565 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001566 Binaries: nil,
1567 },
Jooyung Han85d61762020-06-24 23:50:26 +09001568 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001569
Jiyong Park397e55e2018-10-24 21:09:55 +09001570 // Add native modules targetting both ABIs
1571 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001572 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001573 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001574 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001575
Alex Light3d673592019-01-18 14:37:31 -08001576 isPrimaryAbi := i == 0
1577 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001578 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001579 // multilib.first
1580 addDependenciesForNativeModules(ctx,
1581 ApexNativeDependencies{
1582 Native_shared_libs: nil,
1583 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001584 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001585 Binaries: a.properties.Binaries,
1586 },
Jooyung Han85d61762020-06-24 23:50:26 +09001587 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001588
1589 // Add native modules targetting the first ABI
1590 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001591 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001592 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001593 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001594 }
1595
1596 switch target.Arch.ArchType.Multilib {
1597 case "lib32":
1598 // Add native modules targetting 32-bit ABI
1599 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001600 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001601 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001602 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001603
1604 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001605 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001606 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001607 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001608 case "lib64":
1609 // Add native modules targetting 64-bit ABI
1610 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001611 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001612 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001613 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001614
1615 if !has32BitTarget {
1616 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001617 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001618 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001619 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001620 }
1621 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001622 }
1623
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001624 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1625 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1626 // b/144532908
1627 archForPrebuiltEtc := config.Arches()[0]
1628 for _, arch := range config.Arches() {
1629 // Prefer 64-bit arch if there is any
1630 if arch.ArchType.Multilib == "lib64" {
1631 archForPrebuiltEtc = arch
1632 break
1633 }
1634 }
1635 ctx.AddFarVariationDependencies([]blueprint.Variation{
1636 {Mutator: "os", Variation: ctx.Os().String()},
1637 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1638 }, prebuiltTag, a.properties.Prebuilts...)
1639
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001640 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1641 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001642
markchien2f59ec92020-09-02 16:23:38 +08001643 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1644 bpfTag, a.properties.Bpfs...)
1645
Ulya Trafimovich44561882020-01-03 13:25:54 +00001646 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1647 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1648 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1649 javaLibTag, "jacocoagent")
1650 }
1651
Jiyong Park23c52b02019-02-02 13:13:47 +09001652 if String(a.properties.Key) == "" {
1653 ctx.ModuleErrorf("key is missing")
1654 return
1655 }
1656 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001657
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001658 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001659 if cert != "" {
1660 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001661 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001662
1663 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1664 if len(a.properties.Uses_sdks) > 0 {
1665 sdkRefs := []android.SdkRef{}
1666 for _, str := range a.properties.Uses_sdks {
1667 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1668 sdkRefs = append(sdkRefs, parsed)
1669 }
1670 a.BuildWithSdks(sdkRefs)
1671 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001672}
1673
Jiyong Park5d790c32019-11-15 18:40:32 +09001674func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001675 if a.overridableProperties.Allowed_files != nil {
1676 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1677 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001678 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1679 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001680 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1681 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001682}
1683
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001684func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1685 // direct deps of an APEX bundle are all part of the APEX bundle
1686 return true
1687}
1688
Colin Cross0ea8ba82019-06-06 14:33:29 -07001689func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001690 moduleName := ctx.ModuleName()
1691 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1692 // we check with the pseudo module name to see if its certificate is overridden.
1693 if a.vndkApex {
1694 moduleName = vndkApexName
1695 }
1696 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001697 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001698 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001699 }
1700 return String(a.properties.Certificate)
1701}
1702
Colin Cross41955e82019-05-29 14:40:35 -07001703func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1704 switch tag {
1705 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001706 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001707 default:
1708 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001709 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001710}
1711
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001712func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001713 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001714}
1715
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001716func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1717 return proptools.Bool(a.properties.Test_only_no_hashtree)
1718}
1719
Dario Frenica913392020-04-27 18:21:11 +01001720func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1721 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1722}
1723
Jooyung Han85d61762020-06-24 23:50:26 +09001724func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1725 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001726 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001727 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001728 }
Jooyung Han85d61762020-06-24 23:50:26 +09001729
1730 var prefix string
1731 var vndkVersion string
1732 if deviceConfig.VndkVersion() != "" {
1733 if proptools.Bool(a.properties.Use_vendor) {
1734 prefix = cc.VendorVariationPrefix
1735 vndkVersion = deviceConfig.PlatformVndkVersion()
1736 } else if a.SocSpecific() || a.DeviceSpecific() {
1737 prefix = cc.VendorVariationPrefix
1738 vndkVersion = deviceConfig.VndkVersion()
1739 } else if a.ProductSpecific() {
1740 prefix = cc.ProductVariationPrefix
1741 vndkVersion = deviceConfig.ProductVndkVersion()
1742 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001743 }
Jooyung Han85d61762020-06-24 23:50:26 +09001744 if vndkVersion == "current" {
1745 vndkVersion = deviceConfig.PlatformVndkVersion()
1746 }
1747 if vndkVersion != "" {
1748 return prefix + vndkVersion
1749 }
1750 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001751}
1752
Jiyong Parkf97782b2019-02-13 20:28:58 +09001753func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1754 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1755 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1756 }
1757}
1758
Jiyong Park388ef3f2019-01-28 19:47:32 +09001759func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001760 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1761 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001762 }
1763
1764 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001765 globalSanitizerNames := []string{}
1766 if a.Host() {
1767 globalSanitizerNames = ctx.Config().SanitizeHost()
1768 } else {
1769 arches := ctx.Config().SanitizeDeviceArch()
1770 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1771 globalSanitizerNames = ctx.Config().SanitizeDevice()
1772 }
1773 }
1774 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001775}
1776
Jooyung Han8ce8db92020-05-15 19:05:05 +09001777func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1778 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1779 for _, target := range ctx.MultiTargets() {
1780 if target.Arch.ArchType.Multilib == "lib64" {
1781 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001782 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001783 {Mutator: "link", Variation: "shared"},
1784 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1785 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1786 break
1787 }
1788 }
1789 }
1790}
1791
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001792var _ cc.Coverage = (*apexBundle)(nil)
1793
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001794func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001795 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001796}
1797
1798func (a *apexBundle) PreventInstall() {
1799 a.properties.PreventInstall = true
1800}
1801
1802func (a *apexBundle) HideFromMake() {
1803 a.properties.HideFromMake = true
1804}
1805
Jiyong Park956305c2020-01-09 12:32:06 +09001806func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1807 a.properties.IsCoverageVariant = coverage
1808}
1809
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001810func (a *apexBundle) EnableCoverageIfNeeded() {}
1811
Jiyong Parkf653b052019-11-18 15:39:01 +09001812// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001813func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001814 // Decide the APEX-local directory by the multilib of the library
1815 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001816 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001817 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001818 case "lib32":
1819 dirInApex = "lib"
1820 case "lib64":
1821 dirInApex = "lib64"
1822 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001823 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001824 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001825 }
Jooyung Han35155c42020-02-06 17:33:20 +09001826 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001827 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001828 // Special case for Bionic libs and other libs installed with them. This is
1829 // to prevent those libs from being included in the search path
1830 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1831 // those libs in the Runtime APEX are available via the legacy paths in
1832 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1833 // to the legacy paths and thus will be loaded into the default linker
1834 // namespace (aka "platform" namespace). If the libs are directly in
1835 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1836 // into the runtime linker namespace, which will result in double loading of
1837 // them, which isn't supported.
1838 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001839 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001840
Jiyong Parkf653b052019-11-18 15:39:01 +09001841 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001842 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1843 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001844}
1845
Jiyong Park1833cef2019-12-13 13:28:36 +09001846func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001847 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001848 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001849 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001850 }
Jooyung Han35155c42020-02-06 17:33:20 +09001851 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001852 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001853 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1854 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001855 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001856 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001858}
1859
Jiyong Park1833cef2019-12-13 13:28:36 +09001860func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001861 dirInApex := "bin"
1862 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001863 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001864}
Jiyong Park1833cef2019-12-13 13:28:36 +09001865func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001866 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001867 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1868 if err != nil {
1869 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001870 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001871 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 fileToCopy := android.PathForOutput(ctx, s)
1873 // NB: Since go binaries are static we don't need the module for anything here, which is
1874 // good since the go tool is a blueprint.Module not an android.Module like we would
1875 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001876 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001877}
1878
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001879func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001880 dirInApex := filepath.Join("bin", sh.SubDir())
1881 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001882 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001883 af.symlinks = sh.Symlinks()
1884 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001885}
1886
Yo Chiange8128052020-07-23 20:09:18 +08001887type javaModule interface {
1888 android.Module
1889 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001890 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001891 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001892 LintDepSets() java.LintDepSets
1893
Jiyong Parka62aa232020-05-28 23:46:55 +09001894 Stem() string
1895}
1896
Yo Chiange8128052020-07-23 20:09:18 +08001897var _ javaModule = (*java.Library)(nil)
1898var _ javaModule = (*java.SdkLibrary)(nil)
1899var _ javaModule = (*java.DexImport)(nil)
1900var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001901
Yo Chiange8128052020-07-23 20:09:18 +08001902func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001904 fileToCopy := module.DexJarBuildPath()
1905 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1906 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1907 af.lintDepSets = module.LintDepSets()
1908 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001909 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001910}
1911
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001912func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001913 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001914 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001915 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001916}
1917
atrost6e126252020-01-27 17:01:16 +00001918func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1919 dirInApex := filepath.Join("etc", config.SubDir())
1920 fileToCopy := config.CompatConfig()
1921 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1922}
1923
Jiyong Park1833cef2019-12-13 13:28:36 +09001924func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 android.Module
1926 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001927 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001928 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001929 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001930 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001931 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001932}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001933 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001934 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001935 appDir = "priv-app"
1936 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001937 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001938 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001939 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001940 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001941 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001942
1943 if app, ok := aapp.(interface {
1944 OverriddenManifestPackageName() string
1945 }); ok {
1946 af.overriddenPackageName = app.OverriddenManifestPackageName()
1947 }
Jiyong Park618922e2020-01-08 13:35:43 +09001948 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001949}
1950
Jiyong Park69aeba92020-04-24 21:16:36 +09001951func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1952 rroDir := "overlay"
1953 dirInApex := filepath.Join(rroDir, rro.Theme())
1954 fileToCopy := rro.OutputFile()
1955 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1956 af.certificate = rro.Certificate()
1957
1958 if a, ok := rro.(interface {
1959 OverriddenManifestPackageName() string
1960 }); ok {
1961 af.overriddenPackageName = a.OverriddenManifestPackageName()
1962 }
1963 return af
1964}
1965
markchien2f59ec92020-09-02 16:23:38 +08001966func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1967 dirInApex := filepath.Join("etc", "bpf")
1968 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1969}
1970
Roland Levillain935639d2019-08-13 14:55:28 +01001971// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1972type flattenedApexContext struct {
1973 android.ModuleContext
1974}
1975
1976func (c *flattenedApexContext) InstallBypassMake() bool {
1977 return true
1978}
1979
Jiyong Park201cedd2020-02-07 17:25:49 +09001980// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001981func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001982 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001983 am, ok := child.(android.ApexModule)
1984 if !ok || !am.CanHaveApexVariants() {
1985 return false
1986 }
1987
Colin Cross56a83212020-09-15 18:30:11 -07001988 childApexInfo := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1989
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001990 dt := ctx.OtherModuleDependencyTag(child)
1991
1992 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1993 return false
1994 }
1995
Jiyong Park0f80c182020-01-31 02:49:53 +09001996 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001997 if adt, ok := dt.(dependencyTag); ok {
1998 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001999 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002000 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002001 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09002002 return false
2003 }
2004
2005 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Cross56a83212020-09-15 18:30:11 -07002006 if android.InList(ctx.ModuleName(), childApexInfo.InApexes) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002007 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002008 }
2009
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002010 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002011 })
2012}
2013
Dan Albertc8060532020-07-22 22:32:17 -07002014func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
Jooyung Han749dc692020-04-15 11:03:39 +09002015 ver := proptools.String(a.properties.Min_sdk_version)
2016 if ver == "" {
Dan Albert0b176c82020-07-23 16:43:25 -07002017 return android.FutureApiLevel
Jooyung Han749dc692020-04-15 11:03:39 +09002018 }
Dan Albertc8060532020-07-22 22:32:17 -07002019 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
Jooyung Hanaed150d2020-04-02 01:41:41 +09002020 if err != nil {
2021 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Dan Albertc8060532020-07-22 22:32:17 -07002022 return android.NoneApiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002023 }
Dan Albertc8060532020-07-22 22:32:17 -07002024 if apiLevel.IsPreview() {
2025 // All codenames should build against "current".
Dan Albert0b176c82020-07-23 16:43:25 -07002026 return android.FutureApiLevel
Dan Albertc8060532020-07-22 22:32:17 -07002027 }
2028 return apiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002029}
2030
Artur Satayev849f8442020-04-28 14:57:42 +01002031func (a *apexBundle) Updatable() bool {
2032 return proptools.Bool(a.properties.Updatable)
2033}
2034
2035var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
2036
Jiyong Park201cedd2020-02-07 17:25:49 +09002037// Ensures that the dependencies are marked as available for this APEX
2038func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2039 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2040 if ctx.Host() || a.testApex || a.vndkApex {
2041 return
2042 }
2043
Jooyung Han85d61762020-06-24 23:50:26 +09002044 // Because APEXes targeting other than system/system_ext partitions
2045 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09002046 if a.SocSpecific() || a.DeviceSpecific() ||
2047 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002048 return
2049 }
2050
Jiyong Park58d10902020-03-28 14:43:19 +09002051 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2052 // Requiring them and their transitive depencies with apex_available is not right
2053 // because they just add noise.
2054 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2055 return
2056 }
2057
Jooyung Han749dc692020-04-15 11:03:39 +09002058 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002059 if externalDep {
2060 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2061 return false
2062 }
2063
Jiyong Park201cedd2020-02-07 17:25:49 +09002064 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002065 fromName := ctx.OtherModuleName(from)
2066 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01002067
2068 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2069 // do any of its dependencies.
2070 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2071 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2072 return false
2073 }
2074
Colin Cross440e0d02020-06-11 11:32:11 -07002075 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002076 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002077 }
Jiyong Park1c7e9622020-05-07 16:12:13 +09002078 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 +01002079 // Visit this module's dependencies to check and report any issues with their availability.
2080 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002081 })
2082}
2083
Jooyung Han548640b2020-04-27 12:10:30 +09002084func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01002085 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09002086 if String(a.properties.Min_sdk_version) == "" {
2087 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2088 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01002089
2090 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002091 }
2092}
2093
Jooyung Han749dc692020-04-15 11:03:39 +09002094func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2095 if a.testApex || a.vndkApex {
2096 return
2097 }
2098 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
2099 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
2100 return
2101 }
Dan Albertc8060532020-07-22 22:32:17 -07002102 // apexBundle::minSdkVersion reports its own errors.
2103 minSdkVersion := a.minSdkVersion(ctx)
2104 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002105}
2106
Jiyong Park7d95a512020-05-10 15:16:24 +09002107// Ensures that a lib providing stub isn't statically linked
2108func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2109 // Practically, we only care about regular APEXes on the device.
2110 if ctx.Host() || a.testApex || a.vndkApex {
2111 return
2112 }
2113
Colin Cross56a83212020-09-15 18:30:11 -07002114 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2115
Jooyung Han749dc692020-04-15 11:03:39 +09002116 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09002117 if ccm, ok := to.(*cc.Module); ok {
2118 apexName := ctx.ModuleName()
2119 fromName := ctx.OtherModuleName(from)
2120 toName := ctx.OtherModuleName(to)
2121
2122 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2123 // do any of its dependencies.
2124 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2125 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2126 return false
2127 }
2128
Jiyong Park7d95a512020-05-10 15:16:24 +09002129 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
2130 // It can't make the static dependencies dynamic because it can't
2131 // do the dynamic linking for itself.
2132 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2133 return false
2134 }
2135
Colin Cross56a83212020-09-15 18:30:11 -07002136 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
Jiyong Park7d95a512020-05-10 15:16:24 +09002137 if isStubLibraryFromOtherApex && !externalDep {
2138 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2139 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2140 }
2141
2142 }
2143 return true
2144 })
2145}
2146
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002147func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01002148 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09002149 switch a.properties.ApexType {
2150 case imageApex:
2151 if buildFlattenedAsDefault {
2152 a.suffix = imageApexSuffix
2153 } else {
2154 a.suffix = ""
2155 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002156
2157 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002158 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002159 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002160 }
2161 case zipApex:
2162 if proptools.String(a.properties.Payload_type) == "zip" {
2163 a.suffix = ""
2164 a.primaryApexType = true
2165 } else {
2166 a.suffix = zipApexSuffix
2167 }
2168 case flattenedApex:
2169 if buildFlattenedAsDefault {
2170 a.suffix = ""
2171 a.primaryApexType = true
2172 } else {
2173 a.suffix = flattenedSuffix
2174 }
Alex Light5098a612018-11-29 17:12:15 -08002175 }
2176
Roland Levillain630846d2019-06-26 12:48:34 +01002177 if len(a.properties.Tests) > 0 && !a.testApex {
2178 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2179 return
2180 }
2181
Jiyong Park0f80c182020-01-31 02:49:53 +09002182 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002183 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002184 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002185 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002186
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002187 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2188
Jooyung Hane1633032019-08-01 17:41:43 +09002189 // native lib dependencies
2190 var provideNativeLibs []string
2191 var requireNativeLibs []string
2192
Jooyung Han5c998b92019-06-27 11:30:33 +09002193 // Check if "uses" requirements are met with dependent apexBundles
2194 var providedNativeSharedLibs []string
2195 useVendor := proptools.Bool(a.properties.Use_vendor)
2196 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2197 if ctx.OtherModuleDependencyTag(m) != usesTag {
2198 return
2199 }
2200 otherName := ctx.OtherModuleName(m)
2201 other, ok := m.(*apexBundle)
2202 if !ok {
2203 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2204 return
2205 }
2206 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2207 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2208 return
2209 }
2210 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2211 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2212 return
2213 }
2214 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2215 })
2216
Jiyong Parkf653b052019-11-18 15:39:01 +09002217 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002218 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002219 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002220 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002221 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2222 return false
2223 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002224 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002225 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002226 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002227 case sharedLibTag, jniLibTag:
2228 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002229 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002230 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2231 fi.isJniLib = isJniLib
2232 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002233 // Collect the list of stub-providing libs except:
2234 // - VNDK libs are only for vendors
2235 // - bootstrap bionic libs are treated as provided by system
2236 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002237 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2238 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002239 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002240 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002241 propertyName := "native_shared_libs"
2242 if isJniLib {
2243 propertyName = "jni_libs"
2244 }
2245 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002246 }
2247 case executableTag:
2248 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002249 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002250 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002251 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002252 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002253 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002254 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002255 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002256 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002257 } else {
Alex Light778127a2019-02-27 14:19:50 -08002258 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 +09002259 }
2260 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002261 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002262 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002263 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002264 if !af.Ok() {
2265 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2266 return false
2267 }
2268 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002269 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002270 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002271 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002272 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002273 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002274 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002275 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002276 return true // track transitive dependencies
2277 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002278 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002279 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002280 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002281 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2282 appDir := "app"
2283 if ap.Privileged() {
2284 appDir = "priv-app"
2285 }
Yo Chiange8128052020-07-23 20:09:18 +08002286 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002287 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2288 af.certificate = java.PresignedCertificate
2289 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002290 } else {
2291 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2292 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002293 case rroTag:
2294 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2295 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2296 } else {
2297 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2298 }
markchien2f59ec92020-09-02 16:23:38 +08002299 case bpfTag:
2300 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2301 filesToCopy, _ := bpfProgram.OutputFiles("")
2302 for _, bpfFile := range filesToCopy {
2303 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2304 }
2305 } else {
2306 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2307 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002308 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002309 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002310 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002311 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2312 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002313 } else {
atrost6e126252020-01-27 17:01:16 +00002314 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002315 }
Roland Levillain630846d2019-06-26 12:48:34 +01002316 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002317 if ccTest, ok := child.(*cc.Module); ok {
2318 if ccTest.IsTestPerSrcAllTestsVariation() {
2319 // Multiple-output test module (where `test_per_src: true`).
2320 //
2321 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2322 // We do not add this variation to `filesInfo`, as it has no output;
2323 // however, we do add the other variations of this module as indirect
2324 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002325 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002326 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002327 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002328 af.class = nativeTest
2329 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002330 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002331 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002332 } else {
2333 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2334 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002335 case keyTag:
2336 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002337 a.private_key_file = key.private_key_file
2338 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002339 } else {
2340 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002341 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002342 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002343 case certificateTag:
2344 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002345 a.container_certificate_file = dep.Certificate.Pem
2346 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002347 } else {
2348 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2349 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002350 case android.PrebuiltDepTag:
2351 // If the prebuilt is force disabled, remember to delete the prebuilt file
2352 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002353 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002354 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2355 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002356 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002357 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002358 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002359 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002360 // We cannot use a switch statement on `depTag` here as the checked
2361 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002362 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002363 if cc, ok := child.(*cc.Module); ok {
2364 if android.InList(cc.Name(), providedNativeSharedLibs) {
2365 // If we're using a shared library which is provided from other APEX,
2366 // don't include it in this APEX
2367 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002368 }
Jooyung Handf78e212020-07-22 15:54:47 +09002369 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002370 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002371 return false
2372 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002373 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2374 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07002375 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2376 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002377 // If the dependency is a stubs lib, don't include it in this APEX,
2378 // but make sure that the lib is installed on the device.
2379 // In case no APEX is having the lib, the lib is installed to the system
2380 // partition.
2381 //
2382 // Always include if we are a host-apex however since those won't have any
2383 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002384 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002385 // we need a module name for Make
2386 name := cc.BaseModuleName() + cc.Properties.SubName
2387 if proptools.Bool(a.properties.Use_vendor) {
2388 // we don't use subName(.vendor) for a "use_vendor: true" apex
2389 // which is supposed to be installed in /system
2390 name = cc.BaseModuleName()
2391 }
2392 if !android.InList(name, a.requiredDeps) {
2393 a.requiredDeps = append(a.requiredDeps, name)
2394 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002395 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002396 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002397 // Don't track further
2398 return false
2399 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002400 filesInfo = append(filesInfo, af)
2401 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002402 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002403 } else if cc.IsTestPerSrcDepTag(depTag) {
2404 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002405 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002406 // Handle modules created as `test_per_src` variations of a single test module:
2407 // use the name of the generated test binary (`fileToCopy`) instead of the name
2408 // of the original test module (`depName`, shared by all `test_per_src`
2409 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002410 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002411 // these are not considered transitive dep
2412 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002413 filesInfo = append(filesInfo, af)
2414 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002415 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002416 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002417 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2418 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002419 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002420 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002421 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2422 }
Colin Cross56a83212020-09-15 18:30:11 -07002423 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2424 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002425 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002426 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002427 }
2428 }
2429 }
2430 return false
2431 })
2432
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002433 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2434 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2435 // via the global boot image config.
2436 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002437 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002438 dirInApex := filepath.Join("javalib", arch.String())
2439 for _, f := range files {
2440 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002441 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002442 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002443 }
2444 }
2445 }
2446
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002447 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002448 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2449 return
2450 }
2451
Jiyong Park8fd61922018-11-08 02:50:25 +09002452 // remove duplicates in filesInfo
2453 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002454 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002455 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002456 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002457 if e, ok := encountered[dest]; !ok {
2458 encountered[dest] = f
2459 } else {
2460 // If a module is directly included and also transitively depended on
2461 // consider it as directly included.
2462 e.transitiveDep = e.transitiveDep && f.transitiveDep
2463 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002464 }
2465 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002466 var result []apexFile
2467 for _, v := range encountered {
2468 result = append(result, v)
2469 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002470 return result
2471 }
2472 filesInfo = removeDup(filesInfo)
2473
2474 // to have consistent build rules
2475 sort.Slice(filesInfo, func(i, j int) bool {
2476 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2477 })
2478
Jiyong Park8fd61922018-11-08 02:50:25 +09002479 a.installDir = android.PathForModuleInstall(ctx, "apex")
2480 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002481
Theotime Combes4ba38c12020-06-12 12:46:59 +00002482 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2483 case ext4FsType:
2484 a.payloadFsType = ext4
2485 case f2fsFsType:
2486 a.payloadFsType = f2fs
2487 default:
2488 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
2489 }
2490
Jiyong Park7cd10e32020-01-14 09:22:18 +09002491 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2492 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2493 // the same library in the system partition, thus effectively sharing the same libraries
2494 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2495 // in the APEX.
2496 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2497 a.installable() &&
2498 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002499
Jooyung Han85d61762020-06-24 23:50:26 +09002500 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2501 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002502 if a.SocSpecific() || a.DeviceSpecific() ||
2503 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002504 a.linkToSystemLib = false
2505 }
2506
Jiyong Park9d677202020-02-19 16:29:35 +09002507 // We don't need the optimization for updatable APEXes, as it might give false signal
2508 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002509 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002510 a.linkToSystemLib = false
2511 }
2512
Jiyong Park638d30e2020-02-26 18:27:19 +09002513 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2514 if ctx.Host() {
2515 a.linkToSystemLib = false
2516 }
2517
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002518 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002519 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2520
Jooyung Han580eb4f2020-06-24 19:33:06 +09002521 a.buildFileContexts(ctx)
2522
Jooyung Han01a3ee22019-11-02 02:52:25 +09002523 a.setCertificateAndPrivateKey(ctx)
2524 if a.properties.ApexType == flattenedApex {
2525 a.buildFlattenedApex(ctx)
2526 } else {
2527 a.buildUnflattenedApex(ctx)
2528 }
2529
Jooyung Han002ab682020-01-08 01:57:58 +09002530 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002531
2532 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002533
2534 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002535}
2536
Artur Satayev8cf899a2020-04-15 17:29:42 +01002537// Enforce that Java deps of the apex are using stable SDKs to compile
2538func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2539 // Visit direct deps only. As long as we guarantee top-level deps are using
2540 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2541 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2542 tag := ctx.OtherModuleDependencyTag(module)
2543 switch tag {
2544 case javaLibTag, androidAppTag:
2545 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2546 if err := m.CheckStableSdkVersion(); err != nil {
2547 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2548 }
2549 }
2550 }
2551 })
2552}
2553
Colin Cross440e0d02020-06-11 11:32:11 -07002554func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002555 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002556 moduleName = normalizeModuleName(moduleName)
2557
Colin Cross440e0d02020-06-11 11:32:11 -07002558 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002559 return true
2560 }
2561
2562 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002563 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002564 return true
2565 }
2566
2567 return false
2568}
2569
2570func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002571 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2572 // system. Trim the prefix for the check since they are confusing
2573 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2574 if strings.HasPrefix(moduleName, "libclang_rt.") {
2575 // This module has many arch variants that depend on the product being built.
2576 // We don't want to list them all
2577 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002578 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002579 if strings.HasPrefix(moduleName, "androidx.") {
2580 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2581 moduleName = "androidx"
2582 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002583 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002584}
2585
Jooyung Han344d5432019-08-23 11:17:39 +09002586func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002587 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002588 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002589 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002590 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002591 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002592 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002593 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002594 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002595 return module
2596}
Jiyong Park30ca9372019-02-07 16:27:23 +09002597
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002598func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002599 bundle := newApexBundle()
2600 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002601 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002602 return bundle
2603}
2604
Jiyong Parkfce0b422020-02-11 03:56:06 +09002605// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2606// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002607func testApexBundleFactory() android.Module {
2608 bundle := newApexBundle()
2609 bundle.testApex = true
2610 return bundle
2611}
2612
Jiyong Parkfce0b422020-02-11 03:56:06 +09002613// apex packages other modules into an APEX file which is a packaging format for system-level
2614// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002615func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002616 return newApexBundle()
2617}
2618
Jiyong Park30ca9372019-02-07 16:27:23 +09002619//
2620// Defaults
2621//
2622type Defaults struct {
2623 android.ModuleBase
2624 android.DefaultsModuleBase
2625}
2626
Jiyong Park30ca9372019-02-07 16:27:23 +09002627func defaultsFactory() android.Module {
2628 return DefaultsFactory()
2629}
2630
2631func DefaultsFactory(props ...interface{}) android.Module {
2632 module := &Defaults{}
2633
2634 module.AddProperties(props...)
2635 module.AddProperties(
2636 &apexBundleProperties{},
2637 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002638 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002639 )
2640
2641 android.InitDefaultsModule(module)
2642 return module
2643}
Jiyong Park5d790c32019-11-15 18:40:32 +09002644
2645//
2646// OverrideApex
2647//
2648type OverrideApex struct {
2649 android.ModuleBase
2650 android.OverrideModuleBase
2651}
2652
2653func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2654 // All the overrides happen in the base module.
2655}
2656
2657// override_apex is used to create an apex module based on another apex module
2658// by overriding some of its properties.
2659func overrideApexFactory() android.Module {
2660 m := &OverrideApex{}
2661 m.AddProperties(&overridableProperties{})
2662
2663 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2664 android.InitOverrideModule(m)
2665 return m
2666}