blob: 7da8e1cf2154a1c9c58c800629cf0847658135ec [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"
Jooyung Han54aca7b2019-11-20 02:26:02 +090019 "path"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090020 "path/filepath"
Paul Duffinf0207962020-03-31 11:31:36 +010021 "regexp"
Jiyong Parkab3ceb32018-10-10 14:05:29 +090022 "sort"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090023 "strings"
Jooyung Han344d5432019-08-23 11:17:39 +090024 "sync"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090025
Jiyong Park48ca7dc2018-10-10 14:01:00 +090026 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080027 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090028 "github.com/google/blueprint/proptools"
Jaewoong Jungfccad6b2020-06-01 10:45:49 -070029
30 "android/soong/android"
31 "android/soong/cc"
32 prebuilt_etc "android/soong/etc"
33 "android/soong/java"
34 "android/soong/python"
35 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090036)
37
Jooyung Han72bd2f82019-10-23 16:46:38 +090038const (
39 imageApexSuffix = ".apex"
40 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090041 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080042
Sundong Ahnabb64432019-10-22 13:58:29 +090043 imageApexType = "image"
44 zipApexType = "zip"
45 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090046)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090047
48type dependencyTag struct {
49 blueprint.BaseDependencyTag
50 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090051
52 // determines if the dependent will be part of the APEX payload
53 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090054}
55
56var (
Jiyong Parkfa899442020-01-31 02:49:53 +090057 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
58 executableTag = dependencyTag{name: "executable", payload: true}
59 javaLibTag = dependencyTag{name: "javaLib", payload: true}
60 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
61 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090062 keyTag = dependencyTag{name: "key"}
63 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090064 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090065 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Paul Duffin404db3f2020-03-06 12:30:13 +000066
Colin Cross95f7b342020-06-11 11:32:11 -070067 apexAvailBaseline = makeApexAvailableBaseline()
68
69 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090070)
71
Paul Duffin404db3f2020-03-06 12:30:13 +000072// Transform the map of apex -> modules to module -> apexes.
Colin Cross95f7b342020-06-11 11:32:11 -070073func invertApexBaseline(m map[string][]string) map[string][]string {
Paul Duffin404db3f2020-03-06 12:30:13 +000074 r := make(map[string][]string)
75 for apex, modules := range m {
76 for _, module := range modules {
77 r[module] = append(r[module], apex)
78 }
79 }
80 return r
81}
82
Colin Cross95f7b342020-06-11 11:32:11 -070083// Retrieve the baseline of apexes to which the supplied module belongs.
84func BaselineApexAvailable(moduleName string) []string {
85 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
Paul Duffin404db3f2020-03-06 12:30:13 +000086}
87
Anton Hansson5053c292020-01-10 15:12:39 +000088// This is a map from apex to modules, which overrides the
89// apex_available setting for that particular module to make
90// it available for the apex regardless of its setting.
91// TODO(b/147364041): remove this
Colin Cross95f7b342020-06-11 11:32:11 -070092func makeApexAvailableBaseline() map[string][]string {
Anton Hansson5053c292020-01-10 15:12:39 +000093 // The "Module separator"s below are employed to minimize merge conflicts.
94 m := make(map[string][]string)
95 //
96 // Module separator
97 //
Jiyong Park8b399192020-04-29 22:34:13 +090098 m["com.android.appsearch"] = []string{
99 "icing-java-proto-lite",
100 "libprotobuf-java-lite",
Anton Hansson5053c292020-01-10 15:12:39 +0000101 }
102 //
103 // Module separator
104 //
105 m["com.android.bluetooth.updatable"] = []string{
106 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000107 "android.hardware.bluetooth.a2dp@1.0",
108 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 "android.hardware.bluetooth@1.0",
110 "android.hardware.bluetooth@1.1",
111 "android.hardware.graphics.bufferqueue@1.0",
112 "android.hardware.graphics.bufferqueue@2.0",
113 "android.hardware.graphics.common@1.0",
114 "android.hardware.graphics.common@1.1",
115 "android.hardware.graphics.common@1.2",
116 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000117 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900118 "android.hidl.token@1.0",
119 "android.hidl.token@1.0-utils",
120 "avrcp-target-service",
121 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900122 "bluetooth-protos-lite",
123 "bluetooth.mapsapi",
124 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900125 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900126 "ipmemorystore-aidl-interfaces-V5-java",
127 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900128 "internal_include_headers",
129 "lib-bt-packets",
130 "lib-bt-packets-avrcp",
131 "lib-bt-packets-base",
132 "libFraunhoferAAC",
133 "libaudio-a2dp-hw-utils",
134 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900135 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000136 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libbluetooth-types",
138 "libbluetooth-types-header",
139 "libbluetooth_gd",
140 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000141 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900142 "libbt-audio-hal-interface",
143 "libbt-bta",
144 "libbt-common",
145 "libbt-hci",
146 "libbt-platform-protos-lite",
147 "libbt-protos-lite",
148 "libbt-sbc-decoder",
149 "libbt-sbc-encoder",
150 "libbt-stack",
151 "libbt-utils",
152 "libbtcore",
153 "libbtdevice",
154 "libbte",
155 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000156 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000157 "libevent",
158 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900160 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libmedia_headers",
162 "libmodpb64",
163 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900164 "libstagefright_foundation_headers",
165 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000166 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900167 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000168 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900169 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000170 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900172 "net-utils-services-common",
173 "netd_aidl_interface-unstable-java",
174 "netd_event_listener_interface-java",
175 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900176 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900177 "sap-api-java-static",
178 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000179 }
180 //
181 // Module separator
182 //
183 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
184 //
185 // Module separator
186 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900187 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900189 }
Anton Hansson5053c292020-01-10 15:12:39 +0000190 //
191 // Module separator
192 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900193 m["com.android.extservices"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900194 "error_prone_annotations",
195 "ExtServices-core",
196 "ExtServices",
197 "libtextclassifier-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900198 "libz_current",
Jooyung Han11c20932020-05-19 15:47:01 +0900199 "textclassifier-statsd",
200 "TextClassifierNotificationLibNoManifest",
201 "TextClassifierServiceLibNoManifest",
Jiyong Parkfa899442020-01-31 02:49:53 +0900202 }
203 //
204 // Module separator
205 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900206 m["com.android.neuralnetworks"] = []string{
207 "android.hardware.neuralnetworks@1.0",
208 "android.hardware.neuralnetworks@1.1",
209 "android.hardware.neuralnetworks@1.2",
210 "android.hardware.neuralnetworks@1.3",
211 "android.hidl.allocator@1.0",
212 "android.hidl.memory.token@1.0",
213 "android.hidl.memory@1.0",
214 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900216 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900218 "libprocpartition",
219 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900220 }
Anton Hansson5053c292020-01-10 15:12:39 +0000221 //
222 // Module separator
223 //
Anton Hansson5053c292020-01-10 15:12:39 +0000224 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900225 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000226 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900227 "android.hardware.cas@1.0",
228 "android.hardware.configstore-utils",
229 "android.hardware.configstore@1.0",
230 "android.hardware.configstore@1.1",
231 "android.hardware.graphics.allocator@2.0",
232 "android.hardware.graphics.allocator@3.0",
233 "android.hardware.graphics.bufferqueue@1.0",
234 "android.hardware.graphics.bufferqueue@2.0",
235 "android.hardware.graphics.common@1.0",
236 "android.hardware.graphics.common@1.1",
237 "android.hardware.graphics.common@1.2",
238 "android.hardware.graphics.mapper@2.0",
239 "android.hardware.graphics.mapper@2.1",
240 "android.hardware.graphics.mapper@3.0",
241 "android.hardware.media.omx@1.0",
242 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000243 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000244 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900245 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "android.hidl.token@1.0",
247 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 "bionic_libc_platform_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900249 "exoplayer2-extractor",
250 "exoplayer2-extractor-annotation-stubs",
Jiyong Parkfa899442020-01-31 02:49:53 +0900251 "gl_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900252 "jsr305",
Jiyong Parkfa899442020-01-31 02:49:53 +0900253 "libEGL",
254 "libEGL_blobCache",
255 "libEGL_getProcAddress",
256 "libFLAC",
257 "libFLAC-config",
258 "libFLAC-headers",
259 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000260 "libaacextractor",
261 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900262 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900263 "libaudio_system_headers",
264 "libaudioclient",
265 "libaudioclient_headers",
266 "libaudiofoundation",
267 "libaudiofoundation_headers",
268 "libaudiomanager",
269 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000270 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900271 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900273 "libbluetooth-types-header",
274 "libbufferhub",
275 "libbufferhub_headers",
276 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900277 "libc_malloc_debug_backtrace",
278 "libcamera_client",
279 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900280 "libdexfile_external_headers",
281 "libdexfile_support",
282 "libdvr_headers",
283 "libexpat",
284 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000285 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900286 "libgrallocusage",
287 "libgraphicsenv",
288 "libgui",
289 "libgui_headers",
290 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900291 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900292 "liblzma",
293 "libmath",
294 "libmedia",
295 "libmedia_codeclist",
296 "libmedia_headers",
297 "libmedia_helper",
298 "libmedia_helper_headers",
299 "libmedia_midiiowrapper",
300 "libmedia_omx",
301 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000302 "libmidiextractor",
303 "libmkvextractor",
304 "libmp3extractor",
305 "libmp4extractor",
306 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900307 "libnativebase_headers",
308 "libnativebridge-headers",
309 "libnativebridge_lazy",
310 "libnativeloader-headers",
311 "libnativeloader_lazy",
312 "libnativewindow_headers",
313 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000314 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900315 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900316 "libpdx",
317 "libpdx_default_transport",
318 "libpdx_headers",
319 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000321 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900322 "libspeexresampler",
323 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000324 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900325 "libstagefright_flacdec",
326 "libstagefright_foundation",
327 "libstagefright_foundation_headers",
328 "libstagefright_foundation_without_imemory",
329 "libstagefright_headers",
330 "libstagefright_id3",
331 "libstagefright_metadatautils",
332 "libstagefright_mpeg2extractor",
333 "libstagefright_mpeg2support",
334 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900335 "libui",
336 "libui_headers",
337 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900338 "libvibrator",
339 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000340 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900341 "libwebm",
342 "media_ndk_headers",
343 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000344 "updatable-media",
345 }
346 //
347 // Module separator
348 //
349 m["com.android.media.swcodec"] = []string{
350 "android.frameworks.bufferhub@1.0",
351 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900352 "android.hardware.configstore-utils",
353 "android.hardware.configstore@1.0",
354 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000355 "android.hardware.graphics.allocator@2.0",
356 "android.hardware.graphics.allocator@3.0",
357 "android.hardware.graphics.allocator@4.0",
358 "android.hardware.graphics.bufferqueue@1.0",
359 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900360 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000361 "android.hardware.graphics.common@1.0",
362 "android.hardware.graphics.common@1.1",
363 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000364 "android.hardware.graphics.mapper@2.0",
365 "android.hardware.graphics.mapper@2.1",
366 "android.hardware.graphics.mapper@3.0",
367 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000368 "android.hardware.media.bufferpool@2.0",
369 "android.hardware.media.c2@1.0",
370 "android.hardware.media.c2@1.1",
371 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900372 "android.hardware.media@1.0",
373 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000374 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900375 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "android.hidl.safe_union@1.0",
377 "android.hidl.token@1.0",
378 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900379 "libEGL",
380 "libFLAC",
381 "libFLAC-config",
382 "libFLAC-headers",
383 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900384 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900385 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900386 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000387 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900388 "libaudioutils",
389 "libaudioutils_fixedfft",
390 "libavcdec",
391 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000392 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900393 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900394 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900395 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900396 "libbluetooth-types-header",
397 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000399 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900400 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000401 "libcodec2_hidl@1.0",
402 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900403 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000404 "libcodec2_soft_aacdec",
405 "libcodec2_soft_aacenc",
406 "libcodec2_soft_amrnbdec",
407 "libcodec2_soft_amrnbenc",
408 "libcodec2_soft_amrwbdec",
409 "libcodec2_soft_amrwbenc",
410 "libcodec2_soft_av1dec_gav1",
411 "libcodec2_soft_avcdec",
412 "libcodec2_soft_avcenc",
413 "libcodec2_soft_common",
414 "libcodec2_soft_flacdec",
415 "libcodec2_soft_flacenc",
416 "libcodec2_soft_g711alawdec",
417 "libcodec2_soft_g711mlawdec",
418 "libcodec2_soft_gsmdec",
419 "libcodec2_soft_h263dec",
420 "libcodec2_soft_h263enc",
421 "libcodec2_soft_hevcdec",
422 "libcodec2_soft_hevcenc",
423 "libcodec2_soft_mp3dec",
424 "libcodec2_soft_mpeg2dec",
425 "libcodec2_soft_mpeg4dec",
426 "libcodec2_soft_mpeg4enc",
427 "libcodec2_soft_opusdec",
428 "libcodec2_soft_opusenc",
429 "libcodec2_soft_rawdec",
430 "libcodec2_soft_vorbisdec",
431 "libcodec2_soft_vp8dec",
432 "libcodec2_soft_vp8enc",
433 "libcodec2_soft_vp9dec",
434 "libcodec2_soft_vp9enc",
435 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libdexfile_support",
437 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000438 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900439 "libfmq",
440 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000441 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900442 "libgrallocusage",
443 "libgraphicsenv",
444 "libgsm",
445 "libgui_bufferqueue_static",
446 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000447 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900448 "libhardware_headers",
449 "libhevcdec",
450 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000451 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900452 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900453 "liblzma",
454 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000455 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900457 "libmpeg2dec",
458 "libnativebase_headers",
459 "libnativebridge_lazy",
460 "libnativeloader_lazy",
461 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900462 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000463 "libscudo_wrapper",
464 "libsfplugin_ccodec_utils",
465 "libspeexresampler",
466 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900467 "libstagefright_amrnbdec",
468 "libstagefright_amrnbenc",
469 "libstagefright_amrwbdec",
470 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000471 "libstagefright_bufferpool@2.0.1",
472 "libstagefright_bufferqueue_helper",
473 "libstagefright_enc_common",
474 "libstagefright_flacdec",
475 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900476 "libstagefright_foundation_headers",
477 "libstagefright_headers",
478 "libstagefright_m4vh263dec",
479 "libstagefright_m4vh263enc",
480 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000481 "libsync",
482 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900483 "libui_headers",
484 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000485 "libvorbisidec",
486 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900487 "libyuv",
488 "libyuv_static",
489 "media_ndk_headers",
490 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000491 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000492 }
493 //
494 // Module separator
495 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900496 m["com.android.mediaprovider"] = []string{
497 "MediaProvider",
498 "MediaProviderGoogle",
499 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libbase_ndk",
501 "libfuse",
502 "libfuse_jni",
503 "libnativehelper_header_only",
504 }
505 //
506 // Module separator
507 //
508 m["com.android.permission"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900509 "car-ui-lib",
510 "iconloader",
Jiyong Parkfa899442020-01-31 02:49:53 +0900511 "kotlin-annotations",
512 "kotlin-stdlib",
513 "kotlin-stdlib-jdk7",
514 "kotlin-stdlib-jdk8",
515 "kotlinx-coroutines-android",
516 "kotlinx-coroutines-android-nodeps",
517 "kotlinx-coroutines-core",
518 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900519 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900520 "GooglePermissionController",
521 "PermissionController",
Jooyung Han11c20932020-05-19 15:47:01 +0900522 "SettingsLibActionBarShadow",
523 "SettingsLibAppPreference",
524 "SettingsLibBarChartPreference",
525 "SettingsLibLayoutPreference",
526 "SettingsLibProgressBar",
527 "SettingsLibSearchWidget",
528 "SettingsLibSettingsTheme",
529 "SettingsLibRestrictedLockUtils",
530 "SettingsLibHelpUtils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900531 }
Anton Hansson5053c292020-01-10 15:12:39 +0000532 //
533 // Module separator
534 //
Anton Hansson5053c292020-01-10 15:12:39 +0000535 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900538 "libc_aeabi",
539 "libc_bionic",
540 "libc_bionic_ndk",
541 "libc_bootstrap",
542 "libc_common",
543 "libc_common_shared",
544 "libc_common_static",
545 "libc_dns",
546 "libc_dynamic_dispatch",
547 "libc_fortify",
548 "libc_freebsd",
549 "libc_freebsd_large_stack",
550 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900551 "libc_init_dynamic",
552 "libc_init_static",
553 "libc_jemalloc_wrapper",
554 "libc_netbsd",
555 "libc_nomalloc",
556 "libc_nopthread",
557 "libc_openbsd",
558 "libc_openbsd_large_stack",
559 "libc_openbsd_ndk",
560 "libc_pthread",
561 "libc_static_dispatch",
562 "libc_syscalls",
563 "libc_tzcode",
564 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900565 "libdebuggerd",
566 "libdebuggerd_common_headers",
567 "libdebuggerd_handler_core",
568 "libdebuggerd_handler_fallback",
569 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000570 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900571 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900572 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libjemalloc5",
574 "liblinker_main",
575 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900576 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000577 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900578 "libprocinfo",
579 "libpropertyinfoparser",
580 "libscudo",
581 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900582 "libsystemproperties",
583 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000584 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900585 "libz",
586 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000587 }
588 //
589 // Module separator
590 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900591 m["com.android.tethering"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900592 "android.hardware.tetheroffload.config-V1.0-java",
593 "android.hardware.tetheroffload.control-V1.0-java",
594 "android.hidl.base-V1.0-java",
595 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900596 "libcgrouprc",
597 "libcgrouprc_format",
Jooyung Han11c20932020-05-19 15:47:01 +0900598 "libnativehelper_compat_libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900599 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900600 "libvndksupport",
Jooyung Han11c20932020-05-19 15:47:01 +0900601 "net-utils-framework-common",
602 "netd_aidl_interface-V3-java",
603 "netlink-client",
604 "networkstack-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900605 "tethering-aidl-interfaces-java",
Jooyung Han11c20932020-05-19 15:47:01 +0900606 "TetheringApiCurrentLib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900607 }
Anton Hansson5053c292020-01-10 15:12:39 +0000608 //
609 // Module separator
610 //
611 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900612 "PlatformProperties",
613 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900614 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900615 "android.hardware.wifi-V1.1-java",
616 "android.hardware.wifi-V1.2-java",
617 "android.hardware.wifi-V1.3-java",
618 "android.hardware.wifi-V1.4-java",
619 "android.hardware.wifi.hostapd-V1.0-java",
620 "android.hardware.wifi.hostapd-V1.1-java",
621 "android.hardware.wifi.hostapd-V1.2-java",
622 "android.hardware.wifi.supplicant-V1.0-java",
623 "android.hardware.wifi.supplicant-V1.1-java",
624 "android.hardware.wifi.supplicant-V1.2-java",
625 "android.hardware.wifi.supplicant-V1.3-java",
626 "android.hidl.base-V1.0-java",
627 "android.hidl.manager-V1.0-java",
628 "android.hidl.manager-V1.1-java",
629 "android.hidl.manager-V1.2-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "bouncycastle-unbundled",
631 "dnsresolver_aidl_interface-V2-java",
632 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900633 "framework-wifi-pre-jarjar",
634 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900635 "ipmemorystore-aidl-interfaces-V3-java",
636 "ipmemorystore-aidl-interfaces-java",
637 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900638 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000639 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "net-utils-services-common",
641 "netd_aidl_interface-V2-java",
642 "netd_aidl_interface-unstable-java",
643 "netd_event_listener_interface-java",
644 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900645 "networkstack-client",
646 "services.net",
647 "wifi-lite-protos",
648 "wifi-nano-protos",
649 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000650 "wifi-service-resources",
651 }
652 //
653 // Module separator
654 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900655 m["com.android.sdkext"] = []string{
656 "fmtlib_ndk",
657 "libbase_ndk",
658 "libprotobuf-cpp-lite-ndk",
659 }
660 //
661 // Module separator
662 //
663 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900664 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900665 }
666 //
667 // Module separator
668 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000669 m[android.AvailableToAnyApex] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900670 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
671 "androidx",
672 "androidx-constraintlayout_constraintlayout",
673 "androidx-constraintlayout_constraintlayout-nodeps",
674 "androidx-constraintlayout_constraintlayout-solver",
675 "androidx-constraintlayout_constraintlayout-solver-nodeps",
676 "com.google.android.material_material",
677 "com.google.android.material_material-nodeps",
678
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900680 "libclang_rt",
681 "libgcc_stripped",
682 "libprofile-clang-extras",
683 "libprofile-clang-extras_ndk",
684 "libprofile-extras",
685 "libprofile-extras_ndk",
686 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900687 }
Anton Hansson5053c292020-01-10 15:12:39 +0000688 return m
689}
690
Andrei Onea115e7e72020-06-05 21:14:03 +0100691// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
692// Adding code to the bootclasspath in new packages will cause issues on module update.
693func qModulesPackages() map[string][]string {
694 return map[string][]string{
695 "com.android.conscrypt": []string{
696 "android.net.ssl",
697 "com.android.org.conscrypt",
698 },
699 "com.android.media": []string{
700 "android.media",
701 },
702 }
703}
704
705// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
706// Adding code to the bootclasspath in new packages will cause issues on module update.
707func rModulesPackages() map[string][]string {
708 return map[string][]string{
709 "com.android.mediaprovider": []string{
710 "android.provider",
711 },
712 "com.android.permission": []string{
713 "android.permission",
714 "android.app.role",
715 "com.android.permission",
716 "com.android.role",
717 },
718 "com.android.sdkext": []string{
719 "android.os.ext",
720 },
721 "com.android.os.statsd": []string{
722 "android.app",
723 "android.os",
724 "android.util",
725 "com.android.internal.statsd",
726 "com.android.server.stats",
727 },
728 "com.android.wifi": []string{
729 "com.android.server.wifi",
730 "com.android.wifi.x",
731 "android.hardware.wifi",
732 "android.net.wifi",
733 },
734 "com.android.tethering": []string{
735 "android.net",
736 },
737 }
738}
739
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900740func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900741 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800742 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900743 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900744 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700745 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900746 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700747 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900748
Jooyung Han31c470b2019-10-18 16:26:59 +0900749 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900750 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900751
752 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
753 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
754 sort.Strings(*apexFileContextsInfos)
755 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
756 })
Andrei Onea115e7e72020-06-05 21:14:03 +0100757
758 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
759 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
760}
761
762func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
763 rules := make([]android.Rule, 0, len(modules_packages))
764 for module_name, module_packages := range modules_packages {
765 permitted_packages_rule := android.NeverAllow().
766 BootclasspathJar().
767 With("apex_available", module_name).
768 WithMatcher("permitted_packages", android.NotInList(module_packages)).
769 Because("jars that are part of the " + module_name +
770 " module may only allow these packages: " + strings.Join(module_packages, ",") +
771 ". Please jarjar or move code around.")
772 rules = append(rules, permitted_packages_rule)
773 }
774 return rules
Jiyong Parkd1063c12019-07-17 20:08:41 +0900775}
776
Jooyung Han31c470b2019-10-18 16:26:59 +0900777func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
778 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
779 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
780}
781
Jiyong Parkd1063c12019-07-17 20:08:41 +0900782func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900783 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900784 ctx.BottomUp("apex", apexMutator).Parallel()
785 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
786 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900787 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900788}
789
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900790// Mark the direct and transitive dependencies of apex bundles so that they
791// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900792func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900793 if !mctx.Module().Enabled() {
794 return
795 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800796 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900797 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000798 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900799 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900800 ApexName: mctx.ModuleName(),
801 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100802 Updatable: a.Updatable(),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900803 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900804 directDep = true
805 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800806 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900807 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900808 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900809
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800810 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900811 return
812 }
813
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100814 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900815
Jiyong Parkf760cae2020-02-12 07:53:12 +0900816 mctx.VisitDirectDeps(func(child android.Module) {
817 depName := mctx.OtherModuleName(child)
818 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100819 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800820 android.UpdateApexDependency(apexBundles, depName, directDep)
821 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900822 }
823 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900824}
825
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900826// mark if a module cannot be available to platform. A module cannot be available
827// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
828// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
829func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
830 // Host and recovery are not considered as platform
831 if mctx.Host() || mctx.Module().InstallInRecovery() {
832 return
833 }
834
835 if am, ok := mctx.Module().(android.ApexModule); ok {
836 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
837
838 // In a rare case when a lib is marked as available only to an apex
839 // but the apex doesn't exist. This can happen in a partial manifest branch
840 // like master-art. Currently, libstatssocket in the stats APEX is causing
841 // this problem.
842 // Include the lib in platform because the module SDK that ought to provide
843 // it doesn't exist, so it would otherwise be left out completely.
844 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
845 // this check for libraries provided by SDKs.
846 if !availableToPlatform && !android.InAnyApex(am.Name()) {
847 availableToPlatform = true
848 }
849
850 // If any of the dep is not available to platform, this module is also considered
851 // as being not available to platform even if it has "//apex_available:platform"
852 mctx.VisitDirectDeps(func(child android.Module) {
853 if !am.DepIsInSameApex(mctx, child) {
854 // if the dependency crosses apex boundary, don't consider it
855 return
856 }
857 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
858 availableToPlatform = false
859 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
860 }
861 })
862
863 // Exception 1: stub libraries and native bridge libraries are always available to platform
864 if cc, ok := mctx.Module().(*cc.Module); ok &&
865 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
866 availableToPlatform = true
867 }
868
869 // Exception 2: bootstrap bionic libraries are also always available to platform
870 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
871 availableToPlatform = true
872 }
873
874 if !availableToPlatform {
875 am.SetNotAvailableForPlatform()
876 }
877 }
878}
879
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100880// If a module in an APEX depends on a module from an SDK then it needs an APEX
881// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
882func inAnySdk(module android.Module) bool {
883 if sa, ok := module.(android.SdkAware); ok {
884 return sa.IsInAnySdk()
885 }
886
887 return false
888}
889
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900890// Create apex variations if a module is included in APEX(s).
891func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900892 if !mctx.Module().Enabled() {
893 return
894 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900895 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900896 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000897 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900898 // apex bundle itself is mutated so that it and its modules have same
899 // apex variant.
900 apexBundleName := mctx.ModuleName()
901 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900902 } else if o, ok := mctx.Module().(*OverrideApex); ok {
903 apexBundleName := o.GetOverriddenModuleName()
904 if apexBundleName == "" {
905 mctx.ModuleErrorf("base property is not set")
906 return
907 }
908 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900909 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900910
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900911}
Sundong Ahne9b55722019-09-06 17:37:42 +0900912
Jooyung Han7a78a922019-10-08 21:59:58 +0900913var (
914 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
915 apexFileContextsInfosMutex sync.Mutex
916)
917
918func apexFileContextsInfos(config android.Config) *[]string {
919 return config.Once(apexFileContextsInfosKey, func() interface{} {
920 return &[]string{}
921 }).(*[]string)
922}
923
Jooyung Han54aca7b2019-11-20 02:26:02 +0900924func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900925 apexFileContextsInfosMutex.Lock()
926 defer apexFileContextsInfosMutex.Unlock()
927 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900928 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900929}
930
Sundong Ahne9b55722019-09-06 17:37:42 +0900931func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900932 if !mctx.Module().Enabled() {
933 return
934 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900935 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900936 var variants []string
937 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
938 case "image":
939 variants = append(variants, imageApexType, flattenedApexType)
940 case "zip":
941 variants = append(variants, zipApexType)
942 case "both":
943 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
944 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900945 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900946 return
947 }
948
949 modules := mctx.CreateLocalVariations(variants...)
950
951 for i, v := range variants {
952 switch v {
953 case imageApexType:
954 modules[i].(*apexBundle).properties.ApexType = imageApex
955 case zipApexType:
956 modules[i].(*apexBundle).properties.ApexType = zipApex
957 case flattenedApexType:
958 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900959 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900960 modules[i].(*apexBundle).MakeAsSystemExt()
961 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900962 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900963 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900964 } else if _, ok := mctx.Module().(*OverrideApex); ok {
965 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900966 }
967}
968
Jooyung Han5c998b92019-06-27 11:30:33 +0900969func apexUsesMutator(mctx android.BottomUpMutatorContext) {
970 if ab, ok := mctx.Module().(*apexBundle); ok {
971 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
972 }
973}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900974
Jooyung Handc782442019-11-01 03:14:38 +0900975var (
Colin Cross95f7b342020-06-11 11:32:11 -0700976 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900977)
978
Colin Cross95f7b342020-06-11 11:32:11 -0700979// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900980// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
981// which may cause compatibility issues. (e.g. libbinder)
982// Even though libbinder restricts its availability via 'apex_available' property and relies on
983// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
984// to avoid similar problems.
Colin Cross95f7b342020-06-11 11:32:11 -0700985func useVendorAllowList(config android.Config) []string {
986 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900987 return []string{
988 // swcodec uses "vendor" variants for smaller size
989 "com.android.media.swcodec",
990 "test_com.android.media.swcodec",
991 }
992 }).([]string)
993}
994
Colin Cross95f7b342020-06-11 11:32:11 -0700995// setUseVendorAllowListForTest overrides useVendorAllowList and must be
996// called before the first call to useVendorAllowList()
997func setUseVendorAllowListForTest(config android.Config, allowList []string) {
998 config.Once(useVendorAllowListKey, func() interface{} {
999 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001000 })
1001}
1002
Alex Light9670d332019-01-29 18:07:33 -08001003type apexNativeDependencies struct {
1004 // List of native libraries
1005 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001006
Alex Light9670d332019-01-29 18:07:33 -08001007 // List of native executables
1008 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001009
Roland Levillain630846d2019-06-26 12:48:34 +01001010 // List of native tests
1011 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001012}
Jooyung Han344d5432019-08-23 11:17:39 +09001013
Alex Light9670d332019-01-29 18:07:33 -08001014type apexMultilibProperties struct {
1015 // Native dependencies whose compile_multilib is "first"
1016 First apexNativeDependencies
1017
1018 // Native dependencies whose compile_multilib is "both"
1019 Both apexNativeDependencies
1020
1021 // Native dependencies whose compile_multilib is "prefer32"
1022 Prefer32 apexNativeDependencies
1023
1024 // Native dependencies whose compile_multilib is "32"
1025 Lib32 apexNativeDependencies
1026
1027 // Native dependencies whose compile_multilib is "64"
1028 Lib64 apexNativeDependencies
1029}
1030
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001031type apexBundleProperties struct {
1032 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001033 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001034 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001035
Jiyong Park40e26a22019-02-08 02:53:06 +09001036 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1037 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001038 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001039
Roland Levillain411c5842019-09-19 16:37:20 +01001040 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1041 // device (/apex/<apex_name>).
1042 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001043 Apex_name *string
1044
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001045 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001046 // For platform APEXes, this should points to a file under /system/sepolicy
1047 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1048 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001049
1050 // List of native shared libs that are embedded inside this APEX bundle
1051 Native_shared_libs []string
1052
Roland Levillain630846d2019-06-26 12:48:34 +01001053 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001054 Binaries []string
1055
1056 // List of java libraries that are embedded inside this APEX bundle
1057 Java_libs []string
1058
1059 // List of prebuilt files that are embedded inside this APEX bundle
1060 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001061
Roland Levillain630846d2019-06-26 12:48:34 +01001062 // List of tests that are embedded inside this APEX bundle
1063 Tests []string
1064
Jiyong Parkff1458f2018-10-12 21:49:38 +09001065 // Name of the apex_key module that provides the private key to sign APEX
1066 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001067
Alex Light5098a612018-11-29 17:12:15 -08001068 // The type of APEX to build. Controls what the APEX payload is. Either
1069 // 'image', 'zip' or 'both'. Default: 'image'.
1070 Payload_type *string
1071
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001072 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1073 // or an android_app_certificate module name in the form ":module".
1074 Certificate *string
1075
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001076 // Whether this APEX is installable to one of the partitions. Default: true.
1077 Installable *bool
1078
Jiyong Parkda6eb592018-12-19 17:12:36 +09001079 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1080 // Default is false.
1081 Use_vendor *bool
1082
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001083 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1084 Ignore_system_library_special_case *bool
1085
Alex Light9670d332019-01-29 18:07:33 -08001086 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001087
Jiyong Parkf97782b2019-02-13 20:28:58 +09001088 // List of sanitizer names that this APEX is enabled for
1089 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001090
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001091 PreventInstall bool `blueprint:"mutated"`
1092
1093 HideFromMake bool `blueprint:"mutated"`
1094
Jooyung Han5c998b92019-06-27 11:30:33 +09001095 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1096 Provide_cpp_shared_libs *bool
1097
1098 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1099 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001100
Sundong Ahnabb64432019-10-22 13:58:29 +09001101 // package format of this apex variant; could be non-flattened, flattened, or zip.
1102 // imageApex, zipApex or flattened
1103 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001104
Jiyong Parkd1063c12019-07-17 20:08:41 +09001105 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1106 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1107 // is implied. This value affects all modules included in this APEX. In other words, they are
1108 // also built with the SDKs specified here.
1109 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001110
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001111 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1112 // Should be only used in tests#.
1113 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001114
Dario Freni98410fd2020-04-27 18:21:11 +01001115 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1116 // Should be only used in tests#.
1117 Test_only_unsigned_payload *bool
1118
Jiyong Park956305c2020-01-09 12:32:06 +09001119 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001120
1121 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001122 // rules for making sure that the APEX is truly updatable.
1123 // - To be updatable, min_sdk_version should be set as well
1124 // This will also disable the size optimizations like symlinking to the system libs.
1125 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001126 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001127
1128 // The minimum SDK version that this apex must be compatible with.
1129 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001130}
1131
1132type apexTargetBundleProperties struct {
1133 Target struct {
1134 // Multilib properties only for android.
1135 Android struct {
1136 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001137 }
Jooyung Han344d5432019-08-23 11:17:39 +09001138
Alex Light9670d332019-01-29 18:07:33 -08001139 // Multilib properties only for host.
1140 Host struct {
1141 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001142 }
Jooyung Han344d5432019-08-23 11:17:39 +09001143
Alex Light9670d332019-01-29 18:07:33 -08001144 // Multilib properties only for host linux_bionic.
1145 Linux_bionic struct {
1146 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001147 }
Jooyung Han344d5432019-08-23 11:17:39 +09001148
Alex Light9670d332019-01-29 18:07:33 -08001149 // Multilib properties only for host linux_glibc.
1150 Linux_glibc struct {
1151 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001152 }
1153 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001154}
1155
Jiyong Park5d790c32019-11-15 18:40:32 +09001156type overridableProperties struct {
1157 // List of APKs to package inside APEX
1158 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001159
1160 // Names of modules to be overridden. Listed modules can only be other binaries
1161 // (in Make or Soong).
1162 // This does not completely prevent installation of the overridden binaries, but if both
1163 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1164 // from PRODUCT_PACKAGES.
1165 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001166
1167 // Logging Parent value
1168 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001169
1170 // Apex Container Package Name.
1171 // Override value for attribute package:name in AndroidManifest.xml
1172 Package_name string
Jooyung Hanfaa53992020-06-20 12:47:47 +09001173
1174 // A txt file containing list of files that are allowed to be included in this APEX.
1175 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001176}
1177
Alex Light5098a612018-11-29 17:12:15 -08001178type apexPackaging int
1179
1180const (
1181 imageApex apexPackaging = iota
1182 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001183 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001184)
1185
Sundong Ahnabb64432019-10-22 13:58:29 +09001186// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001187func (a apexPackaging) suffix() string {
1188 switch a {
1189 case imageApex:
1190 return imageApexSuffix
1191 case zipApex:
1192 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001193 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001194 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001195 }
1196}
1197
1198func (a apexPackaging) name() string {
1199 switch a {
1200 case imageApex:
1201 return imageApexType
1202 case zipApex:
1203 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001204 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001205 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001206 }
1207}
1208
Jiyong Parkf653b052019-11-18 15:39:01 +09001209type apexFileClass int
1210
1211const (
1212 etc apexFileClass = iota
1213 nativeSharedLib
1214 nativeExecutable
1215 shBinary
1216 pyBinary
1217 goBinary
1218 javaSharedLib
1219 nativeTest
1220 app
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001221 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001222)
1223
Jiyong Park8fd61922018-11-08 02:50:25 +09001224func (class apexFileClass) NameInMake() string {
1225 switch class {
1226 case etc:
1227 return "ETC"
1228 case nativeSharedLib:
1229 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001230 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001231 return "EXECUTABLES"
1232 case javaSharedLib:
1233 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001234 case nativeTest:
1235 return "NATIVE_TESTS"
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001236 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001237 // b/142537672 Why isn't this APP? We want to have full control over
1238 // the paths and file names of the apk file under the flattend APEX.
1239 // If this is set to APP, then the paths and file names are modified
1240 // by the Make build system. For example, it is installed to
1241 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1242 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1243 // appends module name (which is <apexname>.<Appname> to the path.
1244 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001245 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001246 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001247 }
1248}
1249
Jiyong Parkf653b052019-11-18 15:39:01 +09001250// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001251type apexFile struct {
1252 builtFile android.Path
Jiyong Parked50ca82020-05-28 23:46:55 +09001253 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001254 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001255 installDir string
1256 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001257 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001258 // list of symlinks that will be created in installDir that point to this apexFile
1259 symlinks []string
1260 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001261 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001262
1263 requiredModuleNames []string
1264 targetRequiredModuleNames []string
1265 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001266
Colin Cross503c1d02020-01-28 14:00:53 -08001267 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross5bc17442020-07-21 20:31:17 -07001268 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001269 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001270 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001271}
1272
Jiyong Park1833cef2019-12-13 13:28:36 +09001273func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1274 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001275 builtFile: builtFile,
1276 moduleName: moduleName,
1277 installDir: installDir,
1278 class: class,
1279 module: module,
1280 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001281 if module != nil {
1282 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001283 ret.requiredModuleNames = module.RequiredModuleNames()
1284 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1285 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001286 }
1287 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001288}
1289
1290func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001291 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001292}
1293
Jiyong Parked50ca82020-05-28 23:46:55 +09001294func (af *apexFile) apexRelativePath(path string) string {
1295 return filepath.Join(af.installDir, path)
1296}
1297
Jiyong Park7cd10e32020-01-14 09:22:18 +09001298// Path() returns path of this apex file relative to the APEX root
1299func (af *apexFile) Path() string {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001300 return af.apexRelativePath(af.Stem())
1301}
1302
1303func (af *apexFile) Stem() string {
Jiyong Parked50ca82020-05-28 23:46:55 +09001304 if af.stem != "" {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001305 return af.stem
Jiyong Parked50ca82020-05-28 23:46:55 +09001306 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001307 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001308}
1309
1310// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1311func (af *apexFile) SymlinkPaths() []string {
1312 var ret []string
1313 for _, symlink := range af.symlinks {
1314 ret = append(ret, filepath.Join(af.installDir, symlink))
1315 }
1316 return ret
1317}
1318
1319func (af *apexFile) AvailableToPlatform() bool {
1320 if af.module == nil {
1321 return false
1322 }
1323 if am, ok := af.module.(android.ApexModule); ok {
1324 return am.AvailableFor(android.AvailableToPlatform)
1325 }
1326 return false
1327}
1328
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001329type apexBundle struct {
1330 android.ModuleBase
1331 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001332 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001333 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001334
Jiyong Park5d790c32019-11-15 18:40:32 +09001335 properties apexBundleProperties
1336 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001337 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001338
Jooyung Hanf21c7972019-12-16 22:32:06 +09001339 // specific to apex_vndk modules
1340 vndkProperties apexVndkProperties
1341
Colin Crossa4925902018-11-16 11:36:28 -08001342 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001343 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001344 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001345
Jiyong Park03b68dd2019-07-26 23:20:40 +09001346 prebuiltFileToDelete string
1347
Jiyong Park42cca6c2019-04-01 11:15:50 +09001348 public_key_file android.Path
1349 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001350
1351 container_certificate_file android.Path
1352 container_private_key_file android.Path
1353
Jooyung Han54aca7b2019-11-20 02:26:02 +09001354 fileContexts android.Path
1355
Jiyong Park8fd61922018-11-08 02:50:25 +09001356 // list of files to be included in this apex
1357 filesInfo []apexFile
1358
Jiyong Park956305c2020-01-09 12:32:06 +09001359 // list of module names that should be installed along with this APEX
1360 requiredDeps []string
1361
Jiyong Park956305c2020-01-09 12:32:06 +09001362 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001363 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001364
Sundong Ahnabb64432019-10-22 13:58:29 +09001365 testApex bool
1366 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001367 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001368 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001369
Jooyung Han214bf372019-11-12 13:03:50 +09001370 manifestJsonOut android.WritablePath
1371 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001372
Jooyung Han002ab682020-01-08 01:57:58 +09001373 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001374 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001375 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001376 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1377 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001378
1379 // Suffix of module name in Android.mk
1380 // ".flattened", ".apex", ".zipapex", or ""
1381 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001382
1383 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001384
1385 // Whether to create symlink to the system file instead of having a file
1386 // inside the apex or not
1387 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001388
1389 // Struct holding the merged notice file paths in different formats
1390 mergedNotices android.NoticeOutputs
Colin Cross5bc17442020-07-21 20:31:17 -07001391
1392 // Optional list of lint report zip files for apexes that contain java or app modules
1393 lintReports android.Paths
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001394}
1395
Jiyong Park397e55e2018-10-24 21:09:55 +09001396func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001397 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001398 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001399 // Use *FarVariation* to be able to depend on modules having
1400 // conflicting variations with this module. This is required since
1401 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1402 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001403 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001404 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001405 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001406 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001407 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001408
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001409 ctx.AddFarVariationDependencies(append(target.Variations(),
1410 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1411 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001412
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001413 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001414 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001415 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001416 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001417}
1418
Alex Light9670d332019-01-29 18:07:33 -08001419func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1420 if ctx.Os().Class == android.Device {
1421 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1422 } else {
1423 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1424 if ctx.Os().Bionic() {
1425 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1426 } else {
1427 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1428 }
1429 }
1430}
1431
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001432func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross95f7b342020-06-11 11:32:11 -07001433 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001434 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1435 }
1436
Jiyong Park397e55e2018-10-24 21:09:55 +09001437 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001438 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001439
1440 a.combineProperties(ctx)
1441
Jiyong Park397e55e2018-10-24 21:09:55 +09001442 has32BitTarget := false
1443 for _, target := range targets {
1444 if target.Arch.ArchType.Multilib == "lib32" {
1445 has32BitTarget = true
1446 }
1447 }
1448 for i, target := range targets {
1449 // When multilib.* is omitted for native_shared_libs, it implies
1450 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001451 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001452 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001453 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001454 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001455
Roland Levillain630846d2019-06-26 12:48:34 +01001456 // When multilib.* is omitted for tests, it implies
1457 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001459 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001460 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001461 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001462
Jiyong Park397e55e2018-10-24 21:09:55 +09001463 // Add native modules targetting both ABIs
1464 addDependenciesForNativeModules(ctx,
1465 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001466 a.properties.Multilib.Both.Binaries,
1467 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001468 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001469 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001470
Alex Light3d673592019-01-18 14:37:31 -08001471 isPrimaryAbi := i == 0
1472 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001473 // When multilib.* is omitted for binaries, it implies
1474 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001475 ctx.AddFarVariationDependencies(append(target.Variations(),
1476 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1477 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001478
1479 // Add native modules targetting the first ABI
1480 addDependenciesForNativeModules(ctx,
1481 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001482 a.properties.Multilib.First.Binaries,
1483 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001484 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001485 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001486 }
1487
1488 switch target.Arch.ArchType.Multilib {
1489 case "lib32":
1490 // Add native modules targetting 32-bit ABI
1491 addDependenciesForNativeModules(ctx,
1492 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001493 a.properties.Multilib.Lib32.Binaries,
1494 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001495 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001496 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001497
1498 addDependenciesForNativeModules(ctx,
1499 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001500 a.properties.Multilib.Prefer32.Binaries,
1501 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001502 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001503 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001504 case "lib64":
1505 // Add native modules targetting 64-bit ABI
1506 addDependenciesForNativeModules(ctx,
1507 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001508 a.properties.Multilib.Lib64.Binaries,
1509 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001510 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001511 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001512
1513 if !has32BitTarget {
1514 addDependenciesForNativeModules(ctx,
1515 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001516 a.properties.Multilib.Prefer32.Binaries,
1517 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001518 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001519 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001520 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001521
1522 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1523 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1524 if sanitizer == "hwaddress" {
1525 addDependenciesForNativeModules(ctx,
1526 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001527 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001528 break
1529 }
1530 }
1531 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001532 }
1533
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001534 }
1535
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001536 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1537 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1538 // b/144532908
1539 archForPrebuiltEtc := config.Arches()[0]
1540 for _, arch := range config.Arches() {
1541 // Prefer 64-bit arch if there is any
1542 if arch.ArchType.Multilib == "lib64" {
1543 archForPrebuiltEtc = arch
1544 break
1545 }
1546 }
1547 ctx.AddFarVariationDependencies([]blueprint.Variation{
1548 {Mutator: "os", Variation: ctx.Os().String()},
1549 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1550 }, prebuiltTag, a.properties.Prebuilts...)
1551
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001552 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1553 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001554
Ulya Trafimovich44561882020-01-03 13:25:54 +00001555 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1556 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1557 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1558 javaLibTag, "jacocoagent")
1559 }
1560
Jiyong Park23c52b02019-02-02 13:13:47 +09001561 if String(a.properties.Key) == "" {
1562 ctx.ModuleErrorf("key is missing")
1563 return
1564 }
1565 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001566
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001567 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001568 if cert != "" {
1569 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001570 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001571
1572 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1573 if len(a.properties.Uses_sdks) > 0 {
1574 sdkRefs := []android.SdkRef{}
1575 for _, str := range a.properties.Uses_sdks {
1576 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1577 sdkRefs = append(sdkRefs, parsed)
1578 }
1579 a.BuildWithSdks(sdkRefs)
1580 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001581}
1582
Jiyong Park5d790c32019-11-15 18:40:32 +09001583func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Hanfaa53992020-06-20 12:47:47 +09001584 if a.overridableProperties.Allowed_files != nil {
1585 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1586 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001587 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1588 androidAppTag, a.overridableProperties.Apps...)
1589}
1590
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001591func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1592 // direct deps of an APEX bundle are all part of the APEX bundle
1593 return true
1594}
1595
Colin Cross0ea8ba82019-06-06 14:33:29 -07001596func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001597 moduleName := ctx.ModuleName()
1598 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1599 // we check with the pseudo module name to see if its certificate is overridden.
1600 if a.vndkApex {
1601 moduleName = vndkApexName
1602 }
1603 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001604 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001605 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001606 }
1607 return String(a.properties.Certificate)
1608}
1609
Colin Cross41955e82019-05-29 14:40:35 -07001610func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1611 switch tag {
1612 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001613 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001614 default:
1615 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001616 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001617}
1618
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001619func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001620 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001621}
1622
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001623func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1624 return proptools.Bool(a.properties.Test_only_no_hashtree)
1625}
1626
Dario Freni98410fd2020-04-27 18:21:11 +01001627func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1628 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1629}
1630
Jiyong Park7c1dc612019-01-05 11:15:24 +09001631func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001632 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001633 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001634 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001635 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001636 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001637 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001638 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001639 }
1640}
1641
Jiyong Parkf97782b2019-02-13 20:28:58 +09001642func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1643 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1644 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1645 }
1646}
1647
Jiyong Park388ef3f2019-01-28 19:47:32 +09001648func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001649 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1650 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001651 }
1652
1653 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001654 globalSanitizerNames := []string{}
1655 if a.Host() {
1656 globalSanitizerNames = ctx.Config().SanitizeHost()
1657 } else {
1658 arches := ctx.Config().SanitizeDeviceArch()
1659 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1660 globalSanitizerNames = ctx.Config().SanitizeDevice()
1661 }
1662 }
1663 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001664}
1665
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001666func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross72cabc62020-06-16 17:51:46 -07001667 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001668}
1669
1670func (a *apexBundle) PreventInstall() {
1671 a.properties.PreventInstall = true
1672}
1673
1674func (a *apexBundle) HideFromMake() {
1675 a.properties.HideFromMake = true
1676}
1677
Jiyong Park956305c2020-01-09 12:32:06 +09001678func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1679 a.properties.IsCoverageVariant = coverage
1680}
1681
Jiyong Parkf653b052019-11-18 15:39:01 +09001682// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001683func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001684 // Decide the APEX-local directory by the multilib of the library
1685 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001687 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001688 case "lib32":
1689 dirInApex = "lib"
1690 case "lib64":
1691 dirInApex = "lib64"
1692 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001693 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001694 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001695 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001696 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001697 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001698 // Special case for Bionic libs and other libs installed with them. This is
1699 // to prevent those libs from being included in the search path
1700 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1701 // those libs in the Runtime APEX are available via the legacy paths in
1702 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1703 // to the legacy paths and thus will be loaded into the default linker
1704 // namespace (aka "platform" namespace). If the libs are directly in
1705 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1706 // into the runtime linker namespace, which will result in double loading of
1707 // them, which isn't supported.
1708 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001709 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001710
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001712 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001713}
1714
Jiyong Park1833cef2019-12-13 13:28:36 +09001715func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001716 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001717 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001718 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001719 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001720 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001721 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001722 af.symlinks = cc.Symlinks()
1723 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001724}
1725
Jiyong Park1833cef2019-12-13 13:28:36 +09001726func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001727 dirInApex := "bin"
1728 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001729 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001730}
Jiyong Park1833cef2019-12-13 13:28:36 +09001731func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001732 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001733 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1734 if err != nil {
1735 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001736 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001737 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001738 fileToCopy := android.PathForOutput(ctx, s)
1739 // NB: Since go binaries are static we don't need the module for anything here, which is
1740 // good since the go tool is a blueprint.Module not an android.Module like we would
1741 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001742 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001743}
1744
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001745func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 dirInApex := filepath.Join("bin", sh.SubDir())
1747 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001748 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001749 af.symlinks = sh.Symlinks()
1750 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001751}
1752
Jiyong Parked50ca82020-05-28 23:46:55 +09001753type javaDependency interface {
Jiyong Park2cd081c2020-06-01 21:39:15 +09001754 DexJar() android.Path
1755 JacocoReportClassesFile() android.Path
Colin Cross5bc17442020-07-21 20:31:17 -07001756 LintDepSets() java.LintDepSets
1757
Jiyong Parked50ca82020-05-28 23:46:55 +09001758 Stem() string
1759}
1760
Colin Cross5bc17442020-07-21 20:31:17 -07001761var _ javaDependency = (*java.Library)(nil)
1762var _ javaDependency = (*java.SdkLibrary)(nil)
1763var _ javaDependency = (*java.DexImport)(nil)
1764var _ javaDependency = (*java.SdkLibraryImport)(nil)
1765
Jiyong Parked50ca82020-05-28 23:46:55 +09001766func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001767 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001768 fileToCopy := lib.DexJar()
Paul Duffin9ee66da2020-06-17 16:59:43 +01001769 // Remove prebuilt_ if necessary so the source and prebuilt modules have the same name.
1770 name := strings.TrimPrefix(module.Name(), "prebuilt_")
1771 af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001772 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Colin Cross5bc17442020-07-21 20:31:17 -07001773 af.lintDepSets = lib.LintDepSets()
Jiyong Parked50ca82020-05-28 23:46:55 +09001774 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001775 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001776}
1777
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001778func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001779 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1780 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001781 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001782}
1783
atrost6e126252020-01-27 17:01:16 +00001784func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1785 dirInApex := filepath.Join("etc", config.SubDir())
1786 fileToCopy := config.CompatConfig()
1787 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1788}
1789
Jiyong Park1833cef2019-12-13 13:28:36 +09001790func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001791 android.Module
1792 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001793 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001794 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001795 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001796 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001797}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001798 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001799 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001800 appDir = "priv-app"
1801 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001802 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001803 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001804 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1805 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001806 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001807
1808 if app, ok := aapp.(interface {
1809 OverriddenManifestPackageName() string
1810 }); ok {
1811 af.overriddenPackageName = app.OverriddenManifestPackageName()
1812 }
Jiyong Park618922e2020-01-08 13:35:43 +09001813 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001814}
1815
Roland Levillain935639d2019-08-13 14:55:28 +01001816// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1817type flattenedApexContext struct {
1818 android.ModuleContext
1819}
1820
1821func (c *flattenedApexContext) InstallBypassMake() bool {
1822 return true
1823}
1824
Paul Duffin133608f2020-03-30 15:54:08 +01001825// Function called while walking an APEX's payload dependencies.
1826//
1827// Return true if the `to` module should be visited, false otherwise.
1828type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1829
Jiyong Park201cedd2020-02-07 17:25:49 +09001830// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001831func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001832 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001833 am, ok := child.(android.ApexModule)
1834 if !ok || !am.CanHaveApexVariants() {
1835 return false
1836 }
1837
1838 // Check for the direct dependencies that contribute to the payload
1839 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1840 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001841 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001842 }
Paul Duffin133608f2020-03-30 15:54:08 +01001843 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001844 return false
1845 }
1846
1847 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001848 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001849 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001850 }
1851
Paul Duffin133608f2020-03-30 15:54:08 +01001852 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001853 })
1854}
1855
Jooyung Han0c4e0162020-02-26 22:45:42 +09001856func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1857 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001858 intVer, err := android.ApiStrToNum(ctx, ver)
1859 if err != nil {
1860 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001861 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001862 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001863}
1864
Paul Duffinf0207962020-03-31 11:31:36 +01001865// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1866// a dependency tag.
1867var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1868
1869func PrettyPrintTag(tag blueprint.DependencyTag) string {
1870 // Use tag's custom String() method if available.
1871 if stringer, ok := tag.(fmt.Stringer); ok {
1872 return stringer.String()
1873 }
1874
1875 // Otherwise, get a default string representation of the tag's struct.
1876 tagString := fmt.Sprintf("%#v", tag)
1877
1878 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1879 tagString = tagCleaner.ReplaceAllString(tagString, "")
1880 return tagString
1881}
1882
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001883func (a *apexBundle) Updatable() bool {
1884 return proptools.Bool(a.properties.Updatable)
1885}
1886
1887var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1888
Jiyong Park201cedd2020-02-07 17:25:49 +09001889// Ensures that the dependencies are marked as available for this APEX
1890func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1891 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1892 if ctx.Host() || a.testApex || a.vndkApex {
1893 return
1894 }
1895
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001896 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1897 // Requiring them and their transitive depencies with apex_available is not right
1898 // because they just add noise.
1899 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1900 return
1901 }
1902
Paul Duffin133608f2020-03-30 15:54:08 +01001903 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1904 if externalDep {
1905 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1906 return false
1907 }
1908
Jiyong Park201cedd2020-02-07 17:25:49 +09001909 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001910 fromName := ctx.OtherModuleName(from)
1911 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001912
1913 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1914 // do any of its dependencies.
1915 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1916 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1917 return false
1918 }
1919
Colin Cross95f7b342020-06-11 11:32:11 -07001920 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffin133608f2020-03-30 15:54:08 +01001921 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001922 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001923 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001924 tagPath := ctx.GetTagPath()
1925 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1926 walkPath := ctx.GetWalkPath()[1:]
1927 for i, m := range walkPath {
1928 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001929 }
1930 ctx.ModuleErrorf("%q requires %q that is not available for the APEX. Dependency path:%s", fromName, toName, message)
Paul Duffin133608f2020-03-30 15:54:08 +01001931 // Visit this module's dependencies to check and report any issues with their availability.
1932 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001933 })
1934}
1935
Jooyung Hanced674e2020-04-27 12:10:30 +09001936func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001937 if a.Updatable() {
Jooyung Hanced674e2020-04-27 12:10:30 +09001938 if String(a.properties.Min_sdk_version) == "" {
1939 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1940 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001941
1942 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001943 }
1944}
1945
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001946func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001947 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1948 switch a.properties.ApexType {
1949 case imageApex:
1950 if buildFlattenedAsDefault {
1951 a.suffix = imageApexSuffix
1952 } else {
1953 a.suffix = ""
1954 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001955
1956 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001957 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001958 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001959 }
1960 case zipApex:
1961 if proptools.String(a.properties.Payload_type) == "zip" {
1962 a.suffix = ""
1963 a.primaryApexType = true
1964 } else {
1965 a.suffix = zipApexSuffix
1966 }
1967 case flattenedApex:
1968 if buildFlattenedAsDefault {
1969 a.suffix = ""
1970 a.primaryApexType = true
1971 } else {
1972 a.suffix = flattenedSuffix
1973 }
Alex Light5098a612018-11-29 17:12:15 -08001974 }
1975
Roland Levillain630846d2019-06-26 12:48:34 +01001976 if len(a.properties.Tests) > 0 && !a.testApex {
1977 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1978 return
1979 }
1980
Jiyong Parkfa899442020-01-31 02:49:53 +09001981 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001982 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001983
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001984 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1985
Jooyung Hane1633032019-08-01 17:41:43 +09001986 // native lib dependencies
1987 var provideNativeLibs []string
1988 var requireNativeLibs []string
1989
Jooyung Han5c998b92019-06-27 11:30:33 +09001990 // Check if "uses" requirements are met with dependent apexBundles
1991 var providedNativeSharedLibs []string
1992 useVendor := proptools.Bool(a.properties.Use_vendor)
1993 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1994 if ctx.OtherModuleDependencyTag(m) != usesTag {
1995 return
1996 }
1997 otherName := ctx.OtherModuleName(m)
1998 other, ok := m.(*apexBundle)
1999 if !ok {
2000 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2001 return
2002 }
2003 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2004 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2005 return
2006 }
2007 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2008 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2009 return
2010 }
2011 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2012 })
2013
Jiyong Parkf653b052019-11-18 15:39:01 +09002014 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002015 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002016 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002017 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01002018 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2019 return false
2020 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002021 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002022 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002023 switch depTag {
2024 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002025 if c, ok := child.(*cc.Module); ok {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002026 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2027 filesInfo = append(filesInfo, fi)
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002028 // bootstrap bionic libs are treated as provided by system
2029 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002030 provideNativeLibs = append(provideNativeLibs, fi.Stem())
Jooyung Hane1633032019-08-01 17:41:43 +09002031 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002032 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002033 } else {
2034 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002035 }
2036 case executableTag:
2037 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002038 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002039 return true // track transitive dependencies
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002040 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002041 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002042 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002043 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002044 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002045 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002046 } else {
Alex Light778127a2019-02-27 14:19:50 -08002047 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 +09002048 }
2049 case javaLibTag:
Jiyong Park2cd081c2020-06-01 21:39:15 +09002050 switch child.(type) {
Paul Duffinf642a312020-06-12 17:46:39 +01002051 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Park2cd081c2020-06-01 21:39:15 +09002052 af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002053 if !af.Ok() {
2054 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2055 return false
2056 }
2057 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002058 return true // track transitive dependencies
Jiyong Park2cd081c2020-06-01 21:39:15 +09002059 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002060 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002061 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002062 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002063 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002064 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002065 return true // track transitive dependencies
2066 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002067 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002068 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002069 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07002070 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2071 appDir := "app"
2072 if ap.Privileged() {
2073 appDir = "priv-app"
2074 }
2075 af := newApexFile(ctx, ap.OutputFile(), ap.Name(),
2076 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2077 af.certificate = java.PresignedCertificate
2078 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002079 } else {
2080 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2081 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002082 case prebuiltTag:
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002083 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002084 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002085 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2086 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002087 } else {
atrost6e126252020-01-27 17:01:16 +00002088 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002089 }
Roland Levillain630846d2019-06-26 12:48:34 +01002090 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002091 if ccTest, ok := child.(*cc.Module); ok {
2092 if ccTest.IsTestPerSrcAllTestsVariation() {
2093 // Multiple-output test module (where `test_per_src: true`).
2094 //
2095 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2096 // We do not add this variation to `filesInfo`, as it has no output;
2097 // however, we do add the other variations of this module as indirect
2098 // dependencies (see below).
2099 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002100 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002101 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002102 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002103 af.class = nativeTest
2104 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002105 }
Roland Levillain630846d2019-06-26 12:48:34 +01002106 } else {
2107 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2108 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002109 case keyTag:
2110 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002111 a.private_key_file = key.private_key_file
2112 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002113 } else {
2114 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002115 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002116 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002117 case certificateTag:
2118 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002119 a.container_certificate_file = dep.Certificate.Pem
2120 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002121 } else {
2122 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2123 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002124 case android.PrebuiltDepTag:
2125 // If the prebuilt is force disabled, remember to delete the prebuilt file
2126 // that might have been installed in the previous builds
Jiyong Parkf220db82020-07-16 21:38:56 +09002127 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002128 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2129 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002130 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002131 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002132 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002133 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002134 // We cannot use a switch statement on `depTag` here as the checked
2135 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002136 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002137 if cc, ok := child.(*cc.Module); ok {
2138 if android.InList(cc.Name(), providedNativeSharedLibs) {
2139 // If we're using a shared library which is provided from other APEX,
2140 // don't include it in this APEX
2141 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002142 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002143 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2144 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002145 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002146 // If the dependency is a stubs lib, don't include it in this APEX,
2147 // but make sure that the lib is installed on the device.
2148 // In case no APEX is having the lib, the lib is installed to the system
2149 // partition.
2150 //
2151 // Always include if we are a host-apex however since those won't have any
2152 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002153 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2154 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002155 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002156 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002157 // Don't track further
2158 return false
2159 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002160 filesInfo = append(filesInfo, af)
2161 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002162 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002163 } else if cc.IsTestPerSrcDepTag(depTag) {
2164 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002165 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002166 // Handle modules created as `test_per_src` variations of a single test module:
2167 // use the name of the generated test binary (`fileToCopy`) instead of the name
2168 // of the original test module (`depName`, shared by all `test_per_src`
2169 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002170 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002171 // these are not considered transitive dep
2172 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002173 filesInfo = append(filesInfo, af)
2174 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002175 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002176 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002177 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2178 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002179 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002180 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002181 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2182 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002183 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002184 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002185 }
2186 }
2187 }
2188 return false
2189 })
2190
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002191 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2192 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2193 // via the global boot image config.
2194 if a.artApex {
2195 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2196 dirInApex := filepath.Join("javalib", arch.String())
2197 for _, f := range files {
2198 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002199 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002200 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002201 }
2202 }
2203 }
2204
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002205 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002206 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2207 return
2208 }
2209
Jiyong Park8fd61922018-11-08 02:50:25 +09002210 // remove duplicates in filesInfo
2211 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002212 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002213 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002214 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002215 if e, ok := encountered[dest]; !ok {
2216 encountered[dest] = f
2217 } else {
2218 // If a module is directly included and also transitively depended on
2219 // consider it as directly included.
2220 e.transitiveDep = e.transitiveDep && f.transitiveDep
2221 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002222 }
2223 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002224 var result []apexFile
2225 for _, v := range encountered {
2226 result = append(result, v)
2227 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002228 return result
2229 }
2230 filesInfo = removeDup(filesInfo)
2231
2232 // to have consistent build rules
2233 sort.Slice(filesInfo, func(i, j int) bool {
2234 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2235 })
2236
Jiyong Park8fd61922018-11-08 02:50:25 +09002237 a.installDir = android.PathForModuleInstall(ctx, "apex")
2238 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002239
Jooyung Han54aca7b2019-11-20 02:26:02 +09002240 if a.properties.ApexType != zipApex {
2241 if a.properties.File_contexts == nil {
2242 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2243 } else {
2244 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2245 if a.Platform() {
2246 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2247 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2248 }
2249 }
2250 }
2251 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2252 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2253 return
2254 }
2255 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002256 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2257 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2258 // the same library in the system partition, thus effectively sharing the same libraries
2259 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2260 // in the APEX.
2261 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2262 a.installable() &&
2263 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002264
Jiyong Park9d677202020-02-19 16:29:35 +09002265 // We don't need the optimization for updatable APEXes, as it might give false signal
2266 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01002267 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002268 a.linkToSystemLib = false
2269 }
2270
Jiyong Park9b964182020-02-26 18:27:19 +09002271 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2272 if ctx.Host() {
2273 a.linkToSystemLib = false
2274 }
2275
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002276 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002277 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2278
2279 a.setCertificateAndPrivateKey(ctx)
2280 if a.properties.ApexType == flattenedApex {
2281 a.buildFlattenedApex(ctx)
2282 } else {
2283 a.buildUnflattenedApex(ctx)
2284 }
2285
Jooyung Han002ab682020-01-08 01:57:58 +09002286 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002287
2288 a.buildApexDependencyInfo(ctx)
Colin Cross5bc17442020-07-21 20:31:17 -07002289
2290 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002291}
2292
Artur Satayev2eedf622020-04-15 17:29:42 +01002293// Enforce that Java deps of the apex are using stable SDKs to compile
2294func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2295 // Visit direct deps only. As long as we guarantee top-level deps are using
2296 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2297 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2298 tag := ctx.OtherModuleDependencyTag(module)
2299 switch tag {
2300 case javaLibTag, androidAppTag:
2301 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2302 if err := m.CheckStableSdkVersion(); err != nil {
2303 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2304 }
2305 }
2306 }
2307 })
2308}
2309
Colin Cross95f7b342020-06-11 11:32:11 -07002310func baselineApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002311 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002312 moduleName = normalizeModuleName(moduleName)
2313
Colin Cross95f7b342020-06-11 11:32:11 -07002314 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin404db3f2020-03-06 12:30:13 +00002315 return true
2316 }
2317
2318 key = android.AvailableToAnyApex
Colin Cross95f7b342020-06-11 11:32:11 -07002319 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin404db3f2020-03-06 12:30:13 +00002320 return true
2321 }
2322
2323 return false
2324}
2325
2326func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002327 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2328 // system. Trim the prefix for the check since they are confusing
2329 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2330 if strings.HasPrefix(moduleName, "libclang_rt.") {
2331 // This module has many arch variants that depend on the product being built.
2332 // We don't want to list them all
2333 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002334 }
Jooyung Han11c20932020-05-19 15:47:01 +09002335 if strings.HasPrefix(moduleName, "androidx.") {
2336 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2337 moduleName = "androidx"
2338 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002339 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002340}
2341
Jooyung Han344d5432019-08-23 11:17:39 +09002342func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002343 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002344 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002345 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002346 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002347 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002348 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2349 })
Alex Light5098a612018-11-29 17:12:15 -08002350 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002351 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002352 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002353 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002354 return module
2355}
Jiyong Park30ca9372019-02-07 16:27:23 +09002356
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002357func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002358 bundle := newApexBundle()
2359 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002360 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002361 return bundle
2362}
2363
Jiyong Parkfce0b422020-02-11 03:56:06 +09002364// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2365// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002366func testApexBundleFactory() android.Module {
2367 bundle := newApexBundle()
2368 bundle.testApex = true
2369 return bundle
2370}
2371
Jiyong Parkfce0b422020-02-11 03:56:06 +09002372// apex packages other modules into an APEX file which is a packaging format for system-level
2373// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002374func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002375 return newApexBundle()
2376}
2377
Jiyong Park30ca9372019-02-07 16:27:23 +09002378//
2379// Defaults
2380//
2381type Defaults struct {
2382 android.ModuleBase
2383 android.DefaultsModuleBase
2384}
2385
Jiyong Park30ca9372019-02-07 16:27:23 +09002386func defaultsFactory() android.Module {
2387 return DefaultsFactory()
2388}
2389
2390func DefaultsFactory(props ...interface{}) android.Module {
2391 module := &Defaults{}
2392
2393 module.AddProperties(props...)
2394 module.AddProperties(
2395 &apexBundleProperties{},
2396 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002397 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002398 )
2399
2400 android.InitDefaultsModule(module)
2401 return module
2402}
Jiyong Park5d790c32019-11-15 18:40:32 +09002403
2404//
2405// OverrideApex
2406//
2407type OverrideApex struct {
2408 android.ModuleBase
2409 android.OverrideModuleBase
2410}
2411
2412func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2413 // All the overrides happen in the base module.
2414}
2415
2416// override_apex is used to create an apex module based on another apex module
2417// by overriding some of its properties.
2418func overrideApexFactory() android.Module {
2419 m := &OverrideApex{}
2420 m.AddProperties(&overridableProperties{})
2421
2422 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2423 android.InitOverrideModule(m)
2424 return m
2425}