blob: 8488f6f141d3f7c01fae4b892c3bb643a8e83b5b [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"
markchien80092e32020-09-02 16:23:38 +080031 "android/soong/bpf"
Jaewoong Jungfccad6b2020-06-01 10:45:49 -070032 "android/soong/cc"
33 prebuilt_etc "android/soong/etc"
34 "android/soong/java"
35 "android/soong/python"
36 "android/soong/sh"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090037)
38
Jooyung Han72bd2f82019-10-23 16:46:38 +090039const (
40 imageApexSuffix = ".apex"
41 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090042 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080043
Sundong Ahnabb64432019-10-22 13:58:29 +090044 imageApexType = "image"
45 zipApexType = "zip"
46 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090047)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090048
49type dependencyTag struct {
50 blueprint.BaseDependencyTag
51 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090052
53 // determines if the dependent will be part of the APEX payload
54 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090055}
56
57var (
Jiyong Parkfa899442020-01-31 02:49:53 +090058 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
59 executableTag = dependencyTag{name: "executable", payload: true}
60 javaLibTag = dependencyTag{name: "javaLib", payload: true}
61 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
62 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090063 keyTag = dependencyTag{name: "key"}
64 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090065 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090066 androidAppTag = dependencyTag{name: "androidApp", payload: true}
markchien80092e32020-09-02 16:23:38 +080067 bpfTag = dependencyTag{name: "bpf", payload: true}
Paul Duffin404db3f2020-03-06 12:30:13 +000068
Colin Cross95f7b342020-06-11 11:32:11 -070069 apexAvailBaseline = makeApexAvailableBaseline()
70
71 inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090072)
73
Paul Duffin404db3f2020-03-06 12:30:13 +000074// Transform the map of apex -> modules to module -> apexes.
Colin Cross95f7b342020-06-11 11:32:11 -070075func invertApexBaseline(m map[string][]string) map[string][]string {
Paul Duffin404db3f2020-03-06 12:30:13 +000076 r := make(map[string][]string)
77 for apex, modules := range m {
78 for _, module := range modules {
79 r[module] = append(r[module], apex)
80 }
81 }
82 return r
83}
84
Colin Cross95f7b342020-06-11 11:32:11 -070085// Retrieve the baseline of apexes to which the supplied module belongs.
86func BaselineApexAvailable(moduleName string) []string {
87 return inverseApexAvailBaseline[normalizeModuleName(moduleName)]
Paul Duffin404db3f2020-03-06 12:30:13 +000088}
89
Anton Hansson5053c292020-01-10 15:12:39 +000090// This is a map from apex to modules, which overrides the
91// apex_available setting for that particular module to make
92// it available for the apex regardless of its setting.
93// TODO(b/147364041): remove this
Colin Cross95f7b342020-06-11 11:32:11 -070094func makeApexAvailableBaseline() map[string][]string {
Anton Hansson5053c292020-01-10 15:12:39 +000095 // The "Module separator"s below are employed to minimize merge conflicts.
96 m := make(map[string][]string)
97 //
98 // Module separator
99 //
Jiyong Park8b399192020-04-29 22:34:13 +0900100 m["com.android.appsearch"] = []string{
101 "icing-java-proto-lite",
102 "libprotobuf-java-lite",
Anton Hansson5053c292020-01-10 15:12:39 +0000103 }
104 //
105 // Module separator
106 //
107 m["com.android.bluetooth.updatable"] = []string{
108 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000109 "android.hardware.bluetooth.a2dp@1.0",
110 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900111 "android.hardware.bluetooth@1.0",
112 "android.hardware.bluetooth@1.1",
113 "android.hardware.graphics.bufferqueue@1.0",
114 "android.hardware.graphics.bufferqueue@2.0",
115 "android.hardware.graphics.common@1.0",
116 "android.hardware.graphics.common@1.1",
117 "android.hardware.graphics.common@1.2",
118 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000119 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900120 "android.hidl.token@1.0",
121 "android.hidl.token@1.0-utils",
122 "avrcp-target-service",
123 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "bluetooth-protos-lite",
125 "bluetooth.mapsapi",
126 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900127 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900128 "ipmemorystore-aidl-interfaces-V5-java",
129 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900130 "internal_include_headers",
131 "lib-bt-packets",
132 "lib-bt-packets-avrcp",
133 "lib-bt-packets-base",
134 "libFraunhoferAAC",
135 "libaudio-a2dp-hw-utils",
136 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900137 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000138 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900139 "libbluetooth-types",
140 "libbluetooth-types-header",
141 "libbluetooth_gd",
142 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000143 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900144 "libbt-audio-hal-interface",
145 "libbt-bta",
146 "libbt-common",
147 "libbt-hci",
148 "libbt-platform-protos-lite",
149 "libbt-protos-lite",
150 "libbt-sbc-decoder",
151 "libbt-sbc-encoder",
152 "libbt-stack",
153 "libbt-utils",
154 "libbtcore",
155 "libbtdevice",
156 "libbte",
157 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000158 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000159 "libevent",
160 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900161 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900163 "libmedia_headers",
164 "libmodpb64",
165 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900166 "libstagefright_foundation_headers",
167 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000168 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900169 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000170 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000172 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900173 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900174 "net-utils-services-common",
175 "netd_aidl_interface-unstable-java",
176 "netd_event_listener_interface-java",
177 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900178 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900179 "sap-api-java-static",
180 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000181 }
182 //
183 // Module separator
184 //
185 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
186 //
187 // Module separator
188 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900189 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900191 }
Anton Hansson5053c292020-01-10 15:12:39 +0000192 //
193 // Module separator
194 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 m["com.android.extservices"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900196 "error_prone_annotations",
197 "ExtServices-core",
198 "ExtServices",
199 "libtextclassifier-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900200 "libz_current",
Jooyung Han11c20932020-05-19 15:47:01 +0900201 "textclassifier-statsd",
202 "TextClassifierNotificationLibNoManifest",
203 "TextClassifierServiceLibNoManifest",
Jiyong Parkfa899442020-01-31 02:49:53 +0900204 }
205 //
206 // Module separator
207 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900208 m["com.android.neuralnetworks"] = []string{
209 "android.hardware.neuralnetworks@1.0",
210 "android.hardware.neuralnetworks@1.1",
211 "android.hardware.neuralnetworks@1.2",
212 "android.hardware.neuralnetworks@1.3",
213 "android.hidl.allocator@1.0",
214 "android.hidl.memory.token@1.0",
215 "android.hidl.memory@1.0",
216 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900218 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900219 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900220 "libprocpartition",
221 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900222 }
Anton Hansson5053c292020-01-10 15:12:39 +0000223 //
224 // Module separator
225 //
Anton Hansson5053c292020-01-10 15:12:39 +0000226 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900227 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000228 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900229 "android.hardware.cas@1.0",
230 "android.hardware.configstore-utils",
231 "android.hardware.configstore@1.0",
232 "android.hardware.configstore@1.1",
233 "android.hardware.graphics.allocator@2.0",
234 "android.hardware.graphics.allocator@3.0",
235 "android.hardware.graphics.bufferqueue@1.0",
236 "android.hardware.graphics.bufferqueue@2.0",
237 "android.hardware.graphics.common@1.0",
238 "android.hardware.graphics.common@1.1",
239 "android.hardware.graphics.common@1.2",
240 "android.hardware.graphics.mapper@2.0",
241 "android.hardware.graphics.mapper@2.1",
242 "android.hardware.graphics.mapper@3.0",
243 "android.hardware.media.omx@1.0",
244 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000245 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000246 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000248 "android.hidl.token@1.0",
249 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900250 "bionic_libc_platform_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900251 "exoplayer2-extractor",
252 "exoplayer2-extractor-annotation-stubs",
Jiyong Parkfa899442020-01-31 02:49:53 +0900253 "gl_headers",
Jooyung Han11c20932020-05-19 15:47:01 +0900254 "jsr305",
Jiyong Parkfa899442020-01-31 02:49:53 +0900255 "libEGL",
256 "libEGL_blobCache",
257 "libEGL_getProcAddress",
258 "libFLAC",
259 "libFLAC-config",
260 "libFLAC-headers",
261 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000262 "libaacextractor",
263 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900265 "libaudio_system_headers",
266 "libaudioclient",
267 "libaudioclient_headers",
268 "libaudiofoundation",
269 "libaudiofoundation_headers",
270 "libaudiomanager",
271 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000272 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900273 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900274 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900275 "libbluetooth-types-header",
276 "libbufferhub",
277 "libbufferhub_headers",
278 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900279 "libc_malloc_debug_backtrace",
280 "libcamera_client",
281 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900282 "libdexfile_external_headers",
283 "libdexfile_support",
284 "libdvr_headers",
285 "libexpat",
286 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000287 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900288 "libgrallocusage",
289 "libgraphicsenv",
290 "libgui",
291 "libgui_headers",
292 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900293 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900294 "liblzma",
295 "libmath",
296 "libmedia",
297 "libmedia_codeclist",
298 "libmedia_headers",
299 "libmedia_helper",
300 "libmedia_helper_headers",
301 "libmedia_midiiowrapper",
302 "libmedia_omx",
303 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000304 "libmidiextractor",
305 "libmkvextractor",
306 "libmp3extractor",
307 "libmp4extractor",
308 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900309 "libnativebase_headers",
310 "libnativebridge-headers",
311 "libnativebridge_lazy",
312 "libnativeloader-headers",
313 "libnativeloader_lazy",
314 "libnativewindow_headers",
315 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000316 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900317 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900318 "libpdx",
319 "libpdx_default_transport",
320 "libpdx_headers",
321 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900322 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000323 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900324 "libspeexresampler",
325 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000326 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900327 "libstagefright_flacdec",
328 "libstagefright_foundation",
329 "libstagefright_foundation_headers",
330 "libstagefright_foundation_without_imemory",
331 "libstagefright_headers",
332 "libstagefright_id3",
333 "libstagefright_metadatautils",
334 "libstagefright_mpeg2extractor",
335 "libstagefright_mpeg2support",
336 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900337 "libui",
338 "libui_headers",
339 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900340 "libvibrator",
341 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000342 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900343 "libwebm",
344 "media_ndk_headers",
345 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000346 "updatable-media",
347 }
348 //
349 // Module separator
350 //
351 m["com.android.media.swcodec"] = []string{
352 "android.frameworks.bufferhub@1.0",
353 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900354 "android.hardware.configstore-utils",
355 "android.hardware.configstore@1.0",
356 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000357 "android.hardware.graphics.allocator@2.0",
358 "android.hardware.graphics.allocator@3.0",
359 "android.hardware.graphics.allocator@4.0",
360 "android.hardware.graphics.bufferqueue@1.0",
361 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900362 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000363 "android.hardware.graphics.common@1.0",
364 "android.hardware.graphics.common@1.1",
365 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000366 "android.hardware.graphics.mapper@2.0",
367 "android.hardware.graphics.mapper@2.1",
368 "android.hardware.graphics.mapper@3.0",
369 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000370 "android.hardware.media.bufferpool@2.0",
371 "android.hardware.media.c2@1.0",
372 "android.hardware.media.c2@1.1",
373 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900374 "android.hardware.media@1.0",
375 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000376 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900377 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000378 "android.hidl.safe_union@1.0",
379 "android.hidl.token@1.0",
380 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900381 "libEGL",
382 "libFLAC",
383 "libFLAC-config",
384 "libFLAC-headers",
385 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900386 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900387 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900388 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000389 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900390 "libaudioutils",
391 "libaudioutils_fixedfft",
392 "libavcdec",
393 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000394 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900396 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900397 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900398 "libbluetooth-types-header",
399 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900400 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000401 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900402 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000403 "libcodec2_hidl@1.0",
404 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900405 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000406 "libcodec2_soft_aacdec",
407 "libcodec2_soft_aacenc",
408 "libcodec2_soft_amrnbdec",
409 "libcodec2_soft_amrnbenc",
410 "libcodec2_soft_amrwbdec",
411 "libcodec2_soft_amrwbenc",
412 "libcodec2_soft_av1dec_gav1",
413 "libcodec2_soft_avcdec",
414 "libcodec2_soft_avcenc",
415 "libcodec2_soft_common",
416 "libcodec2_soft_flacdec",
417 "libcodec2_soft_flacenc",
418 "libcodec2_soft_g711alawdec",
419 "libcodec2_soft_g711mlawdec",
420 "libcodec2_soft_gsmdec",
421 "libcodec2_soft_h263dec",
422 "libcodec2_soft_h263enc",
423 "libcodec2_soft_hevcdec",
424 "libcodec2_soft_hevcenc",
425 "libcodec2_soft_mp3dec",
426 "libcodec2_soft_mpeg2dec",
427 "libcodec2_soft_mpeg4dec",
428 "libcodec2_soft_mpeg4enc",
429 "libcodec2_soft_opusdec",
430 "libcodec2_soft_opusenc",
431 "libcodec2_soft_rawdec",
432 "libcodec2_soft_vorbisdec",
433 "libcodec2_soft_vp8dec",
434 "libcodec2_soft_vp8enc",
435 "libcodec2_soft_vp9dec",
436 "libcodec2_soft_vp9enc",
437 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900438 "libdexfile_support",
439 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000440 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900441 "libfmq",
442 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000443 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900444 "libgrallocusage",
445 "libgraphicsenv",
446 "libgsm",
447 "libgui_bufferqueue_static",
448 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000449 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900450 "libhardware_headers",
451 "libhevcdec",
452 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000453 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900454 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900455 "liblzma",
456 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000457 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900458 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900459 "libmpeg2dec",
460 "libnativebase_headers",
461 "libnativebridge_lazy",
462 "libnativeloader_lazy",
463 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900464 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000465 "libscudo_wrapper",
466 "libsfplugin_ccodec_utils",
467 "libspeexresampler",
468 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900469 "libstagefright_amrnbdec",
470 "libstagefright_amrnbenc",
471 "libstagefright_amrwbdec",
472 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000473 "libstagefright_bufferpool@2.0.1",
474 "libstagefright_bufferqueue_helper",
475 "libstagefright_enc_common",
476 "libstagefright_flacdec",
477 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900478 "libstagefright_foundation_headers",
479 "libstagefright_headers",
480 "libstagefright_m4vh263dec",
481 "libstagefright_m4vh263enc",
482 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000483 "libsync",
484 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900485 "libui_headers",
486 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000487 "libvorbisidec",
488 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900489 "libyuv",
490 "libyuv_static",
491 "media_ndk_headers",
492 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000493 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000494 }
495 //
496 // Module separator
497 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900498 m["com.android.mediaprovider"] = []string{
499 "MediaProvider",
500 "MediaProviderGoogle",
501 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900502 "libbase_ndk",
503 "libfuse",
504 "libfuse_jni",
505 "libnativehelper_header_only",
506 }
507 //
508 // Module separator
509 //
510 m["com.android.permission"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900511 "car-ui-lib",
512 "iconloader",
Jiyong Parkfa899442020-01-31 02:49:53 +0900513 "kotlin-annotations",
514 "kotlin-stdlib",
515 "kotlin-stdlib-jdk7",
516 "kotlin-stdlib-jdk8",
517 "kotlinx-coroutines-android",
518 "kotlinx-coroutines-android-nodeps",
519 "kotlinx-coroutines-core",
520 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900521 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900522 "GooglePermissionController",
523 "PermissionController",
Jooyung Han11c20932020-05-19 15:47:01 +0900524 "SettingsLibActionBarShadow",
525 "SettingsLibAppPreference",
526 "SettingsLibBarChartPreference",
527 "SettingsLibLayoutPreference",
528 "SettingsLibProgressBar",
529 "SettingsLibSearchWidget",
530 "SettingsLibSettingsTheme",
531 "SettingsLibRestrictedLockUtils",
532 "SettingsLibHelpUtils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900533 }
Anton Hansson5053c292020-01-10 15:12:39 +0000534 //
535 // Module separator
536 //
Anton Hansson5053c292020-01-10 15:12:39 +0000537 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900538 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900539 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900540 "libc_aeabi",
541 "libc_bionic",
542 "libc_bionic_ndk",
543 "libc_bootstrap",
544 "libc_common",
545 "libc_common_shared",
546 "libc_common_static",
547 "libc_dns",
548 "libc_dynamic_dispatch",
549 "libc_fortify",
550 "libc_freebsd",
551 "libc_freebsd_large_stack",
552 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900553 "libc_init_dynamic",
554 "libc_init_static",
555 "libc_jemalloc_wrapper",
556 "libc_netbsd",
557 "libc_nomalloc",
558 "libc_nopthread",
559 "libc_openbsd",
560 "libc_openbsd_large_stack",
561 "libc_openbsd_ndk",
562 "libc_pthread",
563 "libc_static_dispatch",
564 "libc_syscalls",
565 "libc_tzcode",
566 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900567 "libdebuggerd",
568 "libdebuggerd_common_headers",
569 "libdebuggerd_handler_core",
570 "libdebuggerd_handler_fallback",
571 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000572 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900573 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900574 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "libjemalloc5",
576 "liblinker_main",
577 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900578 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000579 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900580 "libprocinfo",
581 "libpropertyinfoparser",
582 "libscudo",
583 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900584 "libsystemproperties",
585 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000586 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900587 "libz",
588 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000589 }
590 //
591 // Module separator
592 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900593 m["com.android.tethering"] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900594 "android.hardware.tetheroffload.config-V1.0-java",
595 "android.hardware.tetheroffload.control-V1.0-java",
596 "android.hidl.base-V1.0-java",
597 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900598 "libcgrouprc",
599 "libcgrouprc_format",
Jooyung Han11c20932020-05-19 15:47:01 +0900600 "libnativehelper_compat_libc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900601 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900602 "libvndksupport",
Jooyung Han11c20932020-05-19 15:47:01 +0900603 "net-utils-framework-common",
604 "netd_aidl_interface-V3-java",
605 "netlink-client",
606 "networkstack-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900607 "tethering-aidl-interfaces-java",
Jooyung Han11c20932020-05-19 15:47:01 +0900608 "TetheringApiCurrentLib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900609 }
Anton Hansson5053c292020-01-10 15:12:39 +0000610 //
611 // Module separator
612 //
613 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900614 "PlatformProperties",
615 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900616 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900617 "android.hardware.wifi-V1.1-java",
618 "android.hardware.wifi-V1.2-java",
619 "android.hardware.wifi-V1.3-java",
620 "android.hardware.wifi-V1.4-java",
621 "android.hardware.wifi.hostapd-V1.0-java",
622 "android.hardware.wifi.hostapd-V1.1-java",
623 "android.hardware.wifi.hostapd-V1.2-java",
624 "android.hardware.wifi.supplicant-V1.0-java",
625 "android.hardware.wifi.supplicant-V1.1-java",
626 "android.hardware.wifi.supplicant-V1.2-java",
627 "android.hardware.wifi.supplicant-V1.3-java",
628 "android.hidl.base-V1.0-java",
629 "android.hidl.manager-V1.0-java",
630 "android.hidl.manager-V1.1-java",
631 "android.hidl.manager-V1.2-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 "bouncycastle-unbundled",
633 "dnsresolver_aidl_interface-V2-java",
634 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900635 "framework-wifi-pre-jarjar",
636 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900637 "ipmemorystore-aidl-interfaces-V3-java",
638 "ipmemorystore-aidl-interfaces-java",
639 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900640 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000641 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "net-utils-services-common",
643 "netd_aidl_interface-V2-java",
644 "netd_aidl_interface-unstable-java",
645 "netd_event_listener_interface-java",
646 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900647 "networkstack-client",
648 "services.net",
649 "wifi-lite-protos",
650 "wifi-nano-protos",
651 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000652 "wifi-service-resources",
653 }
654 //
655 // Module separator
656 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900657 m["com.android.sdkext"] = []string{
658 "fmtlib_ndk",
659 "libbase_ndk",
660 "libprotobuf-cpp-lite-ndk",
661 }
662 //
663 // Module separator
664 //
665 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900666 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 }
668 //
669 // Module separator
670 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000671 m[android.AvailableToAnyApex] = []string{
Jooyung Han11c20932020-05-19 15:47:01 +0900672 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx/extras support libraries
673 "androidx",
674 "androidx-constraintlayout_constraintlayout",
675 "androidx-constraintlayout_constraintlayout-nodeps",
676 "androidx-constraintlayout_constraintlayout-solver",
677 "androidx-constraintlayout_constraintlayout-solver-nodeps",
678 "com.google.android.material_material",
679 "com.google.android.material_material-nodeps",
680
Jiyong Parkfa899442020-01-31 02:49:53 +0900681 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900682 "libclang_rt",
683 "libgcc_stripped",
684 "libprofile-clang-extras",
685 "libprofile-clang-extras_ndk",
686 "libprofile-extras",
687 "libprofile-extras_ndk",
688 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900689 }
Anton Hansson5053c292020-01-10 15:12:39 +0000690 return m
691}
692
Andrei Onea115e7e72020-06-05 21:14:03 +0100693// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
694// Adding code to the bootclasspath in new packages will cause issues on module update.
695func qModulesPackages() map[string][]string {
696 return map[string][]string{
697 "com.android.conscrypt": []string{
698 "android.net.ssl",
699 "com.android.org.conscrypt",
700 },
701 "com.android.media": []string{
702 "android.media",
703 },
704 }
705}
706
707// DO NOT EDIT! These are the package prefixes that are exempted from being AOT'ed by ART.
708// Adding code to the bootclasspath in new packages will cause issues on module update.
709func rModulesPackages() map[string][]string {
710 return map[string][]string{
711 "com.android.mediaprovider": []string{
712 "android.provider",
713 },
714 "com.android.permission": []string{
715 "android.permission",
716 "android.app.role",
717 "com.android.permission",
718 "com.android.role",
719 },
720 "com.android.sdkext": []string{
721 "android.os.ext",
722 },
723 "com.android.os.statsd": []string{
724 "android.app",
725 "android.os",
726 "android.util",
727 "com.android.internal.statsd",
728 "com.android.server.stats",
729 },
730 "com.android.wifi": []string{
731 "com.android.server.wifi",
732 "com.android.wifi.x",
733 "android.hardware.wifi",
734 "android.net.wifi",
735 },
736 "com.android.tethering": []string{
737 "android.net",
738 },
739 }
740}
741
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900742func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900743 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800744 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900745 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900746 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700747 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900748 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700749 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900750
Jooyung Han31c470b2019-10-18 16:26:59 +0900751 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900752 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900753
754 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
755 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
756 sort.Strings(*apexFileContextsInfos)
757 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
758 })
Andrei Onea115e7e72020-06-05 21:14:03 +0100759
760 android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
761 android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
762}
763
764func createApexPermittedPackagesRules(modules_packages map[string][]string) []android.Rule {
765 rules := make([]android.Rule, 0, len(modules_packages))
766 for module_name, module_packages := range modules_packages {
767 permitted_packages_rule := android.NeverAllow().
768 BootclasspathJar().
769 With("apex_available", module_name).
770 WithMatcher("permitted_packages", android.NotInList(module_packages)).
771 Because("jars that are part of the " + module_name +
772 " module may only allow these packages: " + strings.Join(module_packages, ",") +
773 ". Please jarjar or move code around.")
774 rules = append(rules, permitted_packages_rule)
775 }
776 return rules
Jiyong Parkd1063c12019-07-17 20:08:41 +0900777}
778
Jooyung Han31c470b2019-10-18 16:26:59 +0900779func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
780 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
781 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
782}
783
Jiyong Parkd1063c12019-07-17 20:08:41 +0900784func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900785 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900786 ctx.BottomUp("apex", apexMutator).Parallel()
787 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
788 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900789 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900790}
791
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900792// Mark the direct and transitive dependencies of apex bundles so that they
793// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900794func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900795 if !mctx.Module().Enabled() {
796 return
797 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800798 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900799 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000800 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900801 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900802 ApexName: mctx.ModuleName(),
803 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100804 Updatable: a.Updatable(),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900805 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900806 directDep = true
807 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800808 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900809 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900810 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900811
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800812 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900813 return
814 }
815
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100816 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900817
Jiyong Parkf760cae2020-02-12 07:53:12 +0900818 mctx.VisitDirectDeps(func(child android.Module) {
819 depName := mctx.OtherModuleName(child)
820 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100821 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800822 android.UpdateApexDependency(apexBundles, depName, directDep)
823 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900824 }
825 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900826}
827
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900828// mark if a module cannot be available to platform. A module cannot be available
829// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
830// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
831func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
832 // Host and recovery are not considered as platform
833 if mctx.Host() || mctx.Module().InstallInRecovery() {
834 return
835 }
836
837 if am, ok := mctx.Module().(android.ApexModule); ok {
838 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
839
840 // In a rare case when a lib is marked as available only to an apex
841 // but the apex doesn't exist. This can happen in a partial manifest branch
842 // like master-art. Currently, libstatssocket in the stats APEX is causing
843 // this problem.
844 // Include the lib in platform because the module SDK that ought to provide
845 // it doesn't exist, so it would otherwise be left out completely.
846 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
847 // this check for libraries provided by SDKs.
848 if !availableToPlatform && !android.InAnyApex(am.Name()) {
849 availableToPlatform = true
850 }
851
852 // If any of the dep is not available to platform, this module is also considered
853 // as being not available to platform even if it has "//apex_available:platform"
854 mctx.VisitDirectDeps(func(child android.Module) {
855 if !am.DepIsInSameApex(mctx, child) {
856 // if the dependency crosses apex boundary, don't consider it
857 return
858 }
859 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
860 availableToPlatform = false
861 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
862 }
863 })
864
865 // Exception 1: stub libraries and native bridge libraries are always available to platform
866 if cc, ok := mctx.Module().(*cc.Module); ok &&
867 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
868 availableToPlatform = true
869 }
870
871 // Exception 2: bootstrap bionic libraries are also always available to platform
872 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
873 availableToPlatform = true
874 }
875
876 if !availableToPlatform {
877 am.SetNotAvailableForPlatform()
878 }
879 }
880}
881
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100882// If a module in an APEX depends on a module from an SDK then it needs an APEX
883// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
884func inAnySdk(module android.Module) bool {
885 if sa, ok := module.(android.SdkAware); ok {
886 return sa.IsInAnySdk()
887 }
888
889 return false
890}
891
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900892// Create apex variations if a module is included in APEX(s).
893func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900894 if !mctx.Module().Enabled() {
895 return
896 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900897 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900898 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000899 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900900 // apex bundle itself is mutated so that it and its modules have same
901 // apex variant.
902 apexBundleName := mctx.ModuleName()
903 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900904 } else if o, ok := mctx.Module().(*OverrideApex); ok {
905 apexBundleName := o.GetOverriddenModuleName()
906 if apexBundleName == "" {
907 mctx.ModuleErrorf("base property is not set")
908 return
909 }
910 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900911 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900912
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900913}
Sundong Ahne9b55722019-09-06 17:37:42 +0900914
Jooyung Han7a78a922019-10-08 21:59:58 +0900915var (
916 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
917 apexFileContextsInfosMutex sync.Mutex
918)
919
920func apexFileContextsInfos(config android.Config) *[]string {
921 return config.Once(apexFileContextsInfosKey, func() interface{} {
922 return &[]string{}
923 }).(*[]string)
924}
925
Jooyung Han54aca7b2019-11-20 02:26:02 +0900926func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900927 apexFileContextsInfosMutex.Lock()
928 defer apexFileContextsInfosMutex.Unlock()
929 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900930 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900931}
932
Sundong Ahne9b55722019-09-06 17:37:42 +0900933func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900934 if !mctx.Module().Enabled() {
935 return
936 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900937 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900938 var variants []string
939 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
940 case "image":
941 variants = append(variants, imageApexType, flattenedApexType)
942 case "zip":
943 variants = append(variants, zipApexType)
944 case "both":
945 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
946 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900947 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900948 return
949 }
950
951 modules := mctx.CreateLocalVariations(variants...)
952
953 for i, v := range variants {
954 switch v {
955 case imageApexType:
956 modules[i].(*apexBundle).properties.ApexType = imageApex
957 case zipApexType:
958 modules[i].(*apexBundle).properties.ApexType = zipApex
959 case flattenedApexType:
960 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900961 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900962 modules[i].(*apexBundle).MakeAsSystemExt()
963 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900964 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900965 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900966 } else if _, ok := mctx.Module().(*OverrideApex); ok {
967 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900968 }
969}
970
Jooyung Han5c998b92019-06-27 11:30:33 +0900971func apexUsesMutator(mctx android.BottomUpMutatorContext) {
972 if ab, ok := mctx.Module().(*apexBundle); ok {
973 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
974 }
975}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900976
Jooyung Handc782442019-11-01 03:14:38 +0900977var (
Colin Cross95f7b342020-06-11 11:32:11 -0700978 useVendorAllowListKey = android.NewOnceKey("useVendorAllowList")
Jooyung Handc782442019-11-01 03:14:38 +0900979)
980
Colin Cross95f7b342020-06-11 11:32:11 -0700981// useVendorAllowList returns the list of APEXes which are allowed to use_vendor.
Jooyung Handc782442019-11-01 03:14:38 +0900982// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
983// which may cause compatibility issues. (e.g. libbinder)
984// Even though libbinder restricts its availability via 'apex_available' property and relies on
985// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
986// to avoid similar problems.
Colin Cross95f7b342020-06-11 11:32:11 -0700987func useVendorAllowList(config android.Config) []string {
988 return config.Once(useVendorAllowListKey, func() interface{} {
Jooyung Handc782442019-11-01 03:14:38 +0900989 return []string{
990 // swcodec uses "vendor" variants for smaller size
991 "com.android.media.swcodec",
992 "test_com.android.media.swcodec",
993 }
994 }).([]string)
995}
996
Colin Cross95f7b342020-06-11 11:32:11 -0700997// setUseVendorAllowListForTest overrides useVendorAllowList and must be
998// called before the first call to useVendorAllowList()
999func setUseVendorAllowListForTest(config android.Config, allowList []string) {
1000 config.Once(useVendorAllowListKey, func() interface{} {
1001 return allowList
Jooyung Handc782442019-11-01 03:14:38 +09001002 })
1003}
1004
Alex Light9670d332019-01-29 18:07:33 -08001005type apexNativeDependencies struct {
1006 // List of native libraries
1007 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +09001008
Alex Light9670d332019-01-29 18:07:33 -08001009 // List of native executables
1010 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +09001011
Roland Levillain630846d2019-06-26 12:48:34 +01001012 // List of native tests
1013 Tests []string
Alex Light9670d332019-01-29 18:07:33 -08001014}
Jooyung Han344d5432019-08-23 11:17:39 +09001015
Alex Light9670d332019-01-29 18:07:33 -08001016type apexMultilibProperties struct {
1017 // Native dependencies whose compile_multilib is "first"
1018 First apexNativeDependencies
1019
1020 // Native dependencies whose compile_multilib is "both"
1021 Both apexNativeDependencies
1022
1023 // Native dependencies whose compile_multilib is "prefer32"
1024 Prefer32 apexNativeDependencies
1025
1026 // Native dependencies whose compile_multilib is "32"
1027 Lib32 apexNativeDependencies
1028
1029 // Native dependencies whose compile_multilib is "64"
1030 Lib64 apexNativeDependencies
1031}
1032
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001033type apexBundleProperties struct {
1034 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +00001035 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -08001036 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001037
Jiyong Park40e26a22019-02-08 02:53:06 +09001038 // AndroidManifest.xml file used for the zip container of this APEX bundle.
1039 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -08001040 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +09001041
Roland Levillain411c5842019-09-19 16:37:20 +01001042 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
1043 // device (/apex/<apex_name>).
1044 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001045 Apex_name *string
1046
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001047 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001048 // For platform APEXes, this should points to a file under /system/sepolicy
1049 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1050 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001051
1052 // List of native shared libs that are embedded inside this APEX bundle
1053 Native_shared_libs []string
1054
Roland Levillain630846d2019-06-26 12:48:34 +01001055 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001056 Binaries []string
1057
1058 // List of java libraries that are embedded inside this APEX bundle
1059 Java_libs []string
1060
1061 // List of prebuilt files that are embedded inside this APEX bundle
1062 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001063
Roland Levillain630846d2019-06-26 12:48:34 +01001064 // List of tests that are embedded inside this APEX bundle
1065 Tests []string
1066
markchien80092e32020-09-02 16:23:38 +08001067 // List of BPF programs inside APEX
1068 Bpfs []string
1069
Jiyong Parkff1458f2018-10-12 21:49:38 +09001070 // Name of the apex_key module that provides the private key to sign APEX
1071 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001072
Alex Light5098a612018-11-29 17:12:15 -08001073 // The type of APEX to build. Controls what the APEX payload is. Either
1074 // 'image', 'zip' or 'both'. Default: 'image'.
1075 Payload_type *string
1076
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001077 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1078 // or an android_app_certificate module name in the form ":module".
1079 Certificate *string
1080
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001081 // Whether this APEX is installable to one of the partitions. Default: true.
1082 Installable *bool
1083
Jiyong Parkda6eb592018-12-19 17:12:36 +09001084 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1085 // Default is false.
1086 Use_vendor *bool
1087
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001088 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1089 Ignore_system_library_special_case *bool
1090
Alex Light9670d332019-01-29 18:07:33 -08001091 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001092
Jiyong Parkf97782b2019-02-13 20:28:58 +09001093 // List of sanitizer names that this APEX is enabled for
1094 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001095
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001096 PreventInstall bool `blueprint:"mutated"`
1097
1098 HideFromMake bool `blueprint:"mutated"`
1099
Jooyung Han5c998b92019-06-27 11:30:33 +09001100 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1101 Provide_cpp_shared_libs *bool
1102
1103 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1104 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001105
Sundong Ahnabb64432019-10-22 13:58:29 +09001106 // package format of this apex variant; could be non-flattened, flattened, or zip.
1107 // imageApex, zipApex or flattened
1108 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001109
Jiyong Parkd1063c12019-07-17 20:08:41 +09001110 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1111 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1112 // is implied. This value affects all modules included in this APEX. In other words, they are
1113 // also built with the SDKs specified here.
1114 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001115
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001116 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1117 // Should be only used in tests#.
1118 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001119
Dario Freni98410fd2020-04-27 18:21:11 +01001120 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1121 // Should be only used in tests#.
1122 Test_only_unsigned_payload *bool
1123
Jiyong Park956305c2020-01-09 12:32:06 +09001124 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001125
1126 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001127 // rules for making sure that the APEX is truly updatable.
1128 // - To be updatable, min_sdk_version should be set as well
1129 // This will also disable the size optimizations like symlinking to the system libs.
1130 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001131 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001132
1133 // The minimum SDK version that this apex must be compatible with.
1134 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001135}
1136
1137type apexTargetBundleProperties struct {
1138 Target struct {
1139 // Multilib properties only for android.
1140 Android struct {
1141 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001142 }
Jooyung Han344d5432019-08-23 11:17:39 +09001143
Alex Light9670d332019-01-29 18:07:33 -08001144 // Multilib properties only for host.
1145 Host struct {
1146 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001147 }
Jooyung Han344d5432019-08-23 11:17:39 +09001148
Alex Light9670d332019-01-29 18:07:33 -08001149 // Multilib properties only for host linux_bionic.
1150 Linux_bionic struct {
1151 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001152 }
Jooyung Han344d5432019-08-23 11:17:39 +09001153
Alex Light9670d332019-01-29 18:07:33 -08001154 // Multilib properties only for host linux_glibc.
1155 Linux_glibc struct {
1156 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001157 }
1158 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001159}
1160
Jiyong Park5d790c32019-11-15 18:40:32 +09001161type overridableProperties struct {
1162 // List of APKs to package inside APEX
1163 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001164
1165 // Names of modules to be overridden. Listed modules can only be other binaries
1166 // (in Make or Soong).
1167 // This does not completely prevent installation of the overridden binaries, but if both
1168 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1169 // from PRODUCT_PACKAGES.
1170 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001171
1172 // Logging Parent value
1173 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001174
1175 // Apex Container Package Name.
1176 // Override value for attribute package:name in AndroidManifest.xml
1177 Package_name string
Jooyung Hanfaa53992020-06-20 12:47:47 +09001178
1179 // A txt file containing list of files that are allowed to be included in this APEX.
1180 Allowed_files *string `android:"path"`
Jiyong Park5d790c32019-11-15 18:40:32 +09001181}
1182
Alex Light5098a612018-11-29 17:12:15 -08001183type apexPackaging int
1184
1185const (
1186 imageApex apexPackaging = iota
1187 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001188 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001189)
1190
Sundong Ahnabb64432019-10-22 13:58:29 +09001191// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001192func (a apexPackaging) suffix() string {
1193 switch a {
1194 case imageApex:
1195 return imageApexSuffix
1196 case zipApex:
1197 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001198 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001199 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001200 }
1201}
1202
1203func (a apexPackaging) name() string {
1204 switch a {
1205 case imageApex:
1206 return imageApexType
1207 case zipApex:
1208 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001209 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001210 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001211 }
1212}
1213
Jiyong Parkf653b052019-11-18 15:39:01 +09001214type apexFileClass int
1215
1216const (
1217 etc apexFileClass = iota
1218 nativeSharedLib
1219 nativeExecutable
1220 shBinary
1221 pyBinary
1222 goBinary
1223 javaSharedLib
1224 nativeTest
1225 app
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001226 appSet
Jiyong Parkf653b052019-11-18 15:39:01 +09001227)
1228
Jiyong Park8fd61922018-11-08 02:50:25 +09001229func (class apexFileClass) NameInMake() string {
1230 switch class {
1231 case etc:
1232 return "ETC"
1233 case nativeSharedLib:
1234 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001235 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001236 return "EXECUTABLES"
1237 case javaSharedLib:
1238 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001239 case nativeTest:
1240 return "NATIVE_TESTS"
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001241 case app, appSet:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001242 // b/142537672 Why isn't this APP? We want to have full control over
1243 // the paths and file names of the apk file under the flattend APEX.
1244 // If this is set to APP, then the paths and file names are modified
1245 // by the Make build system. For example, it is installed to
1246 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1247 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1248 // appends module name (which is <apexname>.<Appname> to the path.
1249 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001250 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001251 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001252 }
1253}
1254
Jiyong Parkf653b052019-11-18 15:39:01 +09001255// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001256type apexFile struct {
1257 builtFile android.Path
Jiyong Parked50ca82020-05-28 23:46:55 +09001258 stem string
Jiyong Park8fd61922018-11-08 02:50:25 +09001259 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001260 installDir string
1261 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001262 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001263 // list of symlinks that will be created in installDir that point to this apexFile
1264 symlinks []string
1265 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001266 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001267
1268 requiredModuleNames []string
1269 targetRequiredModuleNames []string
1270 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001271
Colin Cross503c1d02020-01-28 14:00:53 -08001272 jacocoReportClassesFile android.Path // only for javalibs and apps
Colin Cross5bc17442020-07-21 20:31:17 -07001273 lintDepSets java.LintDepSets // only for javalibs and apps
Colin Cross503c1d02020-01-28 14:00:53 -08001274 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001275 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001276}
1277
Jiyong Park1833cef2019-12-13 13:28:36 +09001278func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1279 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001280 builtFile: builtFile,
1281 moduleName: moduleName,
1282 installDir: installDir,
1283 class: class,
1284 module: module,
1285 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001286 if module != nil {
1287 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001288 ret.requiredModuleNames = module.RequiredModuleNames()
1289 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1290 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001291 }
1292 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001293}
1294
1295func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001296 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001297}
1298
Jiyong Parked50ca82020-05-28 23:46:55 +09001299func (af *apexFile) apexRelativePath(path string) string {
1300 return filepath.Join(af.installDir, path)
1301}
1302
Jiyong Park7cd10e32020-01-14 09:22:18 +09001303// Path() returns path of this apex file relative to the APEX root
1304func (af *apexFile) Path() string {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001305 return af.apexRelativePath(af.Stem())
1306}
1307
1308func (af *apexFile) Stem() string {
Jiyong Parked50ca82020-05-28 23:46:55 +09001309 if af.stem != "" {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001310 return af.stem
Jiyong Parked50ca82020-05-28 23:46:55 +09001311 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09001312 return af.builtFile.Base()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001313}
1314
1315// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1316func (af *apexFile) SymlinkPaths() []string {
1317 var ret []string
1318 for _, symlink := range af.symlinks {
1319 ret = append(ret, filepath.Join(af.installDir, symlink))
1320 }
1321 return ret
1322}
1323
1324func (af *apexFile) AvailableToPlatform() bool {
1325 if af.module == nil {
1326 return false
1327 }
1328 if am, ok := af.module.(android.ApexModule); ok {
1329 return am.AvailableFor(android.AvailableToPlatform)
1330 }
1331 return false
1332}
1333
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001334type apexBundle struct {
1335 android.ModuleBase
1336 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001337 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001338 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001339
Jiyong Park5d790c32019-11-15 18:40:32 +09001340 properties apexBundleProperties
1341 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001342 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001343
Jooyung Hanf21c7972019-12-16 22:32:06 +09001344 // specific to apex_vndk modules
1345 vndkProperties apexVndkProperties
1346
Colin Crossa4925902018-11-16 11:36:28 -08001347 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001348 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001349 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001350
Jiyong Park03b68dd2019-07-26 23:20:40 +09001351 prebuiltFileToDelete string
1352
Jiyong Park42cca6c2019-04-01 11:15:50 +09001353 public_key_file android.Path
1354 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001355
1356 container_certificate_file android.Path
1357 container_private_key_file android.Path
1358
Jooyung Han54aca7b2019-11-20 02:26:02 +09001359 fileContexts android.Path
1360
Jiyong Park8fd61922018-11-08 02:50:25 +09001361 // list of files to be included in this apex
1362 filesInfo []apexFile
1363
Jiyong Park956305c2020-01-09 12:32:06 +09001364 // list of module names that should be installed along with this APEX
1365 requiredDeps []string
1366
Jiyong Park956305c2020-01-09 12:32:06 +09001367 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001368 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001369
Sundong Ahnabb64432019-10-22 13:58:29 +09001370 testApex bool
1371 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001372 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001373 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001374
Jooyung Han214bf372019-11-12 13:03:50 +09001375 manifestJsonOut android.WritablePath
1376 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001377
Jooyung Han002ab682020-01-08 01:57:58 +09001378 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001379 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001380 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001381 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1382 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001383
1384 // Suffix of module name in Android.mk
1385 // ".flattened", ".apex", ".zipapex", or ""
1386 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001387
1388 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001389
1390 // Whether to create symlink to the system file instead of having a file
1391 // inside the apex or not
1392 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001393
1394 // Struct holding the merged notice file paths in different formats
1395 mergedNotices android.NoticeOutputs
Colin Cross5bc17442020-07-21 20:31:17 -07001396
1397 // Optional list of lint report zip files for apexes that contain java or app modules
1398 lintReports android.Paths
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001399}
1400
Jiyong Park397e55e2018-10-24 21:09:55 +09001401func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001402 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001403 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001404 // Use *FarVariation* to be able to depend on modules having
1405 // conflicting variations with this module. This is required since
1406 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1407 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001408 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001409 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001410 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001411 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001412 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001413
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001414 ctx.AddFarVariationDependencies(append(target.Variations(),
1415 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1416 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001417
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001418 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001419 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001420 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001421 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001422}
1423
Alex Light9670d332019-01-29 18:07:33 -08001424func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1425 if ctx.Os().Class == android.Device {
1426 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1427 } else {
1428 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1429 if ctx.Os().Bionic() {
1430 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1431 } else {
1432 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1433 }
1434 }
1435}
1436
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001437func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross95f7b342020-06-11 11:32:11 -07001438 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorAllowList(ctx.Config())) {
Jooyung Handc782442019-11-01 03:14:38 +09001439 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1440 }
1441
Jiyong Park397e55e2018-10-24 21:09:55 +09001442 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001443 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001444
1445 a.combineProperties(ctx)
1446
Jiyong Park397e55e2018-10-24 21:09:55 +09001447 has32BitTarget := false
1448 for _, target := range targets {
1449 if target.Arch.ArchType.Multilib == "lib32" {
1450 has32BitTarget = true
1451 }
1452 }
1453 for i, target := range targets {
1454 // When multilib.* is omitted for native_shared_libs, it implies
1455 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001456 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001457 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001458 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001459 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001460
Roland Levillain630846d2019-06-26 12:48:34 +01001461 // When multilib.* is omitted for tests, it implies
1462 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001463 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001464 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001465 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001466 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001467
Jiyong Park397e55e2018-10-24 21:09:55 +09001468 // Add native modules targetting both ABIs
1469 addDependenciesForNativeModules(ctx,
1470 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001471 a.properties.Multilib.Both.Binaries,
1472 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001473 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001474 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001475
Alex Light3d673592019-01-18 14:37:31 -08001476 isPrimaryAbi := i == 0
1477 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001478 // When multilib.* is omitted for binaries, it implies
1479 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001480 ctx.AddFarVariationDependencies(append(target.Variations(),
1481 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1482 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001483
1484 // Add native modules targetting the first ABI
1485 addDependenciesForNativeModules(ctx,
1486 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001487 a.properties.Multilib.First.Binaries,
1488 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001489 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001490 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001491 }
1492
1493 switch target.Arch.ArchType.Multilib {
1494 case "lib32":
1495 // Add native modules targetting 32-bit ABI
1496 addDependenciesForNativeModules(ctx,
1497 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001498 a.properties.Multilib.Lib32.Binaries,
1499 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001500 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001501 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001502
1503 addDependenciesForNativeModules(ctx,
1504 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001505 a.properties.Multilib.Prefer32.Binaries,
1506 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001507 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001508 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001509 case "lib64":
1510 // Add native modules targetting 64-bit ABI
1511 addDependenciesForNativeModules(ctx,
1512 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001513 a.properties.Multilib.Lib64.Binaries,
1514 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001515 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001516 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001517
1518 if !has32BitTarget {
1519 addDependenciesForNativeModules(ctx,
1520 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001521 a.properties.Multilib.Prefer32.Binaries,
1522 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001523 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001524 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001525 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001526
1527 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1528 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1529 if sanitizer == "hwaddress" {
1530 addDependenciesForNativeModules(ctx,
1531 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001532 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001533 break
1534 }
1535 }
1536 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001537 }
1538
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001539 }
1540
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001541 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1542 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1543 // b/144532908
1544 archForPrebuiltEtc := config.Arches()[0]
1545 for _, arch := range config.Arches() {
1546 // Prefer 64-bit arch if there is any
1547 if arch.ArchType.Multilib == "lib64" {
1548 archForPrebuiltEtc = arch
1549 break
1550 }
1551 }
1552 ctx.AddFarVariationDependencies([]blueprint.Variation{
1553 {Mutator: "os", Variation: ctx.Os().String()},
1554 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1555 }, prebuiltTag, a.properties.Prebuilts...)
1556
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001557 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1558 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001559
markchien80092e32020-09-02 16:23:38 +08001560 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1561 bpfTag, a.properties.Bpfs...)
1562
Ulya Trafimovich44561882020-01-03 13:25:54 +00001563 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1564 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1565 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1566 javaLibTag, "jacocoagent")
1567 }
1568
Jiyong Park23c52b02019-02-02 13:13:47 +09001569 if String(a.properties.Key) == "" {
1570 ctx.ModuleErrorf("key is missing")
1571 return
1572 }
1573 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001574
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001575 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001576 if cert != "" {
1577 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001578 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001579
1580 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1581 if len(a.properties.Uses_sdks) > 0 {
1582 sdkRefs := []android.SdkRef{}
1583 for _, str := range a.properties.Uses_sdks {
1584 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1585 sdkRefs = append(sdkRefs, parsed)
1586 }
1587 a.BuildWithSdks(sdkRefs)
1588 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001589}
1590
Jiyong Park5d790c32019-11-15 18:40:32 +09001591func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Hanfaa53992020-06-20 12:47:47 +09001592 if a.overridableProperties.Allowed_files != nil {
1593 android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files)
1594 }
Jiyong Park5d790c32019-11-15 18:40:32 +09001595 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1596 androidAppTag, a.overridableProperties.Apps...)
1597}
1598
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001599func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1600 // direct deps of an APEX bundle are all part of the APEX bundle
1601 return true
1602}
1603
Colin Cross0ea8ba82019-06-06 14:33:29 -07001604func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001605 moduleName := ctx.ModuleName()
1606 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1607 // we check with the pseudo module name to see if its certificate is overridden.
1608 if a.vndkApex {
1609 moduleName = vndkApexName
1610 }
1611 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001612 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001613 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001614 }
1615 return String(a.properties.Certificate)
1616}
1617
Colin Cross41955e82019-05-29 14:40:35 -07001618func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1619 switch tag {
1620 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001621 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001622 default:
1623 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001624 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001625}
1626
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001627func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001628 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001629}
1630
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001631func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1632 return proptools.Bool(a.properties.Test_only_no_hashtree)
1633}
1634
Dario Freni98410fd2020-04-27 18:21:11 +01001635func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1636 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1637}
1638
Jiyong Park7c1dc612019-01-05 11:15:24 +09001639func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001640 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001641 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001642 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001643 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001644 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001645 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001646 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001647 }
1648}
1649
Jiyong Parkf97782b2019-02-13 20:28:58 +09001650func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1651 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1652 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1653 }
1654}
1655
Jiyong Park388ef3f2019-01-28 19:47:32 +09001656func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001657 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1658 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001659 }
1660
1661 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001662 globalSanitizerNames := []string{}
1663 if a.Host() {
1664 globalSanitizerNames = ctx.Config().SanitizeHost()
1665 } else {
1666 arches := ctx.Config().SanitizeDeviceArch()
1667 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1668 globalSanitizerNames = ctx.Config().SanitizeDevice()
1669 }
1670 }
1671 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001672}
1673
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001674func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Colin Cross72cabc62020-06-16 17:51:46 -07001675 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001676}
1677
1678func (a *apexBundle) PreventInstall() {
1679 a.properties.PreventInstall = true
1680}
1681
1682func (a *apexBundle) HideFromMake() {
1683 a.properties.HideFromMake = true
1684}
1685
Jiyong Park956305c2020-01-09 12:32:06 +09001686func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1687 a.properties.IsCoverageVariant = coverage
1688}
1689
Jiyong Parkf653b052019-11-18 15:39:01 +09001690// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001691func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001692 // Decide the APEX-local directory by the multilib of the library
1693 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001694 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001695 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001696 case "lib32":
1697 dirInApex = "lib"
1698 case "lib64":
1699 dirInApex = "lib64"
1700 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001701 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001702 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001703 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001704 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001705 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001706 // Special case for Bionic libs and other libs installed with them. This is
1707 // to prevent those libs from being included in the search path
1708 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1709 // those libs in the Runtime APEX are available via the legacy paths in
1710 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1711 // to the legacy paths and thus will be loaded into the default linker
1712 // namespace (aka "platform" namespace). If the libs are directly in
1713 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1714 // into the runtime linker namespace, which will result in double loading of
1715 // them, which isn't supported.
1716 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001717 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001718
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001720 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001721}
1722
Jiyong Park1833cef2019-12-13 13:28:36 +09001723func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001724 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001725 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001726 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001727 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001728 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001729 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001730 af.symlinks = cc.Symlinks()
1731 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001732}
1733
Jiyong Park1833cef2019-12-13 13:28:36 +09001734func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001735 dirInApex := "bin"
1736 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001737 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001738}
Jiyong Park1833cef2019-12-13 13:28:36 +09001739func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001740 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001741 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1742 if err != nil {
1743 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001744 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001745 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001746 fileToCopy := android.PathForOutput(ctx, s)
1747 // NB: Since go binaries are static we don't need the module for anything here, which is
1748 // good since the go tool is a blueprint.Module not an android.Module like we would
1749 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001750 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001751}
1752
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001753func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001754 dirInApex := filepath.Join("bin", sh.SubDir())
1755 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001756 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001757 af.symlinks = sh.Symlinks()
1758 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001759}
1760
Jiyong Parked50ca82020-05-28 23:46:55 +09001761type javaDependency interface {
Jiyong Park2cd081c2020-06-01 21:39:15 +09001762 DexJar() android.Path
1763 JacocoReportClassesFile() android.Path
Colin Cross5bc17442020-07-21 20:31:17 -07001764 LintDepSets() java.LintDepSets
1765
Jiyong Parked50ca82020-05-28 23:46:55 +09001766 Stem() string
1767}
1768
Colin Cross5bc17442020-07-21 20:31:17 -07001769var _ javaDependency = (*java.Library)(nil)
1770var _ javaDependency = (*java.SdkLibrary)(nil)
1771var _ javaDependency = (*java.DexImport)(nil)
1772var _ javaDependency = (*java.SdkLibraryImport)(nil)
1773
Jiyong Parked50ca82020-05-28 23:46:55 +09001774func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001775 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001776 fileToCopy := lib.DexJar()
Paul Duffin9ee66da2020-06-17 16:59:43 +01001777 // Remove prebuilt_ if necessary so the source and prebuilt modules have the same name.
1778 name := strings.TrimPrefix(module.Name(), "prebuilt_")
1779 af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001780 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
Colin Cross5bc17442020-07-21 20:31:17 -07001781 af.lintDepSets = lib.LintDepSets()
Jiyong Parked50ca82020-05-28 23:46:55 +09001782 af.stem = lib.Stem() + ".jar"
Jiyong Park618922e2020-01-08 13:35:43 +09001783 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001784}
1785
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07001786func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt prebuilt_etc.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001787 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1788 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001789 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001790}
1791
atrost6e126252020-01-27 17:01:16 +00001792func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1793 dirInApex := filepath.Join("etc", config.SubDir())
1794 fileToCopy := config.CompatConfig()
1795 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1796}
1797
Jiyong Park1833cef2019-12-13 13:28:36 +09001798func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001799 android.Module
1800 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001801 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001802 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001803 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001804 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001805}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001806 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001807 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001808 appDir = "priv-app"
1809 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001810 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001811 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001812 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1813 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001814 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001815
1816 if app, ok := aapp.(interface {
1817 OverriddenManifestPackageName() string
1818 }); ok {
1819 af.overriddenPackageName = app.OverriddenManifestPackageName()
1820 }
Jiyong Park618922e2020-01-08 13:35:43 +09001821 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001822}
1823
markchien80092e32020-09-02 16:23:38 +08001824func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
1825 dirInApex := filepath.Join("etc", "bpf")
1826 return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
1827}
1828
Roland Levillain935639d2019-08-13 14:55:28 +01001829// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1830type flattenedApexContext struct {
1831 android.ModuleContext
1832}
1833
1834func (c *flattenedApexContext) InstallBypassMake() bool {
1835 return true
1836}
1837
Paul Duffin133608f2020-03-30 15:54:08 +01001838// Function called while walking an APEX's payload dependencies.
1839//
1840// Return true if the `to` module should be visited, false otherwise.
1841type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1842
Jiyong Park201cedd2020-02-07 17:25:49 +09001843// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001844func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001845 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001846 am, ok := child.(android.ApexModule)
1847 if !ok || !am.CanHaveApexVariants() {
1848 return false
1849 }
1850
1851 // Check for the direct dependencies that contribute to the payload
1852 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1853 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001854 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001855 }
Paul Duffin133608f2020-03-30 15:54:08 +01001856 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001857 return false
1858 }
1859
1860 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001861 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001862 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001863 }
1864
Paul Duffin133608f2020-03-30 15:54:08 +01001865 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001866 })
1867}
1868
Jooyung Han0c4e0162020-02-26 22:45:42 +09001869func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1870 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001871 intVer, err := android.ApiStrToNum(ctx, ver)
1872 if err != nil {
1873 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001874 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001875 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001876}
1877
Paul Duffinf0207962020-03-31 11:31:36 +01001878// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1879// a dependency tag.
1880var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1881
1882func PrettyPrintTag(tag blueprint.DependencyTag) string {
1883 // Use tag's custom String() method if available.
1884 if stringer, ok := tag.(fmt.Stringer); ok {
1885 return stringer.String()
1886 }
1887
1888 // Otherwise, get a default string representation of the tag's struct.
1889 tagString := fmt.Sprintf("%#v", tag)
1890
1891 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1892 tagString = tagCleaner.ReplaceAllString(tagString, "")
1893 return tagString
1894}
1895
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001896func (a *apexBundle) Updatable() bool {
1897 return proptools.Bool(a.properties.Updatable)
1898}
1899
1900var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1901
Jiyong Park201cedd2020-02-07 17:25:49 +09001902// Ensures that the dependencies are marked as available for this APEX
1903func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1904 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1905 if ctx.Host() || a.testApex || a.vndkApex {
1906 return
1907 }
1908
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001909 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1910 // Requiring them and their transitive depencies with apex_available is not right
1911 // because they just add noise.
1912 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1913 return
1914 }
1915
Paul Duffin133608f2020-03-30 15:54:08 +01001916 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1917 if externalDep {
1918 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1919 return false
1920 }
1921
Jiyong Park201cedd2020-02-07 17:25:49 +09001922 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001923 fromName := ctx.OtherModuleName(from)
1924 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001925
1926 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1927 // do any of its dependencies.
1928 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1929 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1930 return false
1931 }
1932
Colin Cross95f7b342020-06-11 11:32:11 -07001933 if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) {
Paul Duffin133608f2020-03-30 15:54:08 +01001934 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001935 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001936 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001937 tagPath := ctx.GetTagPath()
1938 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1939 walkPath := ctx.GetWalkPath()[1:]
1940 for i, m := range walkPath {
1941 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001942 }
1943 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 +01001944 // Visit this module's dependencies to check and report any issues with their availability.
1945 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001946 })
1947}
1948
Jooyung Hanced674e2020-04-27 12:10:30 +09001949func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001950 if a.Updatable() {
Jooyung Hanced674e2020-04-27 12:10:30 +09001951 if String(a.properties.Min_sdk_version) == "" {
1952 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1953 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001954
1955 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001956 }
1957}
1958
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001959func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001960 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1961 switch a.properties.ApexType {
1962 case imageApex:
1963 if buildFlattenedAsDefault {
1964 a.suffix = imageApexSuffix
1965 } else {
1966 a.suffix = ""
1967 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001968
1969 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001970 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001971 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001972 }
1973 case zipApex:
1974 if proptools.String(a.properties.Payload_type) == "zip" {
1975 a.suffix = ""
1976 a.primaryApexType = true
1977 } else {
1978 a.suffix = zipApexSuffix
1979 }
1980 case flattenedApex:
1981 if buildFlattenedAsDefault {
1982 a.suffix = ""
1983 a.primaryApexType = true
1984 } else {
1985 a.suffix = flattenedSuffix
1986 }
Alex Light5098a612018-11-29 17:12:15 -08001987 }
1988
Roland Levillain630846d2019-06-26 12:48:34 +01001989 if len(a.properties.Tests) > 0 && !a.testApex {
1990 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1991 return
1992 }
1993
Jiyong Parkfa899442020-01-31 02:49:53 +09001994 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001995 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001996
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001997 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1998
Jooyung Hane1633032019-08-01 17:41:43 +09001999 // native lib dependencies
2000 var provideNativeLibs []string
2001 var requireNativeLibs []string
2002
Jooyung Han5c998b92019-06-27 11:30:33 +09002003 // Check if "uses" requirements are met with dependent apexBundles
2004 var providedNativeSharedLibs []string
2005 useVendor := proptools.Bool(a.properties.Use_vendor)
2006 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
2007 if ctx.OtherModuleDependencyTag(m) != usesTag {
2008 return
2009 }
2010 otherName := ctx.OtherModuleName(m)
2011 other, ok := m.(*apexBundle)
2012 if !ok {
2013 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
2014 return
2015 }
2016 if proptools.Bool(other.properties.Use_vendor) != useVendor {
2017 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
2018 return
2019 }
2020 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
2021 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
2022 return
2023 }
2024 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
2025 })
2026
Jiyong Parkf653b052019-11-18 15:39:01 +09002027 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09002028 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08002029 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01002030 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01002031 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
2032 return false
2033 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002034 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09002035 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002036 switch depTag {
2037 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002038 if c, ok := child.(*cc.Module); ok {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002039 fi := apexFileForNativeLibrary(ctx, c, handleSpecialLibs)
2040 filesInfo = append(filesInfo, fi)
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09002041 // bootstrap bionic libs are treated as provided by system
2042 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002043 provideNativeLibs = append(provideNativeLibs, fi.Stem())
Jooyung Hane1633032019-08-01 17:41:43 +09002044 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002045 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09002046 } else {
2047 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002048 }
2049 case executableTag:
2050 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002051 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09002052 return true // track transitive dependencies
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002053 } else if sh, ok := child.(*sh.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002054 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08002055 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09002056 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08002057 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09002058 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002059 } else {
Alex Light778127a2019-02-27 14:19:50 -08002060 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 +09002061 }
2062 case javaLibTag:
Jiyong Park2cd081c2020-06-01 21:39:15 +09002063 switch child.(type) {
Paul Duffinf642a312020-06-12 17:46:39 +01002064 case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
Jiyong Park2cd081c2020-06-01 21:39:15 +09002065 af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
Jooyung Han58f26ab2019-12-18 15:34:32 +09002066 if !af.Ok() {
2067 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
2068 return false
2069 }
2070 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09002071 return true // track transitive dependencies
Jiyong Park2cd081c2020-06-01 21:39:15 +09002072 default:
Jiyong Park9e6c2422019-08-09 20:39:45 +09002073 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002074 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002075 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09002076 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002077 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09002078 return true // track transitive dependencies
2079 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002080 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00002081 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09002082 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07002083 } else if ap, ok := child.(*java.AndroidAppSet); ok {
2084 appDir := "app"
2085 if ap.Privileged() {
2086 appDir = "priv-app"
2087 }
2088 af := newApexFile(ctx, ap.OutputFile(), ap.Name(),
2089 filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
2090 af.certificate = java.PresignedCertificate
2091 filesInfo = append(filesInfo, af)
Jiyong Parkf653b052019-11-18 15:39:01 +09002092 } else {
2093 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
2094 }
markchien80092e32020-09-02 16:23:38 +08002095 case bpfTag:
2096 if bpfProgram, ok := child.(bpf.BpfModule); ok {
2097 filesToCopy, _ := bpfProgram.OutputFiles("")
2098 for _, bpfFile := range filesToCopy {
2099 filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
2100 }
2101 } else {
2102 ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
2103 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002104 case prebuiltTag:
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002105 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002106 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002107 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2108 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002109 } else {
atrost6e126252020-01-27 17:01:16 +00002110 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002111 }
Roland Levillain630846d2019-06-26 12:48:34 +01002112 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002113 if ccTest, ok := child.(*cc.Module); ok {
2114 if ccTest.IsTestPerSrcAllTestsVariation() {
2115 // Multiple-output test module (where `test_per_src: true`).
2116 //
2117 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2118 // We do not add this variation to `filesInfo`, as it has no output;
2119 // however, we do add the other variations of this module as indirect
2120 // dependencies (see below).
2121 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002122 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002123 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002124 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002125 af.class = nativeTest
2126 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002127 }
Roland Levillain630846d2019-06-26 12:48:34 +01002128 } else {
2129 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2130 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002131 case keyTag:
2132 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002133 a.private_key_file = key.private_key_file
2134 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002135 } else {
2136 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002137 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002138 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002139 case certificateTag:
2140 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002141 a.container_certificate_file = dep.Certificate.Pem
2142 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002143 } else {
2144 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2145 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002146 case android.PrebuiltDepTag:
2147 // If the prebuilt is force disabled, remember to delete the prebuilt file
2148 // that might have been installed in the previous builds
Jiyong Parkf220db82020-07-16 21:38:56 +09002149 if prebuilt, ok := child.(prebuilt); ok && prebuilt.isForceDisabled() {
Jiyong Park03b68dd2019-07-26 23:20:40 +09002150 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2151 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002152 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002153 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002154 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002155 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002156 // We cannot use a switch statement on `depTag` here as the checked
2157 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002158 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002159 if cc, ok := child.(*cc.Module); ok {
2160 if android.InList(cc.Name(), providedNativeSharedLibs) {
2161 // If we're using a shared library which is provided from other APEX,
2162 // don't include it in this APEX
2163 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002164 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002165 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
2166 af.transitiveDep = true
Jooyung Han671f1ce2019-12-17 12:47:13 +09002167 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002168 // If the dependency is a stubs lib, don't include it in this APEX,
2169 // but make sure that the lib is installed on the device.
2170 // In case no APEX is having the lib, the lib is installed to the system
2171 // partition.
2172 //
2173 // Always include if we are a host-apex however since those won't have any
2174 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002175 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2176 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002177 }
Jiyong Parkcbe50c72020-05-29 21:29:20 +09002178 requireNativeLibs = append(requireNativeLibs, af.Stem())
Roland Levillainf89cd092019-07-29 16:22:59 +01002179 // Don't track further
2180 return false
2181 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002182 filesInfo = append(filesInfo, af)
2183 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002184 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002185 } else if cc.IsTestPerSrcDepTag(depTag) {
2186 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002187 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002188 // Handle modules created as `test_per_src` variations of a single test module:
2189 // use the name of the generated test binary (`fileToCopy`) instead of the name
2190 // of the original test module (`depName`, shared by all `test_per_src`
2191 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002192 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002193 // these are not considered transitive dep
2194 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002195 filesInfo = append(filesInfo, af)
2196 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002197 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002198 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002199 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2200 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002201 } else if java.IsXmlPermissionsFileDepTag(depTag) {
Jaewoong Jungfccad6b2020-06-01 10:45:49 -07002202 if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
Jiyong Parke3833882020-02-17 17:28:10 +09002203 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2204 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002205 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002206 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002207 }
2208 }
2209 }
2210 return false
2211 })
2212
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002213 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2214 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2215 // via the global boot image config.
2216 if a.artApex {
2217 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2218 dirInApex := filepath.Join("javalib", arch.String())
2219 for _, f := range files {
2220 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002221 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002222 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002223 }
2224 }
2225 }
2226
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002227 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002228 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2229 return
2230 }
2231
Jiyong Park8fd61922018-11-08 02:50:25 +09002232 // remove duplicates in filesInfo
2233 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002234 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002235 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002236 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002237 if e, ok := encountered[dest]; !ok {
2238 encountered[dest] = f
2239 } else {
2240 // If a module is directly included and also transitively depended on
2241 // consider it as directly included.
2242 e.transitiveDep = e.transitiveDep && f.transitiveDep
2243 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002244 }
2245 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002246 var result []apexFile
2247 for _, v := range encountered {
2248 result = append(result, v)
2249 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002250 return result
2251 }
2252 filesInfo = removeDup(filesInfo)
2253
2254 // to have consistent build rules
2255 sort.Slice(filesInfo, func(i, j int) bool {
2256 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2257 })
2258
Jiyong Park8fd61922018-11-08 02:50:25 +09002259 a.installDir = android.PathForModuleInstall(ctx, "apex")
2260 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002261
Jooyung Han54aca7b2019-11-20 02:26:02 +09002262 if a.properties.ApexType != zipApex {
2263 if a.properties.File_contexts == nil {
2264 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2265 } else {
2266 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2267 if a.Platform() {
2268 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2269 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2270 }
2271 }
2272 }
2273 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2274 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2275 return
2276 }
2277 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002278 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2279 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2280 // the same library in the system partition, thus effectively sharing the same libraries
2281 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2282 // in the APEX.
2283 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2284 a.installable() &&
2285 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002286
Jiyong Park9d677202020-02-19 16:29:35 +09002287 // We don't need the optimization for updatable APEXes, as it might give false signal
2288 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01002289 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002290 a.linkToSystemLib = false
2291 }
2292
Jiyong Park9b964182020-02-26 18:27:19 +09002293 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2294 if ctx.Host() {
2295 a.linkToSystemLib = false
2296 }
2297
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002298 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002299 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2300
2301 a.setCertificateAndPrivateKey(ctx)
2302 if a.properties.ApexType == flattenedApex {
2303 a.buildFlattenedApex(ctx)
2304 } else {
2305 a.buildUnflattenedApex(ctx)
2306 }
2307
Jooyung Han002ab682020-01-08 01:57:58 +09002308 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002309
2310 a.buildApexDependencyInfo(ctx)
Colin Cross5bc17442020-07-21 20:31:17 -07002311
2312 a.buildLintReports(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002313}
2314
Artur Satayev2eedf622020-04-15 17:29:42 +01002315// Enforce that Java deps of the apex are using stable SDKs to compile
2316func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2317 // Visit direct deps only. As long as we guarantee top-level deps are using
2318 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2319 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2320 tag := ctx.OtherModuleDependencyTag(module)
2321 switch tag {
2322 case javaLibTag, androidAppTag:
2323 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2324 if err := m.CheckStableSdkVersion(); err != nil {
2325 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2326 }
2327 }
2328 }
2329 })
2330}
2331
Colin Cross95f7b342020-06-11 11:32:11 -07002332func baselineApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002333 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002334 moduleName = normalizeModuleName(moduleName)
2335
Colin Cross95f7b342020-06-11 11:32:11 -07002336 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin404db3f2020-03-06 12:30:13 +00002337 return true
2338 }
2339
2340 key = android.AvailableToAnyApex
Colin Cross95f7b342020-06-11 11:32:11 -07002341 if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) {
Paul Duffin404db3f2020-03-06 12:30:13 +00002342 return true
2343 }
2344
2345 return false
2346}
2347
2348func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002349 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2350 // system. Trim the prefix for the check since they are confusing
2351 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2352 if strings.HasPrefix(moduleName, "libclang_rt.") {
2353 // This module has many arch variants that depend on the product being built.
2354 // We don't want to list them all
2355 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002356 }
Jooyung Han11c20932020-05-19 15:47:01 +09002357 if strings.HasPrefix(moduleName, "androidx.") {
2358 // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries
2359 moduleName = "androidx"
2360 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002361 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002362}
2363
Jooyung Han344d5432019-08-23 11:17:39 +09002364func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002365 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002366 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002367 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002368 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002369 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002370 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2371 })
Alex Light5098a612018-11-29 17:12:15 -08002372 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002373 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002374 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002375 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002376 return module
2377}
Jiyong Park30ca9372019-02-07 16:27:23 +09002378
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002379func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002380 bundle := newApexBundle()
2381 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002382 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002383 return bundle
2384}
2385
Jiyong Parkfce0b422020-02-11 03:56:06 +09002386// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2387// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002388func testApexBundleFactory() android.Module {
2389 bundle := newApexBundle()
2390 bundle.testApex = true
2391 return bundle
2392}
2393
Jiyong Parkfce0b422020-02-11 03:56:06 +09002394// apex packages other modules into an APEX file which is a packaging format for system-level
2395// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002396func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002397 return newApexBundle()
2398}
2399
Jiyong Park30ca9372019-02-07 16:27:23 +09002400//
2401// Defaults
2402//
2403type Defaults struct {
2404 android.ModuleBase
2405 android.DefaultsModuleBase
2406}
2407
Jiyong Park30ca9372019-02-07 16:27:23 +09002408func defaultsFactory() android.Module {
2409 return DefaultsFactory()
2410}
2411
2412func DefaultsFactory(props ...interface{}) android.Module {
2413 module := &Defaults{}
2414
2415 module.AddProperties(props...)
2416 module.AddProperties(
2417 &apexBundleProperties{},
2418 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002419 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002420 )
2421
2422 android.InitDefaultsModule(module)
2423 return module
2424}
Jiyong Park5d790c32019-11-15 18:40:32 +09002425
2426//
2427// OverrideApex
2428//
2429type OverrideApex struct {
2430 android.ModuleBase
2431 android.OverrideModuleBase
2432}
2433
2434func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2435 // All the overrides happen in the base module.
2436}
2437
2438// override_apex is used to create an apex module based on another apex module
2439// by overriding some of its properties.
2440func overrideApexFactory() android.Module {
2441 m := &OverrideApex{}
2442 m.AddProperties(&overridableProperties{})
2443
2444 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2445 android.InitOverrideModule(m)
2446 return m
2447}