blob: fe231f677dcf916c532da283c924eccc490f7285 [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
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Alex Light778127a2019-02-27 14:19:50 -080029 "android/soong/python"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090030
31 "github.com/google/blueprint"
Alex Light778127a2019-02-27 14:19:50 -080032 "github.com/google/blueprint/bootstrap"
Jiyong Park48ca7dc2018-10-10 14:01:00 +090033 "github.com/google/blueprint/proptools"
34)
35
Jooyung Han72bd2f82019-10-23 16:46:38 +090036const (
37 imageApexSuffix = ".apex"
38 zipApexSuffix = ".zipapex"
Sundong Ahnabb64432019-10-22 13:58:29 +090039 flattenedSuffix = ".flattened"
Alex Light5098a612018-11-29 17:12:15 -080040
Sundong Ahnabb64432019-10-22 13:58:29 +090041 imageApexType = "image"
42 zipApexType = "zip"
43 flattenedApexType = "flattened"
Jooyung Han72bd2f82019-10-23 16:46:38 +090044)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090045
46type dependencyTag struct {
47 blueprint.BaseDependencyTag
48 name string
Jiyong Parkfa899442020-01-31 02:49:53 +090049
50 // determines if the dependent will be part of the APEX payload
51 payload bool
Jiyong Park48ca7dc2018-10-10 14:01:00 +090052}
53
54var (
Jiyong Parkfa899442020-01-31 02:49:53 +090055 sharedLibTag = dependencyTag{name: "sharedLib", payload: true}
56 executableTag = dependencyTag{name: "executable", payload: true}
57 javaLibTag = dependencyTag{name: "javaLib", payload: true}
58 prebuiltTag = dependencyTag{name: "prebuilt", payload: true}
59 testTag = dependencyTag{name: "test", payload: true}
Jiyong Parkc00cbd92018-10-30 21:20:05 +090060 keyTag = dependencyTag{name: "key"}
61 certificateTag = dependencyTag{name: "certificate"}
Jooyung Han5c998b92019-06-27 11:30:33 +090062 usesTag = dependencyTag{name: "uses"}
Jiyong Parkfa899442020-01-31 02:49:53 +090063 androidAppTag = dependencyTag{name: "androidApp", payload: true}
Anton Hansson5053c292020-01-10 15:12:39 +000064 apexAvailWl = makeApexAvailableWhitelist()
Paul Duffin404db3f2020-03-06 12:30:13 +000065
66 inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
Jiyong Park48ca7dc2018-10-10 14:01:00 +090067)
68
Paul Duffin404db3f2020-03-06 12:30:13 +000069// Transform the map of apex -> modules to module -> apexes.
70func invertApexWhiteList(m map[string][]string) map[string][]string {
71 r := make(map[string][]string)
72 for apex, modules := range m {
73 for _, module := range modules {
74 r[module] = append(r[module], apex)
75 }
76 }
77 return r
78}
79
80// Retrieve the while list of apexes to which the supplied module belongs.
81func WhitelistedApexAvailable(moduleName string) []string {
82 return inverseApexAvailWl[normalizeModuleName(moduleName)]
83}
84
Anton Hansson5053c292020-01-10 15:12:39 +000085// This is a map from apex to modules, which overrides the
86// apex_available setting for that particular module to make
87// it available for the apex regardless of its setting.
88// TODO(b/147364041): remove this
89func makeApexAvailableWhitelist() map[string][]string {
90 // The "Module separator"s below are employed to minimize merge conflicts.
91 m := make(map[string][]string)
92 //
93 // Module separator
94 //
Paul Duffinc23d9f62020-03-10 13:44:19 +000095 artApexContents := []string{
Jiyong Parkfa899442020-01-31 02:49:53 +090096 "art_cmdlineparser_headers",
97 "art_disassembler_headers",
98 "art_libartbase_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +090099 "bionic_libc_platform_headers",
100 "core-repackaged-icu4j",
101 "cpp-define-generator-asm-support",
102 "cpp-define-generator-definitions",
103 "crtbegin_dynamic",
104 "crtbegin_dynamic1",
105 "crtbegin_so1",
106 "crtbrand",
Jiyong Parkfa899442020-01-31 02:49:53 +0900107 "dex2oat_headers",
108 "dt_fd_forward_export",
Jiyong Parkfa899442020-01-31 02:49:53 +0900109 "icu4c_extra_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900110 "javavm_headers",
111 "jni_platform_headers",
112 "libPlatformProperties",
113 "libadbconnection_client",
Anton Hansson5053c292020-01-10 15:12:39 +0000114 "libadbconnection_server",
Jiyong Parkfa899442020-01-31 02:49:53 +0900115 "libandroidicuinit",
116 "libart_runtime_headers_ndk",
Anton Hansson5053c292020-01-10 15:12:39 +0000117 "libartd-disassembler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900118 "libdexfile_all_headers",
119 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000120 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900121 "libdmabufinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000122 "libexpat",
Jiyong Parkfa899442020-01-31 02:49:53 +0900123 "libfdlibm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900124 "libicui18n_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000125 "libicuuc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900126 "libicuuc_headers",
127 "libicuuc_stubdata",
128 "libjdwp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900129 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000130 "liblzma",
131 "libmeminfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900132 "libnativebridge-headers",
133 "libnativehelper_header_only",
134 "libnativeloader-headers",
135 "libnpt_headers",
136 "libopenjdkjvmti_headers",
137 "libperfetto_client_experimental",
Anton Hansson5053c292020-01-10 15:12:39 +0000138 "libprocinfo",
Jiyong Parkfa899442020-01-31 02:49:53 +0900139 "libunwind_llvm",
Anton Hansson5053c292020-01-10 15:12:39 +0000140 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900141 "libv8",
142 "libv8base",
143 "libv8gen",
144 "libv8platform",
145 "libv8sampler",
146 "libv8src",
Anton Hansson5053c292020-01-10 15:12:39 +0000147 "libvixl",
148 "libvixld",
149 "libz",
150 "libziparchive",
Jiyong Parkfa899442020-01-31 02:49:53 +0900151 "perfetto_trace_protos",
Anton Hansson5053c292020-01-10 15:12:39 +0000152 }
Paul Duffinc23d9f62020-03-10 13:44:19 +0000153 m["com.android.art.debug"] = artApexContents
154 m["com.android.art.release"] = artApexContents
Anton Hansson5053c292020-01-10 15:12:39 +0000155 //
156 // Module separator
157 //
158 m["com.android.bluetooth.updatable"] = []string{
159 "android.hardware.audio.common@5.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000160 "android.hardware.bluetooth.a2dp@1.0",
161 "android.hardware.bluetooth.audio@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900162 "android.hardware.bluetooth@1.0",
163 "android.hardware.bluetooth@1.1",
164 "android.hardware.graphics.bufferqueue@1.0",
165 "android.hardware.graphics.bufferqueue@2.0",
166 "android.hardware.graphics.common@1.0",
167 "android.hardware.graphics.common@1.1",
168 "android.hardware.graphics.common@1.2",
169 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000170 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900171 "android.hidl.token@1.0",
172 "android.hidl.token@1.0-utils",
173 "avrcp-target-service",
174 "avrcp_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900175 "bluetooth-protos-lite",
176 "bluetooth.mapsapi",
177 "com.android.vcard",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900178 "dnsresolver_aidl_interface-V2-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900179 "ipmemorystore-aidl-interfaces-V5-java",
180 "ipmemorystore-aidl-interfaces-java",
Jiyong Parkfa899442020-01-31 02:49:53 +0900181 "internal_include_headers",
182 "lib-bt-packets",
183 "lib-bt-packets-avrcp",
184 "lib-bt-packets-base",
185 "libFraunhoferAAC",
186 "libaudio-a2dp-hw-utils",
187 "libaudio-hearing-aid-hw-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900188 "libbinder_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000189 "libbluetooth",
Jiyong Parkfa899442020-01-31 02:49:53 +0900190 "libbluetooth-types",
191 "libbluetooth-types-header",
192 "libbluetooth_gd",
193 "libbluetooth_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000194 "libbluetooth_jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900195 "libbt-audio-hal-interface",
196 "libbt-bta",
197 "libbt-common",
198 "libbt-hci",
199 "libbt-platform-protos-lite",
200 "libbt-protos-lite",
201 "libbt-sbc-decoder",
202 "libbt-sbc-encoder",
203 "libbt-stack",
204 "libbt-utils",
205 "libbtcore",
206 "libbtdevice",
207 "libbte",
208 "libbtif",
Anton Hansson5053c292020-01-10 15:12:39 +0000209 "libchrome",
Anton Hansson5053c292020-01-10 15:12:39 +0000210 "libevent",
211 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900212 "libg722codec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900213 "libgui_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900214 "libmedia_headers",
215 "libmodpb64",
216 "libosi",
Jiyong Parkfa899442020-01-31 02:49:53 +0900217 "libstagefright_foundation_headers",
218 "libstagefright_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000219 "libstatslog",
Jiyong Parkfa899442020-01-31 02:49:53 +0900220 "libstatssocket",
Anton Hansson5053c292020-01-10 15:12:39 +0000221 "libtinyxml2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900222 "libudrv-uipc",
Anton Hansson5053c292020-01-10 15:12:39 +0000223 "libz",
Jiyong Parkfa899442020-01-31 02:49:53 +0900224 "media_plugin_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900225 "net-utils-services-common",
226 "netd_aidl_interface-unstable-java",
227 "netd_event_listener_interface-java",
228 "netlink-client",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900229 "networkstack-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900230 "sap-api-java-static",
231 "services.net",
Anton Hansson5053c292020-01-10 15:12:39 +0000232 }
233 //
234 // Module separator
235 //
236 m["com.android.cellbroadcast"] = []string{"CellBroadcastApp", "CellBroadcastServiceModule"}
237 //
238 // Module separator
239 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900240 m["com.android.conscrypt"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900241 "libnativehelper_header_only",
Jiyong Parkfa899442020-01-31 02:49:53 +0900242 }
Anton Hansson5053c292020-01-10 15:12:39 +0000243 //
244 // Module separator
245 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900246 m["com.android.extservices"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900247 "libz_current",
Jiyong Parkfa899442020-01-31 02:49:53 +0900248 }
249 //
250 // Module separator
251 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900252 m["com.android.neuralnetworks"] = []string{
253 "android.hardware.neuralnetworks@1.0",
254 "android.hardware.neuralnetworks@1.1",
255 "android.hardware.neuralnetworks@1.2",
256 "android.hardware.neuralnetworks@1.3",
257 "android.hidl.allocator@1.0",
258 "android.hidl.memory.token@1.0",
259 "android.hidl.memory@1.0",
260 "android.hidl.safe_union@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900261 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900262 "libbuildversion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900263 "libmath",
Jiyong Parkfa899442020-01-31 02:49:53 +0900264 "libprocpartition",
265 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900266 }
Anton Hansson5053c292020-01-10 15:12:39 +0000267 //
268 // Module separator
269 //
Anton Hansson5053c292020-01-10 15:12:39 +0000270 m["com.android.media"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900271 "android.frameworks.bufferhub@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000272 "android.hardware.cas.native@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900273 "android.hardware.cas@1.0",
274 "android.hardware.configstore-utils",
275 "android.hardware.configstore@1.0",
276 "android.hardware.configstore@1.1",
277 "android.hardware.graphics.allocator@2.0",
278 "android.hardware.graphics.allocator@3.0",
279 "android.hardware.graphics.bufferqueue@1.0",
280 "android.hardware.graphics.bufferqueue@2.0",
281 "android.hardware.graphics.common@1.0",
282 "android.hardware.graphics.common@1.1",
283 "android.hardware.graphics.common@1.2",
284 "android.hardware.graphics.mapper@2.0",
285 "android.hardware.graphics.mapper@2.1",
286 "android.hardware.graphics.mapper@3.0",
287 "android.hardware.media.omx@1.0",
288 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000289 "android.hidl.allocator@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000290 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900291 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000292 "android.hidl.token@1.0",
293 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900294 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900295 "gl_headers",
296 "libEGL",
297 "libEGL_blobCache",
298 "libEGL_getProcAddress",
299 "libFLAC",
300 "libFLAC-config",
301 "libFLAC-headers",
302 "libGLESv2",
Anton Hansson5053c292020-01-10 15:12:39 +0000303 "libaacextractor",
304 "libamrextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900305 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900306 "libaudio_system_headers",
307 "libaudioclient",
308 "libaudioclient_headers",
309 "libaudiofoundation",
310 "libaudiofoundation_headers",
311 "libaudiomanager",
312 "libaudiopolicy",
Anton Hansson5053c292020-01-10 15:12:39 +0000313 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900314 "libaudioutils_fixedfft",
Jiyong Parkfa899442020-01-31 02:49:53 +0900315 "libbinder_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900316 "libbluetooth-types-header",
317 "libbufferhub",
318 "libbufferhub_headers",
319 "libbufferhubqueue",
Jiyong Parkfa899442020-01-31 02:49:53 +0900320 "libc_malloc_debug_backtrace",
321 "libcamera_client",
322 "libcamera_metadata",
Jiyong Parkfa899442020-01-31 02:49:53 +0900323 "libdexfile_external_headers",
324 "libdexfile_support",
325 "libdvr_headers",
326 "libexpat",
327 "libfifo",
Anton Hansson5053c292020-01-10 15:12:39 +0000328 "libflacextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900329 "libgrallocusage",
330 "libgraphicsenv",
331 "libgui",
332 "libgui_headers",
333 "libhardware_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900334 "libinput",
Jiyong Parkfa899442020-01-31 02:49:53 +0900335 "liblzma",
336 "libmath",
337 "libmedia",
338 "libmedia_codeclist",
339 "libmedia_headers",
340 "libmedia_helper",
341 "libmedia_helper_headers",
342 "libmedia_midiiowrapper",
343 "libmedia_omx",
344 "libmediautils",
Anton Hansson5053c292020-01-10 15:12:39 +0000345 "libmidiextractor",
346 "libmkvextractor",
347 "libmp3extractor",
348 "libmp4extractor",
349 "libmpeg2extractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900350 "libnativebase_headers",
351 "libnativebridge-headers",
352 "libnativebridge_lazy",
353 "libnativeloader-headers",
354 "libnativeloader_lazy",
355 "libnativewindow_headers",
356 "libnblog",
Anton Hansson5053c292020-01-10 15:12:39 +0000357 "liboggextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900358 "libpackagelistparser",
Jiyong Parkfa899442020-01-31 02:49:53 +0900359 "libpdx",
360 "libpdx_default_transport",
361 "libpdx_headers",
362 "libpdx_uds",
Jiyong Parkfa899442020-01-31 02:49:53 +0900363 "libprocinfo",
Anton Hansson5053c292020-01-10 15:12:39 +0000364 "libspeexresampler",
Jiyong Parkfa899442020-01-31 02:49:53 +0900365 "libspeexresampler",
366 "libstagefright_esds",
Anton Hansson5053c292020-01-10 15:12:39 +0000367 "libstagefright_flacdec",
Jiyong Parkfa899442020-01-31 02:49:53 +0900368 "libstagefright_flacdec",
369 "libstagefright_foundation",
370 "libstagefright_foundation_headers",
371 "libstagefright_foundation_without_imemory",
372 "libstagefright_headers",
373 "libstagefright_id3",
374 "libstagefright_metadatautils",
375 "libstagefright_mpeg2extractor",
376 "libstagefright_mpeg2support",
377 "libsync",
Jiyong Parkfa899442020-01-31 02:49:53 +0900378 "libui",
379 "libui_headers",
380 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900381 "libvibrator",
382 "libvorbisidec",
Anton Hansson5053c292020-01-10 15:12:39 +0000383 "libwavextractor",
Jiyong Parkfa899442020-01-31 02:49:53 +0900384 "libwebm",
385 "media_ndk_headers",
386 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000387 "updatable-media",
388 }
389 //
390 // Module separator
391 //
392 m["com.android.media.swcodec"] = []string{
393 "android.frameworks.bufferhub@1.0",
394 "android.hardware.common-ndk_platform",
Jiyong Parkfa899442020-01-31 02:49:53 +0900395 "android.hardware.configstore-utils",
396 "android.hardware.configstore@1.0",
397 "android.hardware.configstore@1.1",
Anton Hansson5053c292020-01-10 15:12:39 +0000398 "android.hardware.graphics.allocator@2.0",
399 "android.hardware.graphics.allocator@3.0",
400 "android.hardware.graphics.allocator@4.0",
401 "android.hardware.graphics.bufferqueue@1.0",
402 "android.hardware.graphics.bufferqueue@2.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900403 "android.hardware.graphics.common-ndk_platform",
Anton Hansson5053c292020-01-10 15:12:39 +0000404 "android.hardware.graphics.common@1.0",
405 "android.hardware.graphics.common@1.1",
406 "android.hardware.graphics.common@1.2",
Anton Hansson5053c292020-01-10 15:12:39 +0000407 "android.hardware.graphics.mapper@2.0",
408 "android.hardware.graphics.mapper@2.1",
409 "android.hardware.graphics.mapper@3.0",
410 "android.hardware.graphics.mapper@4.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000411 "android.hardware.media.bufferpool@2.0",
412 "android.hardware.media.c2@1.0",
413 "android.hardware.media.c2@1.1",
414 "android.hardware.media.omx@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900415 "android.hardware.media@1.0",
416 "android.hardware.media@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000417 "android.hidl.memory.token@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900418 "android.hidl.memory@1.0",
Anton Hansson5053c292020-01-10 15:12:39 +0000419 "android.hidl.safe_union@1.0",
420 "android.hidl.token@1.0",
421 "android.hidl.token@1.0-utils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900422 "libEGL",
423 "libFLAC",
424 "libFLAC-config",
425 "libFLAC-headers",
426 "libFraunhoferAAC",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900427 "libLibGuiProperties",
Jiyong Parkfa899442020-01-31 02:49:53 +0900428 "libarect",
Jiyong Parkfa899442020-01-31 02:49:53 +0900429 "libaudio_system_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000430 "libaudioutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900431 "libaudioutils",
432 "libaudioutils_fixedfft",
433 "libavcdec",
434 "libavcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000435 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900436 "libavservices_minijail",
Jiyong Parkfa899442020-01-31 02:49:53 +0900437 "libbinder_headers",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900438 "libbinderthreadstateutils",
Jiyong Parkfa899442020-01-31 02:49:53 +0900439 "libbluetooth-types-header",
440 "libbufferhub_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900441 "libc_scudo",
Anton Hansson5053c292020-01-10 15:12:39 +0000442 "libcodec2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900443 "libcodec2_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000444 "libcodec2_hidl@1.0",
445 "libcodec2_hidl@1.1",
Jiyong Parkfa899442020-01-31 02:49:53 +0900446 "libcodec2_internal",
Anton Hansson5053c292020-01-10 15:12:39 +0000447 "libcodec2_soft_aacdec",
448 "libcodec2_soft_aacenc",
449 "libcodec2_soft_amrnbdec",
450 "libcodec2_soft_amrnbenc",
451 "libcodec2_soft_amrwbdec",
452 "libcodec2_soft_amrwbenc",
453 "libcodec2_soft_av1dec_gav1",
454 "libcodec2_soft_avcdec",
455 "libcodec2_soft_avcenc",
456 "libcodec2_soft_common",
457 "libcodec2_soft_flacdec",
458 "libcodec2_soft_flacenc",
459 "libcodec2_soft_g711alawdec",
460 "libcodec2_soft_g711mlawdec",
461 "libcodec2_soft_gsmdec",
462 "libcodec2_soft_h263dec",
463 "libcodec2_soft_h263enc",
464 "libcodec2_soft_hevcdec",
465 "libcodec2_soft_hevcenc",
466 "libcodec2_soft_mp3dec",
467 "libcodec2_soft_mpeg2dec",
468 "libcodec2_soft_mpeg4dec",
469 "libcodec2_soft_mpeg4enc",
470 "libcodec2_soft_opusdec",
471 "libcodec2_soft_opusenc",
472 "libcodec2_soft_rawdec",
473 "libcodec2_soft_vorbisdec",
474 "libcodec2_soft_vp8dec",
475 "libcodec2_soft_vp8enc",
476 "libcodec2_soft_vp9dec",
477 "libcodec2_soft_vp9enc",
478 "libcodec2_vndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900479 "libdexfile_support",
480 "libdvr_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000481 "libfmq",
Jiyong Parkfa899442020-01-31 02:49:53 +0900482 "libfmq",
483 "libgav1",
Anton Hansson5053c292020-01-10 15:12:39 +0000484 "libgralloctypes",
Jiyong Parkfa899442020-01-31 02:49:53 +0900485 "libgrallocusage",
486 "libgraphicsenv",
487 "libgsm",
488 "libgui_bufferqueue_static",
489 "libgui_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000490 "libhardware",
Jiyong Parkfa899442020-01-31 02:49:53 +0900491 "libhardware_headers",
492 "libhevcdec",
493 "libhevcenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000494 "libion",
Jiyong Parkfa899442020-01-31 02:49:53 +0900495 "libjpeg",
Jiyong Parkfa899442020-01-31 02:49:53 +0900496 "liblzma",
497 "libmath",
Anton Hansson5053c292020-01-10 15:12:39 +0000498 "libmedia_codecserviceregistrant",
Jiyong Parkfa899442020-01-31 02:49:53 +0900499 "libmedia_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900500 "libmpeg2dec",
501 "libnativebase_headers",
502 "libnativebridge_lazy",
503 "libnativeloader_lazy",
504 "libnativewindow_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900505 "libpdx_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000506 "libscudo_wrapper",
507 "libsfplugin_ccodec_utils",
508 "libspeexresampler",
509 "libstagefright_amrnb_common",
Jiyong Parkfa899442020-01-31 02:49:53 +0900510 "libstagefright_amrnbdec",
511 "libstagefright_amrnbenc",
512 "libstagefright_amrwbdec",
513 "libstagefright_amrwbenc",
Anton Hansson5053c292020-01-10 15:12:39 +0000514 "libstagefright_bufferpool@2.0.1",
515 "libstagefright_bufferqueue_helper",
516 "libstagefright_enc_common",
517 "libstagefright_flacdec",
518 "libstagefright_foundation",
Jiyong Parkfa899442020-01-31 02:49:53 +0900519 "libstagefright_foundation_headers",
520 "libstagefright_headers",
521 "libstagefright_m4vh263dec",
522 "libstagefright_m4vh263enc",
523 "libstagefright_mp3dec",
Anton Hansson5053c292020-01-10 15:12:39 +0000524 "libsync",
525 "libui",
Jiyong Parkfa899442020-01-31 02:49:53 +0900526 "libui_headers",
527 "libunwindstack",
Anton Hansson5053c292020-01-10 15:12:39 +0000528 "libvorbisidec",
529 "libvpx",
Jiyong Parkfa899442020-01-31 02:49:53 +0900530 "libyuv",
531 "libyuv_static",
532 "media_ndk_headers",
533 "media_plugin_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000534 "mediaswcodec",
Anton Hansson5053c292020-01-10 15:12:39 +0000535 }
536 //
537 // Module separator
538 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900539 m["com.android.mediaprovider"] = []string{
540 "MediaProvider",
541 "MediaProviderGoogle",
542 "fmtlib_ndk",
Jiyong Parkfa899442020-01-31 02:49:53 +0900543 "libbase_ndk",
544 "libfuse",
545 "libfuse_jni",
546 "libnativehelper_header_only",
547 }
548 //
549 // Module separator
550 //
551 m["com.android.permission"] = []string{
552 "androidx.annotation_annotation",
553 "androidx.annotation_annotation-nodeps",
554 "androidx.lifecycle_lifecycle-common",
555 "androidx.lifecycle_lifecycle-common-java8",
556 "androidx.lifecycle_lifecycle-common-java8-nodeps",
557 "androidx.lifecycle_lifecycle-common-nodeps",
558 "kotlin-annotations",
559 "kotlin-stdlib",
560 "kotlin-stdlib-jdk7",
561 "kotlin-stdlib-jdk8",
562 "kotlinx-coroutines-android",
563 "kotlinx-coroutines-android-nodeps",
564 "kotlinx-coroutines-core",
565 "kotlinx-coroutines-core-nodeps",
Jiyong Parkfa899442020-01-31 02:49:53 +0900566 "permissioncontroller-statsd",
Jiyong Park26fb6bd2020-02-06 16:47:54 +0900567 "GooglePermissionController",
568 "PermissionController",
Jiyong Parkfa899442020-01-31 02:49:53 +0900569 }
Anton Hansson5053c292020-01-10 15:12:39 +0000570 //
571 // Module separator
572 //
Anton Hansson5053c292020-01-10 15:12:39 +0000573 m["com.android.runtime"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900574 "bionic_libc_platform_headers",
Jiyong Parkfa899442020-01-31 02:49:53 +0900575 "libarm-optimized-routines-math",
Jiyong Parkfa899442020-01-31 02:49:53 +0900576 "libc_aeabi",
577 "libc_bionic",
578 "libc_bionic_ndk",
579 "libc_bootstrap",
580 "libc_common",
581 "libc_common_shared",
582 "libc_common_static",
583 "libc_dns",
584 "libc_dynamic_dispatch",
585 "libc_fortify",
586 "libc_freebsd",
587 "libc_freebsd_large_stack",
588 "libc_gdtoa",
Jiyong Parkfa899442020-01-31 02:49:53 +0900589 "libc_init_dynamic",
590 "libc_init_static",
591 "libc_jemalloc_wrapper",
592 "libc_netbsd",
593 "libc_nomalloc",
594 "libc_nopthread",
595 "libc_openbsd",
596 "libc_openbsd_large_stack",
597 "libc_openbsd_ndk",
598 "libc_pthread",
599 "libc_static_dispatch",
600 "libc_syscalls",
601 "libc_tzcode",
602 "libc_unwind_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900603 "libdebuggerd",
604 "libdebuggerd_common_headers",
605 "libdebuggerd_handler_core",
606 "libdebuggerd_handler_fallback",
607 "libdexfile_external_headers",
Anton Hansson5053c292020-01-10 15:12:39 +0000608 "libdexfile_support",
Jiyong Parkfa899442020-01-31 02:49:53 +0900609 "libdexfile_support_static",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900610 "libdl_static",
Jiyong Parkfa899442020-01-31 02:49:53 +0900611 "libjemalloc5",
612 "liblinker_main",
613 "liblinker_malloc",
Jiyong Parkfa899442020-01-31 02:49:53 +0900614 "liblz4",
Anton Hansson5053c292020-01-10 15:12:39 +0000615 "liblzma",
Jiyong Parkfa899442020-01-31 02:49:53 +0900616 "libprocinfo",
617 "libpropertyinfoparser",
618 "libscudo",
619 "libstdc++",
Jiyong Parkfa899442020-01-31 02:49:53 +0900620 "libsystemproperties",
621 "libtombstoned_client_static",
Anton Hansson5053c292020-01-10 15:12:39 +0000622 "libunwindstack",
Jiyong Parkfa899442020-01-31 02:49:53 +0900623 "libz",
624 "libziparchive",
Anton Hansson5053c292020-01-10 15:12:39 +0000625 }
626 //
627 // Module separator
628 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900629 m["com.android.tethering"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900630 "libnativehelper_compat_libc++",
631 "android.hardware.tetheroffload.config@1.0",
Jiyong Parkfa899442020-01-31 02:49:53 +0900632 "libcgrouprc",
633 "libcgrouprc_format",
Jiyong Parkfa899442020-01-31 02:49:53 +0900634 "libtetherutilsjni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900635 "libvndksupport",
636 "tethering-aidl-interfaces-java",
637 }
Anton Hansson5053c292020-01-10 15:12:39 +0000638 //
639 // Module separator
640 //
641 m["com.android.wifi"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900642 "PlatformProperties",
643 "android.hardware.wifi-V1.0-java",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900644 "android.hardware.wifi-V1.0-java-constants",
Jiyong Parkfa899442020-01-31 02:49:53 +0900645 "android.hardware.wifi-V1.1-java",
646 "android.hardware.wifi-V1.2-java",
647 "android.hardware.wifi-V1.3-java",
648 "android.hardware.wifi-V1.4-java",
649 "android.hardware.wifi.hostapd-V1.0-java",
650 "android.hardware.wifi.hostapd-V1.1-java",
651 "android.hardware.wifi.hostapd-V1.2-java",
652 "android.hardware.wifi.supplicant-V1.0-java",
653 "android.hardware.wifi.supplicant-V1.1-java",
654 "android.hardware.wifi.supplicant-V1.2-java",
655 "android.hardware.wifi.supplicant-V1.3-java",
656 "android.hidl.base-V1.0-java",
657 "android.hidl.manager-V1.0-java",
658 "android.hidl.manager-V1.1-java",
659 "android.hidl.manager-V1.2-java",
660 "androidx.annotation_annotation",
661 "androidx.annotation_annotation-nodeps",
662 "bouncycastle-unbundled",
663 "dnsresolver_aidl_interface-V2-java",
664 "error_prone_annotations",
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900665 "framework-wifi-pre-jarjar",
666 "framework-wifi-util-lib",
Jiyong Parkfa899442020-01-31 02:49:53 +0900667 "ipmemorystore-aidl-interfaces-V3-java",
668 "ipmemorystore-aidl-interfaces-java",
669 "ksoap2",
Jiyong Parkfa899442020-01-31 02:49:53 +0900670 "libnanohttpd",
Anton Hansson5053c292020-01-10 15:12:39 +0000671 "libwifi-jni",
Jiyong Parkfa899442020-01-31 02:49:53 +0900672 "net-utils-services-common",
673 "netd_aidl_interface-V2-java",
674 "netd_aidl_interface-unstable-java",
675 "netd_event_listener_interface-java",
676 "netlink-client",
Jiyong Parkfa899442020-01-31 02:49:53 +0900677 "networkstack-client",
678 "services.net",
679 "wifi-lite-protos",
680 "wifi-nano-protos",
681 "wifi-service-pre-jarjar",
Anton Hansson5053c292020-01-10 15:12:39 +0000682 "wifi-service-resources",
Jiyong Parkfa899442020-01-31 02:49:53 +0900683 "prebuilt_androidx.annotation_annotation-nodeps",
Anton Hansson5053c292020-01-10 15:12:39 +0000684 }
685 //
686 // Module separator
687 //
Jiyong Parkfa899442020-01-31 02:49:53 +0900688 m["com.android.sdkext"] = []string{
689 "fmtlib_ndk",
690 "libbase_ndk",
691 "libprotobuf-cpp-lite-ndk",
692 }
693 //
694 // Module separator
695 //
696 m["com.android.os.statsd"] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900697 "libstatssocket",
Jiyong Parkfa899442020-01-31 02:49:53 +0900698 }
699 //
700 // Module separator
701 //
Paul Duffin404db3f2020-03-06 12:30:13 +0000702 m[android.AvailableToAnyApex] = []string{
Jiyong Parkfa899442020-01-31 02:49:53 +0900703 "libatomic",
Jiyong Parkfa899442020-01-31 02:49:53 +0900704 "libclang_rt",
705 "libgcc_stripped",
706 "libprofile-clang-extras",
707 "libprofile-clang-extras_ndk",
708 "libprofile-extras",
709 "libprofile-extras_ndk",
710 "libunwind_llvm",
Jiyong Parkfa899442020-01-31 02:49:53 +0900711 }
Anton Hansson5053c292020-01-10 15:12:39 +0000712 return m
713}
714
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900715func init() {
Jiyong Parkd1063c12019-07-17 20:08:41 +0900716 android.RegisterModuleType("apex", BundleFactory)
Alex Light0851b882019-02-07 13:20:53 -0800717 android.RegisterModuleType("apex_test", testApexBundleFactory)
Jooyung Han344d5432019-08-23 11:17:39 +0900718 android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
Jiyong Park30ca9372019-02-07 16:27:23 +0900719 android.RegisterModuleType("apex_defaults", defaultsFactory)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700720 android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
Jiyong Park5d790c32019-11-15 18:40:32 +0900721 android.RegisterModuleType("override_apex", overrideApexFactory)
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700722 android.RegisterModuleType("apex_set", apexSetFactory)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900723
Jooyung Han31c470b2019-10-18 16:26:59 +0900724 android.PreDepsMutators(RegisterPreDepsMutators)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900725 android.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han7a78a922019-10-08 21:59:58 +0900726
727 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
728 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
729 sort.Strings(*apexFileContextsInfos)
730 ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
731 })
Jiyong Parkd1063c12019-07-17 20:08:41 +0900732}
733
Jooyung Han31c470b2019-10-18 16:26:59 +0900734func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
735 ctx.TopDown("apex_vndk", apexVndkMutator).Parallel()
736 ctx.BottomUp("apex_vndk_deps", apexVndkDepsMutator).Parallel()
737}
738
Jiyong Parkd1063c12019-07-17 20:08:41 +0900739func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900740 ctx.TopDown("apex_deps", apexDepsMutator)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900741 ctx.BottomUp("apex", apexMutator).Parallel()
742 ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
743 ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900744 ctx.BottomUp("mark_platform_availability", markPlatformAvailability).Parallel()
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900745}
746
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900747// Mark the direct and transitive dependencies of apex bundles so that they
748// can be built for the apex bundles.
Jiyong Parkf760cae2020-02-12 07:53:12 +0900749func apexDepsMutator(mctx android.TopDownMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900750 if !mctx.Module().Enabled() {
751 return
752 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800753 var apexBundles []android.ApexInfo
Jiyong Parkf760cae2020-02-12 07:53:12 +0900754 var directDep bool
Jooyung Hana57af4a2020-01-23 05:36:59 +0000755 if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jooyung Han40b286c2020-04-17 13:43:10 +0900756 apexBundles = []android.ApexInfo{{
Jooyung Han23b0adf2020-03-12 18:37:20 +0900757 ApexName: mctx.ModuleName(),
758 MinSdkVersion: a.minSdkVersion(mctx),
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100759 Updatable: a.Updatable(),
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900760 }}
Jiyong Parkf760cae2020-02-12 07:53:12 +0900761 directDep = true
762 } else if am, ok := mctx.Module().(android.ApexModule); ok {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800763 apexBundles = am.ApexVariations()
Jiyong Parkf760cae2020-02-12 07:53:12 +0900764 directDep = false
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900765 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900766
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800767 if len(apexBundles) == 0 {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900768 return
769 }
770
Paul Duffin03e7d0c2020-03-30 15:33:32 +0100771 cur := mctx.Module().(android.DepIsInSameApex)
Jooyung Hanb8fa86a2020-03-10 06:23:13 +0900772
Jiyong Parkf760cae2020-02-12 07:53:12 +0900773 mctx.VisitDirectDeps(func(child android.Module) {
774 depName := mctx.OtherModuleName(child)
775 if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100776 (cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800777 android.UpdateApexDependency(apexBundles, depName, directDep)
778 am.BuildForApexes(apexBundles)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900779 }
780 })
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900781}
782
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900783// mark if a module cannot be available to platform. A module cannot be available
784// to platform if 1) it is explicitly marked as not available (i.e. "//apex_available:platform"
785// is absent) or 2) it depends on another module that isn't (or can't be) available to platform
786func markPlatformAvailability(mctx android.BottomUpMutatorContext) {
787 // Host and recovery are not considered as platform
788 if mctx.Host() || mctx.Module().InstallInRecovery() {
789 return
790 }
791
792 if am, ok := mctx.Module().(android.ApexModule); ok {
793 availableToPlatform := am.AvailableFor(android.AvailableToPlatform)
794
795 // In a rare case when a lib is marked as available only to an apex
796 // but the apex doesn't exist. This can happen in a partial manifest branch
797 // like master-art. Currently, libstatssocket in the stats APEX is causing
798 // this problem.
799 // Include the lib in platform because the module SDK that ought to provide
800 // it doesn't exist, so it would otherwise be left out completely.
801 // TODO(b/154888298) remove this by adding those libraries in module SDKS and skipping
802 // this check for libraries provided by SDKs.
803 if !availableToPlatform && !android.InAnyApex(am.Name()) {
804 availableToPlatform = true
805 }
806
807 // If any of the dep is not available to platform, this module is also considered
808 // as being not available to platform even if it has "//apex_available:platform"
809 mctx.VisitDirectDeps(func(child android.Module) {
810 if !am.DepIsInSameApex(mctx, child) {
811 // if the dependency crosses apex boundary, don't consider it
812 return
813 }
814 if dep, ok := child.(android.ApexModule); ok && dep.NotAvailableForPlatform() {
815 availableToPlatform = false
816 // TODO(b/154889534) trigger an error when 'am' has "//apex_available:platform"
817 }
818 })
819
820 // Exception 1: stub libraries and native bridge libraries are always available to platform
821 if cc, ok := mctx.Module().(*cc.Module); ok &&
822 (cc.IsStubs() || cc.Target().NativeBridge == android.NativeBridgeEnabled) {
823 availableToPlatform = true
824 }
825
826 // Exception 2: bootstrap bionic libraries are also always available to platform
827 if cc.InstallToBootstrap(mctx.ModuleName(), mctx.Config()) {
828 availableToPlatform = true
829 }
830
831 if !availableToPlatform {
832 am.SetNotAvailableForPlatform()
833 }
834 }
835}
836
Paul Duffinb20ad0a2020-03-31 15:23:40 +0100837// If a module in an APEX depends on a module from an SDK then it needs an APEX
838// specific variant created for it. Refer to sdk.sdkDepsReplaceMutator.
839func inAnySdk(module android.Module) bool {
840 if sa, ok := module.(android.SdkAware); ok {
841 return sa.IsInAnySdk()
842 }
843
844 return false
845}
846
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900847// Create apex variations if a module is included in APEX(s).
848func apexMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900849 if !mctx.Module().Enabled() {
850 return
851 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900852 if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900853 am.CreateApexVariations(mctx)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000854 } else if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900855 // apex bundle itself is mutated so that it and its modules have same
856 // apex variant.
857 apexBundleName := mctx.ModuleName()
858 mctx.CreateVariations(apexBundleName)
Jiyong Park5d790c32019-11-15 18:40:32 +0900859 } else if o, ok := mctx.Module().(*OverrideApex); ok {
860 apexBundleName := o.GetOverriddenModuleName()
861 if apexBundleName == "" {
862 mctx.ModuleErrorf("base property is not set")
863 return
864 }
865 mctx.CreateVariations(apexBundleName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900866 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900867
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900868}
Sundong Ahne9b55722019-09-06 17:37:42 +0900869
Jooyung Han7a78a922019-10-08 21:59:58 +0900870var (
871 apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
872 apexFileContextsInfosMutex sync.Mutex
873)
874
875func apexFileContextsInfos(config android.Config) *[]string {
876 return config.Once(apexFileContextsInfosKey, func() interface{} {
877 return &[]string{}
878 }).(*[]string)
879}
880
Jooyung Han54aca7b2019-11-20 02:26:02 +0900881func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
Jooyung Han7a78a922019-10-08 21:59:58 +0900882 apexFileContextsInfosMutex.Lock()
883 defer apexFileContextsInfosMutex.Unlock()
884 apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
Jooyung Han54aca7b2019-11-20 02:26:02 +0900885 *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
Jooyung Han7a78a922019-10-08 21:59:58 +0900886}
887
Sundong Ahne9b55722019-09-06 17:37:42 +0900888func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
Jooyung Han40b286c2020-04-17 13:43:10 +0900889 if !mctx.Module().Enabled() {
890 return
891 }
Sundong Ahne8fb7242019-09-17 13:50:45 +0900892 if ab, ok := mctx.Module().(*apexBundle); ok {
Sundong Ahnabb64432019-10-22 13:58:29 +0900893 var variants []string
894 switch proptools.StringDefault(ab.properties.Payload_type, "image") {
895 case "image":
896 variants = append(variants, imageApexType, flattenedApexType)
897 case "zip":
898 variants = append(variants, zipApexType)
899 case "both":
900 variants = append(variants, imageApexType, zipApexType, flattenedApexType)
901 default:
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900902 mctx.PropertyErrorf("type", "%q is not one of \"image\", \"zip\", or \"both\".", *ab.properties.Payload_type)
Sundong Ahnabb64432019-10-22 13:58:29 +0900903 return
904 }
905
906 modules := mctx.CreateLocalVariations(variants...)
907
908 for i, v := range variants {
909 switch v {
910 case imageApexType:
911 modules[i].(*apexBundle).properties.ApexType = imageApex
912 case zipApexType:
913 modules[i].(*apexBundle).properties.ApexType = zipApex
914 case flattenedApexType:
915 modules[i].(*apexBundle).properties.ApexType = flattenedApex
Jooyung Han91df2082019-11-20 01:49:42 +0900916 if !mctx.Config().FlattenApex() && ab.Platform() {
Sundong Ahnd95aa2d2019-10-08 19:34:03 +0900917 modules[i].(*apexBundle).MakeAsSystemExt()
918 }
Sundong Ahnabb64432019-10-22 13:58:29 +0900919 }
Sundong Ahne9b55722019-09-06 17:37:42 +0900920 }
Jiyong Park5d790c32019-11-15 18:40:32 +0900921 } else if _, ok := mctx.Module().(*OverrideApex); ok {
922 mctx.CreateVariations(imageApexType, flattenedApexType)
Sundong Ahne9b55722019-09-06 17:37:42 +0900923 }
924}
925
Jooyung Han5c998b92019-06-27 11:30:33 +0900926func apexUsesMutator(mctx android.BottomUpMutatorContext) {
927 if ab, ok := mctx.Module().(*apexBundle); ok {
928 mctx.AddFarVariationDependencies(nil, usesTag, ab.properties.Uses...)
929 }
930}
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900931
Jooyung Handc782442019-11-01 03:14:38 +0900932var (
933 useVendorWhitelistKey = android.NewOnceKey("useVendorWhitelist")
934)
935
936// useVendorWhitelist returns the list of APEXes which are allowed to use_vendor.
937// When use_vendor is used, native modules are built with __ANDROID_VNDK__ and __ANDROID_APEX__,
938// which may cause compatibility issues. (e.g. libbinder)
939// Even though libbinder restricts its availability via 'apex_available' property and relies on
940// yet another macro __ANDROID_APEX_<NAME>__, we restrict usage of "use_vendor:" from other APEX modules
941// to avoid similar problems.
942func useVendorWhitelist(config android.Config) []string {
943 return config.Once(useVendorWhitelistKey, func() interface{} {
944 return []string{
945 // swcodec uses "vendor" variants for smaller size
946 "com.android.media.swcodec",
947 "test_com.android.media.swcodec",
948 }
949 }).([]string)
950}
951
952// setUseVendorWhitelistForTest overrides useVendorWhitelist and must be
953// called before the first call to useVendorWhitelist()
954func setUseVendorWhitelistForTest(config android.Config, whitelist []string) {
955 config.Once(useVendorWhitelistKey, func() interface{} {
956 return whitelist
957 })
958}
959
Alex Light9670d332019-01-29 18:07:33 -0800960type apexNativeDependencies struct {
961 // List of native libraries
962 Native_shared_libs []string
Jooyung Han344d5432019-08-23 11:17:39 +0900963
Alex Light9670d332019-01-29 18:07:33 -0800964 // List of native executables
965 Binaries []string
Jooyung Han344d5432019-08-23 11:17:39 +0900966
Roland Levillain630846d2019-06-26 12:48:34 +0100967 // List of native tests
968 Tests []string
Alex Light9670d332019-01-29 18:07:33 -0800969}
Jooyung Han344d5432019-08-23 11:17:39 +0900970
Alex Light9670d332019-01-29 18:07:33 -0800971type apexMultilibProperties struct {
972 // Native dependencies whose compile_multilib is "first"
973 First apexNativeDependencies
974
975 // Native dependencies whose compile_multilib is "both"
976 Both apexNativeDependencies
977
978 // Native dependencies whose compile_multilib is "prefer32"
979 Prefer32 apexNativeDependencies
980
981 // Native dependencies whose compile_multilib is "32"
982 Lib32 apexNativeDependencies
983
984 // Native dependencies whose compile_multilib is "64"
985 Lib64 apexNativeDependencies
986}
987
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900988type apexBundleProperties struct {
989 // Json manifest file describing meta info of this APEX bundle. Default:
Dario Freni4abb1dc2018-11-20 18:04:58 +0000990 // "apex_manifest.json"
Colin Cross27b922f2019-03-04 22:35:41 -0800991 Manifest *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +0900992
Jiyong Park40e26a22019-02-08 02:53:06 +0900993 // AndroidManifest.xml file used for the zip container of this APEX bundle.
994 // If unspecified, a default one is automatically generated.
Colin Cross27b922f2019-03-04 22:35:41 -0800995 AndroidManifest *string `android:"path"`
Jiyong Park40e26a22019-02-08 02:53:06 +0900996
Roland Levillain411c5842019-09-19 16:37:20 +0100997 // Canonical name of the APEX bundle. Used to determine the path to the activated APEX on
998 // device (/apex/<apex_name>).
999 // If unspecified, defaults to the value of name.
Jiyong Park05e70dd2019-03-18 14:26:32 +09001000 Apex_name *string
1001
Jiyong Parkd0a65ba2018-11-10 06:37:15 +09001002 // Determines the file contexts file for setting security context to each file in this APEX bundle.
Jooyung Han54aca7b2019-11-20 02:26:02 +09001003 // For platform APEXes, this should points to a file under /system/sepolicy
1004 // Default: /system/sepolicy/apex/<module_name>_file_contexts.
1005 File_contexts *string `android:"path"`
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001006
1007 // List of native shared libs that are embedded inside this APEX bundle
1008 Native_shared_libs []string
1009
Roland Levillain630846d2019-06-26 12:48:34 +01001010 // List of executables that are embedded inside this APEX bundle
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001011 Binaries []string
1012
1013 // List of java libraries that are embedded inside this APEX bundle
1014 Java_libs []string
1015
1016 // List of prebuilt files that are embedded inside this APEX bundle
1017 Prebuilts []string
Jiyong Parkff1458f2018-10-12 21:49:38 +09001018
Roland Levillain630846d2019-06-26 12:48:34 +01001019 // List of tests that are embedded inside this APEX bundle
1020 Tests []string
1021
Jiyong Parkff1458f2018-10-12 21:49:38 +09001022 // Name of the apex_key module that provides the private key to sign APEX
1023 Key *string
Jiyong Park397e55e2018-10-24 21:09:55 +09001024
Alex Light5098a612018-11-29 17:12:15 -08001025 // The type of APEX to build. Controls what the APEX payload is. Either
1026 // 'image', 'zip' or 'both'. Default: 'image'.
1027 Payload_type *string
1028
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001029 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
1030 // or an android_app_certificate module name in the form ":module".
1031 Certificate *string
1032
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001033 // Whether this APEX is installable to one of the partitions. Default: true.
1034 Installable *bool
1035
Jiyong Parkda6eb592018-12-19 17:12:36 +09001036 // For native libraries and binaries, use the vendor variant instead of the core (platform) variant.
1037 // Default is false.
1038 Use_vendor *bool
1039
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001040 // For telling the apex to ignore special handling for system libraries such as bionic. Default is false.
1041 Ignore_system_library_special_case *bool
1042
Alex Light9670d332019-01-29 18:07:33 -08001043 Multilib apexMultilibProperties
Jiyong Park235e67c2019-02-09 11:50:56 +09001044
Jiyong Parkf97782b2019-02-13 20:28:58 +09001045 // List of sanitizer names that this APEX is enabled for
1046 SanitizerNames []string `blueprint:"mutated"`
Jooyung Han5c998b92019-06-27 11:30:33 +09001047
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001048 PreventInstall bool `blueprint:"mutated"`
1049
1050 HideFromMake bool `blueprint:"mutated"`
1051
Jooyung Han5c998b92019-06-27 11:30:33 +09001052 // Indicates this APEX provides C++ shared libaries to other APEXes. Default: false.
1053 Provide_cpp_shared_libs *bool
1054
1055 // List of providing APEXes' names so that this APEX can depend on provided shared libraries.
1056 Uses []string
Nikita Ioffe5d5ae762019-08-31 14:38:05 +01001057
1058 // A txt file containing list of files that are whitelisted to be included in this APEX.
1059 Whitelisted_files *string
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001060
Sundong Ahnabb64432019-10-22 13:58:29 +09001061 // package format of this apex variant; could be non-flattened, flattened, or zip.
1062 // imageApex, zipApex or flattened
1063 ApexType apexPackaging `blueprint:"mutated"`
Sundong Ahne8fb7242019-09-17 13:50:45 +09001064
Jiyong Parkd1063c12019-07-17 20:08:41 +09001065 // List of SDKs that are used to build this APEX. A reference to an SDK should be either
1066 // `name#version` or `name` which is an alias for `name#current`. If left empty, `platform#current`
1067 // is implied. This value affects all modules included in this APEX. In other words, they are
1068 // also built with the SDKs specified here.
1069 Uses_sdks []string
Jiyong Park5d790c32019-11-15 18:40:32 +09001070
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001071 // Whenever apex_payload.img of the APEX should include dm-verity hashtree.
1072 // Should be only used in tests#.
1073 Test_only_no_hashtree *bool
Jooyung Han214bf372019-11-12 13:03:50 +09001074
Dario Freni98410fd2020-04-27 18:21:11 +01001075 // Whenever apex_payload.img of the APEX should not be dm-verity signed.
1076 // Should be only used in tests#.
1077 Test_only_unsigned_payload *bool
1078
Jiyong Park956305c2020-01-09 12:32:06 +09001079 IsCoverageVariant bool `blueprint:"mutated"`
Jiyong Park9d677202020-02-19 16:29:35 +09001080
1081 // Whether this APEX is considered updatable or not. When set to true, this will enforce additional
Jooyung Hanced674e2020-04-27 12:10:30 +09001082 // rules for making sure that the APEX is truly updatable.
1083 // - To be updatable, min_sdk_version should be set as well
1084 // This will also disable the size optimizations like symlinking to the system libs.
1085 // Default is false.
Jiyong Park9d677202020-02-19 16:29:35 +09001086 Updatable *bool
Colin Cross7365eaa2020-02-19 20:41:10 -08001087
1088 // The minimum SDK version that this apex must be compatible with.
1089 Min_sdk_version *string
Alex Light9670d332019-01-29 18:07:33 -08001090}
1091
1092type apexTargetBundleProperties struct {
1093 Target struct {
1094 // Multilib properties only for android.
1095 Android struct {
1096 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001097 }
Jooyung Han344d5432019-08-23 11:17:39 +09001098
Alex Light9670d332019-01-29 18:07:33 -08001099 // Multilib properties only for host.
1100 Host struct {
1101 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001102 }
Jooyung Han344d5432019-08-23 11:17:39 +09001103
Alex Light9670d332019-01-29 18:07:33 -08001104 // Multilib properties only for host linux_bionic.
1105 Linux_bionic struct {
1106 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001107 }
Jooyung Han344d5432019-08-23 11:17:39 +09001108
Alex Light9670d332019-01-29 18:07:33 -08001109 // Multilib properties only for host linux_glibc.
1110 Linux_glibc struct {
1111 Multilib apexMultilibProperties
Jiyong Park397e55e2018-10-24 21:09:55 +09001112 }
1113 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001114}
1115
Jiyong Park5d790c32019-11-15 18:40:32 +09001116type overridableProperties struct {
1117 // List of APKs to package inside APEX
1118 Apps []string
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08001119
1120 // Names of modules to be overridden. Listed modules can only be other binaries
1121 // (in Make or Soong).
1122 // This does not completely prevent installation of the overridden binaries, but if both
1123 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1124 // from PRODUCT_PACKAGES.
1125 Overrides []string
Baligh Uddin004d7172020-02-19 21:29:28 -08001126
1127 // Logging Parent value
1128 Logging_parent string
Baligh Uddincb6aa122020-03-15 13:01:05 -07001129
1130 // Apex Container Package Name.
1131 // Override value for attribute package:name in AndroidManifest.xml
1132 Package_name string
Jiyong Park5d790c32019-11-15 18:40:32 +09001133}
1134
Alex Light5098a612018-11-29 17:12:15 -08001135type apexPackaging int
1136
1137const (
1138 imageApex apexPackaging = iota
1139 zipApex
Sundong Ahnabb64432019-10-22 13:58:29 +09001140 flattenedApex
Alex Light5098a612018-11-29 17:12:15 -08001141)
1142
Sundong Ahnabb64432019-10-22 13:58:29 +09001143// The suffix for the output "file", not the module
Alex Light5098a612018-11-29 17:12:15 -08001144func (a apexPackaging) suffix() string {
1145 switch a {
1146 case imageApex:
1147 return imageApexSuffix
1148 case zipApex:
1149 return zipApexSuffix
Alex Light5098a612018-11-29 17:12:15 -08001150 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001151 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001152 }
1153}
1154
1155func (a apexPackaging) name() string {
1156 switch a {
1157 case imageApex:
1158 return imageApexType
1159 case zipApex:
1160 return zipApexType
Alex Light5098a612018-11-29 17:12:15 -08001161 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001162 panic(fmt.Errorf("unknown APEX type %d", a))
Alex Light5098a612018-11-29 17:12:15 -08001163 }
1164}
1165
Jiyong Parkf653b052019-11-18 15:39:01 +09001166type apexFileClass int
1167
1168const (
1169 etc apexFileClass = iota
1170 nativeSharedLib
1171 nativeExecutable
1172 shBinary
1173 pyBinary
1174 goBinary
1175 javaSharedLib
1176 nativeTest
1177 app
1178)
1179
Jiyong Park8fd61922018-11-08 02:50:25 +09001180func (class apexFileClass) NameInMake() string {
1181 switch class {
1182 case etc:
1183 return "ETC"
1184 case nativeSharedLib:
1185 return "SHARED_LIBRARIES"
Alex Light778127a2019-02-27 14:19:50 -08001186 case nativeExecutable, shBinary, pyBinary, goBinary:
Jiyong Park8fd61922018-11-08 02:50:25 +09001187 return "EXECUTABLES"
1188 case javaSharedLib:
1189 return "JAVA_LIBRARIES"
Roland Levillain630846d2019-06-26 12:48:34 +01001190 case nativeTest:
1191 return "NATIVE_TESTS"
Sundong Ahne1f05aa2019-08-27 13:55:42 +09001192 case app:
Jiyong Parkf383f7c2019-10-11 20:46:25 +09001193 // b/142537672 Why isn't this APP? We want to have full control over
1194 // the paths and file names of the apk file under the flattend APEX.
1195 // If this is set to APP, then the paths and file names are modified
1196 // by the Make build system. For example, it is installed to
1197 // /system/apex/<apexname>/app/<Appname>/<apexname>.<Appname>/ instead of
1198 // /system/apex/<apexname>/app/<Appname> because the build system automatically
1199 // appends module name (which is <apexname>.<Appname> to the path.
1200 return "ETC"
Jiyong Park8fd61922018-11-08 02:50:25 +09001201 default:
Roland Levillain4644b222019-07-31 14:09:17 +01001202 panic(fmt.Errorf("unknown class %d", class))
Jiyong Park8fd61922018-11-08 02:50:25 +09001203 }
1204}
1205
Jiyong Parkf653b052019-11-18 15:39:01 +09001206// apexFile represents a file in an APEX bundle
Jiyong Park8fd61922018-11-08 02:50:25 +09001207type apexFile struct {
1208 builtFile android.Path
1209 moduleName string
Jiyong Park8fd61922018-11-08 02:50:25 +09001210 installDir string
1211 class apexFileClass
Jiyong Parka8894842018-12-19 17:36:39 +09001212 module android.Module
Jiyong Parkf653b052019-11-18 15:39:01 +09001213 // list of symlinks that will be created in installDir that point to this apexFile
1214 symlinks []string
1215 transitiveDep bool
Jiyong Park1833cef2019-12-13 13:28:36 +09001216 moduleDir string
Jiyong Park7afd1072019-12-30 16:56:33 +09001217
1218 requiredModuleNames []string
1219 targetRequiredModuleNames []string
1220 hostRequiredModuleNames []string
Jiyong Park618922e2020-01-08 13:35:43 +09001221
Colin Cross503c1d02020-01-28 14:00:53 -08001222 jacocoReportClassesFile android.Path // only for javalibs and apps
1223 certificate java.Certificate // only for apps
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001224 overriddenPackageName string // only for apps
Jiyong Parkf653b052019-11-18 15:39:01 +09001225}
1226
Jiyong Park1833cef2019-12-13 13:28:36 +09001227func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
1228 ret := apexFile{
Jiyong Parkf653b052019-11-18 15:39:01 +09001229 builtFile: builtFile,
1230 moduleName: moduleName,
1231 installDir: installDir,
1232 class: class,
1233 module: module,
1234 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001235 if module != nil {
1236 ret.moduleDir = ctx.OtherModuleDir(module)
Jiyong Park7afd1072019-12-30 16:56:33 +09001237 ret.requiredModuleNames = module.RequiredModuleNames()
1238 ret.targetRequiredModuleNames = module.TargetRequiredModuleNames()
1239 ret.hostRequiredModuleNames = module.HostRequiredModuleNames()
Jiyong Park1833cef2019-12-13 13:28:36 +09001240 }
1241 return ret
Jiyong Parkf653b052019-11-18 15:39:01 +09001242}
1243
1244func (af *apexFile) Ok() bool {
Jiyong Park479321d2019-12-16 11:47:12 +09001245 return af.builtFile != nil && af.builtFile.String() != ""
Jiyong Park8fd61922018-11-08 02:50:25 +09001246}
1247
Jiyong Park7cd10e32020-01-14 09:22:18 +09001248// Path() returns path of this apex file relative to the APEX root
1249func (af *apexFile) Path() string {
1250 return filepath.Join(af.installDir, af.builtFile.Base())
1251}
1252
1253// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root
1254func (af *apexFile) SymlinkPaths() []string {
1255 var ret []string
1256 for _, symlink := range af.symlinks {
1257 ret = append(ret, filepath.Join(af.installDir, symlink))
1258 }
1259 return ret
1260}
1261
1262func (af *apexFile) AvailableToPlatform() bool {
1263 if af.module == nil {
1264 return false
1265 }
1266 if am, ok := af.module.(android.ApexModule); ok {
1267 return am.AvailableFor(android.AvailableToPlatform)
1268 }
1269 return false
1270}
1271
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001272type apexBundle struct {
1273 android.ModuleBase
1274 android.DefaultableModuleBase
Jiyong Park5d790c32019-11-15 18:40:32 +09001275 android.OverridableModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +09001276 android.SdkBase
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001277
Jiyong Park5d790c32019-11-15 18:40:32 +09001278 properties apexBundleProperties
1279 targetProperties apexTargetBundleProperties
Jiyong Park5d790c32019-11-15 18:40:32 +09001280 overridableProperties overridableProperties
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001281
Jooyung Hanf21c7972019-12-16 22:32:06 +09001282 // specific to apex_vndk modules
1283 vndkProperties apexVndkProperties
1284
Colin Crossa4925902018-11-16 11:36:28 -08001285 bundleModuleFile android.WritablePath
Sundong Ahnabb64432019-10-22 13:58:29 +09001286 outputFile android.WritablePath
Colin Cross70dda7e2019-10-01 22:05:35 -07001287 installDir android.InstallPath
Jiyong Park8fd61922018-11-08 02:50:25 +09001288
Jiyong Park03b68dd2019-07-26 23:20:40 +09001289 prebuiltFileToDelete string
1290
Jiyong Park42cca6c2019-04-01 11:15:50 +09001291 public_key_file android.Path
1292 private_key_file android.Path
Jiyong Park0ca3ce82019-02-18 15:25:04 +09001293
1294 container_certificate_file android.Path
1295 container_private_key_file android.Path
1296
Jooyung Han54aca7b2019-11-20 02:26:02 +09001297 fileContexts android.Path
1298
Jiyong Park8fd61922018-11-08 02:50:25 +09001299 // list of files to be included in this apex
1300 filesInfo []apexFile
1301
Jiyong Park956305c2020-01-09 12:32:06 +09001302 // list of module names that should be installed along with this APEX
1303 requiredDeps []string
1304
Jiyong Park956305c2020-01-09 12:32:06 +09001305 // list of module names that this APEX is including (to be shown via *-deps-info target)
Artur Satayev334b5172020-04-27 17:08:37 +01001306 android.ApexBundleDepsInfo
Jiyong Parkac2bacd2019-02-20 21:49:26 +09001307
Sundong Ahnabb64432019-10-22 13:58:29 +09001308 testApex bool
1309 vndkApex bool
Ulyana Trafimovichde534412019-11-08 10:51:01 +00001310 artApex bool
Sundong Ahnabb64432019-10-22 13:58:29 +09001311 primaryApexType bool
Jooyung Hane1633032019-08-01 17:41:43 +09001312
Jooyung Han214bf372019-11-12 13:03:50 +09001313 manifestJsonOut android.WritablePath
1314 manifestPbOut android.WritablePath
Jooyung Han72bd2f82019-10-23 16:46:38 +09001315
Jooyung Han002ab682020-01-08 01:57:58 +09001316 // list of commands to create symlinks for backward compatibility.
Jooyung Han72bd2f82019-10-23 16:46:38 +09001317 // these commands will be attached as LOCAL_POST_INSTALL_CMD to
Jooyung Han002ab682020-01-08 01:57:58 +09001318 // apex package itself(for unflattened build) or apex_manifest(for flattened build)
Jooyung Han72bd2f82019-10-23 16:46:38 +09001319 // so that compat symlinks are always installed regardless of TARGET_FLATTEN_APEX setting.
1320 compatSymlinks []string
Sundong Ahnabb64432019-10-22 13:58:29 +09001321
1322 // Suffix of module name in Android.mk
1323 // ".flattened", ".apex", ".zipapex", or ""
1324 suffix string
Jiyong Park3a1602e2020-01-14 14:39:19 +09001325
1326 installedFilesFile android.WritablePath
Jiyong Park7cd10e32020-01-14 09:22:18 +09001327
1328 // Whether to create symlink to the system file instead of having a file
1329 // inside the apex or not
1330 linkToSystemLib bool
Jiyong Park19972c72020-01-28 20:05:29 +09001331
1332 // Struct holding the merged notice file paths in different formats
1333 mergedNotices android.NoticeOutputs
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001334}
1335
Jiyong Park397e55e2018-10-24 21:09:55 +09001336func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
Roland Levillain630846d2019-06-26 12:48:34 +01001337 native_shared_libs []string, binaries []string, tests []string,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001338 target android.Target, imageVariation string) {
Jiyong Park397e55e2018-10-24 21:09:55 +09001339 // Use *FarVariation* to be able to depend on modules having
1340 // conflicting variations with this module. This is required since
1341 // arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
1342 // for native shared libs.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001343 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Parkda6eb592018-12-19 17:12:36 +09001344 {Mutator: "image", Variation: imageVariation},
Jiyong Park397e55e2018-10-24 21:09:55 +09001345 {Mutator: "link", Variation: "shared"},
Jiyong Park28d395a2018-12-07 22:42:47 +09001346 {Mutator: "version", Variation: ""}, // "" is the non-stub variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001347 }...), sharedLibTag, native_shared_libs...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001348
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001349 ctx.AddFarVariationDependencies(append(target.Variations(),
1350 blueprint.Variation{Mutator: "image", Variation: imageVariation}),
1351 executableTag, binaries...)
Roland Levillain630846d2019-06-26 12:48:34 +01001352
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001353 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001354 {Mutator: "image", Variation: imageVariation},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001355 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001356 }...), testTag, tests...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001357}
1358
Alex Light9670d332019-01-29 18:07:33 -08001359func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
1360 if ctx.Os().Class == android.Device {
1361 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
1362 } else {
1363 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
1364 if ctx.Os().Bionic() {
1365 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
1366 } else {
1367 proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
1368 }
1369 }
1370}
1371
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001372func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
Jooyung Handc782442019-11-01 03:14:38 +09001373 if proptools.Bool(a.properties.Use_vendor) && !android.InList(a.Name(), useVendorWhitelist(ctx.Config())) {
1374 ctx.PropertyErrorf("use_vendor", "not allowed to set use_vendor: true")
1375 }
1376
Jiyong Park397e55e2018-10-24 21:09:55 +09001377 targets := ctx.MultiTargets()
Jiyong Park7c1dc612019-01-05 11:15:24 +09001378 config := ctx.DeviceConfig()
Alex Light9670d332019-01-29 18:07:33 -08001379
1380 a.combineProperties(ctx)
1381
Jiyong Park397e55e2018-10-24 21:09:55 +09001382 has32BitTarget := false
1383 for _, target := range targets {
1384 if target.Arch.ArchType.Multilib == "lib32" {
1385 has32BitTarget = true
1386 }
1387 }
1388 for i, target := range targets {
1389 // When multilib.* is omitted for native_shared_libs, it implies
1390 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001391 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Jiyong Park7c1dc612019-01-05 11:15:24 +09001392 {Mutator: "image", Variation: a.getImageVariation(config)},
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001393 {Mutator: "link", Variation: "shared"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001394 }...), sharedLibTag, a.properties.Native_shared_libs...)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001395
Roland Levillain630846d2019-06-26 12:48:34 +01001396 // When multilib.* is omitted for tests, it implies
1397 // multilib.both.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001398 ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
Roland Levillain630846d2019-06-26 12:48:34 +01001399 {Mutator: "image", Variation: a.getImageVariation(config)},
Roland Levillain9b5fde92019-06-28 15:41:19 +01001400 {Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001401 }...), testTag, a.properties.Tests...)
Roland Levillain630846d2019-06-26 12:48:34 +01001402
Jiyong Park397e55e2018-10-24 21:09:55 +09001403 // Add native modules targetting both ABIs
1404 addDependenciesForNativeModules(ctx,
1405 a.properties.Multilib.Both.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001406 a.properties.Multilib.Both.Binaries,
1407 a.properties.Multilib.Both.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001408 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001409 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001410
Alex Light3d673592019-01-18 14:37:31 -08001411 isPrimaryAbi := i == 0
1412 if isPrimaryAbi {
Jiyong Park397e55e2018-10-24 21:09:55 +09001413 // When multilib.* is omitted for binaries, it implies
1414 // multilib.first.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001415 ctx.AddFarVariationDependencies(append(target.Variations(),
1416 blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
1417 executableTag, a.properties.Binaries...)
Jiyong Park397e55e2018-10-24 21:09:55 +09001418
1419 // Add native modules targetting the first ABI
1420 addDependenciesForNativeModules(ctx,
1421 a.properties.Multilib.First.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001422 a.properties.Multilib.First.Binaries,
1423 a.properties.Multilib.First.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001424 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001425 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001426 }
1427
1428 switch target.Arch.ArchType.Multilib {
1429 case "lib32":
1430 // Add native modules targetting 32-bit ABI
1431 addDependenciesForNativeModules(ctx,
1432 a.properties.Multilib.Lib32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001433 a.properties.Multilib.Lib32.Binaries,
1434 a.properties.Multilib.Lib32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001435 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001436 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001437
1438 addDependenciesForNativeModules(ctx,
1439 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001440 a.properties.Multilib.Prefer32.Binaries,
1441 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001442 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001443 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001444 case "lib64":
1445 // Add native modules targetting 64-bit ABI
1446 addDependenciesForNativeModules(ctx,
1447 a.properties.Multilib.Lib64.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001448 a.properties.Multilib.Lib64.Binaries,
1449 a.properties.Multilib.Lib64.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001450 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001451 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001452
1453 if !has32BitTarget {
1454 addDependenciesForNativeModules(ctx,
1455 a.properties.Multilib.Prefer32.Native_shared_libs,
Roland Levillain630846d2019-06-26 12:48:34 +01001456 a.properties.Multilib.Prefer32.Binaries,
1457 a.properties.Multilib.Prefer32.Tests,
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001458 target,
Jiyong Park7c1dc612019-01-05 11:15:24 +09001459 a.getImageVariation(config))
Jiyong Park397e55e2018-10-24 21:09:55 +09001460 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001461
1462 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
1463 for _, sanitizer := range ctx.Config().SanitizeDevice() {
1464 if sanitizer == "hwaddress" {
1465 addDependenciesForNativeModules(ctx,
1466 []string{"libclang_rt.hwasan-aarch64-android"},
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001467 nil, nil, target, a.getImageVariation(config))
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001468 break
1469 }
1470 }
1471 }
Jiyong Park397e55e2018-10-24 21:09:55 +09001472 }
1473
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001474 }
1475
Jiyong Parkce6aadc2019-11-20 13:58:28 +09001476 // For prebuilt_etc, use the first variant (64 on 64/32bit device,
1477 // 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
1478 // b/144532908
1479 archForPrebuiltEtc := config.Arches()[0]
1480 for _, arch := range config.Arches() {
1481 // Prefer 64-bit arch if there is any
1482 if arch.ArchType.Multilib == "lib64" {
1483 archForPrebuiltEtc = arch
1484 break
1485 }
1486 }
1487 ctx.AddFarVariationDependencies([]blueprint.Variation{
1488 {Mutator: "os", Variation: ctx.Os().String()},
1489 {Mutator: "arch", Variation: archForPrebuiltEtc.String()},
1490 }, prebuiltTag, a.properties.Prebuilts...)
1491
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001492 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1493 javaLibTag, a.properties.Java_libs...)
Jiyong Parkff1458f2018-10-12 21:49:38 +09001494
Ulya Trafimovich44561882020-01-03 13:25:54 +00001495 // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
1496 if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
1497 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1498 javaLibTag, "jacocoagent")
1499 }
1500
Jiyong Park23c52b02019-02-02 13:13:47 +09001501 if String(a.properties.Key) == "" {
1502 ctx.ModuleErrorf("key is missing")
1503 return
1504 }
1505 ctx.AddDependency(ctx.Module(), keyTag, String(a.properties.Key))
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001506
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001507 cert := android.SrcIsModule(a.getCertString(ctx))
Jiyong Park23c52b02019-02-02 13:13:47 +09001508 if cert != "" {
1509 ctx.AddDependency(ctx.Module(), certificateTag, cert)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001510 }
Jiyong Parkd1063c12019-07-17 20:08:41 +09001511
1512 // TODO(jiyong): ensure that all apexes are with non-empty uses_sdks
1513 if len(a.properties.Uses_sdks) > 0 {
1514 sdkRefs := []android.SdkRef{}
1515 for _, str := range a.properties.Uses_sdks {
1516 parsed := android.ParseSdkRef(ctx, str, "uses_sdks")
1517 sdkRefs = append(sdkRefs, parsed)
1518 }
1519 a.BuildWithSdks(sdkRefs)
1520 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001521}
1522
Jiyong Park5d790c32019-11-15 18:40:32 +09001523func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1524 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
1525 androidAppTag, a.overridableProperties.Apps...)
1526}
1527
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001528func (a *apexBundle) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1529 // direct deps of an APEX bundle are all part of the APEX bundle
1530 return true
1531}
1532
Colin Cross0ea8ba82019-06-06 14:33:29 -07001533func (a *apexBundle) getCertString(ctx android.BaseModuleContext) string {
Jooyung Han27151d92019-12-16 17:45:32 +09001534 moduleName := ctx.ModuleName()
1535 // VNDK APEXes share the same certificate. To avoid adding a new VNDK version to the OVERRIDE_* list,
1536 // we check with the pseudo module name to see if its certificate is overridden.
1537 if a.vndkApex {
1538 moduleName = vndkApexName
1539 }
1540 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(moduleName)
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001541 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +00001542 return ":" + certificate
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001543 }
1544 return String(a.properties.Certificate)
1545}
1546
Colin Cross41955e82019-05-29 14:40:35 -07001547func (a *apexBundle) OutputFiles(tag string) (android.Paths, error) {
1548 switch tag {
1549 case "":
Sundong Ahnabb64432019-10-22 13:58:29 +09001550 return android.Paths{a.outputFile}, nil
Colin Cross41955e82019-05-29 14:40:35 -07001551 default:
1552 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Jiyong Park5a832022018-12-20 09:54:35 +09001553 }
Jiyong Park74e240b2018-11-27 21:27:08 +09001554}
1555
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001556func (a *apexBundle) installable() bool {
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001557 return !a.properties.PreventInstall && (a.properties.Installable == nil || proptools.Bool(a.properties.Installable))
Jiyong Park92c0f9c2018-12-13 23:14:57 +09001558}
1559
Nikita Ioffec72b5dd2019-12-07 17:30:22 +00001560func (a *apexBundle) testOnlyShouldSkipHashtreeGeneration() bool {
1561 return proptools.Bool(a.properties.Test_only_no_hashtree)
1562}
1563
Dario Freni98410fd2020-04-27 18:21:11 +01001564func (a *apexBundle) testOnlyShouldSkipPayloadSign() bool {
1565 return proptools.Bool(a.properties.Test_only_unsigned_payload)
1566}
1567
Jiyong Park7c1dc612019-01-05 11:15:24 +09001568func (a *apexBundle) getImageVariation(config android.DeviceConfig) string {
Jooyung Han31c470b2019-10-18 16:26:59 +09001569 if a.vndkApex {
Colin Cross7228ecd2019-11-18 16:00:16 -08001570 return cc.VendorVariationPrefix + a.vndkVersion(config)
Jooyung Han31c470b2019-10-18 16:26:59 +09001571 }
Jiyong Park7c1dc612019-01-05 11:15:24 +09001572 if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) {
Colin Cross7228ecd2019-11-18 16:00:16 -08001573 return cc.VendorVariationPrefix + config.PlatformVndkVersion()
Jiyong Parkda6eb592018-12-19 17:12:36 +09001574 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -08001575 return android.CoreVariation
Jiyong Parkda6eb592018-12-19 17:12:36 +09001576 }
1577}
1578
Jiyong Parkf97782b2019-02-13 20:28:58 +09001579func (a *apexBundle) EnableSanitizer(sanitizerName string) {
1580 if !android.InList(sanitizerName, a.properties.SanitizerNames) {
1581 a.properties.SanitizerNames = append(a.properties.SanitizerNames, sanitizerName)
1582 }
1583}
1584
Jiyong Park388ef3f2019-01-28 19:47:32 +09001585func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool {
Jiyong Parkf97782b2019-02-13 20:28:58 +09001586 if android.InList(sanitizerName, a.properties.SanitizerNames) {
1587 return true
Jiyong Park235e67c2019-02-09 11:50:56 +09001588 }
1589
1590 // Then follow the global setting
Jiyong Park388ef3f2019-01-28 19:47:32 +09001591 globalSanitizerNames := []string{}
1592 if a.Host() {
1593 globalSanitizerNames = ctx.Config().SanitizeHost()
1594 } else {
1595 arches := ctx.Config().SanitizeDeviceArch()
1596 if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) {
1597 globalSanitizerNames = ctx.Config().SanitizeDevice()
1598 }
1599 }
1600 return android.InList(sanitizerName, globalSanitizerNames)
Jiyong Park379de2f2018-12-19 02:47:14 +09001601}
1602
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001603func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
Oliver Nguyen1382ab62019-12-06 15:22:41 -08001604 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001605}
1606
1607func (a *apexBundle) PreventInstall() {
1608 a.properties.PreventInstall = true
1609}
1610
1611func (a *apexBundle) HideFromMake() {
1612 a.properties.HideFromMake = true
1613}
1614
Jiyong Park956305c2020-01-09 12:32:06 +09001615func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
1616 a.properties.IsCoverageVariant = coverage
1617}
1618
Jiyong Parkf653b052019-11-18 15:39:01 +09001619// TODO(jiyong) move apexFileFor* close to the apexFile type definition
Jiyong Park1833cef2019-12-13 13:28:36 +09001620func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001621 // Decide the APEX-local directory by the multilib of the library
1622 // In the future, we may query this to the module.
Jiyong Parkf653b052019-11-18 15:39:01 +09001623 var dirInApex string
Martin Stjernholm279de572019-09-10 23:18:20 +01001624 switch ccMod.Arch().ArchType.Multilib {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001625 case "lib32":
1626 dirInApex = "lib"
1627 case "lib64":
1628 dirInApex = "lib64"
1629 }
Martin Stjernholm279de572019-09-10 23:18:20 +01001630 dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001631 if ccMod.Target().NativeBridge == android.NativeBridgeEnabled {
Martin Stjernholm279de572019-09-10 23:18:20 +01001632 dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001633 }
Jiyong Park1833cef2019-12-13 13:28:36 +09001634 if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) {
Martin Stjernholm279de572019-09-10 23:18:20 +01001635 // Special case for Bionic libs and other libs installed with them. This is
1636 // to prevent those libs from being included in the search path
1637 // /apex/com.android.runtime/${LIB}. This exclusion is required because
1638 // those libs in the Runtime APEX are available via the legacy paths in
1639 // /system/lib/. By the init process, the libs in the APEX are bind-mounted
1640 // to the legacy paths and thus will be loaded into the default linker
1641 // namespace (aka "platform" namespace). If the libs are directly in
1642 // /apex/com.android.runtime/${LIB} then the same libs will be loaded again
1643 // into the runtime linker namespace, which will result in double loading of
1644 // them, which isn't supported.
1645 dirInApex = filepath.Join(dirInApex, "bionic")
Jiyong Parkb0788572018-12-20 22:10:17 +09001646 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001647
Jiyong Parkf653b052019-11-18 15:39:01 +09001648 fileToCopy := ccMod.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001649 return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001650}
1651
Jiyong Park1833cef2019-12-13 13:28:36 +09001652func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001653 dirInApex := filepath.Join("bin", cc.RelativeInstallPath())
Colin Cross3b19f5d2019-09-17 14:45:31 -07001654 if cc.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry8d6dde82019-07-11 10:23:53 +02001655 dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath)
Jiyong Parkacbf6c72019-07-09 16:19:16 +09001656 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001657 fileToCopy := cc.OutputFile().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001658 af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
Jiyong Parkf653b052019-11-18 15:39:01 +09001659 af.symlinks = cc.Symlinks()
1660 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001661}
1662
Jiyong Park1833cef2019-12-13 13:28:36 +09001663func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001664 dirInApex := "bin"
1665 fileToCopy := py.HostToolPath().Path()
Jiyong Park1833cef2019-12-13 13:28:36 +09001666 return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
Alex Light778127a2019-02-27 14:19:50 -08001667}
Jiyong Park1833cef2019-12-13 13:28:36 +09001668func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001669 dirInApex := "bin"
Alex Light778127a2019-02-27 14:19:50 -08001670 s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath())
1671 if err != nil {
1672 ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
Jiyong Parkf653b052019-11-18 15:39:01 +09001673 return apexFile{}
Alex Light778127a2019-02-27 14:19:50 -08001674 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001675 fileToCopy := android.PathForOutput(ctx, s)
1676 // NB: Since go binaries are static we don't need the module for anything here, which is
1677 // good since the go tool is a blueprint.Module not an android.Module like we would
1678 // normally use.
Jiyong Park1833cef2019-12-13 13:28:36 +09001679 return newApexFile(ctx, fileToCopy, depName, dirInApex, goBinary, nil)
Alex Light778127a2019-02-27 14:19:50 -08001680}
1681
Jiyong Park1833cef2019-12-13 13:28:36 +09001682func apexFileForShBinary(ctx android.BaseModuleContext, sh *android.ShBinary) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001683 dirInApex := filepath.Join("bin", sh.SubDir())
1684 fileToCopy := sh.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001685 af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
Jiyong Parkf653b052019-11-18 15:39:01 +09001686 af.symlinks = sh.Symlinks()
1687 return af
Jiyong Park04480cf2019-02-06 00:16:29 +09001688}
1689
Paul Duffinf299cbe2020-05-14 20:49:32 +01001690func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib java.Dependency, module android.Module) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001691 dirInApex := "javalib"
Jooyung Han58f26ab2019-12-18 15:34:32 +09001692 fileToCopy := lib.DexJar()
Paul Duffinf299cbe2020-05-14 20:49:32 +01001693 af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module)
Jiyong Park618922e2020-01-08 13:35:43 +09001694 af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
1695 return af
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001696}
1697
Jiyong Park1833cef2019-12-13 13:28:36 +09001698func apexFileForPrebuiltEtc(ctx android.BaseModuleContext, prebuilt android.PrebuiltEtcModule, depName string) apexFile {
Jiyong Parkf653b052019-11-18 15:39:01 +09001699 dirInApex := filepath.Join("etc", prebuilt.SubDir())
1700 fileToCopy := prebuilt.OutputFile()
Jiyong Park1833cef2019-12-13 13:28:36 +09001701 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, prebuilt)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001702}
1703
atrost6e126252020-01-27 17:01:16 +00001704func apexFileForCompatConfig(ctx android.BaseModuleContext, config java.PlatformCompatConfigIntf, depName string) apexFile {
1705 dirInApex := filepath.Join("etc", config.SubDir())
1706 fileToCopy := config.CompatConfig()
1707 return newApexFile(ctx, fileToCopy, depName, dirInApex, etc, config)
1708}
1709
Jiyong Park1833cef2019-12-13 13:28:36 +09001710func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
Jiyong Parkf653b052019-11-18 15:39:01 +09001711 android.Module
1712 Privileged() bool
Jooyung Han65cd0f02020-03-23 20:21:11 +09001713 InstallApkName() string
Jiyong Parkf653b052019-11-18 15:39:01 +09001714 OutputFile() android.Path
Jiyong Park618922e2020-01-08 13:35:43 +09001715 JacocoReportClassesFile() android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001716 Certificate() java.Certificate
Jooyung Han65cd0f02020-03-23 20:21:11 +09001717}) apexFile {
Jiyong Parkf7487312019-10-17 12:54:30 +09001718 appDir := "app"
Jiyong Parkf653b052019-11-18 15:39:01 +09001719 if aapp.Privileged() {
Jiyong Parkf7487312019-10-17 12:54:30 +09001720 appDir = "priv-app"
1721 }
Jooyung Han65cd0f02020-03-23 20:21:11 +09001722 dirInApex := filepath.Join(appDir, aapp.InstallApkName())
Jiyong Parkf653b052019-11-18 15:39:01 +09001723 fileToCopy := aapp.OutputFile()
Jiyong Park618922e2020-01-08 13:35:43 +09001724 af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
1725 af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
Colin Cross503c1d02020-01-28 14:00:53 -08001726 af.certificate = aapp.Certificate()
Jiyong Parkaf8998c2020-02-28 16:51:07 +09001727
1728 if app, ok := aapp.(interface {
1729 OverriddenManifestPackageName() string
1730 }); ok {
1731 af.overriddenPackageName = app.OverriddenManifestPackageName()
1732 }
Jiyong Park618922e2020-01-08 13:35:43 +09001733 return af
Dario Frenicde2a032019-10-27 00:29:22 +01001734}
1735
Roland Levillain935639d2019-08-13 14:55:28 +01001736// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
1737type flattenedApexContext struct {
1738 android.ModuleContext
1739}
1740
1741func (c *flattenedApexContext) InstallBypassMake() bool {
1742 return true
1743}
1744
Paul Duffin133608f2020-03-30 15:54:08 +01001745// Function called while walking an APEX's payload dependencies.
1746//
1747// Return true if the `to` module should be visited, false otherwise.
1748type payloadDepsCallback func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool
1749
Jiyong Park201cedd2020-02-07 17:25:49 +09001750// Visit dependencies that contributes to the payload of this APEX
Paul Duffin133608f2020-03-30 15:54:08 +01001751func (a *apexBundle) walkPayloadDeps(ctx android.ModuleContext, do payloadDepsCallback) {
Paul Duffin868ecfd2020-03-30 17:58:21 +01001752 ctx.WalkDeps(func(child, parent android.Module) bool {
Jiyong Parkfa899442020-01-31 02:49:53 +09001753 am, ok := child.(android.ApexModule)
1754 if !ok || !am.CanHaveApexVariants() {
1755 return false
1756 }
1757
1758 // Check for the direct dependencies that contribute to the payload
1759 if dt, ok := ctx.OtherModuleDependencyTag(child).(dependencyTag); ok {
1760 if dt.payload {
Paul Duffin133608f2020-03-30 15:54:08 +01001761 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001762 }
Paul Duffin133608f2020-03-30 15:54:08 +01001763 // As soon as the dependency graph crosses the APEX boundary, don't go further.
Jiyong Parkfa899442020-01-31 02:49:53 +09001764 return false
1765 }
1766
1767 // Check for the indirect dependencies if it is considered as part of the APEX
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001768 if am.ApexName() != "" {
Paul Duffin133608f2020-03-30 15:54:08 +01001769 return do(ctx, parent, am, false /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001770 }
1771
Paul Duffin133608f2020-03-30 15:54:08 +01001772 return do(ctx, parent, am, true /* externalDep */)
Jiyong Parkfa899442020-01-31 02:49:53 +09001773 })
1774}
1775
Jooyung Han0c4e0162020-02-26 22:45:42 +09001776func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
1777 ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
Jooyung Han29e91d22020-04-02 01:41:41 +09001778 intVer, err := android.ApiStrToNum(ctx, ver)
1779 if err != nil {
1780 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
Jooyung Han0c4e0162020-02-26 22:45:42 +09001781 }
Jooyung Han29e91d22020-04-02 01:41:41 +09001782 return intVer
Jooyung Han0c4e0162020-02-26 22:45:42 +09001783}
1784
Paul Duffinf0207962020-03-31 11:31:36 +01001785// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1786// a dependency tag.
1787var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1788
1789func PrettyPrintTag(tag blueprint.DependencyTag) string {
1790 // Use tag's custom String() method if available.
1791 if stringer, ok := tag.(fmt.Stringer); ok {
1792 return stringer.String()
1793 }
1794
1795 // Otherwise, get a default string representation of the tag's struct.
1796 tagString := fmt.Sprintf("%#v", tag)
1797
1798 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1799 tagString = tagCleaner.ReplaceAllString(tagString, "")
1800 return tagString
1801}
1802
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001803func (a *apexBundle) Updatable() bool {
1804 return proptools.Bool(a.properties.Updatable)
1805}
1806
1807var _ android.ApexBundleDepsInfoIntf = (*apexBundle)(nil)
1808
Jiyong Park201cedd2020-02-07 17:25:49 +09001809// Ensures that the dependencies are marked as available for this APEX
1810func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
1811 // Let's be practical. Availability for test, host, and the VNDK apex isn't important
1812 if ctx.Host() || a.testApex || a.vndkApex {
1813 return
1814 }
1815
Jiyong Parkd5e0ea22020-03-28 14:43:19 +09001816 // Coverage build adds additional dependencies for the coverage-only runtime libraries.
1817 // Requiring them and their transitive depencies with apex_available is not right
1818 // because they just add noise.
1819 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || a.IsNativeCoverageNeeded(ctx) {
1820 return
1821 }
1822
Paul Duffin133608f2020-03-30 15:54:08 +01001823 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool {
1824 if externalDep {
1825 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1826 return false
1827 }
1828
Jiyong Park201cedd2020-02-07 17:25:49 +09001829 apexName := ctx.ModuleName()
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001830 fromName := ctx.OtherModuleName(from)
1831 toName := ctx.OtherModuleName(to)
Paul Duffinb20ad0a2020-03-31 15:23:40 +01001832
1833 // If `to` is not actually in the same APEX as `from` then it does not need apex_available and neither
1834 // do any of its dependencies.
1835 if am, ok := from.(android.DepIsInSameApex); ok && !am.DepIsInSameApex(ctx, to) {
1836 // As soon as the dependency graph crosses the APEX boundary, don't go further.
1837 return false
1838 }
1839
Paul Duffin133608f2020-03-30 15:54:08 +01001840 if to.AvailableFor(apexName) || whitelistedApexAvailable(apexName, toName) {
1841 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001842 }
Paul Duffin868ecfd2020-03-30 17:58:21 +01001843 message := ""
Paul Duffinf0207962020-03-31 11:31:36 +01001844 tagPath := ctx.GetTagPath()
1845 // Skip the first module as that will be added at the start of the error message by ctx.ModuleErrorf().
1846 walkPath := ctx.GetWalkPath()[1:]
1847 for i, m := range walkPath {
1848 message = fmt.Sprintf("%s\n via tag %s\n -> %s", message, PrettyPrintTag(tagPath[i]), m.String())
Paul Duffin868ecfd2020-03-30 17:58:21 +01001849 }
1850 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 +01001851 // Visit this module's dependencies to check and report any issues with their availability.
1852 return true
Jiyong Park201cedd2020-02-07 17:25:49 +09001853 })
1854}
1855
Jooyung Hanced674e2020-04-27 12:10:30 +09001856func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01001857 if a.Updatable() {
Jooyung Hanced674e2020-04-27 12:10:30 +09001858 if String(a.properties.Min_sdk_version) == "" {
1859 ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
1860 }
Artur Satayev2eedf622020-04-15 17:29:42 +01001861
1862 a.checkJavaStableSdkVersion(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001863 }
1864}
1865
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001866func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001867 buildFlattenedAsDefault := ctx.Config().FlattenApex() && !ctx.Config().UnbundledBuild()
1868 switch a.properties.ApexType {
1869 case imageApex:
1870 if buildFlattenedAsDefault {
1871 a.suffix = imageApexSuffix
1872 } else {
1873 a.suffix = ""
1874 a.primaryApexType = true
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001875
1876 if ctx.Config().InstallExtraFlattenedApexes() {
Jiyong Park956305c2020-01-09 12:32:06 +09001877 a.requiredDeps = append(a.requiredDeps, a.Name()+flattenedSuffix)
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09001878 }
Sundong Ahnabb64432019-10-22 13:58:29 +09001879 }
1880 case zipApex:
1881 if proptools.String(a.properties.Payload_type) == "zip" {
1882 a.suffix = ""
1883 a.primaryApexType = true
1884 } else {
1885 a.suffix = zipApexSuffix
1886 }
1887 case flattenedApex:
1888 if buildFlattenedAsDefault {
1889 a.suffix = ""
1890 a.primaryApexType = true
1891 } else {
1892 a.suffix = flattenedSuffix
1893 }
Alex Light5098a612018-11-29 17:12:15 -08001894 }
1895
Roland Levillain630846d2019-06-26 12:48:34 +01001896 if len(a.properties.Tests) > 0 && !a.testApex {
1897 ctx.PropertyErrorf("tests", "property not allowed in apex module type")
1898 return
1899 }
1900
Jiyong Parkfa899442020-01-31 02:49:53 +09001901 a.checkApexAvailability(ctx)
Jooyung Hanced674e2020-04-27 12:10:30 +09001902 a.checkUpdatable(ctx)
Jiyong Park678c8812020-02-07 17:25:49 +09001903
Alex Lightfc0bd7c2019-01-29 18:31:59 -08001904 handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
1905
Jooyung Hane1633032019-08-01 17:41:43 +09001906 // native lib dependencies
1907 var provideNativeLibs []string
1908 var requireNativeLibs []string
1909
Jooyung Han5c998b92019-06-27 11:30:33 +09001910 // Check if "uses" requirements are met with dependent apexBundles
1911 var providedNativeSharedLibs []string
1912 useVendor := proptools.Bool(a.properties.Use_vendor)
1913 ctx.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1914 if ctx.OtherModuleDependencyTag(m) != usesTag {
1915 return
1916 }
1917 otherName := ctx.OtherModuleName(m)
1918 other, ok := m.(*apexBundle)
1919 if !ok {
1920 ctx.PropertyErrorf("uses", "%q is not a provider", otherName)
1921 return
1922 }
1923 if proptools.Bool(other.properties.Use_vendor) != useVendor {
1924 ctx.PropertyErrorf("use_vendor", "%q has different value of use_vendor", otherName)
1925 return
1926 }
1927 if !proptools.Bool(other.properties.Provide_cpp_shared_libs) {
1928 ctx.PropertyErrorf("uses", "%q does not provide native_shared_libs", otherName)
1929 return
1930 }
1931 providedNativeSharedLibs = append(providedNativeSharedLibs, other.properties.Native_shared_libs...)
1932 })
1933
Jiyong Parkf653b052019-11-18 15:39:01 +09001934 var filesInfo []apexFile
Jiyong Park678c8812020-02-07 17:25:49 +09001935 // TODO(jiyong) do this using walkPayloadDeps
Alex Light778127a2019-02-27 14:19:50 -08001936 ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool {
Roland Levillainf89cd092019-07-29 16:22:59 +01001937 depTag := ctx.OtherModuleDependencyTag(child)
Paul Duffin3766cb72020-04-07 15:25:44 +01001938 if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
1939 return false
1940 }
Roland Levillainf89cd092019-07-29 16:22:59 +01001941 depName := ctx.OtherModuleName(child)
Jiyong Parkf653b052019-11-18 15:39:01 +09001942 if _, isDirectDep := parent.(*apexBundle); isDirectDep {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001943 switch depTag {
1944 case sharedLibTag:
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001945 if c, ok := child.(*cc.Module); ok {
1946 // bootstrap bionic libs are treated as provided by system
1947 if c.HasStubsVariants() && !cc.InstallToBootstrap(c.BaseModuleName(), ctx.Config()) {
1948 provideNativeLibs = append(provideNativeLibs, c.OutputFile().Path().Base())
Jooyung Hane1633032019-08-01 17:41:43 +09001949 }
Jooyung Hanfaa2d5f2020-02-06 17:42:40 +09001950 filesInfo = append(filesInfo, apexFileForNativeLibrary(ctx, c, handleSpecialLibs))
Jiyong Parkf653b052019-11-18 15:39:01 +09001951 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001952 } else {
1953 ctx.PropertyErrorf("native_shared_libs", "%q is not a cc_library or cc_library_shared module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001954 }
1955 case executableTag:
1956 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001957 filesInfo = append(filesInfo, apexFileForExecutable(ctx, cc))
Jiyong Parkf653b052019-11-18 15:39:01 +09001958 return true // track transitive dependencies
Jiyong Park04480cf2019-02-06 00:16:29 +09001959 } else if sh, ok := child.(*android.ShBinary); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09001960 filesInfo = append(filesInfo, apexFileForShBinary(ctx, sh))
Alex Light778127a2019-02-27 14:19:50 -08001961 } else if py, ok := child.(*python.Module); ok && py.HostToolPath().Valid() {
Jiyong Park1833cef2019-12-13 13:28:36 +09001962 filesInfo = append(filesInfo, apexFileForPyBinary(ctx, py))
Alex Light778127a2019-02-27 14:19:50 -08001963 } else if gb, ok := child.(bootstrap.GoBinaryTool); ok && a.Host() {
Jiyong Parkf653b052019-11-18 15:39:01 +09001964 filesInfo = append(filesInfo, apexFileForGoBinary(ctx, depName, gb))
Jiyong Parkff1458f2018-10-12 21:49:38 +09001965 } else {
Alex Light778127a2019-02-27 14:19:50 -08001966 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 +09001967 }
1968 case javaLibTag:
Jiyong Park9e6c2422019-08-09 20:39:45 +09001969 if javaLib, ok := child.(*java.Library); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001970 af := apexFileForJavaLibrary(ctx, javaLib, javaLib)
Jiyong Parkf653b052019-11-18 15:39:01 +09001971 if !af.Ok() {
Jiyong Park8fd61922018-11-08 02:50:25 +09001972 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1973 } else {
Jiyong Parkf653b052019-11-18 15:39:01 +09001974 filesInfo = append(filesInfo, af)
1975 return true // track transitive dependencies
Jiyong Park9e6c2422019-08-09 20:39:45 +09001976 }
Jooyung Han58f26ab2019-12-18 15:34:32 +09001977 } else if sdkLib, ok := child.(*java.SdkLibrary); ok {
Paul Duffinf299cbe2020-05-14 20:49:32 +01001978 af := apexFileForJavaLibrary(ctx, sdkLib, sdkLib)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001979 if !af.Ok() {
1980 ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
1981 return false
1982 }
1983 filesInfo = append(filesInfo, af)
Jooyung Han58f26ab2019-12-18 15:34:32 +09001984 return true // track transitive dependencies
Jiyong Parkff1458f2018-10-12 21:49:38 +09001985 } else {
Jiyong Park9e6c2422019-08-09 20:39:45 +09001986 ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001987 }
Jiyong Parkf653b052019-11-18 15:39:01 +09001988 case androidAppTag:
Jiyong Parkf653b052019-11-18 15:39:01 +09001989 if ap, ok := child.(*java.AndroidApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001990 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001991 return true // track transitive dependencies
1992 } else if ap, ok := child.(*java.AndroidAppImport); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001993 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Dario Freni6f3937c2019-12-20 22:58:03 +00001994 } else if ap, ok := child.(*java.AndroidTestHelperApp); ok {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001995 filesInfo = append(filesInfo, apexFileForAndroidApp(ctx, ap))
Jiyong Parkf653b052019-11-18 15:39:01 +09001996 } else {
1997 ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
1998 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09001999 case prebuiltTag:
Jooyung Han39edb6c2019-11-06 16:53:07 +09002000 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002001 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
atrost6e126252020-01-27 17:01:16 +00002002 } else if prebuilt, ok := child.(java.PlatformCompatConfigIntf); ok {
2003 filesInfo = append(filesInfo, apexFileForCompatConfig(ctx, prebuilt, depName))
Jiyong Parkff1458f2018-10-12 21:49:38 +09002004 } else {
atrost6e126252020-01-27 17:01:16 +00002005 ctx.PropertyErrorf("prebuilts", "%q is not a prebuilt_etc and not a platform_compat_config module", depName)
Jiyong Parkff1458f2018-10-12 21:49:38 +09002006 }
Roland Levillain630846d2019-06-26 12:48:34 +01002007 case testTag:
Roland Levillainf89cd092019-07-29 16:22:59 +01002008 if ccTest, ok := child.(*cc.Module); ok {
2009 if ccTest.IsTestPerSrcAllTestsVariation() {
2010 // Multiple-output test module (where `test_per_src: true`).
2011 //
2012 // `ccTest` is the "" ("all tests") variation of a `test_per_src` module.
2013 // We do not add this variation to `filesInfo`, as it has no output;
2014 // however, we do add the other variations of this module as indirect
2015 // dependencies (see below).
2016 return true
Roland Levillain9b5fde92019-06-28 15:41:19 +01002017 } else {
Roland Levillainf89cd092019-07-29 16:22:59 +01002018 // Single-output test module (where `test_per_src: false`).
Jiyong Park1833cef2019-12-13 13:28:36 +09002019 af := apexFileForExecutable(ctx, ccTest)
Jiyong Parkf653b052019-11-18 15:39:01 +09002020 af.class = nativeTest
2021 filesInfo = append(filesInfo, af)
Roland Levillain9b5fde92019-06-28 15:41:19 +01002022 }
Roland Levillain630846d2019-06-26 12:48:34 +01002023 } else {
2024 ctx.PropertyErrorf("tests", "%q is not a cc module", depName)
2025 }
Jiyong Parkff1458f2018-10-12 21:49:38 +09002026 case keyTag:
2027 if key, ok := child.(*apexKey); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002028 a.private_key_file = key.private_key_file
2029 a.public_key_file = key.public_key_file
Jiyong Parkff1458f2018-10-12 21:49:38 +09002030 } else {
2031 ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002032 }
Jiyong Parkf653b052019-11-18 15:39:01 +09002033 return false
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002034 case certificateTag:
2035 if dep, ok := child.(*java.AndroidAppCertificate); ok {
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002036 a.container_certificate_file = dep.Certificate.Pem
2037 a.container_private_key_file = dep.Certificate.Key
Jiyong Parkc00cbd92018-10-30 21:20:05 +09002038 } else {
2039 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", depName)
2040 }
Jiyong Park03b68dd2019-07-26 23:20:40 +09002041 case android.PrebuiltDepTag:
2042 // If the prebuilt is force disabled, remember to delete the prebuilt file
2043 // that might have been installed in the previous builds
2044 if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
2045 a.prebuiltFileToDelete = prebuilt.InstallFilename()
2046 }
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002047 }
Jooyung Han8aee2042019-10-29 05:08:31 +09002048 } else if !a.vndkApex {
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002049 // indirect dependencies
Jooyung Han9c80bae2019-08-20 17:30:57 +09002050 if am, ok := child.(android.ApexModule); ok {
Roland Levillainf89cd092019-07-29 16:22:59 +01002051 // We cannot use a switch statement on `depTag` here as the checked
2052 // tags used below are private (e.g. `cc.sharedDepTag`).
Jiyong Park52cd06f2019-11-11 10:14:32 +09002053 if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002054 if cc, ok := child.(*cc.Module); ok {
2055 if android.InList(cc.Name(), providedNativeSharedLibs) {
2056 // If we're using a shared library which is provided from other APEX,
2057 // don't include it in this APEX
2058 return false
Jiyong Parkac2bacd2019-02-20 21:49:26 +09002059 }
Jooyung Han671f1ce2019-12-17 12:47:13 +09002060 if !a.Host() && !android.DirectlyInApex(ctx.ModuleName(), ctx.OtherModuleName(cc)) && (cc.IsStubs() || cc.HasStubsVariants()) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002061 // If the dependency is a stubs lib, don't include it in this APEX,
2062 // but make sure that the lib is installed on the device.
2063 // In case no APEX is having the lib, the lib is installed to the system
2064 // partition.
2065 //
2066 // Always include if we are a host-apex however since those won't have any
2067 // system libraries.
Jiyong Park956305c2020-01-09 12:32:06 +09002068 if !android.DirectlyInAnyApex(ctx, cc.Name()) && !android.InList(cc.Name(), a.requiredDeps) {
2069 a.requiredDeps = append(a.requiredDeps, cc.Name())
Roland Levillainf89cd092019-07-29 16:22:59 +01002070 }
Jooyung Hane1633032019-08-01 17:41:43 +09002071 requireNativeLibs = append(requireNativeLibs, cc.OutputFile().Path().Base())
Roland Levillainf89cd092019-07-29 16:22:59 +01002072 // Don't track further
2073 return false
2074 }
Jiyong Park1833cef2019-12-13 13:28:36 +09002075 af := apexFileForNativeLibrary(ctx, cc, handleSpecialLibs)
Jiyong Parkf653b052019-11-18 15:39:01 +09002076 af.transitiveDep = true
2077 filesInfo = append(filesInfo, af)
2078 return true // track transitive dependencies
Jiyong Park25fc6a92018-11-18 18:02:45 +09002079 }
Roland Levillainf89cd092019-07-29 16:22:59 +01002080 } else if cc.IsTestPerSrcDepTag(depTag) {
2081 if cc, ok := child.(*cc.Module); ok {
Jiyong Park1833cef2019-12-13 13:28:36 +09002082 af := apexFileForExecutable(ctx, cc)
Roland Levillainf89cd092019-07-29 16:22:59 +01002083 // Handle modules created as `test_per_src` variations of a single test module:
2084 // use the name of the generated test binary (`fileToCopy`) instead of the name
2085 // of the original test module (`depName`, shared by all `test_per_src`
2086 // variations of that module).
Jiyong Parkf653b052019-11-18 15:39:01 +09002087 af.moduleName = filepath.Base(af.builtFile.String())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002088 // these are not considered transitive dep
2089 af.transitiveDep = false
Jiyong Parkf653b052019-11-18 15:39:01 +09002090 filesInfo = append(filesInfo, af)
2091 return true // track transitive dependencies
Roland Levillainf89cd092019-07-29 16:22:59 +01002092 }
Jiyong Park52cd06f2019-11-11 10:14:32 +09002093 } else if java.IsJniDepTag(depTag) {
Jooyung Han65041792020-02-25 16:59:29 +09002094 // Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
2095 return false
Jiyong Parke3833882020-02-17 17:28:10 +09002096 } else if java.IsXmlPermissionsFileDepTag(depTag) {
2097 if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
2098 filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))
2099 }
Jooyung Han9c80bae2019-08-20 17:30:57 +09002100 } else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
Paul Duffin3766cb72020-04-07 15:25:44 +01002101 ctx.ModuleErrorf("unexpected tag %s for indirect dependency %q", PrettyPrintTag(depTag), depName)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002102 }
2103 }
2104 }
2105 return false
2106 })
2107
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002108 // Specific to the ART apex: dexpreopt artifacts for libcore Java libraries.
2109 // Build rules are generated by the dexpreopt singleton, and here we access build artifacts
2110 // via the global boot image config.
2111 if a.artApex {
2112 for arch, files := range java.DexpreoptedArtApexJars(ctx) {
2113 dirInApex := filepath.Join("javalib", arch.String())
2114 for _, f := range files {
2115 localModule := "javalib_" + arch.String() + "_" + filepath.Base(f.String())
Jiyong Park1833cef2019-12-13 13:28:36 +09002116 af := newApexFile(ctx, f, localModule, dirInApex, etc, nil)
Jiyong Parkf653b052019-11-18 15:39:01 +09002117 filesInfo = append(filesInfo, af)
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002118 }
2119 }
2120 }
2121
Jiyong Park0ca3ce82019-02-18 15:25:04 +09002122 if a.private_key_file == nil {
Jiyong Parkfa0a3732018-11-09 05:52:26 +09002123 ctx.PropertyErrorf("key", "private_key for %q could not be found", String(a.properties.Key))
2124 return
2125 }
2126
Jiyong Park8fd61922018-11-08 02:50:25 +09002127 // remove duplicates in filesInfo
2128 removeDup := func(filesInfo []apexFile) []apexFile {
Jiyong Park7cd10e32020-01-14 09:22:18 +09002129 encountered := make(map[string]apexFile)
Jiyong Park8fd61922018-11-08 02:50:25 +09002130 for _, f := range filesInfo {
Jooyung Han344d5432019-08-23 11:17:39 +09002131 dest := filepath.Join(f.installDir, f.builtFile.Base())
Jiyong Park7cd10e32020-01-14 09:22:18 +09002132 if e, ok := encountered[dest]; !ok {
2133 encountered[dest] = f
2134 } else {
2135 // If a module is directly included and also transitively depended on
2136 // consider it as directly included.
2137 e.transitiveDep = e.transitiveDep && f.transitiveDep
2138 encountered[dest] = e
Jiyong Park8fd61922018-11-08 02:50:25 +09002139 }
2140 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002141 var result []apexFile
2142 for _, v := range encountered {
2143 result = append(result, v)
2144 }
Jiyong Park8fd61922018-11-08 02:50:25 +09002145 return result
2146 }
2147 filesInfo = removeDup(filesInfo)
2148
2149 // to have consistent build rules
2150 sort.Slice(filesInfo, func(i, j int) bool {
2151 return filesInfo[i].builtFile.String() < filesInfo[j].builtFile.String()
2152 })
2153
Jiyong Park8fd61922018-11-08 02:50:25 +09002154 a.installDir = android.PathForModuleInstall(ctx, "apex")
2155 a.filesInfo = filesInfo
Alex Light5098a612018-11-29 17:12:15 -08002156
Jooyung Han54aca7b2019-11-20 02:26:02 +09002157 if a.properties.ApexType != zipApex {
2158 if a.properties.File_contexts == nil {
2159 a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts")
2160 } else {
2161 a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts)
2162 if a.Platform() {
2163 if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched {
2164 ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts)
2165 }
2166 }
2167 }
2168 if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() {
2169 ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts)
2170 return
2171 }
2172 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09002173 // Optimization. If we are building bundled APEX, for the files that are gathered due to the
2174 // transitive dependencies, don't place them inside the APEX, but place a symlink pointing
2175 // the same library in the system partition, thus effectively sharing the same libraries
2176 // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed
2177 // in the APEX.
2178 a.linkToSystemLib = !ctx.Config().UnbundledBuild() &&
2179 a.installable() &&
2180 !proptools.Bool(a.properties.Use_vendor)
Jooyung Han54aca7b2019-11-20 02:26:02 +09002181
Jiyong Park9d677202020-02-19 16:29:35 +09002182 // We don't need the optimization for updatable APEXes, as it might give false signal
2183 // to the system health when the APEXes are still bundled (b/149805758)
Artur Satayev2b4b7bb2020-04-28 14:57:42 +01002184 if a.Updatable() && a.properties.ApexType == imageApex {
Jiyong Park9d677202020-02-19 16:29:35 +09002185 a.linkToSystemLib = false
2186 }
2187
Jiyong Park9b964182020-02-26 18:27:19 +09002188 // We also don't want the optimization for host APEXes, because it doesn't make sense.
2189 if ctx.Host() {
2190 a.linkToSystemLib = false
2191 }
2192
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002193 // prepare apex_manifest.json
Jooyung Han01a3ee22019-11-02 02:52:25 +09002194 a.buildManifest(ctx, provideNativeLibs, requireNativeLibs)
2195
2196 a.setCertificateAndPrivateKey(ctx)
2197 if a.properties.ApexType == flattenedApex {
2198 a.buildFlattenedApex(ctx)
2199 } else {
2200 a.buildUnflattenedApex(ctx)
2201 }
2202
Jooyung Han002ab682020-01-08 01:57:58 +09002203 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
Jiyong Park956305c2020-01-09 12:32:06 +09002204
2205 a.buildApexDependencyInfo(ctx)
Jooyung Han01a3ee22019-11-02 02:52:25 +09002206}
2207
Artur Satayev2eedf622020-04-15 17:29:42 +01002208// Enforce that Java deps of the apex are using stable SDKs to compile
2209func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
2210 // Visit direct deps only. As long as we guarantee top-level deps are using
2211 // stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
2212 ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
2213 tag := ctx.OtherModuleDependencyTag(module)
2214 switch tag {
2215 case javaLibTag, androidAppTag:
2216 if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
2217 if err := m.CheckStableSdkVersion(); err != nil {
2218 ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
2219 }
2220 }
2221 }
2222 })
2223}
2224
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002225func whitelistedApexAvailable(apex, moduleName string) bool {
Anton Hansson5053c292020-01-10 15:12:39 +00002226 key := apex
Paul Duffin404db3f2020-03-06 12:30:13 +00002227 moduleName = normalizeModuleName(moduleName)
2228
2229 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2230 return true
2231 }
2232
2233 key = android.AvailableToAnyApex
2234 if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
2235 return true
2236 }
2237
2238 return false
2239}
2240
2241func normalizeModuleName(moduleName string) string {
Jiyong Parkfa899442020-01-31 02:49:53 +09002242 // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build
2243 // system. Trim the prefix for the check since they are confusing
2244 moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
2245 if strings.HasPrefix(moduleName, "libclang_rt.") {
2246 // This module has many arch variants that depend on the product being built.
2247 // We don't want to list them all
2248 moduleName = "libclang_rt"
Anton Hansson5053c292020-01-10 15:12:39 +00002249 }
Paul Duffin404db3f2020-03-06 12:30:13 +00002250 return moduleName
Anton Hansson5053c292020-01-10 15:12:39 +00002251}
2252
Jooyung Han344d5432019-08-23 11:17:39 +09002253func newApexBundle() *apexBundle {
Sundong Ahnabb64432019-10-22 13:58:29 +09002254 module := &apexBundle{}
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002255 module.AddProperties(&module.properties)
Alex Light9670d332019-01-29 18:07:33 -08002256 module.AddProperties(&module.targetProperties)
Jiyong Park5d790c32019-11-15 18:40:32 +09002257 module.AddProperties(&module.overridableProperties)
Alex Light5098a612018-11-29 17:12:15 -08002258 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Jiyong Park397e55e2018-10-24 21:09:55 +09002259 return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
2260 })
Alex Light5098a612018-11-29 17:12:15 -08002261 android.InitAndroidMultiTargetsArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002262 android.InitDefaultableModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002263 android.InitSdkAwareModule(module)
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08002264 android.InitOverridableModule(module, &module.overridableProperties.Overrides)
Jiyong Park48ca7dc2018-10-10 14:01:00 +09002265 return module
2266}
Jiyong Park30ca9372019-02-07 16:27:23 +09002267
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002268func ApexBundleFactory(testApex bool, artApex bool) android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002269 bundle := newApexBundle()
2270 bundle.testApex = testApex
Ulyana Trafimovichde534412019-11-08 10:51:01 +00002271 bundle.artApex = artApex
Jooyung Han344d5432019-08-23 11:17:39 +09002272 return bundle
2273}
2274
Jiyong Parkfce0b422020-02-11 03:56:06 +09002275// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
2276// certain compatibility checks such as apex_available are not done for apex_test.
Jooyung Han344d5432019-08-23 11:17:39 +09002277func testApexBundleFactory() android.Module {
2278 bundle := newApexBundle()
2279 bundle.testApex = true
2280 return bundle
2281}
2282
Jiyong Parkfce0b422020-02-11 03:56:06 +09002283// apex packages other modules into an APEX file which is a packaging format for system-level
2284// components like binaries, shared libraries, etc.
Jiyong Parkd1063c12019-07-17 20:08:41 +09002285func BundleFactory() android.Module {
Jooyung Han344d5432019-08-23 11:17:39 +09002286 return newApexBundle()
2287}
2288
Jiyong Park30ca9372019-02-07 16:27:23 +09002289//
2290// Defaults
2291//
2292type Defaults struct {
2293 android.ModuleBase
2294 android.DefaultsModuleBase
2295}
2296
Jiyong Park30ca9372019-02-07 16:27:23 +09002297func defaultsFactory() android.Module {
2298 return DefaultsFactory()
2299}
2300
2301func DefaultsFactory(props ...interface{}) android.Module {
2302 module := &Defaults{}
2303
2304 module.AddProperties(props...)
2305 module.AddProperties(
2306 &apexBundleProperties{},
2307 &apexTargetBundleProperties{},
Jooyung Hanf21c7972019-12-16 22:32:06 +09002308 &overridableProperties{},
Jiyong Park30ca9372019-02-07 16:27:23 +09002309 )
2310
2311 android.InitDefaultsModule(module)
2312 return module
2313}
Jiyong Park5d790c32019-11-15 18:40:32 +09002314
2315//
2316// OverrideApex
2317//
2318type OverrideApex struct {
2319 android.ModuleBase
2320 android.OverrideModuleBase
2321}
2322
2323func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2324 // All the overrides happen in the base module.
2325}
2326
2327// override_apex is used to create an apex module based on another apex module
2328// by overriding some of its properties.
2329func overrideApexFactory() android.Module {
2330 m := &OverrideApex{}
2331 m.AddProperties(&overridableProperties{})
2332
2333 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
2334 android.InitOverrideModule(m)
2335 return m
2336}