blob: b974bcdea1aaac3ab3765b124571c3023aa76032 [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}
Anton Hansson5053c292020-01-10 15:12:39 +000066 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000067
68 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090069)
70
Paul Duffin404db3f2020-03-06 12:30:13 +000071// Transform the map of apex -> modules to module -> apexes.
72func invertApexWhiteList(m map[string][]string) map[string][]string {
73 r := make(map[string][]string)
74 for apex, modules := range m {
75 for _, module := range modules {
76 r[module] = append(r[module], apex)
77 }
78 }
79 return r
80}
81
82// Retrieve the while list of apexes to which the supplied module belongs.
83func WhitelistedApexAvailable(moduleName string) []string {
84 return inverseApexAvailWl[normalizeModuleName(moduleName)]
85}
86
Anton Hansson5053c292020-01-10 15:12:39 +000087// This is a map from apex to modules, which overrides the
88// apex_available setting for that particular module to make
89// it available for the apex regardless of its setting.
90// TODO(b/147364041): remove this
91func makeApexAvailableWhitelist() map[string][]string {
92 // The "Module separator"s below are employed to minimize merge conflicts.
93 m := make(map[string][]string)
94 //
95 // Module separator
96 //
Jiyong Park8b399192020-04-29 22:34:13 +090097 m["com.android.appsearch"] = []string{
98 "icing-java-proto-lite",
99 "libprotobuf-java-lite",
Anton Hansson5053c292020-01-10 15:12:39 +0000100 }
101 //
102 // Module separator
103 //
104 m["com.android.bluetooth.updatable"] = []string{
105 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000106 "android.hardware.bluetooth.a2dp@1.0",
107 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900108 "android.hardware.bluetooth@1.0",
109 "android.hardware.bluetooth@1.1",
110 "android.hardware.graphics.bufferqueue@1.0",
111 "android.hardware.graphics.bufferqueue@2.0",
112 "android.hardware.graphics.common@1.0",
113 "android.hardware.graphics.common@1.1",
114 "android.hardware.graphics.common@1.2",
115 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000116 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900117 "android.hidl.token@1.0",
118 "android.hidl.token@1.0-utils",
119 "avrcp-target-service",
120 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900121 "bluetooth-protos-lite",
122 "bluetooth.mapsapi",
123 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900124 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900125 "ipmemorystore-aidl-interfaces-V5-java",
126 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900127 "internal_include_headers",
128 "lib-bt-packets",
129 "lib-bt-packets-avrcp",
130 "lib-bt-packets-base",
131 "libFraunhoferAAC",
132 "libaudio-a2dp-hw-utils",
133 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900134 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000135 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900136 "libbluetooth-types",
137 "libbluetooth-types-header",
138 "libbluetooth_gd",
139 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libbt-audio-hal-interface",
142 "libbt-bta",
143 "libbt-common",
144 "libbt-hci",
145 "libbt-platform-protos-lite",
146 "libbt-protos-lite",
147 "libbt-sbc-decoder",
148 "libbt-sbc-encoder",
149 "libbt-stack",
150 "libbt-utils",
151 "libbtcore",
152 "libbtdevice",
153 "libbte",
154 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000155 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000156 "libevent",
157 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900158 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900159 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900160 "libmedia_headers",
161 "libmodpb64",
162 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900163 "libstagefright_foundation_headers",
164 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000165 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900166 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000167 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900168 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000169 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900170 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900171 "net-utils-services-common",
172 "netd_aidl_interface-unstable-java",
173 "netd_event_listener_interface-java",
174 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900175 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900176 "sap-api-java-static",
177 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000178 }
179 //
180 // Module separator
181 //
182 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
183 //
184 // Module separator
185 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900186 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900187 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 }
Anton Hansson5053c292020-01-10 15:12:39 +0000189 //
190 // Module separator
191 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900192 m["com.android.extservices"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900193 "error_prone_annotations",
194 "ExtServices-core",
195 "ExtServices",
196 "libtextclassifier-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900197 "libz_current",
Jooyung Han11c20932020-05-19 15:47:01 +0900198 "textclassifier-statsd",
199 "TextClassifierNotificationLibNoManifest",
200 "TextClassifierServiceLibNoManifest",
Jiyong Parkfa899442020-01-31 02:49:53 +0900201 }
202 //
203 // Module separator
204 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900205 m["com.android.neuralnetworks"] = []string{
206 "android.hardware.neuralnetworks@1.0",
207 "android.hardware.neuralnetworks@1.1",
208 "android.hardware.neuralnetworks@1.2",
209 "android.hardware.neuralnetworks@1.3",
210 "android.hidl.allocator@1.0",
211 "android.hidl.memory.token@1.0",
212 "android.hidl.memory@1.0",
213 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900215 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900216 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libprocpartition",
218 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900219 }
Anton Hansson5053c292020-01-10 15:12:39 +0000220 //
221 // Module separator
222 //
Anton Hansson5053c292020-01-10 15:12:39 +0000223 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900224 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000225 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900226 "android.hardware.cas@1.0",
227 "android.hardware.configstore-utils",
228 "android.hardware.configstore@1.0",
229 "android.hardware.configstore@1.1",
230 "android.hardware.graphics.allocator@2.0",
231 "android.hardware.graphics.allocator@3.0",
232 "android.hardware.graphics.bufferqueue@1.0",
233 "android.hardware.graphics.bufferqueue@2.0",
234 "android.hardware.graphics.common@1.0",
235 "android.hardware.graphics.common@1.1",
236 "android.hardware.graphics.common@1.2",
237 "android.hardware.graphics.mapper@2.0",
238 "android.hardware.graphics.mapper@2.1",
239 "android.hardware.graphics.mapper@3.0",
240 "android.hardware.media.omx@1.0",
241 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000242 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000243 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900244 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000245 "android.hidl.token@1.0",
246 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "bionic_libc_platform_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900248 "exoplayer2-extractor",
249 "exoplayer2-extractor-annotation-stubs",
Jiyong Parkfa899442020-01-31 02:49:53 +0900250 "gl_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900251 "jsr305",
Jiyong Parkfa899442020-01-31 02:49:53 +0900252 "libEGL",
253 "libEGL_blobCache",
254 "libEGL_getProcAddress",
255 "libFLAC",
256 "libFLAC-config",
257 "libFLAC-headers",
258 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000259 "libaacextractor",
260 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900261 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900262 "libaudio_system_headers",
263 "libaudioclient",
264 "libaudioclient_headers",
265 "libaudiofoundation",
266 "libaudiofoundation_headers",
267 "libaudiomanager",
268 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000269 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900270 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900271 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900272 "libbluetooth-types-header",
273 "libbufferhub",
274 "libbufferhub_headers",
275 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900276 "libc_malloc_debug_backtrace",
277 "libcamera_client",
278 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900279 "libdexfile_external_headers",
280 "libdexfile_support",
281 "libdvr_headers",
282 "libexpat",
283 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000284 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900285 "libgrallocusage",
286 "libgraphicsenv",
287 "libgui",
288 "libgui_headers",
289 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900290 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900291 "liblzma",
292 "libmath",
293 "libmedia",
294 "libmedia_codeclist",
295 "libmedia_headers",
296 "libmedia_helper",
297 "libmedia_helper_headers",
298 "libmedia_midiiowrapper",
299 "libmedia_omx",
300 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000301 "libmidiextractor",
302 "libmkvextractor",
303 "libmp3extractor",
304 "libmp4extractor",
305 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libnativebase_headers",
307 "libnativebridge-headers",
308 "libnativebridge_lazy",
309 "libnativeloader-headers",
310 "libnativeloader_lazy",
311 "libnativewindow_headers",
312 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000313 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900314 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900315 "libpdx",
316 "libpdx_default_transport",
317 "libpdx_headers",
318 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900319 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000320 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900321 "libspeexresampler",
322 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000323 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900324 "libstagefright_flacdec",
325 "libstagefright_foundation",
326 "libstagefright_foundation_headers",
327 "libstagefright_foundation_without_imemory",
328 "libstagefright_headers",
329 "libstagefright_id3",
330 "libstagefright_metadatautils",
331 "libstagefright_mpeg2extractor",
332 "libstagefright_mpeg2support",
333 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900334 "libui",
335 "libui_headers",
336 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900337 "libvibrator",
338 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000339 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900340 "libwebm",
341 "media_ndk_headers",
342 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000343 "updatable-media",
344 }
345 //
346 // Module separator
347 //
348 m["com.android.media.swcodec"] = []string{
349 "android.frameworks.bufferhub@1.0",
350 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900351 "android.hardware.configstore-utils",
352 "android.hardware.configstore@1.0",
353 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000354 "android.hardware.graphics.allocator@2.0",
355 "android.hardware.graphics.allocator@3.0",
356 "android.hardware.graphics.allocator@4.0",
357 "android.hardware.graphics.bufferqueue@1.0",
358 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900359 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000360 "android.hardware.graphics.common@1.0",
361 "android.hardware.graphics.common@1.1",
362 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000363 "android.hardware.graphics.mapper@2.0",
364 "android.hardware.graphics.mapper@2.1",
365 "android.hardware.graphics.mapper@3.0",
366 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000367 "android.hardware.media.bufferpool@2.0",
368 "android.hardware.media.c2@1.0",
369 "android.hardware.media.c2@1.1",
370 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900371 "android.hardware.media@1.0",
372 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000373 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900374 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000375 "android.hidl.safe_union@1.0",
376 "android.hidl.token@1.0",
377 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900378 "libEGL",
379 "libFLAC",
380 "libFLAC-config",
381 "libFLAC-headers",
382 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900383 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900384 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900385 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000386 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900387 "libaudioutils",
388 "libaudioutils_fixedfft",
389 "libavcdec",
390 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000391 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900392 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900393 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900394 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libbluetooth-types-header",
396 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900397 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900399 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000400 "libcodec2_hidl@1.0",
401 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900402 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000403 "libcodec2_soft_aacdec",
404 "libcodec2_soft_aacenc",
405 "libcodec2_soft_amrnbdec",
406 "libcodec2_soft_amrnbenc",
407 "libcodec2_soft_amrwbdec",
408 "libcodec2_soft_amrwbenc",
409 "libcodec2_soft_av1dec_gav1",
410 "libcodec2_soft_avcdec",
411 "libcodec2_soft_avcenc",
412 "libcodec2_soft_common",
413 "libcodec2_soft_flacdec",
414 "libcodec2_soft_flacenc",
415 "libcodec2_soft_g711alawdec",
416 "libcodec2_soft_g711mlawdec",
417 "libcodec2_soft_gsmdec",
418 "libcodec2_soft_h263dec",
419 "libcodec2_soft_h263enc",
420 "libcodec2_soft_hevcdec",
421 "libcodec2_soft_hevcenc",
422 "libcodec2_soft_mp3dec",
423 "libcodec2_soft_mpeg2dec",
424 "libcodec2_soft_mpeg4dec",
425 "libcodec2_soft_mpeg4enc",
426 "libcodec2_soft_opusdec",
427 "libcodec2_soft_opusenc",
428 "libcodec2_soft_rawdec",
429 "libcodec2_soft_vorbisdec",
430 "libcodec2_soft_vp8dec",
431 "libcodec2_soft_vp8enc",
432 "libcodec2_soft_vp9dec",
433 "libcodec2_soft_vp9enc",
434 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900435 "libdexfile_support",
436 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000437 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libfmq",
439 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000440 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900441 "libgrallocusage",
442 "libgraphicsenv",
443 "libgsm",
444 "libgui_bufferqueue_static",
445 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000446 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900447 "libhardware_headers",
448 "libhevcdec",
449 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000450 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900451 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900452 "liblzma",
453 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000454 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900456 "libmpeg2dec",
457 "libnativebase_headers",
458 "libnativebridge_lazy",
459 "libnativeloader_lazy",
460 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900461 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000462 "libscudo_wrapper",
463 "libsfplugin_ccodec_utils",
464 "libspeexresampler",
465 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900466 "libstagefright_amrnbdec",
467 "libstagefright_amrnbenc",
468 "libstagefright_amrwbdec",
469 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000470 "libstagefright_bufferpool@2.0.1",
471 "libstagefright_bufferqueue_helper",
472 "libstagefright_enc_common",
473 "libstagefright_flacdec",
474 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900475 "libstagefright_foundation_headers",
476 "libstagefright_headers",
477 "libstagefright_m4vh263dec",
478 "libstagefright_m4vh263enc",
479 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000480 "libsync",
481 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900482 "libui_headers",
483 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000484 "libvorbisidec",
485 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900486 "libyuv",
487 "libyuv_static",
488 "media_ndk_headers",
489 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000490 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000491 }
492 //
493 // Module separator
494 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900495 m["com.android.mediaprovider"] = []string{
496 "MediaProvider",
497 "MediaProviderGoogle",
498 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libbase_ndk",
500 "libfuse",
501 "libfuse_jni",
502 "libnativehelper_header_only",
503 }
504 //
505 // Module separator
506 //
507 m["com.android.permission"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900508 "car-ui-lib",
509 "iconloader",
Jiyong Parkfa899442020-01-31 02:49:53 +0900510 "kotlin-annotations",
511 "kotlin-stdlib",
512 "kotlin-stdlib-jdk7",
513 "kotlin-stdlib-jdk8",
514 "kotlinx-coroutines-android",
515 "kotlinx-coroutines-android-nodeps",
516 "kotlinx-coroutines-core",
517 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900518 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900519 "GooglePermissionController",
520 "PermissionController",
Jooyung Han11c20932020-05-19 15:47:01 +0900521 "SettingsLibActionBarShadow",
522 "SettingsLibAppPreference",
523 "SettingsLibBarChartPreference",
524 "SettingsLibLayoutPreference",
525 "SettingsLibProgressBar",
526 "SettingsLibSearchWidget",
527 "SettingsLibSettingsTheme",
528 "SettingsLibRestrictedLockUtils",
529 "SettingsLibHelpUtils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900530 }
Anton Hansson5053c292020-01-10 15:12:39 +0000531 //
532 // Module separator
533 //
Anton Hansson5053c292020-01-10 15:12:39 +0000534 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900535 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900536 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900537 "libc_aeabi",
538 "libc_bionic",
539 "libc_bionic_ndk",
540 "libc_bootstrap",
541 "libc_common",
542 "libc_common_shared",
543 "libc_common_static",
544 "libc_dns",
545 "libc_dynamic_dispatch",
546 "libc_fortify",
547 "libc_freebsd",
548 "libc_freebsd_large_stack",
549 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900550 "libc_init_dynamic",
551 "libc_init_static",
552 "libc_jemalloc_wrapper",
553 "libc_netbsd",
554 "libc_nomalloc",
555 "libc_nopthread",
556 "libc_openbsd",
557 "libc_openbsd_large_stack",
558 "libc_openbsd_ndk",
559 "libc_pthread",
560 "libc_static_dispatch",
561 "libc_syscalls",
562 "libc_tzcode",
563 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900564 "libdebuggerd",
565 "libdebuggerd_common_headers",
566 "libdebuggerd_handler_core",
567 "libdebuggerd_handler_fallback",
568 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000569 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900570 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900571 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900572 "libjemalloc5",
573 "liblinker_main",
574 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000576 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900577 "libprocinfo",
578 "libpropertyinfoparser",
579 "libscudo",
580 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900581 "libsystemproperties",
582 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000583 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900584 "libz",
585 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000586 }
587 //
588 // Module separator
589 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900590 m["com.android.tethering"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900591 "android.hardware.tetheroffload.config-V1.0-java",
592 "android.hardware.tetheroffload.control-V1.0-java",
593 "android.hidl.base-V1.0-java",
594 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900595 "libcgrouprc",
596 "libcgrouprc_format",
Jooyung Han11c20932020-05-19 15:47:01 +0900597 "libnativehelper_compat_libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900598 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900599 "libvndksupport",
Jooyung Han11c20932020-05-19 15:47:01 +0900600 "net-utils-framework-common",
601 "netd_aidl_interface-V3-java",
602 "netlink-client",
603 "networkstack-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900604 "tethering-aidl-interfaces-java",
Jooyung Han11c20932020-05-19 15:47:01 +0900605 "TetheringApiCurrentLib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900606 }
Anton Hansson5053c292020-01-10 15:12:39 +0000607 //
608 // Module separator
609 //
610 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900611 "PlatformProperties",
612 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900613 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900614 "android.hardware.wifi-V1.1-java",
615 "android.hardware.wifi-V1.2-java",
616 "android.hardware.wifi-V1.3-java",
617 "android.hardware.wifi-V1.4-java",
618 "android.hardware.wifi.hostapd-V1.0-java",
619 "android.hardware.wifi.hostapd-V1.1-java",
620 "android.hardware.wifi.hostapd-V1.2-java",
621 "android.hardware.wifi.supplicant-V1.0-java",
622 "android.hardware.wifi.supplicant-V1.1-java",
623 "android.hardware.wifi.supplicant-V1.2-java",
624 "android.hardware.wifi.supplicant-V1.3-java",
625 "android.hidl.base-V1.0-java",
626 "android.hidl.manager-V1.0-java",
627 "android.hidl.manager-V1.1-java",
628 "android.hidl.manager-V1.2-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 "bouncycastle-unbundled",
630 "dnsresolver_aidl_interface-V2-java",
631 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900632 "framework-wifi-pre-jarjar",
633 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900634 "ipmemorystore-aidl-interfaces-V3-java",
635 "ipmemorystore-aidl-interfaces-java",
636 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000638 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900639 "net-utils-services-common",
640 "netd_aidl_interface-V2-java",
641 "netd_aidl_interface-unstable-java",
642 "netd_event_listener_interface-java",
643 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900644 "networkstack-client",
645 "services.net",
646 "wifi-lite-protos",
647 "wifi-nano-protos",
648 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000649 "wifi-service-resources",
650 }
651 //
652 // Module separator
653 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900654 m["com.android.sdkext"] = []string{
655 "fmtlib_ndk",
656 "libbase_ndk",
657 "libprotobuf-cpp-lite-ndk",
658 }
659 //
660 // Module separator
661 //
662 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900663 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900664 }
665 //
666 // Module separator
667 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000668 m[android.AvailableToAnyApex] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900669 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
670 "androidx",
671 "androidx-constraintlayout_constraintlayout",
672 "androidx-constraintlayout_constraintlayout-nodeps",
673 "androidx-constraintlayout_constraintlayout-solver",
674 "androidx-constraintlayout_constraintlayout-solver-nodeps",
675 "com.google.android.material_material",
676 "com.google.android.material_material-nodeps",
677
Jiyong Parkfa899442020-01-31 02:49:53 +0900678 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900679 "libclang_rt",
680 "libgcc_stripped",
681 "libprofile-clang-extras",
682 "libprofile-clang-extras_ndk",
683 "libprofile-extras",
684 "libprofile-extras_ndk",
685 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900686 }
Anton Hansson5053c292020-01-10 15:12:39 +0000687 return m
688}
689
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900690func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900691 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800692 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900693 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900694 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700695 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900696 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700697 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900698
Jooyung Han31c470b2019-10-18 16:26:59 +0900699 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900700 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900701
702 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
703 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
704 sort.Strings(*apexFileContextsInfos)
705 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
706 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900707}
708
Jooyung Han31c470b2019-10-18 16:26:59 +0900709func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
710 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
711 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
712}
713
Jiyong Parkd1063c12019-07-17 20:08:41 +0900714func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900715 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900716 ctx.BottomUp("apex", apexMutator).Parallel()
717 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
718 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900719 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900720}
721
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900722// Mark the direct and transitive dependencies of apex bundles so that they
723// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900724func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900725 if !mctx.Module().Enabled() {
726 return
727 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800728 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900729 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000730 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900731 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900732 ApexName: mctx.ModuleName(),
733 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100734 Updatable: a.Updatable(),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900735 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900736 directDep = true
737 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800738 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900739 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900740 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900741
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800742 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900743 return
744 }
745
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100746 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900747
Jiyong Parkf760cae2020-02-12 07:53:12 +0900748 mctx.VisitDirectDeps(func(child android.Module) {
749 depName := mctx.OtherModuleName(child)
750 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100751 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800752 android.UpdateApexDependency(apexBundles, depName, directDep)
753 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900754 }
755 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900756}
757
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900758// mark if a module cannot be available to platform. A module cannot be available
759// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
760// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
761func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
762 // Host and recovery are not considered as platform
763 if mctx.Host() || mctx.Module().InstallInRecovery() {
764 return
765 }
766
767 if am, ok := mctx.Module().(android.ApexModule); ok {
768 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
769
770 // In a rare case when a lib is marked as available only to an apex
771 // but the apex doesn't exist. This can happen in a partial manifest branch
772 // like master-art. Currently, libstatssocket in the stats APEX is causing
773 // this problem.
774 // Include the lib in platform because the module SDK that ought to provide
775 // it doesn't exist, so it would otherwise be left out completely.
776 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
777 // this check for libraries provided by SDKs.
778 if !availableToPlatform && !android.InAnyApex(am.Name()) {
779 availableToPlatform = true
780 }
781
782 // If any of the dep is not available to platform, this module is also considered
783 // as being not available to platform even if it has "//apex_available:platform"
784 mctx.VisitDirectDeps(func(child android.Module) {
785 if !am.DepIsInSameApex(mctx, child) {
786 // if the dependency crosses apex boundary, don't consider it
787 return
788 }
789 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
790 availableToPlatform = false
791 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
792 }
793 })
794
795 // Exception 1: stub libraries and native bridge libraries are always available to platform
796 if cc, ok := mctx.Module().(*cc.Module); ok &&
797 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
798 availableToPlatform = true
799 }
800
801 // Exception 2: bootstrap bionic libraries are also always available to platform
802 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
803 availableToPlatform = true
804 }
805
806 if !availableToPlatform {
807 am.SetNotAvailableForPlatform()
808 }
809 }
810}
811
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100812// If a module in an APEX depends on a module from an SDK then it needs an APEX
813// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
814func inAnySdk(module android.Module) bool {
815 if sa, ok := module.(android.SdkAware); ok {
816 return sa.IsInAnySdk()
817 }
818
819 return false
820}
821
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900822// Create apex variations if a module is included in APEX(s).
823func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900824 if !mctx.Module().Enabled() {
825 return
826 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900827 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900828 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000829 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900830 // apex bundle itself is mutated so that it and its modules have same
831 // apex variant.
832 apexBundleName := mctx.ModuleName()
833 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900834 } else if o, ok := mctx.Module().(*OverrideApex); ok {
835 apexBundleName := o.GetOverriddenModuleName()
836 if apexBundleName == "" {
837 mctx.ModuleErrorf("base property is not set")
838 return
839 }
840 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900841 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900842
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900843}
Sundong Ahne9b55722019-09-06 17:37:42 +0900844
Jooyung Han7a78a922019-10-08 21:59:58 +0900845var (
846 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
847 apexFileContextsInfosMutex sync.Mutex
848)
849
850func apexFileContextsInfos(config android.Config) *[]string {
851 return config.Once(apexFileContextsInfosKey, func() interface{} {
852 return &[]string{}
853 }).(*[]string)
854}
855
Jooyung Han54aca7b2019-11-20 02:26:02 +0900856func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900857 apexFileContextsInfosMutex.Lock()
858 defer apexFileContextsInfosMutex.Unlock()
859 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900860 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900861}
862
Sundong Ahne9b55722019-09-06 17:37:42 +0900863func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900864 if !mctx.Module().Enabled() {
865 return
866 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900867 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900868 var variants []string
869 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
870 case "image":
871 variants = append(variants, imageApexType, flattenedApexType)
872 case "zip":
873 variants = append(variants, zipApexType)
874 case "both":
875 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
876 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900877 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900878 return
879 }
880
881 modules := mctx.CreateLocalVariations(variants...)
882
883 for i, v := range variants {
884 switch v {
885 case imageApexType:
886 modules[i].(*apexBundle).properties.ApexType = imageApex
887 case zipApexType:
888 modules[i].(*apexBundle).properties.ApexType = zipApex
889 case flattenedApexType:
890 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900891 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900892 modules[i].(*apexBundle).MakeAsSystemExt()
893 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900894 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900895 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900896 } else if _, ok := mctx.Module().(*OverrideApex); ok {
897 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900898 }
899}
900
Jooyung Han5c998b92019-06-27 11:30:33 +0900901func apexUsesMutator(mctx android.BottomUpMutatorContext) {
902 if ab, ok := mctx.Module().(*apexBundle); ok {
903 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
904 }
905}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900906
Jooyung Handc782442019-11-01 03:14:38 +0900907var (
908 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
909)
910
911// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
912// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
913// which may cause compatibility issues. (e.g. libbinder)
914// Even though libbinder restricts its availability via 'apex_available' property and relies on
915// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
916// to avoid similar problems.
917func useVendorWhitelist(config android.Config) []string {
918 return config.Once(useVendorWhitelistKey, func() interface{} {
919 return []string{
920 // swcodec uses "vendor" variants for smaller size
921 "com.android.media.swcodec",
922 "test_com.android.media.swcodec",
923 }
924 }).([]string)
925}
926
927// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
928// called before the first call to useVendorWhitelist()
929func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
930 config.Once(useVendorWhitelistKey, func() interface{} {
931 return whitelist
932 })
933}
934
Alex Light9670d332019-01-29 18:07:33 -0800935type apexNativeDependencies struct {
936 // List of native libraries
937 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900938
Alex Light9670d332019-01-29 18:07:33 -0800939 // List of native executables
940 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900941
Roland Levillain630846d2019-06-26 12:48:34 +0100942 // List of native tests
943 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800944}
Jooyung Han344d5432019-08-23 11:17:39 +0900945
Alex Light9670d332019-01-29 18:07:33 -0800946type apexMultilibProperties struct {
947 // Native dependencies whose compile_multilib is "first"
948 First apexNativeDependencies
949
950 // Native dependencies whose compile_multilib is "both"
951 Both apexNativeDependencies
952
953 // Native dependencies whose compile_multilib is "prefer32"
954 Prefer32 apexNativeDependencies
955
956 // Native dependencies whose compile_multilib is "32"
957 Lib32 apexNativeDependencies
958
959 // Native dependencies whose compile_multilib is "64"
960 Lib64 apexNativeDependencies
961}
962
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900963type apexBundleProperties struct {
964 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000965 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800966 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900967
Jiyong Park40e26a22019-02-08 02:53:06 +0900968 // AndroidManifest.xml file used for the zip container of this APEX bundle.
969 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800970 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900971
Roland Levillain411c5842019-09-19 16:37:20 +0100972 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
973 // device (/apex/<apex_name>).
974 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +0900975 Apex_name *string
976
Jiyong Parkd0a65ba2018-11-10 06:37:15 +0900977 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +0900978 // For platform APEXes, this should points to a file under /system/sepolicy
979 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
980 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900981
982 // List of native shared libs that are embedded inside this APEX bundle
983 Native_shared_libs []string
984
Roland Levillain630846d2019-06-26 12:48:34 +0100985 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900986 Binaries []string
987
988 // List of java libraries that are embedded inside this APEX bundle
989 Java_libs []string
990
991 // List of prebuilt files that are embedded inside this APEX bundle
992 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +0900993
Roland Levillain630846d2019-06-26 12:48:34 +0100994 // List of tests that are embedded inside this APEX bundle
995 Tests []string
996
Jiyong Parkff1458f2018-10-12 21:49:38 +0900997 // Name of the apex_key module that provides the private key to sign APEX
998 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +0900999
Alex Light5098a612018-11-29 17:12:15 -08001000 // The type of APEX to build. Controls what the APEX payload is. Either
1001 // 'image', 'zip' or 'both'. Default: 'image'.
1002 Payload_type *string
1003
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001004 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1005 // or an android_app_certificate module name in the form ":module".
1006 Certificate *string
1007
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001008 // Whether this APEX is installable to one of the partitions. Default: true.
1009 Installable *bool
1010
Jiyong Parkda6eb592018-12-19 17:12:36 +09001011 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1012 // Default is false.
1013 Use_vendor *bool
1014
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001015 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1016 Ignore_system_library_special_case *bool
1017
Alex Light9670d332019-01-29 18:07:33 -08001018 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001019
Jiyong Parkf97782b2019-02-13 20:28:58 +09001020 // List of sanitizer names that this APEX is enabled for
1021 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001022
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001023 PreventInstall bool `blueprint:"mutated"`
1024
1025 HideFromMake bool `blueprint:"mutated"`
1026
Jooyung Han5c998b92019-06-27 11:30:33 +09001027 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1028 Provide_cpp_shared_libs *bool
1029
1030 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1031 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001032
1033 // A txt file containing list of files that are whitelisted to be included in this APEX.
1034 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001035
Sundong Ahnabb64432019-10-22 13:58:29 +09001036 // package format of this apex variant; could be non-flattened, flattened, or zip.
1037 // imageApex, zipApex or flattened
1038 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001039
Jiyong Parkd1063c12019-07-17 20:08:41 +09001040 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1041 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1042 // is implied. This value affects all modules included in this APEX. In other words, they are
1043 // also built with the SDKs specified here.
1044 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001045
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001046 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1047 // Should be only used in tests#.
1048 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001049
Dario Freni98410fd2020-04-27 18:21:11 +01001050 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1051 // Should be only used in tests#.
1052 Test_only_unsigned_payload *bool
1053
Jiyong Park956305c2020-01-09 12:32:06 +09001054 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001055
1056 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001057 // rules for making sure that the APEX is truly updatable.
1058 // - To be updatable, min_sdk_version should be set as well
1059 // This will also disable the size optimizations like symlinking to the system libs.
1060 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001061 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001062
1063 // The minimum SDK version that this apex must be compatible with.
1064 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001065}
1066
1067type apexTargetBundleProperties struct {
1068 Target struct {
1069 // Multilib properties only for android.
1070 Android struct {
1071 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001072 }
Jooyung Han344d5432019-08-23 11:17:39 +09001073
Alex Light9670d332019-01-29 18:07:33 -08001074 // Multilib properties only for host.
1075 Host struct {
1076 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001077 }
Jooyung Han344d5432019-08-23 11:17:39 +09001078
Alex Light9670d332019-01-29 18:07:33 -08001079 // Multilib properties only for host linux_bionic.
1080 Linux_bionic struct {
1081 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001082 }
Jooyung Han344d5432019-08-23 11:17:39 +09001083
Alex Light9670d332019-01-29 18:07:33 -08001084 // Multilib properties only for host linux_glibc.
1085 Linux_glibc struct {
1086 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001087 }
1088 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001089}
1090
Jiyong Park5d790c32019-11-15 18:40:32 +09001091type overridableProperties struct {
1092 // List of APKs to package inside APEX
1093 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001094
1095 // Names of modules to be overridden. Listed modules can only be other binaries
1096 // (in Make or Soong).
1097 // This does not completely prevent installation of the overridden binaries, but if both
1098 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1099 // from PRODUCT_PACKAGES.
1100 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001101
1102 // Logging Parent value
1103 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001104
1105 // Apex Container Package Name.
1106 // Override value for attribute package:name in AndroidManifest.xml
1107 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001108}
1109
Alex Light5098a612018-11-29 17:12:15 -08001110type apexPackaging int
1111
1112const (
1113 imageApex apexPackaging = iota
1114 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001115 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001116)
1117
Sundong Ahnabb64432019-10-22 13:58:29 +09001118// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001119func (a apexPackaging) suffix() string {
1120 switch a {
1121 case imageApex:
1122 return imageApexSuffix
1123 case zipApex:
1124 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001125 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001126 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001127 }
1128}
1129
1130func (a apexPackaging) name() string {
1131 switch a {
1132 case imageApex:
1133 return imageApexType
1134 case zipApex:
1135 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001136 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001137 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001138 }
1139}
1140
Jiyong Parkf653b052019-11-18 15:39:01 +09001141type apexFileClass int
1142
1143const (
1144 etc apexFileClass = iota
1145 nativeSharedLib
1146 nativeExecutable
1147 shBinary
1148 pyBinary
1149 goBinary
1150 javaSharedLib
1151 nativeTest
1152 app
1153)
1154
Jiyong Park8fd61922018-11-08 02:50:25 +09001155func (class apexFileClass) NameInMake() string {
1156 switch class {
1157 case etc:
1158 return "ETC"
1159 case nativeSharedLib:
1160 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001161 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001162 return "EXECUTABLES"
1163 case javaSharedLib:
1164 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001165 case nativeTest:
1166 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001167 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001168 // b/142537672 Why isn't this APP? We want to have full control over
1169 // the paths and file names of the apk file under the flattend APEX.
1170 // If this is set to APP, then the paths and file names are modified
1171 // by the Make build system. For example, it is installed to
1172 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1173 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1174 // appends module name (which is <apexname>.<Appname> to the path.
1175 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001176 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001177 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001178 }
1179}
1180
Jiyong Parkf653b052019-11-18 15:39:01 +09001181// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001182type apexFile struct {
1183 builtFile android.Path
Jiyong Parked50ca82020-05-28 23:46:55 +09001184 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001185 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001186 installDir string
1187 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001188 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001189 // list of symlinks that will be created in installDir that point to this apexFile
1190 symlinks []string
1191 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001192 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001193
1194 requiredModuleNames []string
1195 targetRequiredModuleNames []string
1196 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001197
Colin Cross503c1d02020-01-28 14:00:53 -08001198 jacocoReportClassesFile android.Path // only for javalibs and apps
1199 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001200 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001201}
1202
Jiyong Park1833cef2019-12-13 13:28:36 +09001203func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1204 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001205 builtFile: builtFile,
1206 moduleName: moduleName,
1207 installDir: installDir,
1208 class: class,
1209 module: module,
1210 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001211 if module != nil {
1212 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001213 ret.requiredModuleNames = module.RequiredModuleNames()
1214 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1215 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001216 }
1217 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001218}
1219
1220func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001221 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001222}
1223
Jiyong Parked50ca82020-05-28 23:46:55 +09001224func (af *apexFile) apexRelativePath(path string) string {
1225 return filepath.Join(af.installDir, path)
1226}
1227
Jiyong Park7cd10e32020-01-14 09:22:18 +09001228// Path() returns path of this apex file relative to the APEX root
1229func (af *apexFile) Path() string {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001230 return af.apexRelativePath(af.Stem())
1231}
1232
1233func (af *apexFile) Stem() string {
Jiyong Parked50ca82020-05-28 23:46:55 +09001234 if af.stem != "" {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001235 return af.stem
Jiyong Parked50ca82020-05-28 23:46:55 +09001236 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001237 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001238}
1239
1240// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1241func (af *apexFile) SymlinkPaths() []string {
1242 var ret []string
1243 for _, symlink := range af.symlinks {
1244 ret = append(ret, filepath.Join(af.installDir, symlink))
1245 }
1246 return ret
1247}
1248
1249func (af *apexFile) AvailableToPlatform() bool {
1250 if af.module == nil {
1251 return false
1252 }
1253 if am, ok := af.module.(android.ApexModule); ok {
1254 return am.AvailableFor(android.AvailableToPlatform)
1255 }
1256 return false
1257}
1258
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001259type apexBundle struct {
1260 android.ModuleBase
1261 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001262 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001263 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001264
Jiyong Park5d790c32019-11-15 18:40:32 +09001265 properties apexBundleProperties
1266 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001267 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001268
Jooyung Hanf21c7972019-12-16 22:32:06 +09001269 // specific to apex_vndk modules
1270 vndkProperties apexVndkProperties
1271
Colin Crossa4925902018-11-16 11:36:28 -08001272 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001273 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001274 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001275
Jiyong Park03b68dd2019-07-26 23:20:40 +09001276 prebuiltFileToDelete string
1277
Jiyong Park42cca6c2019-04-01 11:15:50 +09001278 public_key_file android.Path
1279 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001280
1281 container_certificate_file android.Path
1282 container_private_key_file android.Path
1283
Jooyung Han54aca7b2019-11-20 02:26:02 +09001284 fileContexts android.Path
1285
Jiyong Park8fd61922018-11-08 02:50:25 +09001286 // list of files to be included in this apex
1287 filesInfo []apexFile
1288
Jiyong Park956305c2020-01-09 12:32:06 +09001289 // list of module names that should be installed along with this APEX
1290 requiredDeps []string
1291
Jiyong Park956305c2020-01-09 12:32:06 +09001292 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001293 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001294
Sundong Ahnabb64432019-10-22 13:58:29 +09001295 testApex bool
1296 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001297 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001298 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001299
Jooyung Han214bf372019-11-12 13:03:50 +09001300 manifestJsonOut android.WritablePath
1301 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001302
Jooyung Han002ab682020-01-08 01:57:58 +09001303 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001304 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001305 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001306 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1307 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001308
1309 // Suffix of module name in Android.mk
1310 // ".flattened", ".apex", ".zipapex", or ""
1311 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001312
1313 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001314
1315 // Whether to create symlink to the system file instead of having a file
1316 // inside the apex or not
1317 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001318
1319 // Struct holding the merged notice file paths in different formats
1320 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001321}
1322
Jiyong Park397e55e2018-10-24 21:09:55 +09001323func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001324 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001325 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001326 // Use *FarVariation* to be able to depend on modules having
1327 // conflicting variations with this module. This is required since
1328 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1329 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001330 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001331 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001332 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001333 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001334 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001335
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001336 ctx.AddFarVariationDependencies(append(target.Variations(),
1337 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1338 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001339
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001340 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001341 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001342 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001343 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001344}
1345
Alex Light9670d332019-01-29 18:07:33 -08001346func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1347 if ctx.Os().Class == android.Device {
1348 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1349 } else {
1350 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1351 if ctx.Os().Bionic() {
1352 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1353 } else {
1354 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1355 }
1356 }
1357}
1358
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001359func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001360 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1361 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1362 }
1363
Jiyong Park397e55e2018-10-24 21:09:55 +09001364 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001365 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001366
1367 a.combineProperties(ctx)
1368
Jiyong Park397e55e2018-10-24 21:09:55 +09001369 has32BitTarget := false
1370 for _, target := range targets {
1371 if target.Arch.ArchType.Multilib == "lib32" {
1372 has32BitTarget = true
1373 }
1374 }
1375 for i, target := range targets {
1376 // When multilib.* is omitted for native_shared_libs, it implies
1377 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001378 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001379 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001380 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001381 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001382
Roland Levillain630846d2019-06-26 12:48:34 +01001383 // When multilib.* is omitted for tests, it implies
1384 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001385 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001386 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001387 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001388 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001389
Jiyong Park397e55e2018-10-24 21:09:55 +09001390 // Add native modules targetting both ABIs
1391 addDependenciesForNativeModules(ctx,
1392 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001393 a.properties.Multilib.Both.Binaries,
1394 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001395 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001396 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001397
Alex Light3d673592019-01-18 14:37:31 -08001398 isPrimaryAbi := i == 0
1399 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001400 // When multilib.* is omitted for binaries, it implies
1401 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001402 ctx.AddFarVariationDependencies(append(target.Variations(),
1403 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1404 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001405
1406 // Add native modules targetting the first ABI
1407 addDependenciesForNativeModules(ctx,
1408 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001409 a.properties.Multilib.First.Binaries,
1410 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001411 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001412 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 }
1414
1415 switch target.Arch.ArchType.Multilib {
1416 case "lib32":
1417 // Add native modules targetting 32-bit ABI
1418 addDependenciesForNativeModules(ctx,
1419 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001420 a.properties.Multilib.Lib32.Binaries,
1421 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001422 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001423 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001424
1425 addDependenciesForNativeModules(ctx,
1426 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001427 a.properties.Multilib.Prefer32.Binaries,
1428 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001429 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001430 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001431 case "lib64":
1432 // Add native modules targetting 64-bit ABI
1433 addDependenciesForNativeModules(ctx,
1434 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001435 a.properties.Multilib.Lib64.Binaries,
1436 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001437 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001438 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001439
1440 if !has32BitTarget {
1441 addDependenciesForNativeModules(ctx,
1442 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001443 a.properties.Multilib.Prefer32.Binaries,
1444 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001445 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001446 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001447 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001448
1449 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1450 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1451 if sanitizer == "hwaddress" {
1452 addDependenciesForNativeModules(ctx,
1453 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001454 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001455 break
1456 }
1457 }
1458 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001459 }
1460
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001461 }
1462
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001463 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1464 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1465 // b/144532908
1466 archForPrebuiltEtc := config.Arches()[0]
1467 for _, arch := range config.Arches() {
1468 // Prefer 64-bit arch if there is any
1469 if arch.ArchType.Multilib == "lib64" {
1470 archForPrebuiltEtc = arch
1471 break
1472 }
1473 }
1474 ctx.AddFarVariationDependencies([]blueprint.Variation{
1475 {Mutator: "os", Variation: ctx.Os().String()},
1476 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1477 }, prebuiltTag, a.properties.Prebuilts...)
1478
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001479 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1480 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001481
Ulya Trafimovich44561882020-01-03 13:25:54 +00001482 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1483 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1484 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1485 javaLibTag, "jacocoagent")
1486 }
1487
Jiyong Park23c52b02019-02-02 13:13:47 +09001488 if String(a.properties.Key) == "" {
1489 ctx.ModuleErrorf("key is missing")
1490 return
1491 }
1492 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001493
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001494 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001495 if cert != "" {
1496 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001497 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001498
1499 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1500 if len(a.properties.Uses_sdks) > 0 {
1501 sdkRefs := []android.SdkRef{}
1502 for _, str := range a.properties.Uses_sdks {
1503 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1504 sdkRefs = append(sdkRefs, parsed)
1505 }
1506 a.BuildWithSdks(sdkRefs)
1507 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001508}
1509
Jiyong Park5d790c32019-11-15 18:40:32 +09001510func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1511 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1512 androidAppTag, a.overridableProperties.Apps...)
1513}
1514
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001515func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1516 // direct deps of an APEX bundle are all part of the APEX bundle
1517 return true
1518}
1519
Colin Cross0ea8ba82019-06-06 14:33:29 -07001520func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001521 moduleName := ctx.ModuleName()
1522 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1523 // we check with the pseudo module name to see if its certificate is overridden.
1524 if a.vndkApex {
1525 moduleName = vndkApexName
1526 }
1527 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001528 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001529 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001530 }
1531 return String(a.properties.Certificate)
1532}
1533
Colin Cross41955e82019-05-29 14:40:35 -07001534func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1535 switch tag {
1536 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001537 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001538 default:
1539 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001540 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001541}
1542
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001543func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001544 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001545}
1546
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001547func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1548 return proptools.Bool(a.properties.Test_only_no_hashtree)
1549}
1550
Dario Freni98410fd2020-04-27 18:21:11 +01001551func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1552 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1553}
1554
Jiyong Park7c1dc612019-01-05 11:15:24 +09001555func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001556 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001557 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001558 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001559 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001560 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001561 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001562 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001563 }
1564}
1565
Jiyong Parkf97782b2019-02-13 20:28:58 +09001566func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1567 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1568 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1569 }
1570}
1571
Jiyong Park388ef3f2019-01-28 19:47:32 +09001572func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001573 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1574 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001575 }
1576
1577 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001578 globalSanitizerNames := []string{}
1579 if a.Host() {
1580 globalSanitizerNames = ctx.Config().SanitizeHost()
1581 } else {
1582 arches := ctx.Config().SanitizeDeviceArch()
1583 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1584 globalSanitizerNames = ctx.Config().SanitizeDevice()
1585 }
1586 }
1587 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001588}
1589
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001590func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001591 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001592}
1593
1594func (a *apexBundle) PreventInstall() {
1595 a.properties.PreventInstall = true
1596}
1597
1598func (a *apexBundle) HideFromMake() {
1599 a.properties.HideFromMake = true
1600}
1601
Jiyong Park956305c2020-01-09 12:32:06 +09001602func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1603 a.properties.IsCoverageVariant = coverage
1604}
1605
Jiyong Parkf653b052019-11-18 15:39:01 +09001606// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001607func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001608 // Decide the APEX-local directory by the multilib of the library
1609 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001610 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001611 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001612 case "lib32":
1613 dirInApex = "lib"
1614 case "lib64":
1615 dirInApex = "lib64"
1616 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001617 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001618 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001619 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001620 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001621 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001622 // Special case for Bionic libs and other libs installed with them. This is
1623 // to prevent those libs from being included in the search path
1624 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1625 // those libs in the Runtime APEX are available via the legacy paths in
1626 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1627 // to the legacy paths and thus will be loaded into the default linker
1628 // namespace (aka "platform" namespace). If the libs are directly in
1629 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1630 // into the runtime linker namespace, which will result in double loading of
1631 // them, which isn't supported.
1632 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001633 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001634
Jiyong Parkf653b052019-11-18 15:39:01 +09001635 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001636 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001637}
1638
Jiyong Park1833cef2019-12-13 13:28:36 +09001639func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001640 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001641 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001642 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001643 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001644 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001645 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001646 af.symlinks = cc.Symlinks()
1647 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001648}
1649
Jiyong Park1833cef2019-12-13 13:28:36 +09001650func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001651 dirInApex := "bin"
1652 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001653 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001654}
Jiyong Park1833cef2019-12-13 13:28:36 +09001655func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001656 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001657 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1658 if err != nil {
1659 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001660 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001661 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001662 fileToCopy := android.PathForOutput(ctx, s)
1663 // NB: Since go binaries are static we don't need the module for anything here, which is
1664 // good since the go tool is a blueprint.Module not an android.Module like we would
1665 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001666 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001667}
1668
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001669func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001670 dirInApex := filepath.Join("bin", sh.SubDir())
1671 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001672 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001673 af.symlinks = sh.Symlinks()
1674 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001675}
1676
Jiyong Parked50ca82020-05-28 23:46:55 +09001677type javaDependency interface {
Jiyong Park2cd081c2020-06-01 21:39:15 +09001678 DexJar() android.Path
1679 JacocoReportClassesFile() android.Path
Jiyong Parked50ca82020-05-28 23:46:55 +09001680 Stem() string
1681}
1682
1683func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001684 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001685 fileToCopy := lib.DexJar()
Paul Duffinf299cbe2020-05-14 20:49:32 +01001686 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001687 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Jiyong Parked50ca82020-05-28 23:46:55 +09001688 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001689 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001690}
1691
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001692func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001693 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1694 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001695 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001696}
1697
atrost6e126252020-01-27 17:01:16 +00001698func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1699 dirInApex := filepath.Join("etc", config.SubDir())
1700 fileToCopy := config.CompatConfig()
1701 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1702}
1703
Jiyong Park1833cef2019-12-13 13:28:36 +09001704func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001705 android.Module
1706 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001707 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001708 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001709 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001710 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001711}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001712 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001713 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001714 appDir = "priv-app"
1715 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001716 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001717 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001718 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1719 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001720 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001721
1722 if app, ok := aapp.(interface {
1723 OverriddenManifestPackageName() string
1724 }); ok {
1725 af.overriddenPackageName = app.OverriddenManifestPackageName()
1726 }
Jiyong Park618922e2020-01-08 13:35:43 +09001727 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001728}
1729
Roland Levillain935639d2019-08-13 14:55:28 +01001730// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1731type flattenedApexContext struct {
1732 android.ModuleContext
1733}
1734
1735func (c *flattenedApexContext) InstallBypassMake() bool {
1736 return true
1737}
1738
Paul Duffin133608f2020-03-30 15:54:08 +01001739// Function called while walking an APEX's payload dependencies.
1740//
1741// Return true if the `to` module should be visited, false otherwise.
1742type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1743
Jiyong Park201cedd2020-02-07 17:25:49 +09001744// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001745func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001746 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001747 am, ok := child.(android.ApexModule)
1748 if !ok || !am.CanHaveApexVariants() {
1749 return false
1750 }
1751
1752 // Check for the direct dependencies that contribute to the payload
1753 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1754 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001755 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001756 }
Paul Duffin133608f2020-03-30 15:54:08 +01001757 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001758 return false
1759 }
1760
1761 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001762 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001763 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001764 }
1765
Paul Duffin133608f2020-03-30 15:54:08 +01001766 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001767 })
1768}
1769
Jooyung Han0c4e0162020-02-26 22:45:42 +09001770func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1771 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001772 intVer, err := android.ApiStrToNum(ctx, ver)
1773 if err != nil {
1774 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001775 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001776 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001777}
1778
Paul Duffinf0207962020-03-31 11:31:36 +01001779// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1780// a dependency tag.
1781var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1782
1783func PrettyPrintTag(tag blueprint.DependencyTag) string {
1784 // Use tag's custom String() method if available.
1785 if stringer, ok := tag.(fmt.Stringer); ok {
1786 return stringer.String()
1787 }
1788
1789 // Otherwise, get a default string representation of the tag's struct.
1790 tagString := fmt.Sprintf("%#v", tag)
1791
1792 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1793 tagString = tagCleaner.ReplaceAllString(tagString, "")
1794 return tagString
1795}
1796
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001797func (a *apexBundle) Updatable() bool {
1798 return proptools.Bool(a.properties.Updatable)
1799}
1800
1801var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1802
Jiyong Park201cedd2020-02-07 17:25:49 +09001803// Ensures that the dependencies are marked as available for this APEX
1804func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1805 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1806 if ctx.Host() || a.testApex || a.vndkApex {
1807 return
1808 }
1809
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001810 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1811 // Requiring them and their transitive depencies with apex_available is not right
1812 // because they just add noise.
1813 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1814 return
1815 }
1816
Paul Duffin133608f2020-03-30 15:54:08 +01001817 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1818 if externalDep {
1819 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1820 return false
1821 }
1822
Jiyong Park201cedd2020-02-07 17:25:49 +09001823 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001824 fromName := ctx.OtherModuleName(from)
1825 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001826
1827 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1828 // do any of its dependencies.
1829 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1830 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1831 return false
1832 }
1833
Paul Duffin133608f2020-03-30 15:54:08 +01001834 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1835 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001836 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001837 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001838 tagPath := ctx.GetTagPath()
1839 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1840 walkPath := ctx.GetWalkPath()[1:]
1841 for i, m := range walkPath {
1842 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001843 }
1844 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 +01001845 // Visit this module's dependencies to check and report any issues with their availability.
1846 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001847 })
1848}
1849
Jooyung Hanced674e2020-04-27 12:10:30 +09001850func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001851 if a.Updatable() {
Jooyung Hanced674e2020-04-27 12:10:30 +09001852 if String(a.properties.Min_sdk_version) == "" {
1853 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1854 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001855
1856 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001857 }
1858}
1859
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001860func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001861 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1862 switch a.properties.ApexType {
1863 case imageApex:
1864 if buildFlattenedAsDefault {
1865 a.suffix = imageApexSuffix
1866 } else {
1867 a.suffix = ""
1868 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001869
1870 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001871 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001872 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001873 }
1874 case zipApex:
1875 if proptools.String(a.properties.Payload_type) == "zip" {
1876 a.suffix = ""
1877 a.primaryApexType = true
1878 } else {
1879 a.suffix = zipApexSuffix
1880 }
1881 case flattenedApex:
1882 if buildFlattenedAsDefault {
1883 a.suffix = ""
1884 a.primaryApexType = true
1885 } else {
1886 a.suffix = flattenedSuffix
1887 }
Alex Light5098a612018-11-29 17:12:15 -08001888 }
1889
Roland Levillain630846d2019-06-26 12:48:34 +01001890 if len(a.properties.Tests) > 0 && !a.testApex {
1891 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1892 return
1893 }
1894
Jiyong Parkfa899442020-01-31 02:49:53 +09001895 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001896 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001897
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001898 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1899
Jooyung Hane1633032019-08-01 17:41:43 +09001900 // native lib dependencies
1901 var provideNativeLibs []string
1902 var requireNativeLibs []string
1903
Jooyung Han5c998b92019-06-27 11:30:33 +09001904 // Check if "uses" requirements are met with dependent apexBundles
1905 var providedNativeSharedLibs []string
1906 useVendor := proptools.Bool(a.properties.Use_vendor)
1907 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1908 if ctx.OtherModuleDependencyTag(m) != usesTag {
1909 return
1910 }
1911 otherName := ctx.OtherModuleName(m)
1912 other, ok := m.(*apexBundle)
1913 if !ok {
1914 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1915 return
1916 }
1917 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1918 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1919 return
1920 }
1921 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1922 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1923 return
1924 }
1925 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1926 })
1927
Jiyong Parkf653b052019-11-18 15:39:01 +09001928 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001929 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001930 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001931 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001932 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1933 return false
1934 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001935 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001936 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001937 switch depTag {
1938 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001939 if c, ok := child.(*cc.Module); ok {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001940 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
1941 filesInfo = append(filesInfo, fi)
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001942 // bootstrap bionic libs are treated as provided by system
1943 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001944 provideNativeLibs = append(provideNativeLibs, fi.Stem())
Jooyung Hane1633032019-08-01 17:41:43 +09001945 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001946 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001947 } else {
1948 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001949 }
1950 case executableTag:
1951 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001952 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001953 return true // track transitive dependencies
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001954 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001955 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001956 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001957 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001958 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001959 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001960 } else {
Alex Light778127a2019-02-27 14:19:50 -08001961 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 +09001962 }
1963 case javaLibTag:
Jiyong Park2cd081c2020-06-01 21:39:15 +09001964 switch child.(type) {
1965 case *java.Library, *java.SdkLibrary, *java.DexImport:
1966 af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
Jooyung Han58f26ab2019-12-18 15:34:32 +09001967 if !af.Ok() {
1968 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1969 return false
1970 }
1971 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001972 return true // track transitive dependencies
Jiyong Park2cd081c2020-06-01 21:39:15 +09001973 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001974 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001975 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001976 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001977 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001978 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001979 return true // track transitive dependencies
1980 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001981 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001982 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001983 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001984 } else {
1985 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1986 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001987 case prebuiltTag:
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001988 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001989 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00001990 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
1991 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001992 } else {
atrost6e126252020-01-27 17:01:16 +00001993 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001994 }
Roland Levillain630846d2019-06-26 12:48:34 +01001995 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01001996 if ccTest, ok := child.(*cc.Module); ok {
1997 if ccTest.IsTestPerSrcAllTestsVariation() {
1998 // Multiple-output test module (where `test_per_src: true`).
1999 //
2000 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2001 // We do not add this variation to `filesInfo`, as it has no output;
2002 // however, we do add the other variations of this module as indirect
2003 // dependencies (see below).
2004 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002005 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002006 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002007 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002008 af.class = nativeTest
2009 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002010 }
Roland Levillain630846d2019-06-26 12:48:34 +01002011 } else {
2012 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2013 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002014 case keyTag:
2015 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002016 a.private_key_file = key.private_key_file
2017 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002018 } else {
2019 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002020 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002021 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002022 case certificateTag:
2023 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002024 a.container_certificate_file = dep.Certificate.Pem
2025 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002026 } else {
2027 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2028 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002029 case android.PrebuiltDepTag:
2030 // If the prebuilt is force disabled, remember to delete the prebuilt file
2031 // that might have been installed in the previous builds
2032 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2033 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2034 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002035 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002036 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002037 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002038 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002039 // We cannot use a switch statement on `depTag` here as the checked
2040 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002041 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002042 if cc, ok := child.(*cc.Module); ok {
2043 if android.InList(cc.Name(), providedNativeSharedLibs) {
2044 // If we're using a shared library which is provided from other APEX,
2045 // don't include it in this APEX
2046 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002047 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002048 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2049 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002050 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 // If the dependency is a stubs lib, don't include it in this APEX,
2052 // but make sure that the lib is installed on the device.
2053 // In case no APEX is having the lib, the lib is installed to the system
2054 // partition.
2055 //
2056 // Always include if we are a host-apex however since those won't have any
2057 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002058 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2059 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002060 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002061 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002062 // Don't track further
2063 return false
2064 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002065 filesInfo = append(filesInfo, af)
2066 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002067 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002068 } else if cc.IsTestPerSrcDepTag(depTag) {
2069 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002070 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002071 // Handle modules created as `test_per_src` variations of a single test module:
2072 // use the name of the generated test binary (`fileToCopy`) instead of the name
2073 // of the original test module (`depName`, shared by all `test_per_src`
2074 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002075 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002076 // these are not considered transitive dep
2077 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002078 filesInfo = append(filesInfo, af)
2079 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002081 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002082 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2083 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002084 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002085 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002086 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2087 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002088 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002089 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002090 }
2091 }
2092 }
2093 return false
2094 })
2095
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002096 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2097 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2098 // via the global boot image config.
2099 if a.artApex {
2100 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2101 dirInApex := filepath.Join("javalib", arch.String())
2102 for _, f := range files {
2103 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002104 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002105 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002106 }
2107 }
2108 }
2109
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002110 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002111 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2112 return
2113 }
2114
Jiyong Park8fd61922018-11-08 02:50:25 +09002115 // remove duplicates in filesInfo
2116 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002117 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002118 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002119 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002120 if e, ok := encountered[dest]; !ok {
2121 encountered[dest] = f
2122 } else {
2123 // If a module is directly included and also transitively depended on
2124 // consider it as directly included.
2125 e.transitiveDep = e.transitiveDep && f.transitiveDep
2126 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002127 }
2128 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002129 var result []apexFile
2130 for _, v := range encountered {
2131 result = append(result, v)
2132 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002133 return result
2134 }
2135 filesInfo = removeDup(filesInfo)
2136
2137 // to have consistent build rules
2138 sort.Slice(filesInfo, func(i, j int) bool {
2139 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2140 })
2141
Jiyong Park8fd61922018-11-08 02:50:25 +09002142 a.installDir = android.PathForModuleInstall(ctx, "apex")
2143 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002144
Jooyung Han54aca7b2019-11-20 02:26:02 +09002145 if a.properties.ApexType != zipApex {
2146 if a.properties.File_contexts == nil {
2147 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2148 } else {
2149 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2150 if a.Platform() {
2151 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2152 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2153 }
2154 }
2155 }
2156 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2157 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2158 return
2159 }
2160 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002161 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2162 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2163 // the same library in the system partition, thus effectively sharing the same libraries
2164 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2165 // in the APEX.
2166 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2167 a.installable() &&
2168 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002169
Jiyong Park9d677202020-02-19 16:29:35 +09002170 // We don't need the optimization for updatable APEXes, as it might give false signal
2171 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01002172 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002173 a.linkToSystemLib = false
2174 }
2175
Jiyong Park9b964182020-02-26 18:27:19 +09002176 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2177 if ctx.Host() {
2178 a.linkToSystemLib = false
2179 }
2180
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002181 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002182 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2183
2184 a.setCertificateAndPrivateKey(ctx)
2185 if a.properties.ApexType == flattenedApex {
2186 a.buildFlattenedApex(ctx)
2187 } else {
2188 a.buildUnflattenedApex(ctx)
2189 }
2190
Jooyung Han002ab682020-01-08 01:57:58 +09002191 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002192
2193 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002194}
2195
Artur Satayev2eedf622020-04-15 17:29:42 +01002196// Enforce that Java deps of the apex are using stable SDKs to compile
2197func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2198 // Visit direct deps only. As long as we guarantee top-level deps are using
2199 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2200 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2201 tag := ctx.OtherModuleDependencyTag(module)
2202 switch tag {
2203 case javaLibTag, androidAppTag:
2204 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2205 if err := m.CheckStableSdkVersion(); err != nil {
2206 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2207 }
2208 }
2209 }
2210 })
2211}
2212
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002213func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002214 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002215 moduleName = normalizeModuleName(moduleName)
2216
2217 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2218 return true
2219 }
2220
2221 key = android.AvailableToAnyApex
2222 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2223 return true
2224 }
2225
2226 return false
2227}
2228
2229func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002230 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2231 // system. Trim the prefix for the check since they are confusing
2232 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2233 if strings.HasPrefix(moduleName, "libclang_rt.") {
2234 // This module has many arch variants that depend on the product being built.
2235 // We don't want to list them all
2236 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002237 }
Jooyung Han11c20932020-05-19 15:47:01 +09002238 if strings.HasPrefix(moduleName, "androidx.") {
2239 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2240 moduleName = "androidx"
2241 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002242 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002243}
2244
Jooyung Han344d5432019-08-23 11:17:39 +09002245func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002246 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002247 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002248 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002249 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002250 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002251 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2252 })
Alex Light5098a612018-11-29 17:12:15 -08002253 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002254 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002255 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002256 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002257 return module
2258}
Jiyong Park30ca9372019-02-07 16:27:23 +09002259
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002260func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002261 bundle := newApexBundle()
2262 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002263 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002264 return bundle
2265}
2266
Jiyong Parkfce0b422020-02-11 03:56:06 +09002267// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2268// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002269func testApexBundleFactory() android.Module {
2270 bundle := newApexBundle()
2271 bundle.testApex = true
2272 return bundle
2273}
2274
Jiyong Parkfce0b422020-02-11 03:56:06 +09002275// apex packages other modules into an APEX file which is a packaging format for system-level
2276// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002277func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002278 return newApexBundle()
2279}
2280
Jiyong Park30ca9372019-02-07 16:27:23 +09002281//
2282// Defaults
2283//
2284type Defaults struct {
2285 android.ModuleBase
2286 android.DefaultsModuleBase
2287}
2288
Jiyong Park30ca9372019-02-07 16:27:23 +09002289func defaultsFactory() android.Module {
2290 return DefaultsFactory()
2291}
2292
2293func DefaultsFactory(props ...interface{}) android.Module {
2294 module := &Defaults{}
2295
2296 module.AddProperties(props...)
2297 module.AddProperties(
2298 &apexBundleProperties{},
2299 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002300 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002301 )
2302
2303 android.InitDefaultsModule(module)
2304 return module
2305}
Jiyong Park5d790c32019-11-15 18:40:32 +09002306
2307//
2308// OverrideApex
2309//
2310type OverrideApex struct {
2311 android.ModuleBase
2312 android.OverrideModuleBase
2313}
2314
2315func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2316 // All the overrides happen in the base module.
2317}
2318
2319// override_apex is used to create an apex module based on another apex module
2320// by overriding some of its properties.
2321func overrideApexFactory() android.Module {
2322 m := &OverrideApex{}
2323 m.AddProperties(&overridableProperties{})
2324
2325 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2326 android.InitOverrideModule(m)
2327 return m
2328}