blob: 8268966547c58f8ba08325423179a55439f2eeb7 [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
Anton Hansson82d502a2020-11-11 12:33:14 +00001480
1481 distFiles android.TaggedDistFiles
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001482}
1483
Jiyong Park397e55e2018-10-24 21:09:55 +09001484func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Jooyung Han01a868d2020-02-27 13:40:44 +09001485 nativeModules ApexNativeDependencies,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001486 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001487 // Use *FarVariation* to be able to depend on modules having
1488 // conflicting variations with this module. This is required since
1489 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1490 // for native shared libs.
Jiyong Park397e55e2018-10-24 21:09:55 +09001491
Colin Cross42507332020-08-21 16:15:23 -07001492 binVariations := target.Variations()
1493 libVariations := append(target.Variations(),
1494 blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han643adc42020-02-27 13:50:06 +09001495
Colin Cross42507332020-08-21 16:15:23 -07001496 if ctx.Device() {
1497 binVariations = append(binVariations,
1498 blueprint.Variation{Mutator: "image", Variation: imageVariation})
1499 libVariations = append(libVariations,
1500 blueprint.Variation{Mutator: "image", Variation: imageVariation},
1501 blueprint.Variation{Mutator: "version", Variation: ""}) // "" is the non-stub variant
Colin Cross42507332020-08-21 16:15:23 -07001502 }
Roland Levillain630846d2019-06-26 12:48:34 +01001503
Colin Cross42507332020-08-21 16:15:23 -07001504 ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...)
1505
1506 ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...)
1507
1508 ctx.AddFarVariationDependencies(binVariations, executableTag, nativeModules.Binaries...)
1509
Colin Cross90dab342020-08-21 15:55:50 -07001510 ctx.AddFarVariationDependencies(binVariations, testTag, nativeModules.Tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001511}
1512
Alex Light9670d332019-01-29 18:07:33 -08001513func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1514 if ctx.Os().Class == android.Device {
1515 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1516 } else {
1517 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1518 if ctx.Os().Bionic() {
1519 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1520 } else {
1521 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1522 }
1523 }
1524}
1525
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001526func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross440e0d02020-06-11 11:32:11 -07001527 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001528 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1529 }
1530
Jiyong Park397e55e2018-10-24 21:09:55 +09001531 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001532 config := ctx.DeviceConfig()
Jooyung Han85d61762020-06-24 23:50:26 +09001533 imageVariation := a.getImageVariation(ctx)
Alex Light9670d332019-01-29 18:07:33 -08001534
1535 a.combineProperties(ctx)
1536
Jiyong Park397e55e2018-10-24 21:09:55 +09001537 has32BitTarget := false
1538 for _, target := range targets {
1539 if target.Arch.ArchType.Multilib == "lib32" {
1540 has32BitTarget = true
1541 }
1542 }
1543 for i, target := range targets {
Jiyong Parkccb406f2020-09-29 10:58:10 +09001544 if target.HostCross {
1545 // Don't include artifats for the host cross targets because there is no way
1546 // for us to run those artifacts natively on host
1547 continue
1548 }
1549
Jooyung Han643adc42020-02-27 13:50:06 +09001550 // When multilib.* is omitted for native_shared_libs/jni_libs/tests, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001551 // multilib.both
1552 addDependenciesForNativeModules(ctx,
1553 ApexNativeDependencies{
1554 Native_shared_libs: a.properties.Native_shared_libs,
1555 Tests: a.properties.Tests,
Jooyung Han643adc42020-02-27 13:50:06 +09001556 Jni_libs: a.properties.Jni_libs,
Jooyung Han01a868d2020-02-27 13:40:44 +09001557 Binaries: nil,
1558 },
Jooyung Han85d61762020-06-24 23:50:26 +09001559 target, imageVariation)
Roland Levillain630846d2019-06-26 12:48:34 +01001560
Jiyong Park397e55e2018-10-24 21:09:55 +09001561 // Add native modules targetting both ABIs
1562 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001563 a.properties.Multilib.Both,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001564 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001565 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001566
Alex Light3d673592019-01-18 14:37:31 -08001567 isPrimaryAbi := i == 0
1568 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001569 // When multilib.* is omitted for binaries, it implies
Jooyung Han01a868d2020-02-27 13:40:44 +09001570 // multilib.first
1571 addDependenciesForNativeModules(ctx,
1572 ApexNativeDependencies{
1573 Native_shared_libs: nil,
1574 Tests: nil,
Jooyung Han643adc42020-02-27 13:50:06 +09001575 Jni_libs: nil,
Jooyung Han01a868d2020-02-27 13:40:44 +09001576 Binaries: a.properties.Binaries,
1577 },
Jooyung Han85d61762020-06-24 23:50:26 +09001578 target, imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001579
1580 // Add native modules targetting the first ABI
1581 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001582 a.properties.Multilib.First,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001583 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001584 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001585 }
1586
1587 switch target.Arch.ArchType.Multilib {
1588 case "lib32":
1589 // Add native modules targetting 32-bit ABI
1590 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001591 a.properties.Multilib.Lib32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001592 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001593 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001594
1595 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001596 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001597 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001598 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001599 case "lib64":
1600 // Add native modules targetting 64-bit ABI
1601 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001602 a.properties.Multilib.Lib64,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001603 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001604 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001605
1606 if !has32BitTarget {
1607 addDependenciesForNativeModules(ctx,
Jooyung Han01a868d2020-02-27 13:40:44 +09001608 a.properties.Multilib.Prefer32,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001609 target,
Jooyung Han85d61762020-06-24 23:50:26 +09001610 imageVariation)
Jiyong Park397e55e2018-10-24 21:09:55 +09001611 }
1612 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001613 }
1614
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001615 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1616 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1617 // b/144532908
1618 archForPrebuiltEtc := config.Arches()[0]
1619 for _, arch := range config.Arches() {
1620 // Prefer 64-bit arch if there is any
1621 if arch.ArchType.Multilib == "lib64" {
1622 archForPrebuiltEtc = arch
1623 break
1624 }
1625 }
1626 ctx.AddFarVariationDependencies([]blueprint.Variation{
1627 {Mutator: "os", Variation: ctx.Os().String()},
1628 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1629 }, prebuiltTag, a.properties.Prebuilts...)
1630
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001631 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1632 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001633
markchien2f59ec92020-09-02 16:23:38 +08001634 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1635 bpfTag, a.properties.Bpfs...)
1636
Ulya Trafimovich44561882020-01-03 13:25:54 +00001637 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1638 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1639 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1640 javaLibTag, "jacocoagent")
1641 }
1642
Jiyong Park23c52b02019-02-02 13:13:47 +09001643 if String(a.properties.Key) == "" {
1644 ctx.ModuleErrorf("key is missing")
1645 return
1646 }
1647 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001648
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001649 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001650 if cert != "" {
1651 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001652 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001653
1654 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1655 if len(a.properties.Uses_sdks) > 0 {
1656 sdkRefs := []android.SdkRef{}
1657 for _, str := range a.properties.Uses_sdks {
1658 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1659 sdkRefs = append(sdkRefs, parsed)
1660 }
1661 a.BuildWithSdks(sdkRefs)
1662 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001663}
1664
Jiyong Park5d790c32019-11-15 18:40:32 +09001665func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Han938b5932020-06-20 12:47:47 +09001666 if a.overridableProperties.Allowed_files != nil {
1667 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1668 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001669 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1670 androidAppTag, a.overridableProperties.Apps...)
Jiyong Park69aeba92020-04-24 21:16:36 +09001671 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1672 rroTag, a.overridableProperties.Rros...)
Jiyong Park5d790c32019-11-15 18:40:32 +09001673}
1674
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001675func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1676 // direct deps of an APEX bundle are all part of the APEX bundle
1677 return true
1678}
1679
Colin Cross0ea8ba82019-06-06 14:33:29 -07001680func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001681 moduleName := ctx.ModuleName()
1682 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1683 // we check with the pseudo module name to see if its certificate is overridden.
1684 if a.vndkApex {
1685 moduleName = vndkApexName
1686 }
1687 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001688 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001689 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001690 }
1691 return String(a.properties.Certificate)
1692}
1693
Colin Cross41955e82019-05-29 14:40:35 -07001694func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1695 switch tag {
1696 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001697 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001698 default:
1699 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001700 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001701}
1702
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001703func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001704 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001705}
1706
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001707func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1708 return proptools.Bool(a.properties.Test_only_no_hashtree)
1709}
1710
Dario Frenica913392020-04-27 18:21:11 +01001711func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1712 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1713}
1714
Jooyung Han85d61762020-06-24 23:50:26 +09001715func (a *apexBundle) getImageVariation(ctx android.BottomUpMutatorContext) string {
1716 deviceConfig := ctx.DeviceConfig()
Jooyung Han31c470b2019-10-18 16:26:59 +09001717 if a.vndkApex {
Jooyung Han85d61762020-06-24 23:50:26 +09001718 return cc.VendorVariationPrefix + a.vndkVersion(deviceConfig)
Jooyung Han31c470b2019-10-18 16:26:59 +09001719 }
Jooyung Han85d61762020-06-24 23:50:26 +09001720
1721 var prefix string
1722 var vndkVersion string
1723 if deviceConfig.VndkVersion() != "" {
1724 if proptools.Bool(a.properties.Use_vendor) {
1725 prefix = cc.VendorVariationPrefix
1726 vndkVersion = deviceConfig.PlatformVndkVersion()
1727 } else if a.SocSpecific() || a.DeviceSpecific() {
1728 prefix = cc.VendorVariationPrefix
1729 vndkVersion = deviceConfig.VndkVersion()
1730 } else if a.ProductSpecific() {
1731 prefix = cc.ProductVariationPrefix
1732 vndkVersion = deviceConfig.ProductVndkVersion()
1733 }
Jiyong Parkda6eb592018-12-19 17:12:36 +09001734 }
Jooyung Han85d61762020-06-24 23:50:26 +09001735 if vndkVersion == "current" {
1736 vndkVersion = deviceConfig.PlatformVndkVersion()
1737 }
1738 if vndkVersion != "" {
1739 return prefix + vndkVersion
1740 }
1741 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001742}
1743
Jiyong Parkf97782b2019-02-13 20:28:58 +09001744func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1745 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1746 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1747 }
1748}
1749
Jiyong Park388ef3f2019-01-28 19:47:32 +09001750func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001751 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1752 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001753 }
1754
1755 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001756 globalSanitizerNames := []string{}
1757 if a.Host() {
1758 globalSanitizerNames = ctx.Config().SanitizeHost()
1759 } else {
1760 arches := ctx.Config().SanitizeDeviceArch()
1761 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1762 globalSanitizerNames = ctx.Config().SanitizeDevice()
1763 }
1764 }
1765 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001766}
1767
Jooyung Han8ce8db92020-05-15 19:05:05 +09001768func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
1769 if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
1770 for _, target := range ctx.MultiTargets() {
1771 if target.Arch.ArchType.Multilib == "lib64" {
1772 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jooyung Han85d61762020-06-24 23:50:26 +09001773 {Mutator: "image", Variation: a.getImageVariation(ctx)},
Jooyung Han8ce8db92020-05-15 19:05:05 +09001774 {Mutator: "link", Variation: "shared"},
1775 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
1776 }...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
1777 break
1778 }
1779 }
1780 }
1781}
1782
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001783var _ cc.Coverage = (*apexBundle)(nil)
1784
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001785func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross1a6acd42020-06-16 17:51:46 -07001786 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001787}
1788
1789func (a *apexBundle) PreventInstall() {
1790 a.properties.PreventInstall = true
1791}
1792
1793func (a *apexBundle) HideFromMake() {
1794 a.properties.HideFromMake = true
1795}
1796
Jiyong Park956305c2020-01-09 12:32:06 +09001797func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1798 a.properties.IsCoverageVariant = coverage
1799}
1800
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001801func (a *apexBundle) EnableCoverageIfNeeded() {}
1802
Jiyong Parkf653b052019-11-18 15:39:01 +09001803// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001804func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001805 // Decide the APEX-local directory by the multilib of the library
1806 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001807 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001808 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001809 case "lib32":
1810 dirInApex = "lib"
1811 case "lib64":
1812 dirInApex = "lib64"
1813 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001814 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001815 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001816 }
Jooyung Han35155c42020-02-06 17:33:20 +09001817 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Jiyong Park1833cef2019-12-13 13:28:36 +09001818 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001819 // Special case for Bionic libs and other libs installed with them. This is
1820 // to prevent those libs from being included in the search path
1821 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1822 // those libs in the Runtime APEX are available via the legacy paths in
1823 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1824 // to the legacy paths and thus will be loaded into the default linker
1825 // namespace (aka "platform" namespace). If the libs are directly in
1826 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1827 // into the runtime linker namespace, which will result in double loading of
1828 // them, which isn't supported.
1829 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001830 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001831
Jiyong Parkf653b052019-11-18 15:39:01 +09001832 fileToCopy := ccMod.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001833 androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
1834 return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001835}
1836
Jiyong Park1833cef2019-12-13 13:28:36 +09001837func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jooyung Han35155c42020-02-06 17:33:20 +09001838 dirInApex := "bin"
Colin Cross3b19f5d2019-09-17 14:45:31 -07001839 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001840 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001841 }
Jooyung Han35155c42020-02-06 17:33:20 +09001842 dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001843 fileToCopy := cc.OutputFile().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001844 androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
1845 af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001846 af.symlinks = cc.Symlinks()
Liz Kammer1c14a212020-05-12 15:26:55 -07001847 af.dataPaths = cc.DataPaths()
Jiyong Parkf653b052019-11-18 15:39:01 +09001848 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001849}
1850
Jiyong Park1833cef2019-12-13 13:28:36 +09001851func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001852 dirInApex := "bin"
1853 fileToCopy := py.HostToolPath().Path()
Yo Chiange8128052020-07-23 20:09:18 +08001854 return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001855}
Jiyong Park1833cef2019-12-13 13:28:36 +09001856func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001857 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001858 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1859 if err != nil {
1860 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001861 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001862 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001863 fileToCopy := android.PathForOutput(ctx, s)
1864 // NB: Since go binaries are static we don't need the module for anything here, which is
1865 // good since the go tool is a blueprint.Module not an android.Module like we would
1866 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001867 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001868}
1869
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001870func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001871 dirInApex := filepath.Join("bin", sh.SubDir())
1872 fileToCopy := sh.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001873 af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001874 af.symlinks = sh.Symlinks()
1875 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001876}
1877
Yo Chiange8128052020-07-23 20:09:18 +08001878type javaModule interface {
1879 android.Module
1880 BaseModuleName() string
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001881 DexJarBuildPath() android.Path
Jiyong Park77acec62020-06-01 21:39:15 +09001882 JacocoReportClassesFile() android.Path
Colin Cross08dca382020-07-21 20:31:17 -07001883 LintDepSets() java.LintDepSets
1884
Jiyong Parka62aa232020-05-28 23:46:55 +09001885 Stem() string
1886}
1887
Yo Chiange8128052020-07-23 20:09:18 +08001888var _ javaModule = (*java.Library)(nil)
1889var _ javaModule = (*java.SdkLibrary)(nil)
1890var _ javaModule = (*java.DexImport)(nil)
1891var _ javaModule = (*java.SdkLibraryImport)(nil)
Colin Cross08dca382020-07-21 20:31:17 -07001892
Yo Chiange8128052020-07-23 20:09:18 +08001893func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001894 dirInApex := "javalib"
Yo Chiange8128052020-07-23 20:09:18 +08001895 fileToCopy := module.DexJarBuildPath()
1896 af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
1897 af.jacocoReportClassesFile = module.JacocoReportClassesFile()
1898 af.lintDepSets = module.LintDepSets()
1899 af.stem = module.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001900 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001901}
1902
Jaewoong Jung4b79e982020-06-01 10:45:49 -07001903func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jooyung Han0703fd82020-08-26 22:11:53 +09001904 dirInApex := filepath.Join(prebuilt.BaseDir(), prebuilt.SubDir())
Jiyong Parkf653b052019-11-18 15:39:01 +09001905 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001906 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001907}
1908
atrost6e126252020-01-27 17:01:16 +00001909func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1910 dirInApex := filepath.Join("etc", config.SubDir())
1911 fileToCopy := config.CompatConfig()
1912 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1913}
1914
Jiyong Park1833cef2019-12-13 13:28:36 +09001915func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001916 android.Module
1917 Privileged() bool
Jooyung Han39ee1192020-03-23 20:21:11 +09001918 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001919 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001920 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001921 Certificate() java.Certificate
Yo Chiange8128052020-07-23 20:09:18 +08001922 BaseModuleName() string
Jooyung Han39ee1192020-03-23 20:21:11 +09001923}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001924 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001925 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001926 appDir = "priv-app"
1927 }
Jooyung Han39ee1192020-03-23 20:21:11 +09001928 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001929 fileToCopy := aapp.OutputFile()
Yo Chiange8128052020-07-23 20:09:18 +08001930 af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
Jiyong Park618922e2020-01-08 13:35:43 +09001931 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001932 af.certificate = aapp.Certificate()
Jiyong Parkcfaa1642020-02-28 16:51:07 +09001933
1934 if app, ok := aapp.(interface {
1935 OverriddenManifestPackageName() string
1936 }); ok {
1937 af.overriddenPackageName = app.OverriddenManifestPackageName()
1938 }
Jiyong Park618922e2020-01-08 13:35:43 +09001939 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001940}
1941
Jiyong Park69aeba92020-04-24 21:16:36 +09001942func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.RuntimeResourceOverlayModule) apexFile {
1943 rroDir := "overlay"
1944 dirInApex := filepath.Join(rroDir, rro.Theme())
1945 fileToCopy := rro.OutputFile()
1946 af := newApexFile(ctx, fileToCopy, rro.Name(), dirInApex, app, rro)
1947 af.certificate = rro.Certificate()
1948
1949 if a, ok := rro.(interface {
1950 OverriddenManifestPackageName() string
1951 }); ok {
1952 af.overriddenPackageName = a.OverriddenManifestPackageName()
1953 }
1954 return af
1955}
1956
markchien2f59ec92020-09-02 16:23:38 +08001957func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1958 dirInApex := filepath.Join("etc", "bpf")
1959 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1960}
1961
Roland Levillain935639d2019-08-13 14:55:28 +01001962// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1963type flattenedApexContext struct {
1964 android.ModuleContext
1965}
1966
1967func (c *flattenedApexContext) InstallBypassMake() bool {
1968 return true
1969}
1970
Jiyong Park201cedd2020-02-07 17:25:49 +09001971// Visit dependencies that contributes to the payload of this APEX
Jooyung Han749dc692020-04-15 11:03:39 +09001972func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.PayloadDepsCallback) {
Paul Duffindf915ff2020-03-30 17:58:21 +01001973 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001974 am, ok := child.(android.ApexModule)
1975 if !ok || !am.CanHaveApexVariants() {
1976 return false
1977 }
1978
Colin Cross56a83212020-09-15 18:30:11 -07001979 childApexInfo := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
1980
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001981 dt := ctx.OtherModuleDependencyTag(child)
1982
1983 if _, ok := dt.(android.ExcludeFromApexContentsTag); ok {
1984 return false
1985 }
1986
Jiyong Park0f80c182020-01-31 02:49:53 +09001987 // Check for the direct dependencies that contribute to the payload
Martin Stjernholm58c33f02020-07-06 22:56:01 +01001988 if adt, ok := dt.(dependencyTag); ok {
1989 if adt.payload {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001990 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001991 }
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001992 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Park0f80c182020-01-31 02:49:53 +09001993 return false
1994 }
1995
1996 // Check for the indirect dependencies if it is considered as part of the APEX
Colin Cross56a83212020-09-15 18:30:11 -07001997 if android.InList(ctx.ModuleName(), childApexInfo.InApexes) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01001998 return do(ctx, parent, am, false /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09001999 }
2000
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002001 return do(ctx, parent, am, true /* externalDep */)
Jiyong Park0f80c182020-01-31 02:49:53 +09002002 })
2003}
2004
Dan Albertc8060532020-07-22 22:32:17 -07002005func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
Jooyung Han749dc692020-04-15 11:03:39 +09002006 ver := proptools.String(a.properties.Min_sdk_version)
2007 if ver == "" {
Dan Albert0b176c82020-07-23 16:43:25 -07002008 return android.FutureApiLevel
Jooyung Han749dc692020-04-15 11:03:39 +09002009 }
Dan Albertc8060532020-07-22 22:32:17 -07002010 apiLevel, err := android.ApiLevelFromUser(ctx, ver)
Jooyung Hanaed150d2020-04-02 01:41:41 +09002011 if err != nil {
2012 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Dan Albertc8060532020-07-22 22:32:17 -07002013 return android.NoneApiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002014 }
Dan Albertc8060532020-07-22 22:32:17 -07002015 if apiLevel.IsPreview() {
2016 // All codenames should build against "current".
Dan Albert0b176c82020-07-23 16:43:25 -07002017 return android.FutureApiLevel
Dan Albertc8060532020-07-22 22:32:17 -07002018 }
2019 return apiLevel
Jooyung Han03b51852020-02-26 22:45:42 +09002020}
2021
Artur Satayev849f8442020-04-28 14:57:42 +01002022func (a *apexBundle) Updatable() bool {
2023 return proptools.Bool(a.properties.Updatable)
2024}
2025
2026var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
2027
Jiyong Park201cedd2020-02-07 17:25:49 +09002028// Ensures that the dependencies are marked as available for this APEX
2029func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
2030 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
2031 if ctx.Host() || a.testApex || a.vndkApex {
2032 return
2033 }
2034
Jooyung Han85d61762020-06-24 23:50:26 +09002035 // Because APEXes targeting other than system/system_ext partitions
2036 // can't set apex_available, we skip checks for these APEXes
Jooyung Handf78e212020-07-22 15:54:47 +09002037 if a.SocSpecific() || a.DeviceSpecific() ||
2038 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002039 return
2040 }
2041
Jiyong Park58d10902020-03-28 14:43:19 +09002042 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
2043 // Requiring them and their transitive depencies with apex_available is not right
2044 // because they just add noise.
2045 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
2046 return
2047 }
2048
Jooyung Han749dc692020-04-15 11:03:39 +09002049 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002050 if externalDep {
2051 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2052 return false
2053 }
2054
Jiyong Park201cedd2020-02-07 17:25:49 +09002055 apexName := ctx.ModuleName()
Jooyung Han5e9013b2020-03-10 06:23:13 +09002056 fromName := ctx.OtherModuleName(from)
2057 toName := ctx.OtherModuleName(to)
Paul Duffin65347702020-03-31 15:23:40 +01002058
2059 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2060 // do any of its dependencies.
2061 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2062 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2063 return false
2064 }
2065
Colin Cross440e0d02020-06-11 11:32:11 -07002066 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffinbe5a5be2020-03-30 15:54:08 +01002067 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002068 }
Steven Moreland6e36cd62020-10-22 01:08:35 +00002069 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 +01002070 // Visit this module's dependencies to check and report any issues with their availability.
2071 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09002072 })
2073}
2074
Jooyung Han548640b2020-04-27 12:10:30 +09002075func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +01002076 if a.Updatable() {
Jooyung Han548640b2020-04-27 12:10:30 +09002077 if String(a.properties.Min_sdk_version) == "" {
2078 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
2079 }
Artur Satayev8cf899a2020-04-15 17:29:42 +01002080
2081 a.checkJavaStableSdkVersion(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002082 }
2083}
2084
Jooyung Han749dc692020-04-15 11:03:39 +09002085func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
2086 if a.testApex || a.vndkApex {
2087 return
2088 }
2089 // Meaningless to check min_sdk_version when building use_vendor modules against non-Trebleized targets
2090 if proptools.Bool(a.properties.Use_vendor) && ctx.DeviceConfig().VndkVersion() == "" {
2091 return
2092 }
Dan Albertc8060532020-07-22 22:32:17 -07002093 // apexBundle::minSdkVersion reports its own errors.
2094 minSdkVersion := a.minSdkVersion(ctx)
2095 android.CheckMinSdkVersion(a, ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002096}
2097
Jiyong Park7d95a512020-05-10 15:16:24 +09002098// Ensures that a lib providing stub isn't statically linked
2099func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext) {
2100 // Practically, we only care about regular APEXes on the device.
2101 if ctx.Host() || a.testApex || a.vndkApex {
2102 return
2103 }
2104
Colin Cross56a83212020-09-15 18:30:11 -07002105 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2106
Jooyung Han749dc692020-04-15 11:03:39 +09002107 a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
Jiyong Park7d95a512020-05-10 15:16:24 +09002108 if ccm, ok := to.(*cc.Module); ok {
2109 apexName := ctx.ModuleName()
2110 fromName := ctx.OtherModuleName(from)
2111 toName := ctx.OtherModuleName(to)
2112
2113 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
2114 // do any of its dependencies.
2115 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
2116 // As soon as the dependency graph crosses the APEX boundary, don't go further.
2117 return false
2118 }
2119
Jiyong Park7d95a512020-05-10 15:16:24 +09002120 // The dynamic linker and crash_dump tool in the runtime APEX is the only exception to this rule.
2121 // It can't make the static dependencies dynamic because it can't
2122 // do the dynamic linking for itself.
2123 if apexName == "com.android.runtime" && (fromName == "linker" || fromName == "crash_dump") {
2124 return false
2125 }
2126
Colin Cross56a83212020-09-15 18:30:11 -07002127 isStubLibraryFromOtherApex := ccm.HasStubsVariants() && !abInfo.Contents.DirectlyInApex(toName)
Jiyong Park7d95a512020-05-10 15:16:24 +09002128 if isStubLibraryFromOtherApex && !externalDep {
2129 ctx.ModuleErrorf("%q required by %q is a native library providing stub. "+
2130 "It shouldn't be included in this APEX via static linking. Dependency path: %s", to.String(), fromName, ctx.GetPathString(false))
2131 }
2132
2133 }
2134 return true
2135 })
2136}
2137
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002138func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Martin Stjernholm56507b42020-06-24 22:31:36 +01002139 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuildApps()
Sundong Ahnabb64432019-10-22 13:58:29 +09002140 switch a.properties.ApexType {
2141 case imageApex:
2142 if buildFlattenedAsDefault {
2143 a.suffix = imageApexSuffix
2144 } else {
2145 a.suffix = ""
2146 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002147
2148 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09002149 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002150 }
Sundong Ahnabb64432019-10-22 13:58:29 +09002151 }
2152 case zipApex:
2153 if proptools.String(a.properties.Payload_type) == "zip" {
2154 a.suffix = ""
2155 a.primaryApexType = true
2156 } else {
2157 a.suffix = zipApexSuffix
2158 }
2159 case flattenedApex:
2160 if buildFlattenedAsDefault {
2161 a.suffix = ""
2162 a.primaryApexType = true
2163 } else {
2164 a.suffix = flattenedSuffix
2165 }
Alex Light5098a612018-11-29 17:12:15 -08002166 }
2167
Roland Levillain630846d2019-06-26 12:48:34 +01002168 if len(a.properties.Tests) > 0 && !a.testApex {
2169 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
2170 return
2171 }
2172
Jiyong Park0f80c182020-01-31 02:49:53 +09002173 a.checkApexAvailability(ctx)
Jooyung Han548640b2020-04-27 12:10:30 +09002174 a.checkUpdatable(ctx)
Jooyung Han749dc692020-04-15 11:03:39 +09002175 a.checkMinSdkVersion(ctx)
Jiyong Park7d95a512020-05-10 15:16:24 +09002176 a.checkStaticLinkingToStubLibraries(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09002177
Alex Lightfc0bd7c2019-01-29 18:31:59 -08002178 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
2179
Jooyung Hane1633032019-08-01 17:41:43 +09002180 // native lib dependencies
2181 var provideNativeLibs []string
2182 var requireNativeLibs []string
2183
Jooyung Han5c998b92019-06-27 11:30:33 +09002184 // Check if "uses" requirements are met with dependent apexBundles
2185 var providedNativeSharedLibs []string
2186 useVendor := proptools.Bool(a.properties.Use_vendor)
2187 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2188 if ctx.OtherModuleDependencyTag(m) != usesTag {
2189 return
2190 }
2191 otherName := ctx.OtherModuleName(m)
2192 other, ok := m.(*apexBundle)
2193 if !ok {
2194 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2195 return
2196 }
2197 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2198 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2199 return
2200 }
2201 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2202 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2203 return
2204 }
2205 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2206 })
2207
Jiyong Parkf653b052019-11-18 15:39:01 +09002208 var filesInfo []apexFile
Jooyung Han749dc692020-04-15 11:03:39 +09002209 // TODO(jiyong) do this using WalkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002210 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002211 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffindddd5462020-04-07 15:25:44 +01002212 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2213 return false
2214 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002215 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002216 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002217 switch depTag {
Jooyung Han643adc42020-02-27 13:50:06 +09002218 case sharedLibTag, jniLibTag:
2219 isJniLib := depTag == jniLibTag
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002220 if c, ok := child.(*cc.Module); ok {
Jooyung Han643adc42020-02-27 13:50:06 +09002221 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2222 fi.isJniLib = isJniLib
2223 filesInfo = append(filesInfo, fi)
Jooyung Han45a96772020-06-15 14:59:42 +09002224 // Collect the list of stub-providing libs except:
2225 // - VNDK libs are only for vendors
2226 // - bootstrap bionic libs are treated as provided by system
2227 if c.HasStubsVariants() && !a.vndkApex && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002228 provideNativeLibs = append(provideNativeLibs, fi.Stem())
2229 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002230 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002231 } else {
Jooyung Han643adc42020-02-27 13:50:06 +09002232 propertyName := "native_shared_libs"
2233 if isJniLib {
2234 propertyName = "jni_libs"
2235 }
2236 ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002237 }
2238 case executableTag:
2239 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002240 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002241 return true // track transitive dependencies
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002242 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002243 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002244 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002245 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002246 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002247 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002248 } else {
Alex Light778127a2019-02-27 14:19:50 -08002249 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 +09002250 }
2251 case javaLibTag:
Jiyong Park77acec62020-06-01 21:39:15 +09002252 switch child.(type) {
Paul Duffineedc5d52020-06-12 17:46:39 +01002253 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Yo Chiange8128052020-07-23 20:09:18 +08002254 af := apexFileForJavaLibrary(ctx, child.(javaModule))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002255 if !af.Ok() {
2256 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2257 return false
2258 }
2259 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002260 return true // track transitive dependencies
Jiyong Park77acec62020-06-01 21:39:15 +09002261 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002262 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002263 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002264 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002265 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002266 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002267 return true // track transitive dependencies
2268 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002269 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002270 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han39ee1192020-03-23 20:21:11 +09002271 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002272 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2273 appDir := "app"
2274 if ap.Privileged() {
2275 appDir = "priv-app"
2276 }
Yo Chiange8128052020-07-23 20:09:18 +08002277 af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
Sasha Smundak18d98bc2020-05-27 16:36:07 -07002278 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2279 af.certificate = java.PresignedCertificate
2280 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002281 } else {
2282 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2283 }
Jiyong Park69aeba92020-04-24 21:16:36 +09002284 case rroTag:
2285 if rro, ok := child.(java.RuntimeResourceOverlayModule); ok {
2286 filesInfo = append(filesInfo, apexFileForRuntimeResourceOverlay(ctx, rro))
2287 } else {
2288 ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
2289 }
markchien2f59ec92020-09-02 16:23:38 +08002290 case bpfTag:
2291 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2292 filesToCopy, _ := bpfProgram.OutputFiles("")
2293 for _, bpfFile := range filesToCopy {
2294 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2295 }
2296 } else {
2297 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2298 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002299 case prebuiltTag:
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002300 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002301 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002302 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2303 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002304 } else {
atrost6e126252020-01-27 17:01:16 +00002305 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002306 }
Roland Levillain630846d2019-06-26 12:48:34 +01002307 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002308 if ccTest, ok := child.(*cc.Module); ok {
2309 if ccTest.IsTestPerSrcAllTestsVariation() {
2310 // Multiple-output test module (where `test_per_src: true`).
2311 //
2312 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2313 // We do not add this variation to `filesInfo`, as it has no output;
2314 // however, we do add the other variations of this module as indirect
2315 // dependencies (see below).
Roland Levillain9b5fde92019-06-28 15:41:19 +01002316 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002317 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002318 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002319 af.class = nativeTest
2320 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002321 }
Jiyong Parkaf9539f2020-05-04 10:31:32 +09002322 return true // track transitive dependencies
Roland Levillain630846d2019-06-26 12:48:34 +01002323 } else {
2324 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2325 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002326 case keyTag:
2327 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002328 a.private_key_file = key.private_key_file
2329 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002330 } else {
2331 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002332 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002333 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002334 case certificateTag:
2335 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002336 a.container_certificate_file = dep.Certificate.Pem
2337 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002338 } else {
2339 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2340 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002341 case android.PrebuiltDepTag:
2342 // If the prebuilt is force disabled, remember to delete the prebuilt file
2343 // that might have been installed in the previous builds
Jiyong Park10e926b2020-07-16 21:38:56 +09002344 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002345 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2346 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002347 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002348 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002349 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002350 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002351 // We cannot use a switch statement on `depTag` here as the checked
2352 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002353 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002354 if cc, ok := child.(*cc.Module); ok {
2355 if android.InList(cc.Name(), providedNativeSharedLibs) {
2356 // If we're using a shared library which is provided from other APEX,
2357 // don't include it in this APEX
2358 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002359 }
Jooyung Handf78e212020-07-22 15:54:47 +09002360 if cc.UseVndk() && proptools.Bool(a.properties.Use_vndk_as_stable) && cc.IsVndk() {
Jooyung Han6c4cc9c2020-07-29 16:00:54 +09002361 requireNativeLibs = append(requireNativeLibs, ":vndk")
Jooyung Handf78e212020-07-22 15:54:47 +09002362 return false
2363 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002364 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2365 af.transitiveDep = true
Colin Cross56a83212020-09-15 18:30:11 -07002366 abInfo := ctx.Provider(ApexBundleInfoProvider).(ApexBundleInfo)
2367 if !a.Host() && !abInfo.Contents.DirectlyInApex(depName) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002368 // If the dependency is a stubs lib, don't include it in this APEX,
2369 // but make sure that the lib is installed on the device.
2370 // In case no APEX is having the lib, the lib is installed to the system
2371 // partition.
2372 //
2373 // Always include if we are a host-apex however since those won't have any
2374 // system libraries.
Colin Cross56a83212020-09-15 18:30:11 -07002375 if !am.DirectlyInAnyApex() {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002376 // we need a module name for Make
Colin Cross0477b422020-10-13 18:43:54 -07002377 name := cc.ImplementationModuleName(ctx)
2378
2379 if !proptools.Bool(a.properties.Use_vendor) {
Jooyung Hanefb184e2020-06-25 17:14:25 +09002380 // we don't use subName(.vendor) for a "use_vendor: true" apex
2381 // which is supposed to be installed in /system
Colin Cross0477b422020-10-13 18:43:54 -07002382 name += cc.Properties.SubName
Jooyung Hanefb184e2020-06-25 17:14:25 +09002383 }
2384 if !android.InList(name, a.requiredDeps) {
2385 a.requiredDeps = append(a.requiredDeps, name)
2386 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002387 }
Jiyong Parkf1493cc2020-05-29 21:29:20 +09002388 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002389 // Don't track further
2390 return false
2391 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002392 filesInfo = append(filesInfo, af)
2393 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002394 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002395 } else if cc.IsTestPerSrcDepTag(depTag) {
2396 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002397 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002398 // Handle modules created as `test_per_src` variations of a single test module:
2399 // use the name of the generated test binary (`fileToCopy`) instead of the name
2400 // of the original test module (`depName`, shared by all `test_per_src`
2401 // variations of that module).
Yo Chiange8128052020-07-23 20:09:18 +08002402 af.androidMkModuleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002403 // these are not considered transitive dep
2404 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002405 filesInfo = append(filesInfo, af)
2406 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002407 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002408 } else if java.IsJniDepTag(depTag) {
Jooyung Hanb7bebe22020-02-25 16:59:29 +09002409 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2410 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002411 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jung4b79e982020-06-01 10:45:49 -07002412 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002413 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2414 }
Colin Cross56a83212020-09-15 18:30:11 -07002415 } else if _, ok := depTag.(android.CopyDirectlyInAnyApexTag); ok {
2416 // nothing
Jooyung Han9c80bae2019-08-20 17:30:57 +09002417 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Jiyong Park1c7e9622020-05-07 16:12:13 +09002418 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", android.PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002419 }
2420 }
2421 }
2422 return false
2423 })
2424
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002425 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2426 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2427 // via the global boot image config.
2428 if a.artApex {
Tim Joinesc1ef1bb2020-03-18 18:00:41 +00002429 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002430 dirInApex := filepath.Join("javalib", arch.String())
2431 for _, f := range files {
2432 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002433 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002434 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002435 }
2436 }
2437 }
2438
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002439 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002440 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2441 return
2442 }
2443
Jiyong Park8fd61922018-11-08 02:50:25 +09002444 // remove duplicates in filesInfo
2445 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002446 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002447 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002448 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002449 if e, ok := encountered[dest]; !ok {
2450 encountered[dest] = f
2451 } else {
2452 // If a module is directly included and also transitively depended on
2453 // consider it as directly included.
2454 e.transitiveDep = e.transitiveDep && f.transitiveDep
2455 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002456 }
2457 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002458 var result []apexFile
2459 for _, v := range encountered {
2460 result = append(result, v)
2461 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002462 return result
2463 }
2464 filesInfo = removeDup(filesInfo)
2465
2466 // to have consistent build rules
2467 sort.Slice(filesInfo, func(i, j int) bool {
2468 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2469 })
2470
Jiyong Park8fd61922018-11-08 02:50:25 +09002471 a.installDir = android.PathForModuleInstall(ctx, "apex")
2472 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002473
Theotime Combes4ba38c12020-06-12 12:46:59 +00002474 switch proptools.StringDefault(a.properties.Payload_fs_type, ext4FsType) {
2475 case ext4FsType:
2476 a.payloadFsType = ext4
2477 case f2fsFsType:
2478 a.payloadFsType = f2fs
2479 default:
2480 ctx.PropertyErrorf("payload_fs_type", "%q is not a valid filesystem for apex [ext4, f2fs]", *a.properties.Payload_fs_type)
2481 }
2482
Jiyong Park7cd10e32020-01-14 09:22:18 +09002483 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2484 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2485 // the same library in the system partition, thus effectively sharing the same libraries
2486 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2487 // in the APEX.
2488 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2489 a.installable() &&
2490 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002491
Jooyung Han85d61762020-06-24 23:50:26 +09002492 // APEXes targeting other than system/system_ext partitions use vendor/product variants.
2493 // So we can't link them to /system/lib libs which are core variants.
Jooyung Handf78e212020-07-22 15:54:47 +09002494 if a.SocSpecific() || a.DeviceSpecific() ||
2495 (a.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
Jooyung Han85d61762020-06-24 23:50:26 +09002496 a.linkToSystemLib = false
2497 }
2498
Jiyong Park9d677202020-02-19 16:29:35 +09002499 // We don't need the optimization for updatable APEXes, as it might give false signal
2500 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev849f8442020-04-28 14:57:42 +01002501 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002502 a.linkToSystemLib = false
2503 }
2504
Jiyong Park638d30e2020-02-26 18:27:19 +09002505 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2506 if ctx.Host() {
2507 a.linkToSystemLib = false
2508 }
2509
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002510 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002511 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2512
Jooyung Han580eb4f2020-06-24 19:33:06 +09002513 a.buildFileContexts(ctx)
2514
Jooyung Han01a3ee22019-11-02 02:52:25 +09002515 a.setCertificateAndPrivateKey(ctx)
2516 if a.properties.ApexType == flattenedApex {
2517 a.buildFlattenedApex(ctx)
2518 } else {
2519 a.buildUnflattenedApex(ctx)
2520 }
2521
Jooyung Han002ab682020-01-08 01:57:58 +09002522 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002523
2524 a.buildApexDependencyInfo(ctx)
Colin Cross08dca382020-07-21 20:31:17 -07002525
2526 a.buildLintReports(ctx)
Anton Hansson82d502a2020-11-11 12:33:14 +00002527
2528 a.distFiles = a.GenerateTaggedDistFiles(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002529}
2530
Artur Satayev8cf899a2020-04-15 17:29:42 +01002531// Enforce that Java deps of the apex are using stable SDKs to compile
2532func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2533 // Visit direct deps only. As long as we guarantee top-level deps are using
2534 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2535 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2536 tag := ctx.OtherModuleDependencyTag(module)
2537 switch tag {
2538 case javaLibTag, androidAppTag:
2539 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2540 if err := m.CheckStableSdkVersion(); err != nil {
2541 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2542 }
2543 }
2544 }
2545 })
2546}
2547
Colin Cross440e0d02020-06-11 11:32:11 -07002548func baselineApexAvailable(apex, moduleName string) bool {
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002549 key := apex
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002550 moduleName = normalizeModuleName(moduleName)
2551
Colin Cross440e0d02020-06-11 11:32:11 -07002552 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002553 return true
2554 }
2555
2556 key = android.AvailableToAnyApex
Colin Cross440e0d02020-06-11 11:32:11 -07002557 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002558 return true
2559 }
2560
2561 return false
2562}
2563
2564func normalizeModuleName(moduleName string) string {
Jiyong Park0f80c182020-01-31 02:49:53 +09002565 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2566 // system. Trim the prefix for the check since they are confusing
2567 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2568 if strings.HasPrefix(moduleName, "libclang_rt.") {
2569 // This module has many arch variants that depend on the product being built.
2570 // We don't want to list them all
2571 moduleName = "libclang_rt"
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002572 }
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09002573 if strings.HasPrefix(moduleName, "androidx.") {
2574 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2575 moduleName = "androidx"
2576 }
Paul Duffin7d74e7b2020-03-06 12:30:13 +00002577 return moduleName
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002578}
2579
Jooyung Han344d5432019-08-23 11:17:39 +09002580func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002581 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002582 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002583 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002584 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002585 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002586 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002587 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002588 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002589 return module
2590}
Jiyong Park30ca9372019-02-07 16:27:23 +09002591
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002592func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002593 bundle := newApexBundle()
2594 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002595 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002596 return bundle
2597}
2598
Jiyong Parkfce0b422020-02-11 03:56:06 +09002599// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2600// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002601func testApexBundleFactory() android.Module {
2602 bundle := newApexBundle()
2603 bundle.testApex = true
2604 return bundle
2605}
2606
Jiyong Parkfce0b422020-02-11 03:56:06 +09002607// apex packages other modules into an APEX file which is a packaging format for system-level
2608// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002609func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002610 return newApexBundle()
2611}
2612
Jiyong Park30ca9372019-02-07 16:27:23 +09002613//
2614// Defaults
2615//
2616type Defaults struct {
2617 android.ModuleBase
2618 android.DefaultsModuleBase
2619}
2620
Jiyong Park30ca9372019-02-07 16:27:23 +09002621func defaultsFactory() android.Module {
2622 return DefaultsFactory()
2623}
2624
2625func DefaultsFactory(props ...interface{}) android.Module {
2626 module := &Defaults{}
2627
2628 module.AddProperties(props...)
2629 module.AddProperties(
2630 &apexBundleProperties{},
2631 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002632 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002633 )
2634
2635 android.InitDefaultsModule(module)
2636 return module
2637}
Jiyong Park5d790c32019-11-15 18:40:32 +09002638
2639//
2640// OverrideApex
2641//
2642type OverrideApex struct {
2643 android.ModuleBase
2644 android.OverrideModuleBase
2645}
2646
2647func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2648 // All the overrides happen in the base module.
2649}
2650
2651// override_apex is used to create an apex module based on another apex module
2652// by overriding some of its properties.
2653func overrideApexFactory() android.Module {
2654 m := &OverrideApex{}
2655 m.AddProperties(&overridableProperties{})
2656
2657 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2658 android.InitOverrideModule(m)
2659 return m
2660}