blob: fdc105e3761963a21d9038c60964e7cd6049b750 [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 "libdvr_headers",
280 "libexpat",
281 "libfifo",
282 "libflacextractor",
283 "libgrallocusage",
284 "libgraphicsenv",
285 "libgui",
286 "libgui_headers",
287 "libhardware_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900288 "libinput",
Jiyong Park0f80c182020-01-31 02:49:53 +0900289 "liblzma",
290 "libmath",
291 "libmedia",
292 "libmedia_codeclist",
293 "libmedia_headers",
294 "libmedia_helper",
295 "libmedia_helper_headers",
296 "libmedia_midiiowrapper",
297 "libmedia_omx",
298 "libmediautils",
299 "libmidiextractor",
300 "libmkvextractor",
301 "libmp3extractor",
302 "libmp4extractor",
303 "libmpeg2extractor",
304 "libnativebase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900305 "libnativewindow_headers",
306 "libnblog",
307 "liboggextractor",
308 "libpackagelistparser",
Jiyong Park0f80c182020-01-31 02:49:53 +0900309 "libpdx",
310 "libpdx_default_transport",
311 "libpdx_headers",
312 "libpdx_uds",
Jiyong Park0f80c182020-01-31 02:49:53 +0900313 "libprocinfo",
Jiyong Park0f80c182020-01-31 02:49:53 +0900314 "libspeexresampler",
315 "libspeexresampler",
316 "libstagefright_esds",
317 "libstagefright_flacdec",
318 "libstagefright_flacdec",
319 "libstagefright_foundation",
320 "libstagefright_foundation_headers",
321 "libstagefright_foundation_without_imemory",
322 "libstagefright_headers",
323 "libstagefright_id3",
324 "libstagefright_metadatautils",
325 "libstagefright_mpeg2extractor",
326 "libstagefright_mpeg2support",
327 "libsync",
Jiyong Park0f80c182020-01-31 02:49:53 +0900328 "libui",
329 "libui_headers",
330 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900331 "libvibrator",
332 "libvorbisidec",
333 "libwavextractor",
334 "libwebm",
335 "media_ndk_headers",
336 "media_plugin_headers",
337 "updatable-media",
338 }
339 //
340 // Module separator
341 //
342 m["com.android.media.swcodec"] = []string{
343 "android.frameworks.bufferhub@1.0",
344 "android.hardware.common-ndk_platform",
345 "android.hardware.configstore-utils",
346 "android.hardware.configstore@1.0",
347 "android.hardware.configstore@1.1",
348 "android.hardware.graphics.allocator@2.0",
349 "android.hardware.graphics.allocator@3.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000350 "android.hardware.graphics.allocator@4.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900351 "android.hardware.graphics.bufferqueue@1.0",
352 "android.hardware.graphics.bufferqueue@2.0",
353 "android.hardware.graphics.common-ndk_platform",
354 "android.hardware.graphics.common@1.0",
355 "android.hardware.graphics.common@1.1",
356 "android.hardware.graphics.common@1.2",
357 "android.hardware.graphics.mapper@2.0",
358 "android.hardware.graphics.mapper@2.1",
359 "android.hardware.graphics.mapper@3.0",
360 "android.hardware.graphics.mapper@4.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000361 "android.hardware.media.bufferpool@2.0",
362 "android.hardware.media.c2@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000363 "android.hardware.media.c2@1.1",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000364 "android.hardware.media.omx@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900365 "android.hardware.media@1.0",
366 "android.hardware.media@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000367 "android.hidl.memory.token@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900368 "android.hidl.memory@1.0",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000369 "android.hidl.safe_union@1.0",
370 "android.hidl.token@1.0",
371 "android.hidl.token@1.0-utils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900372 "libEGL",
373 "libFLAC",
374 "libFLAC-config",
375 "libFLAC-headers",
376 "libFraunhoferAAC",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900377 "libLibGuiProperties",
Jiyong Park0f80c182020-01-31 02:49:53 +0900378 "libarect",
Jiyong Park0f80c182020-01-31 02:49:53 +0900379 "libaudio_system_headers",
380 "libaudioutils",
381 "libaudioutils",
382 "libaudioutils_fixedfft",
383 "libavcdec",
384 "libavcenc",
385 "libavservices_minijail",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000386 "libavservices_minijail",
Jiyong Park0f80c182020-01-31 02:49:53 +0900387 "libbinder_headers",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900388 "libbinderthreadstateutils",
Jiyong Park0f80c182020-01-31 02:49:53 +0900389 "libbluetooth-types-header",
390 "libbufferhub_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000391 "libcodec2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900392 "libcodec2_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000393 "libcodec2_hidl@1.0",
Jiyong Park0f80c182020-01-31 02:49:53 +0900394 "libcodec2_hidl@1.1",
395 "libcodec2_internal",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000396 "libcodec2_soft_aacdec",
397 "libcodec2_soft_aacenc",
398 "libcodec2_soft_amrnbdec",
399 "libcodec2_soft_amrnbenc",
400 "libcodec2_soft_amrwbdec",
401 "libcodec2_soft_amrwbenc",
402 "libcodec2_soft_av1dec_gav1",
403 "libcodec2_soft_avcdec",
404 "libcodec2_soft_avcenc",
405 "libcodec2_soft_common",
406 "libcodec2_soft_flacdec",
407 "libcodec2_soft_flacenc",
408 "libcodec2_soft_g711alawdec",
409 "libcodec2_soft_g711mlawdec",
410 "libcodec2_soft_gsmdec",
411 "libcodec2_soft_h263dec",
412 "libcodec2_soft_h263enc",
413 "libcodec2_soft_hevcdec",
414 "libcodec2_soft_hevcenc",
415 "libcodec2_soft_mp3dec",
416 "libcodec2_soft_mpeg2dec",
417 "libcodec2_soft_mpeg4dec",
418 "libcodec2_soft_mpeg4enc",
419 "libcodec2_soft_opusdec",
420 "libcodec2_soft_opusenc",
421 "libcodec2_soft_rawdec",
422 "libcodec2_soft_vorbisdec",
423 "libcodec2_soft_vp8dec",
424 "libcodec2_soft_vp8enc",
425 "libcodec2_soft_vp9dec",
426 "libcodec2_soft_vp9enc",
427 "libcodec2_vndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900428 "libdvr_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000429 "libfmq",
Jiyong Park0f80c182020-01-31 02:49:53 +0900430 "libfmq",
431 "libgav1",
432 "libgralloctypes",
433 "libgrallocusage",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000434 "libgraphicsenv",
Jiyong Park0f80c182020-01-31 02:49:53 +0900435 "libgsm",
436 "libgui_bufferqueue_static",
437 "libgui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000438 "libhardware",
Jiyong Park0f80c182020-01-31 02:49:53 +0900439 "libhardware_headers",
440 "libhevcdec",
441 "libhevcenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000442 "libion",
Jiyong Park0f80c182020-01-31 02:49:53 +0900443 "libjpeg",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000444 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900445 "libmath",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000446 "libmedia_codecserviceregistrant",
Jiyong Park0f80c182020-01-31 02:49:53 +0900447 "libmedia_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900448 "libmpeg2dec",
449 "libnativebase_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900450 "libnativewindow_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900451 "libpdx_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000452 "libscudo_wrapper",
453 "libsfplugin_ccodec_utils",
Anton Hansson5053c292020-01-10 15:12:39 +0000454 "libspeexresampler",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000455 "libstagefright_amrnb_common",
Jiyong Park0f80c182020-01-31 02:49:53 +0900456 "libstagefright_amrnbdec",
457 "libstagefright_amrnbenc",
458 "libstagefright_amrwbdec",
459 "libstagefright_amrwbenc",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000460 "libstagefright_bufferpool@2.0.1",
461 "libstagefright_bufferqueue_helper",
462 "libstagefright_enc_common",
463 "libstagefright_flacdec",
464 "libstagefright_foundation",
Jiyong Park0f80c182020-01-31 02:49:53 +0900465 "libstagefright_foundation_headers",
466 "libstagefright_headers",
467 "libstagefright_m4vh263dec",
468 "libstagefright_m4vh263enc",
469 "libstagefright_mp3dec",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000470 "libsync",
471 "libui",
Jiyong Park0f80c182020-01-31 02:49:53 +0900472 "libui_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000473 "libunwindstack",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000474 "libvorbisidec",
475 "libvpx",
Jiyong Park0f80c182020-01-31 02:49:53 +0900476 "libyuv",
477 "libyuv_static",
478 "media_ndk_headers",
479 "media_plugin_headers",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000480 "mediaswcodec",
Jiyong Park0f80c182020-01-31 02:49:53 +0900481 }
482 //
483 // Module separator
484 //
485 m["com.android.mediaprovider"] = []string{
486 "MediaProvider",
487 "MediaProviderGoogle",
488 "fmtlib_ndk",
Jiyong Park0f80c182020-01-31 02:49:53 +0900489 "libbase_ndk",
490 "libfuse",
491 "libfuse_jni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900492 }
493 //
494 // Module separator
495 //
496 m["com.android.permission"] = []string{
Jooyung Han040ff3d2020-05-19 15:47:01 +0900497 "car-ui-lib",
498 "iconloader",
Jiyong Park0f80c182020-01-31 02:49:53 +0900499 "kotlin-annotations",
500 "kotlin-stdlib",
501 "kotlin-stdlib-jdk7",
502 "kotlin-stdlib-jdk8",
503 "kotlinx-coroutines-android",
504 "kotlinx-coroutines-android-nodeps",
505 "kotlinx-coroutines-core",
506 "kotlinx-coroutines-core-nodeps",
Jiyong Park0f80c182020-01-31 02:49:53 +0900507 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900508 "GooglePermissionController",
509 "PermissionController",
Jooyung Han040ff3d2020-05-19 15:47:01 +0900510 "SettingsLibActionBarShadow",
511 "SettingsLibAppPreference",
512 "SettingsLibBarChartPreference",
513 "SettingsLibLayoutPreference",
514 "SettingsLibProgressBar",
515 "SettingsLibSearchWidget",
516 "SettingsLibSettingsTheme",
517 "SettingsLibRestrictedLockUtils",
518 "SettingsLibHelpUtils",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000519 }
520 //
521 // Module separator
522 //
523 m["com.android.runtime"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900524 "bionic_libc_platform_headers",
Jiyong Park0f80c182020-01-31 02:49:53 +0900525 "libarm-optimized-routines-math",
Jiyong Park0f80c182020-01-31 02:49:53 +0900526 "libc_aeabi",
527 "libc_bionic",
528 "libc_bionic_ndk",
529 "libc_bootstrap",
530 "libc_common",
531 "libc_common_shared",
532 "libc_common_static",
533 "libc_dns",
534 "libc_dynamic_dispatch",
535 "libc_fortify",
536 "libc_freebsd",
537 "libc_freebsd_large_stack",
538 "libc_gdtoa",
Jiyong Park0f80c182020-01-31 02:49:53 +0900539 "libc_init_dynamic",
540 "libc_init_static",
541 "libc_jemalloc_wrapper",
542 "libc_netbsd",
543 "libc_nomalloc",
544 "libc_nopthread",
545 "libc_openbsd",
546 "libc_openbsd_large_stack",
547 "libc_openbsd_ndk",
548 "libc_pthread",
549 "libc_static_dispatch",
550 "libc_syscalls",
551 "libc_tzcode",
552 "libc_unwind_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900553 "libdebuggerd",
554 "libdebuggerd_common_headers",
555 "libdebuggerd_handler_core",
556 "libdebuggerd_handler_fallback",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900557 "libdl_static",
Jiyong Park0f80c182020-01-31 02:49:53 +0900558 "libjemalloc5",
559 "liblinker_main",
560 "liblinker_malloc",
Jiyong Park0f80c182020-01-31 02:49:53 +0900561 "liblz4",
562 "liblzma",
Jiyong Park0f80c182020-01-31 02:49:53 +0900563 "libprocinfo",
564 "libpropertyinfoparser",
565 "libscudo",
566 "libstdc++",
Jiyong Park0f80c182020-01-31 02:49:53 +0900567 "libsystemproperties",
568 "libtombstoned_client_static",
569 "libunwindstack",
Jiyong Park0f80c182020-01-31 02:49:53 +0900570 "libz",
571 "libziparchive",
572 }
573 //
574 // Module separator
575 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900576 m["com.android.tethering"] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900577 "android.hardware.tetheroffload.config-V1.0-java",
578 "android.hardware.tetheroffload.control-V1.0-java",
579 "android.hidl.base-V1.0-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900580 "libcgrouprc",
581 "libcgrouprc_format",
Jiyong Park0f80c182020-01-31 02:49:53 +0900582 "libtetherutilsjni",
Jiyong Park0f80c182020-01-31 02:49:53 +0900583 "libvndksupport",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900584 "net-utils-framework-common",
585 "netd_aidl_interface-V3-java",
586 "netlink-client",
587 "networkstack-aidl-interfaces-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900588 "tethering-aidl-interfaces-java",
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900589 "TetheringApiCurrentLib",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000590 }
591 //
592 // Module separator
593 //
Jiyong Park0f80c182020-01-31 02:49:53 +0900594 m["com.android.wifi"] = []string{
595 "PlatformProperties",
596 "android.hardware.wifi-V1.0-java",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900597 "android.hardware.wifi-V1.0-java-constants",
Jiyong Park0f80c182020-01-31 02:49:53 +0900598 "android.hardware.wifi-V1.1-java",
599 "android.hardware.wifi-V1.2-java",
600 "android.hardware.wifi-V1.3-java",
601 "android.hardware.wifi-V1.4-java",
602 "android.hardware.wifi.hostapd-V1.0-java",
603 "android.hardware.wifi.hostapd-V1.1-java",
604 "android.hardware.wifi.hostapd-V1.2-java",
605 "android.hardware.wifi.supplicant-V1.0-java",
606 "android.hardware.wifi.supplicant-V1.1-java",
607 "android.hardware.wifi.supplicant-V1.2-java",
608 "android.hardware.wifi.supplicant-V1.3-java",
609 "android.hidl.base-V1.0-java",
610 "android.hidl.manager-V1.0-java",
611 "android.hidl.manager-V1.1-java",
612 "android.hidl.manager-V1.2-java",
Jiyong Park0f80c182020-01-31 02:49:53 +0900613 "bouncycastle-unbundled",
614 "dnsresolver_aidl_interface-V2-java",
615 "error_prone_annotations",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900616 "framework-wifi-pre-jarjar",
617 "framework-wifi-util-lib",
Jiyong Park0f80c182020-01-31 02:49:53 +0900618 "ipmemorystore-aidl-interfaces-V3-java",
619 "ipmemorystore-aidl-interfaces-java",
620 "ksoap2",
Jiyong Park0f80c182020-01-31 02:49:53 +0900621 "libnanohttpd",
Jiyong Park0f80c182020-01-31 02:49:53 +0900622 "libwifi-jni",
623 "net-utils-services-common",
624 "netd_aidl_interface-V2-java",
625 "netd_aidl_interface-unstable-java",
626 "netd_event_listener_interface-java",
627 "netlink-client",
Jiyong Park0f80c182020-01-31 02:49:53 +0900628 "networkstack-client",
629 "services.net",
630 "wifi-lite-protos",
631 "wifi-nano-protos",
632 "wifi-service-pre-jarjar",
633 "wifi-service-resources",
Jiyong Park0f80c182020-01-31 02:49:53 +0900634 }
635 //
636 // Module separator
637 //
638 m["com.android.sdkext"] = []string{
639 "fmtlib_ndk",
640 "libbase_ndk",
641 "libprotobuf-cpp-lite-ndk",
642 }
643 //
644 // Module separator
645 //
646 m["com.android.os.statsd"] = []string{
Jiyong Park0f80c182020-01-31 02:49:53 +0900647 "libstatssocket",
Jiyong Park0f80c182020-01-31 02:49:53 +0900648 }
649 //
650 // Module separator
651 //
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000652 m[android.AvailableToAnyApex] = []string{
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900653 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
654 "androidx",
655 "androidx-constraintlayout_constraintlayout",
656 "androidx-constraintlayout_constraintlayout-nodeps",
657 "androidx-constraintlayout_constraintlayout-solver",
658 "androidx-constraintlayout_constraintlayout-solver-nodeps",
659 "com.google.android.material_material",
660 "com.google.android.material_material-nodeps",
661
Jiyong Park0f80c182020-01-31 02:49:53 +0900662 "libatomic",
Jiyong Park0f80c182020-01-31 02:49:53 +0900663 "libclang_rt",
664 "libgcc_stripped",
665 "libprofile-clang-extras",
666 "libprofile-clang-extras_ndk",
667 "libprofile-extras",
668 "libprofile-extras_ndk",
669 "libunwind_llvm",
Jiyong Park0f80c182020-01-31 02:49:53 +0900670 }
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000671 return m
672}
673
Andrei Onea115e7e72020-06-05 21:14:03 +0100674// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
675// Adding code to the bootclasspath in new packages will cause issues on module update.
676func qModulesPackages() map[string][]string {
677 return map[string][]string{
678 "com.android.conscrypt": []string{
679 "android.net.ssl",
680 "com.android.org.conscrypt",
681 },
682 "com.android.media": []string{
683 "android.media",
684 },
685 }
686}
687
688// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
689// Adding code to the bootclasspath in new packages will cause issues on module update.
690func rModulesPackages() map[string][]string {
691 return map[string][]string{
692 "com.android.mediaprovider": []string{
693 "android.provider",
694 },
695 "com.android.permission": []string{
696 "android.permission",
697 "android.app.role",
698 "com.android.permission",
699 "com.android.role",
700 },
701 "com.android.sdkext": []string{
702 "android.os.ext",
703 },
704 "com.android.os.statsd": []string{
705 "android.app",
706 "android.os",
707 "android.util",
708 "com.android.internal.statsd",
709 "com.android.server.stats",
710 },
711 "com.android.wifi": []string{
712 "com.android.server.wifi",
713 "com.android.wifi.x",
714 "android.hardware.wifi",
715 "android.net.wifi",
716 },
717 "com.android.tethering": []string{
718 "android.net",
719 },
720 }
721}
722
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900723func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900724 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800725 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900726 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900727 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700728 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900729 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700730 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900731
Jooyung Han31c470b2019-10-18 16:26:59 +0900732 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900733 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900734
Andrei Onea115e7e72020-06-05 21:14:03 +0100735 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
736 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
737}
738
739func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
740 rules := make([]android.Rule, 0, len(modules_packages))
741 for module_name, module_packages := range modules_packages {
742 permitted_packages_rule := android.NeverAllow().
743 BootclasspathJar().
744 With("apex_available", module_name).
745 WithMatcher("permitted_packages", android.NotInList(module_packages)).
746 Because("jars that are part of the " + module_name +
747 " module may only allow these packages: " + strings.Join(module_packages, ",") +
748 ". Please jarjar or move code around.")
749 rules = append(rules, permitted_packages_rule)
750 }
751 return rules
Jiyong Parkd1063c12019-07-17 20:08:41 +0900752}
753
Jooyung Han31c470b2019-10-18 16:26:59 +0900754func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
755 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
756 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
757}
758
Jiyong Parkd1063c12019-07-17 20:08:41 +0900759func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900760 ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
Colin Crossaede88c2020-08-11 12:17:01 -0700761 ctx.BottomUp("apex_unique", apexUniqueVariationsMutator).Parallel()
Colin Cross56a83212020-09-15 18:30:11 -0700762 ctx.BottomUp("apex_test_for_deps", apexTestForDepsMutator).Parallel()
763 ctx.BottomUp("apex_test_for", apexTestForMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900764 ctx.BottomUp("apex", apexMutator).Parallel()
Colin Cross56a83212020-09-15 18:30:11 -0700765 ctx.BottomUp("apex_directly_in_any", apexDirectlyInAnyMutator).Parallel()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900766 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
767 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park89e850a2020-04-07 16:37:39 +0900768 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900769}
770
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900771// Mark the direct and transitive dependencies of apex bundles so that they
772// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900773func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900774 if !mctx.Module().Enabled() {
775 return
776 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900777 a, ok := mctx.Module().(*apexBundle)
778 if !ok || a.vndkApex {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900779 return
780 }
Jooyung Handf78e212020-07-22 15:54:47 +0900781
782 useVndk := a.SocSpecific() || a.DeviceSpecific() || (a.ProductSpecific() && mctx.Config().EnforceProductPartitionInterface())
783 excludeVndkLibs := useVndk && proptools.Bool(a.properties.Use_vndk_as_stable)
784 if !useVndk && proptools.Bool(a.properties.Use_vndk_as_stable) {
785 mctx.PropertyErrorf("use_vndk_as_stable", "not supported for system/system_ext APEXes")
786 return
787 }
788
Colin Cross56a83212020-09-15 18:30:11 -0700789 contents := make(map[string]android.ApexMembership)
790
791 continueApexDepsWalk := func(child, parent android.Module) bool {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900792 am, ok := child.(android.ApexModule)
793 if !ok || !am.CanHaveApexVariants() {
794 return false
Jiyong Parkf760cae2020-02-12 07:53:12 +0900795 }
Paul Duffina37eca22020-07-22 13:00:54 +0100796 if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
Jooyung Han698dd9f2020-07-22 15:17:19 +0900797 return false
798 }
Jooyung Handf78e212020-07-22 15:54:47 +0900799 if excludeVndkLibs {
800 if c, ok := child.(*cc.Module); ok && c.IsVndk() {
801 return false
802 }
803 }
Colin Cross56a83212020-09-15 18:30:11 -0700804 return true
805 }
806
807 mctx.WalkDeps(func(child, parent android.Module) bool {
808 if !continueApexDepsWalk(child, parent) {
809 return false
810 }
Jooyung Han698dd9f2020-07-22 15:17:19 +0900811
812 depName := mctx.OtherModuleName(child)
813 // If the parent is apexBundle, this child is directly depended.
814 _, directDep := parent.(*apexBundle)
Colin Cross56a83212020-09-15 18:30:11 -0700815 contents[depName] = contents[depName].Add(directDep)
816 return true
817 })
818
819 apexContents := android.NewApexContents(mctx.ModuleName(), contents)
820 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
821 Contents: apexContents,
822 })
823
824 apexInfo := android.ApexInfo{
825 ApexVariationName: mctx.ModuleName(),
826 MinSdkVersionStr: a.minSdkVersion(mctx).String(),
827 RequiredSdks: a.RequiredSdks(),
828 Updatable: a.Updatable(),
829 InApexes: []string{mctx.ModuleName()},
830 ApexContents: []*android.ApexContents{apexContents},
831 }
832
833 mctx.WalkDeps(func(child, parent android.Module) bool {
834 if !continueApexDepsWalk(child, parent) {
835 return false
836 }
837
838 child.(android.ApexModule).BuildForApex(apexInfo)
Jooyung Han698dd9f2020-07-22 15:17:19 +0900839 return true
Jiyong Parkf760cae2020-02-12 07:53:12 +0900840 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900841}
842
Colin Crossaede88c2020-08-11 12:17:01 -0700843func apexUniqueVariationsMutator(mctx android.BottomUpMutatorContext) {
844 if !mctx.Module().Enabled() {
845 return
846 }
847 if am, ok := mctx.Module().(android.ApexModule); ok {
848 // Check if any dependencies use unique apex variations. If so, use unique apex variations
849 // for this module.
Colin Cross56a83212020-09-15 18:30:11 -0700850 android.UpdateUniqueApexVariationsForDeps(mctx, am)
851 }
852}
853
854func apexTestForDepsMutator(mctx android.BottomUpMutatorContext) {
855 if !mctx.Module().Enabled() {
856 return
857 }
858 // Check if this module is a test for an apex. If so, add a dependency on the apex
859 // in order to retrieve its contents later.
860 if am, ok := mctx.Module().(android.ApexModule); ok {
861 if testFor := am.TestFor(); len(testFor) > 0 {
862 mctx.AddFarVariationDependencies([]blueprint.Variation{
863 {Mutator: "os", Variation: am.Target().OsVariation()},
864 {"arch", "common"},
865 }, testForTag, testFor...)
866 }
867 }
868}
869
870func apexTestForMutator(mctx android.BottomUpMutatorContext) {
871 if !mctx.Module().Enabled() {
872 return
873 }
874
875 if _, ok := mctx.Module().(android.ApexModule); ok {
876 var contents []*android.ApexContents
877 for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) {
878 abInfo := mctx.OtherModuleProvider(testFor, ApexBundleInfoProvider).(ApexBundleInfo)
879 contents = append(contents, abInfo.Contents)
880 }
881 mctx.SetProvider(android.ApexTestForInfoProvider, android.ApexTestForInfo{
882 ApexContents: contents,
883 })
Colin Crossaede88c2020-08-11 12:17:01 -0700884 }
885}
886
Jiyong Park89e850a2020-04-07 16:37:39 +0900887// mark if a module cannot be available to platform. A module cannot be available
888// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
889// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
890func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
891 // Host and recovery are not considered as platform
892 if mctx.Host() || mctx.Module().InstallInRecovery() {
893 return
894 }
895
896 if am, ok := mctx.Module().(android.ApexModule); ok {
897 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
898
Jiyong Park89e850a2020-04-07 16:37:39 +0900899 // If any of the dep is not available to platform, this module is also considered
900 // as being not available to platform even if it has "//apex_available:platform"
901 mctx.VisitDirectDeps(func(child android.Module) {
902 if !am.DepIsInSameApex(mctx, child) {
903 // if the dependency crosses apex boundary, don't consider it
904 return
905 }
906 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
907 availableToPlatform = false
908 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
909 }
910 })
911
912 // Exception 1: stub libraries and native bridge libraries are always available to platform
913 if cc, ok := mctx.Module().(*cc.Module); ok &&
914 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
915 availableToPlatform = true
916 }
917
918 // Exception 2: bootstrap bionic libraries are also always available to platform
919 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
920 availableToPlatform = true
921 }
922
923 if !availableToPlatform {
924 am.SetNotAvailableForPlatform()
925 }
926 }
927}
928
Paul Duffin65347702020-03-31 15:23:40 +0100929// If a module in an APEX depends on a module from an SDK then it needs an APEX
930// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
931func inAnySdk(module android.Module) bool {
932 if sa, ok := module.(android.SdkAware); ok {
933 return sa.IsInAnySdk()
934 }
935
936 return false
937}
938
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900939// Create apex variations if a module is included in APEX(s).
940func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900941 if !mctx.Module().Enabled() {
942 return
943 }
Colin Cross56a83212020-09-15 18:30:11 -0700944
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900945 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Colin Cross56a83212020-09-15 18:30:11 -0700946 android.CreateApexVariations(mctx, am)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000947 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900948 // apex bundle itself is mutated so that it and its modules have same
949 // apex variant.
950 apexBundleName := mctx.ModuleName()
951 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900952 } else if o, ok := mctx.Module().(*OverrideApex); ok {
953 apexBundleName := o.GetOverriddenModuleName()
954 if apexBundleName == "" {
955 mctx.ModuleErrorf("base property is not set")
956 return
957 }
958 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900959 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900960
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900961}
Sundong Ahne9b55722019-09-06 17:37:42 +0900962
Colin Cross56a83212020-09-15 18:30:11 -0700963func apexDirectlyInAnyMutator(mctx android.BottomUpMutatorContext) {
964 if !mctx.Module().Enabled() {
965 return
966 }
967 if am, ok := mctx.Module().(android.ApexModule); ok {
968 android.UpdateDirectlyInAnyApex(mctx, am)
969 }
970}
971
Sundong Ahne9b55722019-09-06 17:37:42 +0900972func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han49f67012020-04-17 13:43:10 +0900973 if !mctx.Module().Enabled() {
974 return
975 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900976 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900977 var variants []string
978 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
979 case "image":
980 variants = append(variants, imageApexType, flattenedApexType)
981 case "zip":
982 variants = append(variants, zipApexType)
983 case "both":
984 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
985 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900986 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900987 return
988 }
989
990 modules := mctx.CreateLocalVariations(variants...)
991
992 for i, v := range variants {
993 switch v {
994 case imageApexType:
995 modules[i].(*apexBundle).properties.ApexType = imageApex
996 case zipApexType:
997 modules[i].(*apexBundle).properties.ApexType = zipApex
998 case flattenedApexType:
999 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +09001000 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001001 modules[i].(*apexBundle).MakeAsSystemExt()
1002 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001003 }
Sundong Ahne9b55722019-09-06 17:37:42 +09001004 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001005 } else if _, ok := mctx.Module().(*OverrideApex); ok {
1006 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +09001007 }
1008}
1009
Jooyung Han5c998b92019-06-27 11:30:33 +09001010func apexUsesMutator(mctx android.BottomUpMutatorContext) {
1011 if ab, ok := mctx.Module().(*apexBundle); ok {
1012 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
1013 }
1014}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001015
Jooyung Handc782442019-11-01 03:14:38 +09001016var (
Colin Cross440e0d02020-06-11 11:32:11 -07001017 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +09001018)
1019
Colin Cross440e0d02020-06-11 11:32:11 -07001020// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +09001021// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
1022// which may cause compatibility issues. (e.g. libbinder)
1023// Even though libbinder restricts its availability via 'apex_available' property and relies on
1024// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
1025// to avoid similar problems.
Colin Cross440e0d02020-06-11 11:32:11 -07001026func useVendorAllowList(config android.Config) []string {
1027 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +09001028 return []string{
1029 // swcodec uses "vendor" variants for smaller size
1030 "com.android.media.swcodec",
1031 "test_com.android.media.swcodec",
1032 }
1033 }).([]string)
1034}
1035
Colin Cross440e0d02020-06-11 11:32:11 -07001036// setUseVendorAllowListForTest overrides useVendorAllowList and must be
1037// called before the first call to useVendorAllowList()
1038func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1039 config.Once(useVendorAllowListKey, func() interface{} {
1040 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001041 })
1042}
1043
Jooyung Han01a868d2020-02-27 13:40:44 +09001044type ApexNativeDependencies struct {
Alex Light9670d332019-01-29 18:07:33 -08001045 // List of native libraries
1046 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001047
Jooyung Han643adc42020-02-27 13:50:06 +09001048 // List of JNI libraries
1049 Jni_libs []string
1050
Alex Light9670d332019-01-29 18:07:33 -08001051 // List of native executables
1052 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001053
Roland Levillain630846d2019-06-26 12:48:34 +01001054 // List of native tests
1055 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001056}
Jooyung Han344d5432019-08-23 11:17:39 +09001057
Alex Light9670d332019-01-29 18:07:33 -08001058type apexMultilibProperties struct {
1059 // Native dependencies whose compile_multilib is "first"
Jooyung Han01a868d2020-02-27 13:40:44 +09001060 First ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001061
1062 // Native dependencies whose compile_multilib is "both"
Jooyung Han01a868d2020-02-27 13:40:44 +09001063 Both ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001064
1065 // Native dependencies whose compile_multilib is "prefer32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001066 Prefer32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001067
1068 // Native dependencies whose compile_multilib is "32"
Jooyung Han01a868d2020-02-27 13:40:44 +09001069 Lib32 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001070
1071 // Native dependencies whose compile_multilib is "64"
Jooyung Han01a868d2020-02-27 13:40:44 +09001072 Lib64 ApexNativeDependencies
Alex Light9670d332019-01-29 18:07:33 -08001073}
1074
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001075type apexBundleProperties struct {
1076 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001077 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001078 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001079
Jiyong Park40e26a22019-02-08 02:53:06 +09001080 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1081 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001082 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001083
Roland Levillain411c5842019-09-19 16:37:20 +01001084 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1085 // device (/apex/<apex_name>).
1086 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001087 Apex_name *string
1088
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001089 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001090 // For platform APEXes, this should points to a file under /system/sepolicy
1091 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1092 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001093
Jooyung Han01a868d2020-02-27 13:40:44 +09001094 ApexNativeDependencies
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001095
1096 // List of java libraries that are embedded inside this APEX bundle
1097 Java_libs []string
1098
1099 // List of prebuilt files that are embedded inside this APEX bundle
1100 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001101
markchien2f59ec92020-09-02 16:23:38 +08001102 // List of BPF programs inside APEX
1103 Bpfs []string
1104
Jiyong Parkff1458f2018-10-12 21:49:38 +09001105 // Name of the apex_key module that provides the private key to sign APEX
1106 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001107
Alex Light5098a612018-11-29 17:12:15 -08001108 // The type of APEX to build. Controls what the APEX payload is. Either
1109 // 'image', 'zip' or 'both'. Default: 'image'.
1110 Payload_type *string
1111
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001112 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1113 // or an android_app_certificate module name in the form ":module".
1114 Certificate *string
1115
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001116 // Whether this APEX is installable to one of the partitions. Default: true.
1117 Installable *bool
1118
Jiyong Parkda6eb592018-12-19 17:12:36 +09001119 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1120 // Default is false.
1121 Use_vendor *bool
1122
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001123 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1124 Ignore_system_library_special_case *bool
1125
Alex Light9670d332019-01-29 18:07:33 -08001126 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001127
Jiyong Parkf97782b2019-02-13 20:28:58 +09001128 // List of sanitizer names that this APEX is enabled for
1129 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001130
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001131 PreventInstall bool `blueprint:"mutated"`
1132
1133 HideFromMake bool `blueprint:"mutated"`
1134
Jooyung Han5c998b92019-06-27 11:30:33 +09001135 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1136 Provide_cpp_shared_libs *bool
1137
1138 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1139 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001140
Sundong Ahnabb64432019-10-22 13:58:29 +09001141 // package format of this apex variant; could be non-flattened, flattened, or zip.
1142 // imageApex, zipApex or flattened
1143 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001144
Jiyong Parkd1063c12019-07-17 20:08:41 +09001145 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1146 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1147 // is implied. This value affects all modules included in this APEX. In other words, they are
1148 // also built with the SDKs specified here.
1149 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001150
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001151 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1152 // Should be only used in tests#.
1153 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001154
Dario Frenica913392020-04-27 18:21:11 +01001155 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1156 // Should be only used in tests#.
1157 Test_only_unsigned_payload *bool
1158
Jiyong Park956305c2020-01-09 12:32:06 +09001159 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001160
1161 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Han548640b2020-04-27 12:10:30 +09001162 // rules for making sure that the APEX is truly updatable.
1163 // - To be updatable, min_sdk_version should be set as well
1164 // This will also disable the size optimizations like symlinking to the system libs.
1165 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001166 Updatable *bool
Colin Cross50317872020-02-19 20:41:10 -08001167
1168 // The minimum SDK version that this apex must be compatibile with.
1169 Min_sdk_version *string
Jooyung Handf78e212020-07-22 15:54:47 +09001170
1171 // If set true, VNDK libs are considered as stable libs and are not included in this apex.
1172 // Should be only used in non-system apexes (e.g. vendor: true).
1173 // Default is false.
1174 Use_vndk_as_stable *bool
Theotime Combes4ba38c12020-06-12 12:46:59 +00001175
1176 // The type of filesystem to use for an image apex. Either 'ext4' or 'f2fs'.
1177 // Default 'ext4'.
1178 Payload_fs_type *string
Alex Light9670d332019-01-29 18:07:33 -08001179}
1180
Colin Cross56a83212020-09-15 18:30:11 -07001181type ApexBundleInfo struct {
1182 Contents *android.ApexContents
1183}
1184
1185var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_deps")
1186
Alex Light9670d332019-01-29 18:07:33 -08001187type apexTargetBundleProperties struct {
1188 Target struct {
1189 // Multilib properties only for android.
1190 Android struct {
1191 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001192 }
Jooyung Han344d5432019-08-23 11:17:39 +09001193
Alex Light9670d332019-01-29 18:07:33 -08001194 // Multilib properties only for host.
1195 Host struct {
1196 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001197 }
Jooyung Han344d5432019-08-23 11:17:39 +09001198
Alex Light9670d332019-01-29 18:07:33 -08001199 // Multilib properties only for host linux_bionic.
1200 Linux_bionic struct {
1201 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001202 }
Jooyung Han344d5432019-08-23 11:17:39 +09001203
Alex Light9670d332019-01-29 18:07:33 -08001204 // Multilib properties only for host linux_glibc.
1205 Linux_glibc struct {
1206 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001207 }
1208 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001209}
1210
Jiyong Park5d790c32019-11-15 18:40:32 +09001211type overridableProperties struct {
1212 // List of APKs to package inside APEX
1213 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001214
Jiyong Park69aeba92020-04-24 21:16:36 +09001215 // List of runtime resource overlays (RROs) inside APEX
1216 Rros []string
1217
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001218 // Names of modules to be overridden. Listed modules can only be other binaries
1219 // (in Make or Soong).
1220 // This does not completely prevent installation of the overridden binaries, but if both
1221 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1222 // from PRODUCT_PACKAGES.
1223 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001224
1225 // Logging Parent value
1226 Logging_parent string
Baligh Uddin5b57dba2020-03-15 13:01:05 -07001227
1228 // Apex Container Package Name.
1229 // Override value for attribute package:name in AndroidManifest.xml
1230 Package_name string
Jooyung Han938b5932020-06-20 12:47:47 +09001231
1232 // A txt file containing list of files that are allowed to be included in this APEX.
1233 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001234}
1235
Alex Light5098a612018-11-29 17:12:15 -08001236type apexPackaging int
1237
1238const (
1239 imageApex apexPackaging = iota
1240 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001241 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001242)
1243
Sundong Ahnabb64432019-10-22 13:58:29 +09001244// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001245func (a apexPackaging) suffix() string {
1246 switch a {
1247 case imageApex:
1248 return imageApexSuffix
1249 case zipApex:
1250 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001251 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001252 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001253 }
1254}
1255
1256func (a apexPackaging) name() string {
1257 switch a {
1258 case imageApex:
1259 return imageApexType
1260 case zipApex:
1261 return zipApexType
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
Jiyong Parkf653b052019-11-18 15:39:01 +09001267type apexFileClass int
1268
1269const (
1270 etc apexFileClass = iota
1271 nativeSharedLib
1272 nativeExecutable
1273 shBinary
1274 pyBinary
1275 goBinary
1276 javaSharedLib
1277 nativeTest
1278 app
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001279 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001280)
1281
Jiyong Park8fd61922018-11-08 02:50:25 +09001282func (class apexFileClass) NameInMake() string {
1283 switch class {
1284 case etc:
1285 return "ETC"
1286 case nativeSharedLib:
1287 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001288 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001289 return "EXECUTABLES"
1290 case javaSharedLib:
1291 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001292 case nativeTest:
1293 return "NATIVE_TESTS"
Sasha Smundak18d98bc2020-05-27 16:36:07 -07001294 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001295 // b/142537672 Why isn't this APP? We want to have full control over
1296 // the paths and file names of the apk file under the flattend APEX.
1297 // If this is set to APP, then the paths and file names are modified
1298 // by the Make build system. For example, it is installed to
1299 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1300 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1301 // appends module name (which is <apexname>.<Appname> to the path.
1302 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001303 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001304 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001305 }
1306}
1307
Jiyong Parkf653b052019-11-18 15:39:01 +09001308// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001309type apexFile struct {
Yo Chiange8128052020-07-23 20:09:18 +08001310 builtFile android.Path
1311 stem string
1312 // Module name of `module` in AndroidMk. Note the generated AndroidMk module for
1313 // apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
1314 androidMkModuleName string
1315 installDir string
1316 class apexFileClass
1317 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001318 // list of symlinks that will be created in installDir that point to this apexFile
1319 symlinks []string
Chris Parsons216e10a2020-07-09 17:12:52 -04001320 dataPaths []android.DataPath
Jiyong Parkf653b052019-11-18 15:39:01 +09001321 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001322 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001323
1324 requiredModuleNames []string
1325 targetRequiredModuleNames []string
1326 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001327
Colin Cross503c1d02020-01-28 14:00:53 -08001328 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross08dca382020-07-21 20:31:17 -07001329 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001330 certificate java.Certificate // only for apps
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001331 overriddenPackageName string // only for apps
Jooyung Han643adc42020-02-27 13:50:06 +09001332
1333 isJniLib bool
Jiyong Park41f637d2020-09-09 13:18:02 +09001334
1335 noticeFiles android.Paths
Jiyong Parkf653b052019-11-18 15:39:01 +09001336}
1337
Yo Chiange8128052020-07-23 20:09:18 +08001338func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
Jiyong Park1833cef2019-12-13 13:28:36 +09001339 ret := apexFile{
Yo Chiange8128052020-07-23 20:09:18 +08001340 builtFile: builtFile,
1341 androidMkModuleName: androidMkModuleName,
1342 installDir: installDir,
1343 class: class,
1344 module: module,
Jiyong Parkf653b052019-11-18 15:39:01 +09001345 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001346 if module != nil {
1347 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001348 ret.requiredModuleNames = module.RequiredModuleNames()
1349 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1350 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park41f637d2020-09-09 13:18:02 +09001351 ret.noticeFiles = module.NoticeFiles()
Jiyong Park1833cef2019-12-13 13:28:36 +09001352 }
1353 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001354}
1355
1356func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001357 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001358}
1359
Liz Kammer1c14a212020-05-12 15:26:55 -07001360func (af *apexFile) apexRelativePath(path string) string {
1361 return filepath.Join(af.installDir, path)
1362}
1363
Jiyong Park7cd10e32020-01-14 09:22:18 +09001364// Path() returns path of this apex file relative to the APEX root
1365func (af *apexFile) Path() string {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001366 return af.apexRelativePath(af.Stem())
1367}
1368
1369func (af *apexFile) Stem() string {
Jiyong Parka62aa232020-05-28 23:46:55 +09001370 if af.stem != "" {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001371 return af.stem
Jiyong Parka62aa232020-05-28 23:46:55 +09001372 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09001373 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001374}
1375
1376// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1377func (af *apexFile) SymlinkPaths() []string {
1378 var ret []string
1379 for _, symlink := range af.symlinks {
Liz Kammer1c14a212020-05-12 15:26:55 -07001380 ret = append(ret, af.apexRelativePath(symlink))
Jiyong Park7cd10e32020-01-14 09:22:18 +09001381 }
1382 return ret
1383}
1384
1385func (af *apexFile) AvailableToPlatform() bool {
1386 if af.module == nil {
1387 return false
1388 }
1389 if am, ok := af.module.(android.ApexModule); ok {
1390 return am.AvailableFor(android.AvailableToPlatform)
1391 }
1392 return false
1393}
1394
Theotime Combes4ba38c12020-06-12 12:46:59 +00001395type fsType int
1396
1397const (
1398 ext4 fsType = iota
1399 f2fs
1400)
1401
1402func (f fsType) string() string {
1403 switch f {
1404 case ext4:
1405 return ext4FsType
1406 case f2fs:
1407 return f2fsFsType
1408 default:
1409 panic(fmt.Errorf("unknown APEX payload type %d", f))
1410 }
1411}
1412
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001413type apexBundle struct {
1414 android.ModuleBase
1415 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001416 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001417 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001418
Jiyong Park5d790c32019-11-15 18:40:32 +09001419 properties apexBundleProperties
1420 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001421 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001422
Jooyung Hanf21c7972019-12-16 22:32:06 +09001423 // specific to apex_vndk modules
1424 vndkProperties apexVndkProperties
1425
Colin Crossa4925902018-11-16 11:36:28 -08001426 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001427 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001428 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001429
Jiyong Park03b68dd2019-07-26 23:20:40 +09001430 prebuiltFileToDelete string
1431
Jiyong Park42cca6c2019-04-01 11:15:50 +09001432 public_key_file android.Path
1433 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001434
1435 container_certificate_file android.Path
1436 container_private_key_file android.Path
1437
Jooyung Han580eb4f2020-06-24 19:33:06 +09001438 fileContexts android.WritablePath
Jooyung Han54aca7b2019-11-20 02:26:02 +09001439
Jiyong Park8fd61922018-11-08 02:50:25 +09001440 // list of files to be included in this apex
1441 filesInfo []apexFile
1442
Jiyong Park956305c2020-01-09 12:32:06 +09001443 // list of module names that should be installed along with this APEX
1444 requiredDeps []string
1445
Jiyong Park956305c2020-01-09 12:32:06 +09001446 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev872a1442020-04-27 17:08:37 +01001447 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001448
Sundong Ahnabb64432019-10-22 13:58:29 +09001449 testApex bool
1450 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001451 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001452 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001453
Jooyung Han214bf372019-11-12 13:03:50 +09001454 manifestJsonOut android.WritablePath
1455 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001456
Jooyung Han002ab682020-01-08 01:57:58 +09001457 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001458 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001459 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001460 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1461 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001462
1463 // Suffix of module name in Android.mk
1464 // ".flattened", ".apex", ".zipapex", or ""
1465 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001466
1467 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001468
1469 // Whether to create symlink to the system file instead of having a file
1470 // inside the apex or not
1471 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001472
1473 // Struct holding the merged notice file paths in different formats
1474 mergedNotices android.NoticeOutputs
Colin Cross08dca382020-07-21 20:31:17 -07001475
1476 // Optional list of lint report zip files for apexes that contain java or app modules
1477 lintReports android.Paths
Theotime Combes4ba38c12020-06-12 12:46:59 +00001478
1479 payloadFsType fsType
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001480}
1481
Jiyong Park397e55e2018-10-24 21:09:55 +09001482func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001483 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001485 // Use *FarVariation* to be able to depend on modules having
1486 // conflicting variations with this module. This is required since
1487 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1488 // for native shared libs.
Jiyong Park397e55e2018-10-24 21:09:55 +09001489
Colin Cross42507332020-08-21 16:15:23 -07001490 binVariations := target.Variations()
1491 libVariations := append(target.Variations(),
1492 blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han643adc42020-02-27 13:50:06 +09001493
Colin Cross42507332020-08-21 16:15:23 -07001494 if ctx.Device() {
1495 binVariations = append(binVariations,
1496 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1497 libVariations = append(libVariations,
1498 blueprint.Variation{Mutator: "image", Variation: imageVariation},
1499 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
Colin Cross42507332020-08-21 16:15:23 -07001500 }
Roland Levillain630846d2019-06-26 12:48:34 +01001501
Colin Cross42507332020-08-21 16:15:23 -07001502 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
1503
1504 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
1505
1506 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
1507
Colin Cross90dab342020-08-21 15:55:50 -07001508 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001509}
1510
Alex Light9670d332019-01-29 18:07:33 -08001511func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1512 if ctx.Os().Class == android.Device {
1513 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1514 } else {
1515 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1516 if ctx.Os().Bionic() {
1517 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1518 } else {
1519 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1520 }
1521 }
1522}
1523
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001524func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001525 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001526 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1527 }
1528
Jiyong Park397e55e2018-10-24 21:09:55 +09001529 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001530 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001531 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001532
1533 a.combineProperties(ctx)
1534
Jiyong Park397e55e2018-10-24 21:09:55 +09001535 has32BitTarget := false
1536 for _, target := range targets {
1537 if target.Arch.ArchType.Multilib == "lib32" {
1538 has32BitTarget = true
1539 }
1540 }
1541 for i, target := range targets {
Jiyong Parkccb406f2020-09-29 10:58:10 +09001542 if target.HostCross {
1543 // Don't include artifats for the host cross targets because there is no way
1544 // for us to run those artifacts natively on host
1545 continue
1546 }
1547
Jooyung Han643adc42020-02-27 13:50:06 +09001548 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001549 // multilib.both
1550 addDependenciesForNativeModules(ctx,
1551 ApexNativeDependencies{
1552 Native_shared_libs: a.properties.Native_shared_libs,
1553 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001554 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001555 Binaries: nil,
1556 },
Jooyung Han85d61762020-06-24 23:50:26 +09001557 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001558
Jiyong Park397e55e2018-10-24 21:09:55 +09001559 // Add native modules targetting both ABIs
1560 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001561 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001562 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001563 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001564
Alex Light3d673592019-01-18 14:37:31 -08001565 isPrimaryAbi := i == 0
1566 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001567 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001568 // multilib.first
1569 addDependenciesForNativeModules(ctx,
1570 ApexNativeDependencies{
1571 Native_shared_libs: nil,
1572 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001573 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001574 Binaries: a.properties.Binaries,
1575 },
Jooyung Han85d61762020-06-24 23:50:26 +09001576 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001577
1578 // Add native modules targetting the first ABI
1579 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001580 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001581 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001582 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001583 }
1584
1585 switch target.Arch.ArchType.Multilib {
1586 case "lib32":
1587 // Add native modules targetting 32-bit ABI
1588 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001589 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001590 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001591 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001592
1593 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001594 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001595 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001596 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001597 case "lib64":
1598 // Add native modules targetting 64-bit ABI
1599 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001600 a.properties.Multilib.Lib64,
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 if !has32BitTarget {
1605 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001606 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001607 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001608 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001609 }
1610 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001611 }
1612
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001613 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1614 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1615 // b/144532908
1616 archForPrebuiltEtc := config.Arches()[0]
1617 for _, arch := range config.Arches() {
1618 // Prefer 64-bit arch if there is any
1619 if arch.ArchType.Multilib == "lib64" {
1620 archForPrebuiltEtc = arch
1621 break
1622 }
1623 }
1624 ctx.AddFarVariationDependencies([]blueprint.Variation{
1625 {Mutator: "os", Variation: ctx.Os().String()},
1626 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1627 }, prebuiltTag, a.properties.Prebuilts...)
1628
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001629 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1630 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001631
markchien2f59ec92020-09-02 16:23:38 +08001632 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1633 bpfTag, a.properties.Bpfs...)
1634
Ulya Trafimovich44561882020-01-03 13:25:54 +00001635 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1636 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1637 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1638 javaLibTag, "jacocoagent")
1639 }
1640
Jiyong Park23c52b02019-02-02 13:13:47 +09001641 if String(a.properties.Key) == "" {
1642 ctx.ModuleErrorf("key is missing")
1643 return
1644 }
1645 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001646
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001647 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001648 if cert != "" {
1649 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001650 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001651
1652 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1653 if len(a.properties.Uses_sdks) > 0 {
1654 sdkRefs := []android.SdkRef{}
1655 for _, str := range a.properties.Uses_sdks {
1656 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1657 sdkRefs = append(sdkRefs, parsed)
1658 }
1659 a.BuildWithSdks(sdkRefs)
1660 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001661}
1662
Jiyong Park5d790c32019-11-15 18:40:32 +09001663func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001664 if a.overridableProperties.Allowed_files != nil {
1665 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1666 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001667 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1668 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001669 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1670 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001671}
1672
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001673func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1674 // direct deps of an APEX bundle are all part of the APEX bundle
1675 return true
1676}
1677
Colin Cross0ea8ba82019-06-06 14:33:29 -07001678func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001679 moduleName := ctx.ModuleName()
1680 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1681 // we check with the pseudo module name to see if its certificate is overridden.
1682 if a.vndkApex {
1683 moduleName = vndkApexName
1684 }
1685 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001686 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001687 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001688 }
1689 return String(a.properties.Certificate)
1690}
1691
Colin Cross41955e82019-05-29 14:40:35 -07001692func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1693 switch tag {
1694 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001695 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001696 default:
1697 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001698 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001699}
1700
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001701func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001702 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001703}
1704
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001705func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1706 return proptools.Bool(a.properties.Test_only_no_hashtree)
1707}
1708
Dario Frenica913392020-04-27 18:21:11 +01001709func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1710 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1711}
1712
Jooyung Han85d61762020-06-24 23:50:26 +09001713func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1714 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001715 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001716 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001717 }
Jooyung Han85d61762020-06-24 23:50:26 +09001718
1719 var prefix string
1720 var vndkVersion string
1721 if deviceConfig.VndkVersion() != "" {
1722 if proptools.Bool(a.properties.Use_vendor) {
1723 prefix = cc.VendorVariationPrefix
1724 vndkVersion = deviceConfig.PlatformVndkVersion()
1725 } else if a.SocSpecific() || a.DeviceSpecific() {
1726 prefix = cc.VendorVariationPrefix
1727 vndkVersion = deviceConfig.VndkVersion()
1728 } else if a.ProductSpecific() {
1729 prefix = cc.ProductVariationPrefix
1730 vndkVersion = deviceConfig.ProductVndkVersion()
1731 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001732 }
Jooyung Han85d61762020-06-24 23:50:26 +09001733 if vndkVersion == "current" {
1734 vndkVersion = deviceConfig.PlatformVndkVersion()
1735 }
1736 if vndkVersion != "" {
1737 return prefix + vndkVersion
1738 }
1739 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001740}
1741
Jiyong Parkf97782b2019-02-13 20:28:58 +09001742func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1743 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1744 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1745 }
1746}
1747
Jiyong Park388ef3f2019-01-28 19:47:32 +09001748func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001749 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1750 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001751 }
1752
1753 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001754 globalSanitizerNames := []string{}
1755 if a.Host() {
1756 globalSanitizerNames = ctx.Config().SanitizeHost()
1757 } else {
1758 arches := ctx.Config().SanitizeDeviceArch()
1759 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1760 globalSanitizerNames = ctx.Config().SanitizeDevice()
1761 }
1762 }
1763 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001764}
1765
Jooyung Han8ce8db92020-05-15 19:05:05 +09001766func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1767 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1768 for _, target := range ctx.MultiTargets() {
1769 if target.Arch.ArchType.Multilib == "lib64" {
1770 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001771 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001772 {Mutator: "link", Variation: "shared"},
1773 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1774 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1775 break
1776 }
1777 }
1778 }
1779}
1780
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001781var _ cc.Coverage = (*apexBundle)(nil)
1782
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001783func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001784 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001785}
1786
1787func (a *apexBundle) PreventInstall() {
1788 a.properties.PreventInstall = true
1789}
1790
1791func (a *apexBundle) HideFromMake() {
1792 a.properties.HideFromMake = true
1793}
1794
Jiyong Park956305c2020-01-09 12:32:06 +09001795func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1796 a.properties.IsCoverageVariant = coverage
1797}
1798
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001799func (a *apexBundle) EnableCoverageIfNeeded() {}
1800
Jiyong Parkf653b052019-11-18 15:39:01 +09001801// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001802func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001803 // Decide the APEX-local directory by the multilib of the library
1804 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001805 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001806 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001807 case "lib32":
1808 dirInApex = "lib"
1809 case "lib64":
1810 dirInApex = "lib64"
1811 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001812 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001813 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001814 }
Jooyung Han35155c42020-02-06 17:33:20 +09001815 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001816 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001817 // Special case for Bionic libs and other libs installed with them. This is
1818 // to prevent those libs from being included in the search path
1819 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1820 // those libs in the Runtime APEX are available via the legacy paths in
1821 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1822 // to the legacy paths and thus will be loaded into the default linker
1823 // namespace (aka "platform" namespace). If the libs are directly in
1824 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1825 // into the runtime linker namespace, which will result in double loading of
1826 // them, which isn't supported.
1827 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001828 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001829
Jiyong Parkf653b052019-11-18 15:39:01 +09001830 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001831 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1832 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001833}
1834
Jiyong Park1833cef2019-12-13 13:28:36 +09001835func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001836 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001837 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001838 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001839 }
Jooyung Han35155c42020-02-06 17:33:20 +09001840 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001841 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001842 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1843 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001844 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001845 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001847}
1848
Jiyong Park1833cef2019-12-13 13:28:36 +09001849func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001850 dirInApex := "bin"
1851 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001852 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001853}
Jiyong Park1833cef2019-12-13 13:28:36 +09001854func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001855 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001856 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1857 if err != nil {
1858 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001859 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001860 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001861 fileToCopy := android.PathForOutput(ctx, s)
1862 // NB: Since go binaries are static we don't need the module for anything here, which is
1863 // good since the go tool is a blueprint.Module not an android.Module like we would
1864 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001865 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001866}
1867
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001868func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001869 dirInApex := filepath.Join("bin", sh.SubDir())
1870 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001871 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001872 af.symlinks = sh.Symlinks()
1873 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001874}
1875
Yo Chiange8128052020-07-23 20:09:18 +08001876type javaModule interface {
1877 android.Module
1878 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001879 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001880 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001881 LintDepSets() java.LintDepSets
1882
Jiyong Parka62aa232020-05-28 23:46:55 +09001883 Stem() string
1884}
1885
Yo Chiange8128052020-07-23 20:09:18 +08001886var _ javaModule = (*java.Library)(nil)
1887var _ javaModule = (*java.SdkLibrary)(nil)
1888var _ javaModule = (*java.DexImport)(nil)
1889var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001890
Yo Chiange8128052020-07-23 20:09:18 +08001891func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001892 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001893 fileToCopy := module.DexJarBuildPath()
1894 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1895 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1896 af.lintDepSets = module.LintDepSets()
1897 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001898 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001899}
1900
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001901func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001902 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001903 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001904 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001905}
1906
atrost6e126252020-01-27 17:01:16 +00001907func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1908 dirInApex := filepath.Join("etc", config.SubDir())
1909 fileToCopy := config.CompatConfig()
1910 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1911}
1912
Jiyong Park1833cef2019-12-13 13:28:36 +09001913func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001914 android.Module
1915 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001916 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001917 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001918 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001919 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001920 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001921}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001922 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001923 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001924 appDir = "priv-app"
1925 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001926 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001927 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001928 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001929 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001930 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001931
1932 if app, ok := aapp.(interface {
1933 OverriddenManifestPackageName() string
1934 }); ok {
1935 af.overriddenPackageName = app.OverriddenManifestPackageName()
1936 }
Jiyong Park618922e2020-01-08 13:35:43 +09001937 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001938}
1939
Jiyong Park69aeba92020-04-24 21:16:36 +09001940func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1941 rroDir := "overlay"
1942 dirInApex := filepath.Join(rroDir, rro.Theme())
1943 fileToCopy := rro.OutputFile()
1944 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1945 af.certificate = rro.Certificate()
1946
1947 if a, ok := rro.(interface {
1948 OverriddenManifestPackageName() string
1949 }); ok {
1950 af.overriddenPackageName = a.OverriddenManifestPackageName()
1951 }
1952 return af
1953}
1954
markchien2f59ec92020-09-02 16:23:38 +08001955func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1956 dirInApex := filepath.Join("etc", "bpf")
1957 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1958}
1959
Roland Levillain935639d2019-08-13 14:55:28 +01001960// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1961type flattenedApexContext struct {
1962 android.ModuleContext
1963}
1964
1965func (c *flattenedApexContext) InstallBypassMake() bool {
1966 return true
1967}
1968
Jiyong Park201cedd2020-02-07 17:25:49 +09001969// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001970func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001971 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001972 am, ok := child.(android.ApexModule)
1973 if !ok || !am.CanHaveApexVariants() {
1974 return false
1975 }
1976
Colin Cross56a83212020-09-15 18:30:11 -07001977 childApexInfo := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1978
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001979 dt := ctx.OtherModuleDependencyTag(child)
1980
1981 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1982 return false
1983 }
1984
Jiyong Park0f80c182020-01-31 02:49:53 +09001985 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001986 if adt, ok := dt.(dependencyTag); ok {
1987 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001988 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001989 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001990 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001991 return false
1992 }
1993
1994 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Cross56a83212020-09-15 18:30:11 -07001995 if android.InList(ctx.ModuleName(), childApexInfo.InApexes) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001996 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001997 }
1998
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001999 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002000 })
2001}
2002
Dan Albertc8060532020-07-22 22:32:17 -07002003func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
Jooyung Han749dc692020-04-15 11:03:39 +09002004 ver := proptools.String(a.properties.Min_sdk_version)
2005 if ver == "" {
Dan Albert0b176c82020-07-23 16:43:25 -07002006 return android.FutureApiLevel
Jooyung Han749dc692020-04-15 11:03:39 +09002007 }
Dan Albertc8060532020-07-22 22:32:17 -07002008 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
Jooyung Hanaed150d2020-04-02 01:41:41 +09002009 if err != nil {
2010 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Dan Albertc8060532020-07-22 22:32:17 -07002011 return android.NoneApiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002012 }
Dan Albertc8060532020-07-22 22:32:17 -07002013 if apiLevel.IsPreview() {
2014 // All codenames should build against "current".
Dan Albert0b176c82020-07-23 16:43:25 -07002015 return android.FutureApiLevel
Dan Albertc8060532020-07-22 22:32:17 -07002016 }
2017 return apiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002018}
2019
Artur Satayev849f8442020-04-28 14:57:42 +01002020func (a *apexBundle) Updatable() bool {
2021 return proptools.Bool(a.properties.Updatable)
2022}
2023
2024var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
2025
Jiyong Park201cedd2020-02-07 17:25:49 +09002026// Ensures that the dependencies are marked as available for this APEX
2027func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2028 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2029 if ctx.Host() || a.testApex || a.vndkApex {
2030 return
2031 }
2032
Jooyung Han85d61762020-06-24 23:50:26 +09002033 // Because APEXes targeting other than system/system_ext partitions
2034 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09002035 if a.SocSpecific() || a.DeviceSpecific() ||
2036 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002037 return
2038 }
2039
Jiyong Park58d10902020-03-28 14:43:19 +09002040 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2041 // Requiring them and their transitive depencies with apex_available is not right
2042 // because they just add noise.
2043 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2044 return
2045 }
2046
Jooyung Han749dc692020-04-15 11:03:39 +09002047 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002048 if externalDep {
2049 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2050 return false
2051 }
2052
Jiyong Park201cedd2020-02-07 17:25:49 +09002053 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002054 fromName := ctx.OtherModuleName(from)
2055 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01002056
2057 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2058 // do any of its dependencies.
2059 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2060 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2061 return false
2062 }
2063
Colin Cross440e0d02020-06-11 11:32:11 -07002064 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002065 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002066 }
Steven Moreland6e36cd62020-10-22 01:08:35 +00002067 ctx.ModuleErrorf("%q requires %q that doesn't list the APEX under 'apex_available'. Dependency path:%s", fromName, toName, ctx.GetPathString(true))
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002068 // Visit this module's dependencies to check and report any issues with their availability.
2069 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002070 })
2071}
2072
Jooyung Han548640b2020-04-27 12:10:30 +09002073func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01002074 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09002075 if String(a.properties.Min_sdk_version) == "" {
2076 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2077 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01002078
2079 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002080 }
2081}
2082
Jooyung Han749dc692020-04-15 11:03:39 +09002083func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2084 if a.testApex || a.vndkApex {
2085 return
2086 }
2087 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
2088 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
2089 return
2090 }
Dan Albertc8060532020-07-22 22:32:17 -07002091 // apexBundle::minSdkVersion reports its own errors.
2092 minSdkVersion := a.minSdkVersion(ctx)
2093 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002094}
2095
Jiyong Park7d95a512020-05-10 15:16:24 +09002096// Ensures that a lib providing stub isn't statically linked
2097func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2098 // Practically, we only care about regular APEXes on the device.
2099 if ctx.Host() || a.testApex || a.vndkApex {
2100 return
2101 }
2102
Colin Cross56a83212020-09-15 18:30:11 -07002103 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2104
Jooyung Han749dc692020-04-15 11:03:39 +09002105 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09002106 if ccm, ok := to.(*cc.Module); ok {
2107 apexName := ctx.ModuleName()
2108 fromName := ctx.OtherModuleName(from)
2109 toName := ctx.OtherModuleName(to)
2110
2111 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2112 // do any of its dependencies.
2113 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2114 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2115 return false
2116 }
2117
Jiyong Park7d95a512020-05-10 15:16:24 +09002118 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
2119 // It can't make the static dependencies dynamic because it can't
2120 // do the dynamic linking for itself.
2121 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2122 return false
2123 }
2124
Colin Cross56a83212020-09-15 18:30:11 -07002125 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
Jiyong Park7d95a512020-05-10 15:16:24 +09002126 if isStubLibraryFromOtherApex && !externalDep {
2127 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2128 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2129 }
2130
2131 }
2132 return true
2133 })
2134}
2135
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002136func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01002137 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09002138 switch a.properties.ApexType {
2139 case imageApex:
2140 if buildFlattenedAsDefault {
2141 a.suffix = imageApexSuffix
2142 } else {
2143 a.suffix = ""
2144 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002145
2146 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002147 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002148 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002149 }
2150 case zipApex:
2151 if proptools.String(a.properties.Payload_type) == "zip" {
2152 a.suffix = ""
2153 a.primaryApexType = true
2154 } else {
2155 a.suffix = zipApexSuffix
2156 }
2157 case flattenedApex:
2158 if buildFlattenedAsDefault {
2159 a.suffix = ""
2160 a.primaryApexType = true
2161 } else {
2162 a.suffix = flattenedSuffix
2163 }
Alex Light5098a612018-11-29 17:12:15 -08002164 }
2165
Roland Levillain630846d2019-06-26 12:48:34 +01002166 if len(a.properties.Tests) > 0 && !a.testApex {
2167 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2168 return
2169 }
2170
Jiyong Park0f80c182020-01-31 02:49:53 +09002171 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002172 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002173 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002174 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002175
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002176 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2177
Jooyung Hane1633032019-08-01 17:41:43 +09002178 // native lib dependencies
2179 var provideNativeLibs []string
2180 var requireNativeLibs []string
2181
Jooyung Han5c998b92019-06-27 11:30:33 +09002182 // Check if "uses" requirements are met with dependent apexBundles
2183 var providedNativeSharedLibs []string
2184 useVendor := proptools.Bool(a.properties.Use_vendor)
2185 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2186 if ctx.OtherModuleDependencyTag(m) != usesTag {
2187 return
2188 }
2189 otherName := ctx.OtherModuleName(m)
2190 other, ok := m.(*apexBundle)
2191 if !ok {
2192 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2193 return
2194 }
2195 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2196 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2197 return
2198 }
2199 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2200 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2201 return
2202 }
2203 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2204 })
2205
Jiyong Parkf653b052019-11-18 15:39:01 +09002206 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002207 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002208 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002209 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002210 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2211 return false
2212 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002213 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002214 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002215 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002216 case sharedLibTag, jniLibTag:
2217 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002218 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002219 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2220 fi.isJniLib = isJniLib
2221 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002222 // Collect the list of stub-providing libs except:
2223 // - VNDK libs are only for vendors
2224 // - bootstrap bionic libs are treated as provided by system
2225 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002226 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2227 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002228 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002229 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002230 propertyName := "native_shared_libs"
2231 if isJniLib {
2232 propertyName = "jni_libs"
2233 }
2234 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002235 }
2236 case executableTag:
2237 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002238 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002239 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002240 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002241 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002242 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002243 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002244 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002245 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002246 } else {
Alex Light778127a2019-02-27 14:19:50 -08002247 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 +09002248 }
2249 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002250 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002251 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002252 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002253 if !af.Ok() {
2254 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2255 return false
2256 }
2257 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002258 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002259 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002260 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002261 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002262 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002263 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002264 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002265 return true // track transitive dependencies
2266 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002267 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002268 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002269 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002270 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2271 appDir := "app"
2272 if ap.Privileged() {
2273 appDir = "priv-app"
2274 }
Yo Chiange8128052020-07-23 20:09:18 +08002275 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002276 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2277 af.certificate = java.PresignedCertificate
2278 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002279 } else {
2280 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2281 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002282 case rroTag:
2283 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2284 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2285 } else {
2286 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2287 }
markchien2f59ec92020-09-02 16:23:38 +08002288 case bpfTag:
2289 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2290 filesToCopy, _ := bpfProgram.OutputFiles("")
2291 for _, bpfFile := range filesToCopy {
2292 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2293 }
2294 } else {
2295 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2296 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002297 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002298 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002299 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002300 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2301 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002302 } else {
atrost6e126252020-01-27 17:01:16 +00002303 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002304 }
Roland Levillain630846d2019-06-26 12:48:34 +01002305 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002306 if ccTest, ok := child.(*cc.Module); ok {
2307 if ccTest.IsTestPerSrcAllTestsVariation() {
2308 // Multiple-output test module (where `test_per_src: true`).
2309 //
2310 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2311 // We do not add this variation to `filesInfo`, as it has no output;
2312 // however, we do add the other variations of this module as indirect
2313 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002314 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002315 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002316 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002317 af.class = nativeTest
2318 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002319 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002320 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002321 } else {
2322 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2323 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002324 case keyTag:
2325 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002326 a.private_key_file = key.private_key_file
2327 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002328 } else {
2329 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002330 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002331 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002332 case certificateTag:
2333 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002334 a.container_certificate_file = dep.Certificate.Pem
2335 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002336 } else {
2337 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2338 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002339 case android.PrebuiltDepTag:
2340 // If the prebuilt is force disabled, remember to delete the prebuilt file
2341 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002342 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002343 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2344 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002345 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002346 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002347 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002348 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002349 // We cannot use a switch statement on `depTag` here as the checked
2350 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002351 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002352 if cc, ok := child.(*cc.Module); ok {
2353 if android.InList(cc.Name(), providedNativeSharedLibs) {
2354 // If we're using a shared library which is provided from other APEX,
2355 // don't include it in this APEX
2356 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002357 }
Jooyung Handf78e212020-07-22 15:54:47 +09002358 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002359 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002360 return false
2361 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002362 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2363 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07002364 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2365 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002366 // If the dependency is a stubs lib, don't include it in this APEX,
2367 // but make sure that the lib is installed on the device.
2368 // In case no APEX is having the lib, the lib is installed to the system
2369 // partition.
2370 //
2371 // Always include if we are a host-apex however since those won't have any
2372 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002373 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002374 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07002375 name := cc.ImplementationModuleName(ctx)
2376
2377 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002378 // we don't use subName(.vendor) for a "use_vendor: true" apex
2379 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07002380 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002381 }
2382 if !android.InList(name, a.requiredDeps) {
2383 a.requiredDeps = append(a.requiredDeps, name)
2384 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002385 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002386 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002387 // Don't track further
2388 return false
2389 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002390 filesInfo = append(filesInfo, af)
2391 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002392 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002393 } else if cc.IsTestPerSrcDepTag(depTag) {
2394 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002395 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002396 // Handle modules created as `test_per_src` variations of a single test module:
2397 // use the name of the generated test binary (`fileToCopy`) instead of the name
2398 // of the original test module (`depName`, shared by all `test_per_src`
2399 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002400 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002401 // these are not considered transitive dep
2402 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002403 filesInfo = append(filesInfo, af)
2404 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002405 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002406 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002407 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2408 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002409 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002410 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002411 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2412 }
Colin Cross56a83212020-09-15 18:30:11 -07002413 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2414 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002415 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002416 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002417 }
2418 }
2419 }
2420 return false
2421 })
2422
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002423 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2424 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2425 // via the global boot image config.
2426 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002427 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002428 dirInApex := filepath.Join("javalib", arch.String())
2429 for _, f := range files {
2430 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002431 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002432 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002433 }
2434 }
2435 }
2436
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002437 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002438 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2439 return
2440 }
2441
Jiyong Park8fd61922018-11-08 02:50:25 +09002442 // remove duplicates in filesInfo
2443 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002444 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002445 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002446 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002447 if e, ok := encountered[dest]; !ok {
2448 encountered[dest] = f
2449 } else {
2450 // If a module is directly included and also transitively depended on
2451 // consider it as directly included.
2452 e.transitiveDep = e.transitiveDep && f.transitiveDep
2453 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002454 }
2455 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002456 var result []apexFile
2457 for _, v := range encountered {
2458 result = append(result, v)
2459 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002460 return result
2461 }
2462 filesInfo = removeDup(filesInfo)
2463
2464 // to have consistent build rules
2465 sort.Slice(filesInfo, func(i, j int) bool {
2466 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2467 })
2468
Jiyong Park8fd61922018-11-08 02:50:25 +09002469 a.installDir = android.PathForModuleInstall(ctx, "apex")
2470 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002471
Theotime Combes4ba38c12020-06-12 12:46:59 +00002472 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2473 case ext4FsType:
2474 a.payloadFsType = ext4
2475 case f2fsFsType:
2476 a.payloadFsType = f2fs
2477 default:
2478 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
2479 }
2480
Jiyong Park7cd10e32020-01-14 09:22:18 +09002481 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2482 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2483 // the same library in the system partition, thus effectively sharing the same libraries
2484 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2485 // in the APEX.
2486 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2487 a.installable() &&
2488 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002489
Jooyung Han85d61762020-06-24 23:50:26 +09002490 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2491 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002492 if a.SocSpecific() || a.DeviceSpecific() ||
2493 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002494 a.linkToSystemLib = false
2495 }
2496
Jiyong Park9d677202020-02-19 16:29:35 +09002497 // We don't need the optimization for updatable APEXes, as it might give false signal
2498 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002499 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002500 a.linkToSystemLib = false
2501 }
2502
Jiyong Park638d30e2020-02-26 18:27:19 +09002503 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2504 if ctx.Host() {
2505 a.linkToSystemLib = false
2506 }
2507
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002508 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002509 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2510
Jooyung Han580eb4f2020-06-24 19:33:06 +09002511 a.buildFileContexts(ctx)
2512
Jooyung Han01a3ee22019-11-02 02:52:25 +09002513 a.setCertificateAndPrivateKey(ctx)
2514 if a.properties.ApexType == flattenedApex {
2515 a.buildFlattenedApex(ctx)
2516 } else {
2517 a.buildUnflattenedApex(ctx)
2518 }
2519
Jooyung Han002ab682020-01-08 01:57:58 +09002520 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002521
2522 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002523
2524 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002525}
2526
Artur Satayev8cf899a2020-04-15 17:29:42 +01002527// Enforce that Java deps of the apex are using stable SDKs to compile
2528func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2529 // Visit direct deps only. As long as we guarantee top-level deps are using
2530 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2531 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2532 tag := ctx.OtherModuleDependencyTag(module)
2533 switch tag {
2534 case javaLibTag, androidAppTag:
2535 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2536 if err := m.CheckStableSdkVersion(); err != nil {
2537 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2538 }
2539 }
2540 }
2541 })
2542}
2543
Colin Cross440e0d02020-06-11 11:32:11 -07002544func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002545 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002546 moduleName = normalizeModuleName(moduleName)
2547
Colin Cross440e0d02020-06-11 11:32:11 -07002548 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002549 return true
2550 }
2551
2552 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002553 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002554 return true
2555 }
2556
2557 return false
2558}
2559
2560func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002561 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2562 // system. Trim the prefix for the check since they are confusing
2563 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2564 if strings.HasPrefix(moduleName, "libclang_rt.") {
2565 // This module has many arch variants that depend on the product being built.
2566 // We don't want to list them all
2567 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002568 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002569 if strings.HasPrefix(moduleName, "androidx.") {
2570 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2571 moduleName = "androidx"
2572 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002573 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002574}
2575
Jooyung Han344d5432019-08-23 11:17:39 +09002576func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002577 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002578 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002579 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002580 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002581 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002582 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002583 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002584 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002585 return module
2586}
Jiyong Park30ca9372019-02-07 16:27:23 +09002587
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002588func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002589 bundle := newApexBundle()
2590 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002591 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002592 return bundle
2593}
2594
Jiyong Parkfce0b422020-02-11 03:56:06 +09002595// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2596// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002597func testApexBundleFactory() android.Module {
2598 bundle := newApexBundle()
2599 bundle.testApex = true
2600 return bundle
2601}
2602
Jiyong Parkfce0b422020-02-11 03:56:06 +09002603// apex packages other modules into an APEX file which is a packaging format for system-level
2604// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002605func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002606 return newApexBundle()
2607}
2608
Jiyong Park30ca9372019-02-07 16:27:23 +09002609//
2610// Defaults
2611//
2612type Defaults struct {
2613 android.ModuleBase
2614 android.DefaultsModuleBase
2615}
2616
Jiyong Park30ca9372019-02-07 16:27:23 +09002617func defaultsFactory() android.Module {
2618 return DefaultsFactory()
2619}
2620
2621func DefaultsFactory(props ...interface{}) android.Module {
2622 module := &Defaults{}
2623
2624 module.AddProperties(props...)
2625 module.AddProperties(
2626 &apexBundleProperties{},
2627 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002628 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002629 )
2630
2631 android.InitDefaultsModule(module)
2632 return module
2633}
Jiyong Park5d790c32019-11-15 18:40:32 +09002634
2635//
2636// OverrideApex
2637//
2638type OverrideApex struct {
2639 android.ModuleBase
2640 android.OverrideModuleBase
2641}
2642
2643func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2644 // All the overrides happen in the base module.
2645}
2646
2647// override_apex is used to create an apex module based on another apex module
2648// by overriding some of its properties.
2649func overrideApexFactory() android.Module {
2650 m := &OverrideApex{}
2651 m.AddProperties(&overridableProperties{})
2652
2653 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2654 android.InitOverrideModule(m)
2655 return m
2656}